Show More
@@ -70,7 +70,7 b' class DisableVCSPagesWrapper(object):' | |||
|
70 | 70 | self.handler = handler |
|
71 | 71 | |
|
72 | 72 | def __call__(self, context, request): |
|
73 |
if not self._check_vcs_requirement(request. |
|
|
73 | if not self._check_vcs_requirement(request.path): | |
|
74 | 74 | raise VCSServerUnavailable('VCS Server is not available') |
|
75 | 75 | |
|
76 | 76 | return self.handler(context, request) |
@@ -19,36 +19,35 b'' | |||
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import pytest |
|
22 | from rhodecode.lib.middleware.disable_vcs import DisableVCSPagesWrapper | |
|
22 | from pyramid.response import Response | |
|
23 | from pyramid.testing import DummyRequest | |
|
24 | from rhodecode.lib.middleware.disable_vcs import ( | |
|
25 | DisableVCSPagesWrapper, VCSServerUnavailable) | |
|
23 | 26 | |
|
24 | 27 | |
|
25 |
@pytest.mark.parametrize('url, |
|
|
26 |
('/', |
|
|
27 |
('/_admin/settings', |
|
|
28 |
('/_admin/i_am_fine', |
|
|
29 |
('/_admin/settings/mappings', |
|
|
30 |
('/_admin/my_account/repos', |
|
|
31 |
('/_admin/create_repository', |
|
|
32 |
('/_admin/gists/1', |
|
|
33 |
('/_admin/notifications/1', |
|
|
28 | @pytest.mark.parametrize('url, should_raise', [ | |
|
29 | ('/', False), | |
|
30 | ('/_admin/settings', False), | |
|
31 | ('/_admin/i_am_fine', False), | |
|
32 | ('/_admin/settings/mappings', True), | |
|
33 | ('/_admin/my_account/repos', True), | |
|
34 | ('/_admin/create_repository', True), | |
|
35 | ('/_admin/gists/1', True), | |
|
36 | ('/_admin/notifications/1', True), | |
|
34 | 37 | ]) |
|
35 |
def test_vcs_disabled(url, |
|
|
36 |
app = DisableVCSPagesWrapper( |
|
|
37 | assert expected_url == app(get_environ(url), None) | |
|
38 | ||
|
38 | def test_vcs_disabled(url, should_raise): | |
|
39 | wrapped_view = DisableVCSPagesWrapper(pyramid_view) | |
|
40 | request = DummyRequest(path=url) | |
|
39 | 41 | |
|
40 | def get_environ(url): | |
|
41 | """Construct a minimum WSGI environ based on the URL.""" | |
|
42 | environ = { | |
|
43 | 'PATH_INFO': url, | |
|
44 | } | |
|
45 | return environ | |
|
46 | ||
|
42 | if should_raise: | |
|
43 | with pytest.raises(VCSServerUnavailable): | |
|
44 | response = wrapped_view(None, request) | |
|
45 | else: | |
|
46 | response = wrapped_view(None, request) | |
|
47 | assert response.status_int == 200 | |
|
47 | 48 | |
|
48 | class SimpleApp(object): | |
|
49 | def pyramid_view(context, request): | |
|
49 | 50 | """ |
|
50 |
A mock |
|
|
51 | from the middleware | |
|
51 | A mock pyramid view to be used in the wrapper | |
|
52 | 52 | """ |
|
53 | def __call__(self, environ, start_response): | |
|
54 | return environ['PATH_INFO'] | |
|
53 | return Response('success') |
General Comments 0
You need to be logged in to leave comments.
Login now