##// END OF EJS Templates
fix(svn-ssh): fixed svn ssh wrapper
super-admin -
r5330:b4c6f4ec default
parent child Browse files
Show More
@@ -25,6 +25,8 b' import tempfile'
25 from subprocess import Popen, PIPE
25 from subprocess import Popen, PIPE
26 import urllib.parse
26 import urllib.parse
27
27
28 from rhodecode.lib.str_utils import safe_bytes
29 from rhodecode_tools.lib.utils import safe_str
28 from .base import SshVcsServer
30 from .base import SshVcsServer
29
31
30 log = logging.getLogger(__name__)
32 log = logging.getLogger(__name__)
@@ -81,7 +83,7 b' class SubversionTunnelWrapper(object):'
81
83
82 def sync(self):
84 def sync(self):
83 while self.process.poll() is None:
85 while self.process.poll() is None:
84 next_byte = self.stdin.read(1)
86 next_byte = self.stdin.buffer.read(1)
85 if not next_byte:
87 if not next_byte:
86 break
88 break
87 self.process.stdin.write(next_byte)
89 self.process.stdin.write(next_byte)
@@ -106,7 +108,7 b' class SubversionTunnelWrapper(object):'
106 data['url'] = self._svn_string(data['url'])
108 data['url'] = self._svn_string(data['url'])
107 data['ra_client'] = self._svn_string(data['ra_client'])
109 data['ra_client'] = self._svn_string(data['ra_client'])
108 data['client'] = data['client'] or ''
110 data['client'] = data['client'] or ''
109 buffer_ = (
111 buffer_ = safe_bytes(
110 "( {version} ( {capabilities} ) {url}{ra_client}"
112 "( {version} ( {capabilities} ) {url}{ra_client}"
111 "( {client}) ) ".format(**data))
113 "( {client}) ) ".format(**data))
112 self.process.stdin.write(buffer_)
114 self.process.stdin.write(buffer_)
@@ -127,21 +129,21 b' class SubversionTunnelWrapper(object):'
127 return f'{len(str_)}:{str_} '
129 return f'{len(str_)}:{str_} '
128
130
129 def _read_first_client_response(self):
131 def _read_first_client_response(self):
130 buffer_ = ""
132 buffer_ = b""
131 brackets_stack = []
133 brackets_stack = []
132 while True:
134 while True:
133 next_byte = self.stdin.read(1)
135 next_byte = self.stdin.buffer.read(1)
134 buffer_ += next_byte
136 buffer_ += next_byte
135 if next_byte == "(":
137 if next_byte == b"(":
136 brackets_stack.append(next_byte)
138 brackets_stack.append(next_byte)
137 elif next_byte == ")":
139 elif next_byte == b")":
138 brackets_stack.pop()
140 brackets_stack.pop()
139 elif next_byte == " " and not brackets_stack:
141 elif next_byte == b" " and not brackets_stack:
140 break
142 break
141
143
142 return buffer_
144 return buffer_
143
145
144 def _parse_first_client_response(self, buffer_):
146 def _parse_first_client_response(self, buffer_: bytes):
145 """
147 """
146 According to the Subversion RA protocol, the first request
148 According to the Subversion RA protocol, the first request
147 should look like:
149 should look like:
@@ -151,16 +153,20 b' class SubversionTunnelWrapper(object):'
151
153
152 Please check https://svn.apache.org/repos/asf/subversion/trunk/subversion/libsvn_ra_svn/protocol
154 Please check https://svn.apache.org/repos/asf/subversion/trunk/subversion/libsvn_ra_svn/protocol
153 """
155 """
154 version_re = r'(?P<version>\d+)'
156 version_re = br'(?P<version>\d+)'
155 capabilities_re = r'\(\s(?P<capabilities>[\w\d\-\ ]+)\s\)'
157 capabilities_re = br'\(\s(?P<capabilities>[\w\d\-\ ]+)\s\)'
156 url_re = r'\d+\:(?P<url>[\W\w]+)'
158 url_re = br'\d+\:(?P<url>[\W\w]+)'
157 ra_client_re = r'(\d+\:(?P<ra_client>[\W\w]+)\s)'
159 ra_client_re = br'(\d+\:(?P<ra_client>[\W\w]+)\s)'
158 client_re = r'(\d+\:(?P<client>[\W\w]+)\s)*'
160 client_re = br'(\d+\:(?P<client>[\W\w]+)\s)*'
159 regex = re.compile(
161 regex = re.compile(
160 r'^\(\s{version}\s{capabilities}\s{url}\s{ra_client}'
162 br'^\(\s%b\s%b\s%b\s%b'
161 r'\(\s{client}\)\s\)\s*$'.format(
163 br'\(\s%b\)\s\)\s*$' % (
162 version=version_re, capabilities=capabilities_re,
164 version_re,
163 url=url_re, ra_client=ra_client_re, client=client_re))
165 capabilities_re,
166 url_re,
167 ra_client_re,
168 client_re)
169 )
164 matcher = regex.match(buffer_)
170 matcher = regex.match(buffer_)
165
171
166 return matcher.groupdict() if matcher else None
172 return matcher.groupdict() if matcher else None
@@ -202,7 +208,7 b' class SubversionTunnelWrapper(object):'
202
208
203 url_parts = urllib.parse.urlparse(first_response['url'])
209 url_parts = urllib.parse.urlparse(first_response['url'])
204
210
205 self.server.repo_name = self._match_repo_name(url_parts.path.strip('/'))
211 self.server.repo_name = self._match_repo_name(safe_str(url_parts.path).strip('/'))
206
212
207 exit_code = self.server._check_permissions(action)
213 exit_code = self.server._check_permissions(action)
208 if exit_code:
214 if exit_code:
General Comments 0
You need to be logged in to leave comments. Login now