Show More
@@ -1,110 +1,137 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-2017 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 | import pytest |
|
21 | import pytest | |
22 | import urlparse |
|
22 | import urlparse | |
23 |
|
23 | |||
24 | from rhodecode.tests.lib.middleware import mock_scm_app |
|
24 | from rhodecode.tests.lib.middleware import mock_scm_app | |
25 | import rhodecode.lib.middleware.simplegit as simplegit |
|
25 | import rhodecode.lib.middleware.simplegit as simplegit | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | def get_environ(url): |
|
28 | def get_environ(url, request_method): | |
29 | """Construct a minimum WSGI environ based on the URL.""" |
|
29 | """Construct a minimum WSGI environ based on the URL.""" | |
30 | parsed_url = urlparse.urlparse(url) |
|
30 | parsed_url = urlparse.urlparse(url) | |
31 | environ = { |
|
31 | environ = { | |
32 | 'PATH_INFO': parsed_url.path, |
|
32 | 'PATH_INFO': parsed_url.path, | |
33 | 'QUERY_STRING': parsed_url.query, |
|
33 | 'QUERY_STRING': parsed_url.query, | |
|
34 | 'REQUEST_METHOD': request_method, | |||
34 | } |
|
35 | } | |
35 |
|
36 | |||
36 | return environ |
|
37 | return environ | |
37 |
|
38 | |||
38 |
|
39 | |||
39 | @pytest.mark.parametrize( |
|
40 | @pytest.mark.parametrize( | |
40 | 'url, expected_action', |
|
41 | 'url, expected_action, request_method', | |
41 | [ |
|
42 | [ | |
42 | ('/foo/bar/info/refs?service=git-upload-pack', 'pull'), |
|
43 | ('/foo/bar/info/refs?service=git-upload-pack', 'pull', 'GET'), | |
43 | ('/foo/bar/info/refs?service=git-receive-pack', 'push'), |
|
44 | ('/foo/bar/info/refs?service=git-receive-pack', 'push', 'GET'), | |
44 | ('/foo/bar/git-upload-pack', 'pull'), |
|
45 | ('/foo/bar/git-upload-pack', 'pull', 'GET'), | |
45 | ('/foo/bar/git-receive-pack', 'push'), |
|
46 | ('/foo/bar/git-receive-pack', 'push', 'GET'), | |
46 | # Edge case: missing data for info/refs |
|
47 | # Edge case: missing data for info/refs | |
47 | ('/foo/info/refs?service=', 'pull'), |
|
48 | ('/foo/info/refs?service=', 'pull', 'GET'), | |
48 | ('/foo/info/refs', 'pull'), |
|
49 | ('/foo/info/refs', 'pull', 'GET'), | |
49 | # Edge case: git command comes with service argument |
|
50 | # Edge case: git command comes with service argument | |
50 | ('/foo/git-upload-pack?service=git-receive-pack', 'pull'), |
|
51 | ('/foo/git-upload-pack?service=git-receive-pack', 'pull', 'GET'), | |
51 | ('/foo/git-receive-pack?service=git-upload-pack', 'push'), |
|
52 | ('/foo/git-receive-pack?service=git-upload-pack', 'push', 'GET'), | |
52 | # Edge case: repo name conflicts with git commands |
|
53 | # Edge case: repo name conflicts with git commands | |
53 | ('/git-receive-pack/git-upload-pack', 'pull'), |
|
54 | ('/git-receive-pack/git-upload-pack', 'pull', 'GET'), | |
54 | ('/git-receive-pack/git-receive-pack', 'push'), |
|
55 | ('/git-receive-pack/git-receive-pack', 'push', 'GET'), | |
55 | ('/git-upload-pack/git-upload-pack', 'pull'), |
|
56 | ('/git-upload-pack/git-upload-pack', 'pull', 'GET'), | |
56 | ('/git-upload-pack/git-receive-pack', 'push'), |
|
57 | ('/git-upload-pack/git-receive-pack', 'push', 'GET'), | |
57 | ('/foo/git-receive-pack', 'push'), |
|
58 | ('/foo/git-receive-pack', 'push', 'GET'), | |
58 | # Edge case: not a smart protocol url |
|
59 | # Edge case: not a smart protocol url | |
59 | ('/foo/bar', 'pull'), |
|
60 | ('/foo/bar', 'pull', 'GET'), | |
|
61 | # GIT LFS cases, batch | |||
|
62 | ('/foo/bar/info/lfs/objects/batch', 'push', 'GET'), | |||
|
63 | ('/foo/bar/info/lfs/objects/batch', 'pull', 'POST'), | |||
|
64 | # GIT LFS oid, dl/upl | |||
|
65 | ('/foo/bar/info/lfs/abcdeabcde', 'pull', 'GET'), | |||
|
66 | ('/foo/bar/info/lfs/abcdeabcde', 'push', 'PUT'), | |||
|
67 | ('/foo/bar/info/lfs/abcdeabcde', 'push', 'POST'), | |||
|
68 | # Edge case: repo name conflicts with git commands | |||
|
69 | ('/info/lfs/info/lfs/objects/batch', 'push', 'GET'), | |||
|
70 | ('/info/lfs/info/lfs/objects/batch', 'pull', 'POST'), | |||
|
71 | ||||
60 | ]) |
|
72 | ]) | |
61 | def test_get_action(url, expected_action, pylonsapp): |
|
73 | def test_get_action(url, expected_action, request_method, pylonsapp): | |
62 | app = simplegit.SimpleGit(application=None, |
|
74 | app = simplegit.SimpleGit(application=None, | |
63 | config={'auth_ret_code': '', 'base_path': ''}, |
|
75 | config={'auth_ret_code': '', 'base_path': ''}, | |
64 | registry=None) |
|
76 | registry=None) | |
65 | assert expected_action == app._get_action(get_environ(url)) |
|
77 | assert expected_action == app._get_action(get_environ(url, request_method)) | |
66 |
|
78 | |||
67 |
|
79 | |||
68 | @pytest.mark.parametrize( |
|
80 | @pytest.mark.parametrize( | |
69 | 'url, expected_repo_name', |
|
81 | 'url, expected_repo_name, request_method', | |
70 | [ |
|
82 | [ | |
71 | ('/foo/info/refs?service=git-upload-pack', 'foo'), |
|
83 | ('/foo/info/refs?service=git-upload-pack', 'foo', 'GET'), | |
72 | ('/foo/bar/info/refs?service=git-receive-pack', 'foo/bar'), |
|
84 | ('/foo/bar/info/refs?service=git-receive-pack', 'foo/bar', 'GET'), | |
73 | ('/foo/git-upload-pack', 'foo'), |
|
85 | ('/foo/git-upload-pack', 'foo', 'GET'), | |
74 | ('/foo/git-receive-pack', 'foo'), |
|
86 | ('/foo/git-receive-pack', 'foo', 'GET'), | |
75 | ('/foo/bar/git-upload-pack', 'foo/bar'), |
|
87 | ('/foo/bar/git-upload-pack', 'foo/bar', 'GET'), | |
76 | ('/foo/bar/git-receive-pack', 'foo/bar'), |
|
88 | ('/foo/bar/git-receive-pack', 'foo/bar', 'GET'), | |
|
89 | ||||
|
90 | # GIT LFS cases, batch | |||
|
91 | ('/foo/bar/info/lfs/objects/batch', 'foo/bar', 'GET'), | |||
|
92 | ('/example-git/info/lfs/objects/batch', 'example-git', 'POST'), | |||
|
93 | # GIT LFS oid, dl/upl | |||
|
94 | ('/foo/info/lfs/abcdeabcde', 'foo', 'GET'), | |||
|
95 | ('/foo/bar/info/lfs/abcdeabcde', 'foo/bar', 'PUT'), | |||
|
96 | ('/my-git-repo/info/lfs/abcdeabcde', 'my-git-repo', 'POST'), | |||
|
97 | # Edge case: repo name conflicts with git commands | |||
|
98 | ('/info/lfs/info/lfs/objects/batch', 'info/lfs', 'GET'), | |||
|
99 | ('/info/lfs/info/lfs/objects/batch', 'info/lfs', 'POST'), | |||
|
100 | ||||
77 | ]) |
|
101 | ]) | |
78 | def test_get_repository_name(url, expected_repo_name, pylonsapp): |
|
102 | def test_get_repository_name(url, expected_repo_name, request_method, pylonsapp): | |
79 | app = simplegit.SimpleGit(application=None, |
|
103 | app = simplegit.SimpleGit(application=None, | |
80 | config={'auth_ret_code': '', 'base_path': ''}, |
|
104 | config={'auth_ret_code': '', 'base_path': ''}, | |
81 | registry=None) |
|
105 | registry=None) | |
82 |
assert expected_repo_name == app._get_repository_name( |
|
106 | assert expected_repo_name == app._get_repository_name( | |
|
107 | get_environ(url, request_method)) | |||
83 |
|
108 | |||
84 |
|
109 | |||
85 | def test_get_config(pylonsapp): |
|
110 | def test_get_config(pylonsapp): | |
86 | app = simplegit.SimpleGit(application=None, |
|
111 | app = simplegit.SimpleGit(application=None, | |
87 | config={'auth_ret_code': '', 'base_path': ''}, |
|
112 | config={'auth_ret_code': '', 'base_path': ''}, | |
88 | registry=None) |
|
113 | registry=None) | |
89 | extras = {'foo': 'FOO', 'bar': 'BAR'} |
|
114 | extras = {'foo': 'FOO', 'bar': 'BAR'} | |
90 |
|
115 | |||
91 | # We copy the extras as the method below will change the contents. |
|
116 | # We copy the extras as the method below will change the contents. | |
92 | config = app._create_config(dict(extras), repo_name='test-repo') |
|
117 | config = app._create_config(dict(extras), repo_name='test-repo') | |
93 | expected_config = dict(extras) |
|
118 | expected_config = dict(extras) | |
94 | expected_config.update({ |
|
119 | expected_config.update({ | |
95 | 'git_update_server_info': False, |
|
120 | 'git_update_server_info': False, | |
|
121 | 'git_lfs_enabled': True, | |||
|
122 | 'git_lfs_store_path': simplegit.default_lfs_store() | |||
96 | }) |
|
123 | }) | |
97 |
|
124 | |||
98 | assert config == expected_config |
|
125 | assert config == expected_config | |
99 |
|
126 | |||
100 |
|
127 | |||
101 | def test_create_wsgi_app_uses_scm_app_from_simplevcs(pylonsapp): |
|
128 | def test_create_wsgi_app_uses_scm_app_from_simplevcs(pylonsapp): | |
102 | config = { |
|
129 | config = { | |
103 | 'auth_ret_code': '', |
|
130 | 'auth_ret_code': '', | |
104 | 'base_path': '', |
|
131 | 'base_path': '', | |
105 | 'vcs.scm_app_implementation': |
|
132 | 'vcs.scm_app_implementation': | |
106 | 'rhodecode.tests.lib.middleware.mock_scm_app', |
|
133 | 'rhodecode.tests.lib.middleware.mock_scm_app', | |
107 | } |
|
134 | } | |
108 | app = simplegit.SimpleGit(application=None, config=config, registry=None) |
|
135 | app = simplegit.SimpleGit(application=None, config=config, registry=None) | |
109 | wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {}) |
|
136 | wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {}) | |
110 | assert wsgi_app is mock_scm_app.mock_git_wsgi |
|
137 | assert wsgi_app is mock_scm_app.mock_git_wsgi |
General Comments 0
You need to be logged in to leave comments.
Login now