Show More
@@ -1,134 +1,134 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2016 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-2016 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | from mock import patch, Mock |
|
21 | from mock import patch, Mock | |
22 |
|
22 | |||
23 | import rhodecode |
|
23 | import rhodecode | |
24 | from rhodecode.lib.middleware import vcs |
|
24 | from rhodecode.lib.middleware import vcs | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | def test_is_hg(): |
|
27 | def test_is_hg(): | |
28 | environ = { |
|
28 | environ = { | |
29 | 'PATH_INFO': 'rhodecode-dev', |
|
29 | 'PATH_INFO': '/rhodecode-dev', | |
30 | 'QUERY_STRING': 'cmd=changegroup', |
|
30 | 'QUERY_STRING': 'cmd=changegroup', | |
31 | 'HTTP_ACCEPT': 'application/mercurial' |
|
31 | 'HTTP_ACCEPT': 'application/mercurial' | |
32 | } |
|
32 | } | |
33 | assert vcs.is_hg(environ) |
|
33 | assert vcs.is_hg(environ) | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | def test_is_hg_no_cmd(): |
|
36 | def test_is_hg_no_cmd(): | |
37 | environ = { |
|
37 | environ = { | |
38 | 'PATH_INFO': 'rhodecode-dev', |
|
38 | 'PATH_INFO': '/rhodecode-dev', | |
39 | 'QUERY_STRING': '', |
|
39 | 'QUERY_STRING': '', | |
40 | 'HTTP_ACCEPT': 'application/mercurial' |
|
40 | 'HTTP_ACCEPT': 'application/mercurial' | |
41 | } |
|
41 | } | |
42 | assert not vcs.is_hg(environ) |
|
42 | assert not vcs.is_hg(environ) | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | def test_is_hg_empty_cmd(): |
|
45 | def test_is_hg_empty_cmd(): | |
46 | environ = { |
|
46 | environ = { | |
47 | 'PATH_INFO': 'rhodecode-dev', |
|
47 | 'PATH_INFO': '/rhodecode-dev', | |
48 | 'QUERY_STRING': 'cmd=', |
|
48 | 'QUERY_STRING': 'cmd=', | |
49 | 'HTTP_ACCEPT': 'application/mercurial' |
|
49 | 'HTTP_ACCEPT': 'application/mercurial' | |
50 | } |
|
50 | } | |
51 | assert not vcs.is_hg(environ) |
|
51 | assert not vcs.is_hg(environ) | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | def test_is_svn_returns_true_if_subversion_is_in_a_dav_header(): |
|
54 | def test_is_svn_returns_true_if_subversion_is_in_a_dav_header(): | |
55 | environ = { |
|
55 | environ = { | |
56 | 'PATH_INFO': 'rhodecode-dev', |
|
56 | 'PATH_INFO': '/rhodecode-dev', | |
57 | 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log-revprops' |
|
57 | 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log-revprops' | |
58 | } |
|
58 | } | |
59 | assert vcs.is_svn(environ) is True |
|
59 | assert vcs.is_svn(environ) is True | |
60 |
|
60 | |||
61 |
|
61 | |||
62 | def test_is_svn_returns_false_if_subversion_is_not_in_a_dav_header(): |
|
62 | def test_is_svn_returns_false_if_subversion_is_not_in_a_dav_header(): | |
63 | environ = { |
|
63 | environ = { | |
64 | 'PATH_INFO': 'rhodecode-dev', |
|
64 | 'PATH_INFO': '/rhodecode-dev', | |
65 | 'HTTP_DAV': 'http://stuff.tigris.org/xmlns/dav/svn/log-revprops' |
|
65 | 'HTTP_DAV': 'http://stuff.tigris.org/xmlns/dav/svn/log-revprops' | |
66 | } |
|
66 | } | |
67 | assert vcs.is_svn(environ) is False |
|
67 | assert vcs.is_svn(environ) is False | |
68 |
|
68 | |||
69 |
|
69 | |||
70 | def test_is_svn_returns_false_if_no_dav_header(): |
|
70 | def test_is_svn_returns_false_if_no_dav_header(): | |
71 | environ = { |
|
71 | environ = { | |
72 | 'PATH_INFO': 'rhodecode-dev', |
|
72 | 'PATH_INFO': '/rhodecode-dev', | |
73 | } |
|
73 | } | |
74 | assert vcs.is_svn(environ) is False |
|
74 | assert vcs.is_svn(environ) is False | |
75 |
|
75 | |||
76 |
|
76 | |||
77 | def test_is_svn_returns_true_if_magic_path_segment(): |
|
77 | def test_is_svn_returns_true_if_magic_path_segment(): | |
78 | environ = { |
|
78 | environ = { | |
79 | 'PATH_INFO': '/stub-repository/!svn/rev/4', |
|
79 | 'PATH_INFO': '/stub-repository/!svn/rev/4', | |
80 | } |
|
80 | } | |
81 | assert vcs.is_svn(environ) |
|
81 | assert vcs.is_svn(environ) | |
82 |
|
82 | |||
83 |
|
83 | |||
84 | def test_is_svn_allows_to_configure_the_magic_path(monkeypatch): |
|
84 | def test_is_svn_allows_to_configure_the_magic_path(monkeypatch): | |
85 | """ |
|
85 | """ | |
86 | This is intended as a fallback in case someone has configured his |
|
86 | This is intended as a fallback in case someone has configured his | |
87 | Subversion server with a different magic path segment. |
|
87 | Subversion server with a different magic path segment. | |
88 | """ |
|
88 | """ | |
89 | monkeypatch.setitem( |
|
89 | monkeypatch.setitem( | |
90 | rhodecode.CONFIG, 'rhodecode_subversion_magic_path', '/!my-magic') |
|
90 | rhodecode.CONFIG, 'rhodecode_subversion_magic_path', '/!my-magic') | |
91 | environ = { |
|
91 | environ = { | |
92 | 'PATH_INFO': '/stub-repository/!my-magic/rev/4', |
|
92 | 'PATH_INFO': '/stub-repository/!my-magic/rev/4', | |
93 | } |
|
93 | } | |
94 | assert vcs.is_svn(environ) |
|
94 | assert vcs.is_svn(environ) | |
95 |
|
95 | |||
96 |
|
96 | |||
97 | class TestVCSMiddleware(object): |
|
97 | class TestVCSMiddleware(object): | |
98 | def test_get_handler_app_retuns_svn_app_when_proxy_enabled(self): |
|
98 | def test_get_handler_app_retuns_svn_app_when_proxy_enabled(self): | |
99 | environ = { |
|
99 | environ = { | |
100 | 'PATH_INFO': 'rhodecode-dev', |
|
100 | 'PATH_INFO': 'rhodecode-dev', | |
101 | 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log' |
|
101 | 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log' | |
102 | } |
|
102 | } | |
103 | app = Mock() |
|
103 | app = Mock() | |
104 | config = Mock() |
|
104 | config = Mock() | |
105 | middleware = vcs.VCSMiddleware( |
|
105 | middleware = vcs.VCSMiddleware( | |
106 | app, config=config, appenlight_client=None) |
|
106 | app, config=config, appenlight_client=None) | |
107 | snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn') |
|
107 | snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn') | |
108 | settings_patch = patch.dict( |
|
108 | settings_patch = patch.dict( | |
109 | rhodecode.CONFIG, |
|
109 | rhodecode.CONFIG, | |
110 | {'rhodecode_proxy_subversion_http_requests': True}) |
|
110 | {'rhodecode_proxy_subversion_http_requests': True}) | |
111 | with snv_patch as svn_mock, settings_patch: |
|
111 | with snv_patch as svn_mock, settings_patch: | |
112 | svn_mock.return_value = None |
|
112 | svn_mock.return_value = None | |
113 | middleware._get_handler_app(environ) |
|
113 | middleware._get_handler_app(environ) | |
114 |
|
114 | |||
115 | svn_mock.assert_called_once_with(app, config) |
|
115 | svn_mock.assert_called_once_with(app, config) | |
116 |
|
116 | |||
117 | def test_get_handler_app_retuns_no_svn_app_when_proxy_disabled(self): |
|
117 | def test_get_handler_app_retuns_no_svn_app_when_proxy_disabled(self): | |
118 | environ = { |
|
118 | environ = { | |
119 | 'PATH_INFO': 'rhodecode-dev', |
|
119 | 'PATH_INFO': 'rhodecode-dev', | |
120 | 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log' |
|
120 | 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log' | |
121 | } |
|
121 | } | |
122 | app = Mock() |
|
122 | app = Mock() | |
123 | config = Mock() |
|
123 | config = Mock() | |
124 | middleware = vcs.VCSMiddleware( |
|
124 | middleware = vcs.VCSMiddleware( | |
125 | app, config=config, appenlight_client=None) |
|
125 | app, config=config, appenlight_client=None) | |
126 | snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn') |
|
126 | snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn') | |
127 | settings_patch = patch.dict( |
|
127 | settings_patch = patch.dict( | |
128 | rhodecode.CONFIG, |
|
128 | rhodecode.CONFIG, | |
129 | {'rhodecode_proxy_subversion_http_requests': False}) |
|
129 | {'rhodecode_proxy_subversion_http_requests': False}) | |
130 | with snv_patch as svn_mock, settings_patch: |
|
130 | with snv_patch as svn_mock, settings_patch: | |
131 | app = middleware._get_handler_app(environ) |
|
131 | app = middleware._get_handler_app(environ) | |
132 |
|
132 | |||
133 | assert svn_mock.call_count == 0 |
|
133 | assert svn_mock.call_count == 0 | |
134 | assert app is None |
|
134 | assert app is None |
General Comments 0
You need to be logged in to leave comments.
Login now