Show More
@@ -1,110 +1,137 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import pytest |
|
22 | 22 | import urlparse |
|
23 | 23 | |
|
24 | 24 | from rhodecode.tests.lib.middleware import mock_scm_app |
|
25 | 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 | 29 | """Construct a minimum WSGI environ based on the URL.""" |
|
30 | 30 | parsed_url = urlparse.urlparse(url) |
|
31 | 31 | environ = { |
|
32 | 32 | 'PATH_INFO': parsed_url.path, |
|
33 | 33 | 'QUERY_STRING': parsed_url.query, |
|
34 | 'REQUEST_METHOD': request_method, | |
|
34 | 35 | } |
|
35 | 36 | |
|
36 | 37 | return environ |
|
37 | 38 | |
|
38 | 39 | |
|
39 | 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-receive-pack', 'push'), | |
|
44 | ('/foo/bar/git-upload-pack', 'pull'), | |
|
45 | ('/foo/bar/git-receive-pack', 'push'), | |
|
43 | ('/foo/bar/info/refs?service=git-upload-pack', 'pull', 'GET'), | |
|
44 | ('/foo/bar/info/refs?service=git-receive-pack', 'push', 'GET'), | |
|
45 | ('/foo/bar/git-upload-pack', 'pull', 'GET'), | |
|
46 | ('/foo/bar/git-receive-pack', 'push', 'GET'), | |
|
46 | 47 | # Edge case: missing data for info/refs |
|
47 | ('/foo/info/refs?service=', 'pull'), | |
|
48 | ('/foo/info/refs', 'pull'), | |
|
48 | ('/foo/info/refs?service=', 'pull', 'GET'), | |
|
49 | ('/foo/info/refs', 'pull', 'GET'), | |
|
49 | 50 | # Edge case: git command comes with service argument |
|
50 | ('/foo/git-upload-pack?service=git-receive-pack', 'pull'), | |
|
51 | ('/foo/git-receive-pack?service=git-upload-pack', 'push'), | |
|
51 | ('/foo/git-upload-pack?service=git-receive-pack', 'pull', 'GET'), | |
|
52 | ('/foo/git-receive-pack?service=git-upload-pack', 'push', 'GET'), | |
|
52 | 53 | # Edge case: repo name conflicts with git commands |
|
53 | ('/git-receive-pack/git-upload-pack', 'pull'), | |
|
54 | ('/git-receive-pack/git-receive-pack', 'push'), | |
|
55 | ('/git-upload-pack/git-upload-pack', 'pull'), | |
|
56 | ('/git-upload-pack/git-receive-pack', 'push'), | |
|
57 | ('/foo/git-receive-pack', 'push'), | |
|
54 | ('/git-receive-pack/git-upload-pack', 'pull', 'GET'), | |
|
55 | ('/git-receive-pack/git-receive-pack', 'push', 'GET'), | |
|
56 | ('/git-upload-pack/git-upload-pack', 'pull', 'GET'), | |
|
57 | ('/git-upload-pack/git-receive-pack', 'push', 'GET'), | |
|
58 | ('/foo/git-receive-pack', 'push', 'GET'), | |
|
58 | 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 | 74 | app = simplegit.SimpleGit(application=None, |
|
63 | 75 | config={'auth_ret_code': '', 'base_path': ''}, |
|
64 | 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 | 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'), | |
|
72 | ('/foo/bar/info/refs?service=git-receive-pack', 'foo/bar'), | |
|
73 | ('/foo/git-upload-pack', 'foo'), | |
|
74 | ('/foo/git-receive-pack', 'foo'), | |
|
75 | ('/foo/bar/git-upload-pack', 'foo/bar'), | |
|
76 | ('/foo/bar/git-receive-pack', 'foo/bar'), | |
|
83 | ('/foo/info/refs?service=git-upload-pack', 'foo', 'GET'), | |
|
84 | ('/foo/bar/info/refs?service=git-receive-pack', 'foo/bar', 'GET'), | |
|
85 | ('/foo/git-upload-pack', 'foo', 'GET'), | |
|
86 | ('/foo/git-receive-pack', 'foo', 'GET'), | |
|
87 | ('/foo/bar/git-upload-pack', 'foo/bar', 'GET'), | |
|
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 | 103 | app = simplegit.SimpleGit(application=None, |
|
80 | 104 | config={'auth_ret_code': '', 'base_path': ''}, |
|
81 | 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 | 110 | def test_get_config(pylonsapp): |
|
86 | 111 | app = simplegit.SimpleGit(application=None, |
|
87 | 112 | config={'auth_ret_code': '', 'base_path': ''}, |
|
88 | 113 | registry=None) |
|
89 | 114 | extras = {'foo': 'FOO', 'bar': 'BAR'} |
|
90 | 115 | |
|
91 | 116 | # We copy the extras as the method below will change the contents. |
|
92 | 117 | config = app._create_config(dict(extras), repo_name='test-repo') |
|
93 | 118 | expected_config = dict(extras) |
|
94 | 119 | expected_config.update({ |
|
95 | 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 | 125 | assert config == expected_config |
|
99 | 126 | |
|
100 | 127 | |
|
101 | 128 | def test_create_wsgi_app_uses_scm_app_from_simplevcs(pylonsapp): |
|
102 | 129 | config = { |
|
103 | 130 | 'auth_ret_code': '', |
|
104 | 131 | 'base_path': '', |
|
105 | 132 | 'vcs.scm_app_implementation': |
|
106 | 133 | 'rhodecode.tests.lib.middleware.mock_scm_app', |
|
107 | 134 | } |
|
108 | 135 | app = simplegit.SimpleGit(application=None, config=config, registry=None) |
|
109 | 136 | wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {}) |
|
110 | 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