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