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