Show More
@@ -1,5 +1,5 b'' | |||
|
1 | 1 | [bumpversion] |
|
2 |
current_version = 5. |
|
|
2 | current_version = 5.3.0 | |
|
3 | 3 | message = release: Bump version {current_version} to {new_version} |
|
4 | 4 | |
|
5 | 5 | [bumpversion:file:vcsserver/VERSION] |
@@ -56,7 +56,7 b' pyramid==2.0.2' | |||
|
56 | 56 | venusian==3.0.0 |
|
57 | 57 | webob==1.8.7 |
|
58 | 58 | zope.deprecation==5.0.0 |
|
59 |
zope.interface== |
|
|
59 | zope.interface==7.0.3 | |
|
60 | 60 | redis==5.1.0 |
|
61 | 61 | async-timeout==4.0.3 |
|
62 | 62 | repoze.lru==0.7 |
@@ -14,7 +14,7 b'' | |||
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software Foundation, |
|
16 | 16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
17 | ||
|
17 | import hashlib | |
|
18 | 18 | import re |
|
19 | 19 | import logging |
|
20 | 20 | |
@@ -60,6 +60,7 b' class AuthHeaderRequired:' | |||
|
60 | 60 | request = fargs[1] |
|
61 | 61 | auth = request.authorization |
|
62 | 62 | if not auth: |
|
63 | log.debug('No auth header found, returning 403') | |
|
63 | 64 | return write_response_error(HTTPForbidden) |
|
64 | 65 | return func(*fargs[1:], **fkwargs) |
|
65 | 66 | |
@@ -159,8 +160,14 b' def lfs_objects_oid_upload(request):' | |||
|
159 | 160 | engine = store.get_engine(mode='wb') |
|
160 | 161 | log.debug('LFS: starting chunked write of LFS oid: %s to storage', oid) |
|
161 | 162 | |
|
163 | # validate if OID is not by any chance already in the store | |
|
164 | if store.has_oid(): | |
|
165 | log.debug('LFS: oid %s exists in store', oid) | |
|
166 | return {'upload': 'ok', 'state': 'in-store'} | |
|
167 | ||
|
162 | 168 | body = request.environ['wsgi.input'] |
|
163 | 169 | |
|
170 | digest = hashlib.sha256() | |
|
164 | 171 | with engine as f: |
|
165 | 172 | blksize = 64 * 1024 # 64kb |
|
166 | 173 | while True: |
@@ -174,10 +181,17 b' def lfs_objects_oid_upload(request):' | |||
|
174 | 181 | |
|
175 | 182 | if not chunk: |
|
176 | 183 | break |
|
184 | f.write(chunk) | |
|
185 | digest.update(chunk) | |
|
177 | 186 | |
|
178 | f.write(chunk) | |
|
187 | hex_digest = digest.hexdigest() | |
|
188 | digest_check = hex_digest == oid | |
|
189 | if not digest_check: | |
|
190 | engine.cleanup() # trigger cleanup so we don't save mismatch OID into the store | |
|
191 | return write_response_error( | |
|
192 | HTTPBadRequest, f'oid {oid} does not match expected sha {hex_digest}') | |
|
179 | 193 | |
|
180 | return {'upload': 'ok'} | |
|
194 | return {'upload': 'ok', 'state': 'written'} | |
|
181 | 195 | |
|
182 | 196 | |
|
183 | 197 | def lfs_objects_oid_download(request): |
@@ -222,12 +236,10 b' def lfs_objects_verify(request):' | |||
|
222 | 236 | |
|
223 | 237 | store_size = store.size_oid() |
|
224 | 238 | if store_size != size: |
|
225 |
msg = 'requested file size mismatch store size:{} requested:{}' |
|
|
226 | store_size, size) | |
|
227 | return write_response_error( | |
|
228 | HTTPUnprocessableEntity, msg) | |
|
239 | msg = f'requested file size mismatch store size:{store_size} requested:{size}' | |
|
240 | return write_response_error(HTTPUnprocessableEntity, msg) | |
|
229 | 241 | |
|
230 |
return {'message': {'size': |
|
|
242 | return {'message': {'size': store_size, 'oid': oid}} | |
|
231 | 243 | |
|
232 | 244 | |
|
233 | 245 | def lfs_objects_lock(request): |
@@ -133,12 +133,16 b' class LFSOidStore:' | |||
|
133 | 133 | """ |
|
134 | 134 | |
|
135 | 135 | class StoreEngine: |
|
136 | _cleanup = None | |
|
136 | 137 | def __init__(self, mode, store_path, oid_path, tmp_oid_path): |
|
137 | 138 | self.mode = mode |
|
138 | 139 | self.store_path = store_path |
|
139 | 140 | self.oid_path = oid_path |
|
140 | 141 | self.tmp_oid_path = tmp_oid_path |
|
141 | 142 | |
|
143 | def cleanup(self): | |
|
144 | self._cleanup = True | |
|
145 | ||
|
142 | 146 | def __enter__(self): |
|
143 | 147 | if not os.path.isdir(self.store_path): |
|
144 | 148 | os.makedirs(self.store_path) |
@@ -149,9 +153,13 b' class LFSOidStore:' | |||
|
149 | 153 | return fd |
|
150 | 154 | |
|
151 | 155 | def __exit__(self, exc_type, exc_value, traceback): |
|
152 | # close tmp file, and rename to final destination | |
|
153 | 156 | self.fd.close() |
|
154 | shutil.move(self.tmp_oid_path, self.oid_path) | |
|
157 | ||
|
158 | if self._cleanup is None: | |
|
159 | # close tmp file, and rename to final destination | |
|
160 | shutil.move(self.tmp_oid_path, self.oid_path) | |
|
161 | else: | |
|
162 | os.remove(self.tmp_oid_path) | |
|
155 | 163 | |
|
156 | 164 | return StoreEngine( |
|
157 | 165 | mode, self.store_path, self.oid_path, self.tmp_oid_path) |
@@ -100,22 +100,27 b' class TestLFSApplication:' | |||
|
100 | 100 | |
|
101 | 101 | def test_app_batch_api_download_missing_object( |
|
102 | 102 | self, git_lfs_app, http_auth): |
|
103 |
params = { |
|
|
104 | 'objects': [{'oid': '123', 'size': '1024'}]} | |
|
103 | params = { | |
|
104 | 'operation': 'download', | |
|
105 | 'objects': [{'oid': '123', 'size': '1024'}] | |
|
106 | } | |
|
105 | 107 | response = git_lfs_app.post_json( |
|
106 | 108 | '/repo/info/lfs/objects/batch', params=params, |
|
107 | 109 | extra_environ=http_auth) |
|
108 | 110 | |
|
109 | 111 | expected_objects = [ |
|
110 | {'authenticated': True, | |
|
111 |
' |
|
|
112 |
|
|
|
113 | 'message': 'object: 123 does not exist in store'}}, | |
|
114 | 'oid': '123', | |
|
115 |
|
|
|
112 | { | |
|
113 | 'oid': '123', | |
|
114 | 'size': '1024', | |
|
115 | 'authenticated': True, | |
|
116 | 'errors': {'error': {'code': 404, 'message': 'object: 123 does not exist in store'}}, | |
|
117 | } | |
|
116 | 118 | ] |
|
119 | ||
|
117 | 120 | assert json.loads(response.text) == { |
|
118 |
'objects': expected_objects, |
|
|
121 | 'objects': expected_objects, | |
|
122 | 'transfer': 'basic' | |
|
123 | } | |
|
119 | 124 | |
|
120 | 125 | def test_app_batch_api_download(self, git_lfs_app, http_auth): |
|
121 | 126 | oid = '456' |
@@ -142,7 +147,9 b' class TestLFSApplication:' | |||
|
142 | 147 | 'size': '1024'} |
|
143 | 148 | ] |
|
144 | 149 | assert json.loads(response.text) == { |
|
145 |
'objects': expected_objects, |
|
|
150 | 'objects': expected_objects, | |
|
151 | 'transfer': 'basic' | |
|
152 | } | |
|
146 | 153 | |
|
147 | 154 | def test_app_batch_api_upload(self, git_lfs_app, http_auth): |
|
148 | 155 | params = {'operation': 'upload', |
@@ -151,21 +158,31 b' class TestLFSApplication:' | |||
|
151 | 158 | '/repo/info/lfs/objects/batch', params=params, |
|
152 | 159 | extra_environ=http_auth) |
|
153 | 160 | expected_objects = [ |
|
154 | {'authenticated': True, | |
|
155 |
'a |
|
|
156 |
|
|
|
157 | 'header': {'Authorization': 'Basic XXXXX', | |
|
158 |
|
|
|
159 | 'href': 'http://localhost/repo/info/lfs/objects/123'}, | |
|
160 | 'verify': { | |
|
161 | 'header': {'Authorization': 'Basic XXXXX'}, | |
|
162 |
'href': 'http://localhost/repo/info/lfs/ |
|
|
163 | }, | |
|
164 |
' |
|
|
165 | 'size': '1024'} | |
|
161 | { | |
|
162 | 'authenticated': True, | |
|
163 | 'actions': { | |
|
164 | 'upload': { | |
|
165 | 'header': { | |
|
166 | 'Authorization': 'Basic XXXXX', | |
|
167 | 'Transfer-Encoding': 'chunked' | |
|
168 | }, | |
|
169 | 'href': 'http://localhost/repo/info/lfs/objects/123' | |
|
170 | }, | |
|
171 | 'verify': { | |
|
172 | 'header': { | |
|
173 | 'Authorization': 'Basic XXXXX' | |
|
174 | }, | |
|
175 | 'href': 'http://localhost/repo/info/lfs/verify' | |
|
176 | } | |
|
177 | }, | |
|
178 | 'oid': '123', | |
|
179 | 'size': '1024' | |
|
180 | } | |
|
166 | 181 | ] |
|
167 | 182 | assert json.loads(response.text) == { |
|
168 |
'objects': expected_objects, |
|
|
183 | 'objects': expected_objects, | |
|
184 | 'transfer': 'basic' | |
|
185 | } | |
|
169 | 186 | |
|
170 | 187 | def test_app_batch_api_upload_for_https(self, git_lfs_https_app, http_auth): |
|
171 | 188 | params = {'operation': 'upload', |
@@ -178,7 +195,7 b' class TestLFSApplication:' | |||
|
178 | 195 | 'actions': { |
|
179 | 196 | 'upload': { |
|
180 | 197 | 'header': {'Authorization': 'Basic XXXXX', |
|
181 |
|
|
|
198 | 'Transfer-Encoding': 'chunked'}, | |
|
182 | 199 | 'href': 'https://localhost/repo/info/lfs/objects/123'}, |
|
183 | 200 | 'verify': { |
|
184 | 201 | 'header': {'Authorization': 'Basic XXXXX'}, |
@@ -206,7 +223,8 b' class TestLFSApplication:' | |||
|
206 | 223 | status=404) |
|
207 | 224 | |
|
208 | 225 | assert json.loads(response.text) == { |
|
209 |
'message': 'oid `missing` does not exists in store' |
|
|
226 | 'message': 'oid `missing` does not exists in store' | |
|
227 | } | |
|
210 | 228 | |
|
211 | 229 | def test_app_verify_api_size_mismatch(self, git_lfs_app): |
|
212 | 230 | oid = 'existing' |
@@ -221,8 +239,8 b' class TestLFSApplication:' | |||
|
221 | 239 | '/repo/info/lfs/verify', params=params, status=422) |
|
222 | 240 | |
|
223 | 241 | assert json.loads(response.text) == { |
|
224 | 'message': 'requested file size mismatch ' | |
|
225 | 'store size:11 requested:1024'} | |
|
242 | 'message': 'requested file size mismatch store size:11 requested:1024' | |
|
243 | } | |
|
226 | 244 | |
|
227 | 245 | def test_app_verify_api(self, git_lfs_app): |
|
228 | 246 | oid = 'existing' |
@@ -237,13 +255,13 b' class TestLFSApplication:' | |||
|
237 | 255 | '/repo/info/lfs/verify', params=params) |
|
238 | 256 | |
|
239 | 257 | assert json.loads(response.text) == { |
|
240 |
'message': {'size': |
|
|
258 | 'message': {'size': 11, 'oid': oid} | |
|
259 | } | |
|
241 | 260 | |
|
242 | 261 | def test_app_download_api_oid_not_existing(self, git_lfs_app): |
|
243 | 262 | oid = 'missing' |
|
244 | 263 | |
|
245 | response = git_lfs_app.get( | |
|
246 | '/repo/info/lfs/objects/{oid}'.format(oid=oid), status=404) | |
|
264 | response = git_lfs_app.get(f'/repo/info/lfs/objects/{oid}', status=404) | |
|
247 | 265 | |
|
248 | 266 | assert json.loads(response.text) == { |
|
249 | 267 | 'message': 'requested file with oid `missing` not found in store'} |
@@ -256,19 +274,37 b' class TestLFSApplication:' | |||
|
256 | 274 | with open(oid_path, 'wb') as f: |
|
257 | 275 | f.write(safe_bytes('OID_CONTENT')) |
|
258 | 276 | |
|
259 | response = git_lfs_app.get( | |
|
260 | '/repo/info/lfs/objects/{oid}'.format(oid=oid)) | |
|
277 | response = git_lfs_app.get(f'/repo/info/lfs/objects/{oid}') | |
|
261 | 278 | assert response |
|
262 | 279 | |
|
263 | 280 | def test_app_upload(self, git_lfs_app): |
|
264 | oid = 'uploaded' | |
|
281 | oid = '65f23e22a9bfedda96929b3cfcb8b6d2fdd34a2e877ddb81f45d79ab05710e12' | |
|
265 | 282 | |
|
266 | 283 | response = git_lfs_app.put( |
|
267 |
'/repo/info/lfs/objects/{oid}' |
|
|
284 | f'/repo/info/lfs/objects/{oid}', params='CONTENT') | |
|
268 | 285 | |
|
269 | assert json.loads(response.text) == {'upload': 'ok'} | |
|
286 | assert json.loads(response.text) == {'upload': 'ok', 'state': 'written'} | |
|
270 | 287 | |
|
271 | 288 | # verify that we actually wrote that OID |
|
272 | 289 | oid_path = LFSOidStore(oid=oid, repo=None, store_location=git_lfs_app._store).oid_path |
|
273 | 290 | assert os.path.isfile(oid_path) |
|
274 | 291 | assert 'CONTENT' == open(oid_path).read() |
|
292 | ||
|
293 | response = git_lfs_app.put( | |
|
294 | f'/repo/info/lfs/objects/{oid}', params='CONTENT') | |
|
295 | ||
|
296 | assert json.loads(response.text) == {'upload': 'ok', 'state': 'in-store'} | |
|
297 | ||
|
298 | ||
|
299 | def test_app_upload_wrong_sha(self, git_lfs_app): | |
|
300 | oid = 'i-am-a-wrong-sha' | |
|
301 | ||
|
302 | response = git_lfs_app.put(f'/repo/info/lfs/objects/{oid}', params='CONTENT', status=400) | |
|
303 | ||
|
304 | assert json.loads(response.text) == { | |
|
305 | 'message': 'oid i-am-a-wrong-sha does not match expected sha ' | |
|
306 | '65f23e22a9bfedda96929b3cfcb8b6d2fdd34a2e877ddb81f45d79ab05710e12'} | |
|
307 | ||
|
308 | # check this OID wasn't written to store | |
|
309 | response = git_lfs_app.get(f'/repo/info/lfs/objects/{oid}', status=404) | |
|
310 | assert json.loads(response.text) == {'message': 'requested file with oid `i-am-a-wrong-sha` not found in store'} |
@@ -24,7 +24,7 b' from vcsserver.git_lfs.lib import OidHan' | |||
|
24 | 24 | @pytest.fixture() |
|
25 | 25 | def lfs_store(tmpdir): |
|
26 | 26 | repo = 'test' |
|
27 | oid = '123456789' | |
|
27 | oid = '65f23e22a9bfedda96929b3cfcb8b6d2fdd34a2e877ddb81f45d79ab05710e12' | |
|
28 | 28 | store = LFSOidStore(oid=oid, repo=repo, store_location=str(tmpdir)) |
|
29 | 29 | return store |
|
30 | 30 | |
@@ -63,7 +63,8 b' class TestOidHandler:' | |||
|
63 | 63 | assert response is None |
|
64 | 64 | assert has_errors['error'] == { |
|
65 | 65 | 'code': 404, |
|
66 |
'message': 'object: |
|
|
66 | 'message': 'object: 65f23e22a9bfedda96929b3cfcb8b6d2fdd34a2e877ddb81f45d79ab05710e12 does not exist in store' | |
|
67 | } | |
|
67 | 68 | |
|
68 | 69 | def test_download_oid(self, oid_handler): |
|
69 | 70 | store = oid_handler.get_store() |
@@ -107,7 +107,9 b' class HooksCeleryClient:' | |||
|
107 | 107 | inquired_task = self.celery_app.signature( |
|
108 | 108 | f'rhodecode.lib.celerylib.tasks.{method}' |
|
109 | 109 | ) |
|
110 |
re |
|
|
110 | result = inquired_task.delay(extras).get(timeout=self.TASK_TIMEOUT) | |
|
111 | ||
|
112 | return result | |
|
111 | 113 | |
|
112 | 114 | |
|
113 | 115 | class HooksShadowRepoClient: |
@@ -157,9 +159,11 b' class SvnMessageWriter(RemoteMessageWrit' | |||
|
157 | 159 | self.stderr.write(message) |
|
158 | 160 | |
|
159 | 161 | |
|
160 | def _handle_exception(result): | |
|
162 | def _maybe_handle_exception(result): | |
|
161 | 163 | exception_class = result.get('exception') |
|
162 | 164 | exception_traceback = result.get('exception_traceback') |
|
165 | if not (exception_class and exception_traceback): | |
|
166 | return | |
|
163 | 167 | log.debug('Handling hook-call exception: %s', exception_class) |
|
164 | 168 | |
|
165 | 169 | if exception_traceback: |
@@ -200,7 +204,7 b' def _call_hook(hook_name, extras, writer' | |||
|
200 | 204 | log.debug('Hooks, using client:%s', hooks_client) |
|
201 | 205 | result = hooks_client(hook_name, extras) |
|
202 | 206 | log.debug('Hooks got result: %s', result) |
|
203 | _handle_exception(result) | |
|
207 | _maybe_handle_exception(result) | |
|
204 | 208 | writer.write(result['output']) |
|
205 | 209 | |
|
206 | 210 | return result['status'] |
General Comments 0
You need to be logged in to leave comments.
Login now