Show More
@@ -238,6 +238,10 b' class SimpleVCS(object):' | |||||
238 |
|
238 | |||
239 | return False |
|
239 | return False | |
240 |
|
240 | |||
|
241 | @property | |||
|
242 | def is_shadow_repo_dir(self): | |||
|
243 | return os.path.isdir(self.vcs_repo_name) | |||
|
244 | ||||
241 | def _check_permission(self, action, user, repo_name, ip_addr=None): |
|
245 | def _check_permission(self, action, user, repo_name, ip_addr=None): | |
242 | """ |
|
246 | """ | |
243 | Checks permissions using action (push/pull) user and repository |
|
247 | Checks permissions using action (push/pull) user and repository | |
@@ -331,6 +335,11 b' class SimpleVCS(object):' | |||||
331 | log.debug('User not allowed to proceed, %s', reason) |
|
335 | log.debug('User not allowed to proceed, %s', reason) | |
332 | return HTTPNotAcceptable(reason)(environ, start_response) |
|
336 | return HTTPNotAcceptable(reason)(environ, start_response) | |
333 |
|
337 | |||
|
338 | # Check if the shadow repo actually exists, in case someone refers | |||
|
339 | # to it, and it has been deleted because of successful merge. | |||
|
340 | if self.is_shadow_repo and not self.is_shadow_repo_dir: | |||
|
341 | return HTTPNotFound()(environ, start_response) | |||
|
342 | ||||
334 | # ====================================================================== |
|
343 | # ====================================================================== | |
335 | # CHECK ANONYMOUS PERMISSION |
|
344 | # CHECK ANONYMOUS PERMISSION | |
336 | # ====================================================================== |
|
345 | # ====================================================================== |
@@ -45,9 +45,14 b' class StubVCSController(simplevcs.Simple' | |||||
45 | def __init__(self, *args, **kwargs): |
|
45 | def __init__(self, *args, **kwargs): | |
46 | super(StubVCSController, self).__init__(*args, **kwargs) |
|
46 | super(StubVCSController, self).__init__(*args, **kwargs) | |
47 | self._action = 'pull' |
|
47 | self._action = 'pull' | |
|
48 | self._is_shadow_repo_dir = True | |||
48 | self._name = HG_REPO |
|
49 | self._name = HG_REPO | |
49 | self.set_repo_names(None) |
|
50 | self.set_repo_names(None) | |
50 |
|
51 | |||
|
52 | @property | |||
|
53 | def is_shadow_repo_dir(self): | |||
|
54 | return self._is_shadow_repo_dir | |||
|
55 | ||||
51 | def _get_repository_name(self, environ): |
|
56 | def _get_repository_name(self, environ): | |
52 | return self._name |
|
57 | return self._name | |
53 |
|
58 | |||
@@ -218,6 +223,7 b' class TestShadowRepoExposure(object):' | |||||
218 | controller._check_ssl = mock.Mock() |
|
223 | controller._check_ssl = mock.Mock() | |
219 | controller.is_shadow_repo = True |
|
224 | controller.is_shadow_repo = True | |
220 | controller._action = 'pull' |
|
225 | controller._action = 'pull' | |
|
226 | controller._is_shadow_repo_dir = True | |||
221 | controller.stub_response_body = 'dummy body value' |
|
227 | controller.stub_response_body = 'dummy body value' | |
222 | environ_stub = { |
|
228 | environ_stub = { | |
223 | 'HTTP_HOST': 'test.example.com', |
|
229 | 'HTTP_HOST': 'test.example.com', | |
@@ -232,6 +238,30 b' class TestShadowRepoExposure(object):' | |||||
232 | # Assert that we got the response from the wsgi app. |
|
238 | # Assert that we got the response from the wsgi app. | |
233 | assert response_body == controller.stub_response_body |
|
239 | assert response_body == controller.stub_response_body | |
234 |
|
240 | |||
|
241 | def test_pull_on_shadow_repo_that_is_missing(self, pylonsapp): | |||
|
242 | """ | |||
|
243 | Check that a pull action to a shadow repo is propagated to the | |||
|
244 | underlying wsgi app. | |||
|
245 | """ | |||
|
246 | controller = StubVCSController(pylonsapp, pylonsapp.config, None) | |||
|
247 | controller._check_ssl = mock.Mock() | |||
|
248 | controller.is_shadow_repo = True | |||
|
249 | controller._action = 'pull' | |||
|
250 | controller._is_shadow_repo_dir = False | |||
|
251 | controller.stub_response_body = 'dummy body value' | |||
|
252 | environ_stub = { | |||
|
253 | 'HTTP_HOST': 'test.example.com', | |||
|
254 | 'HTTP_ACCEPT': 'application/mercurial', | |||
|
255 | 'REQUEST_METHOD': 'GET', | |||
|
256 | 'wsgi.url_scheme': 'http', | |||
|
257 | } | |||
|
258 | ||||
|
259 | response = controller(environ_stub, mock.Mock()) | |||
|
260 | response_body = ''.join(response) | |||
|
261 | ||||
|
262 | # Assert that we got the response from the wsgi app. | |||
|
263 | assert '404 Not Found' in response_body | |||
|
264 | ||||
235 | def test_push_on_shadow_repo_raises(self, pylonsapp): |
|
265 | def test_push_on_shadow_repo_raises(self, pylonsapp): | |
236 | """ |
|
266 | """ | |
237 | Check that a push action to a shadow repo is aborted. |
|
267 | Check that a push action to a shadow repo is aborted. |
General Comments 0
You need to be logged in to leave comments.
Login now