Show More
@@ -25,61 +25,86 b' from rhodecode.tests.lib.middleware impo' | |||
|
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): |
@@ -93,6 +118,8 b' def test_get_config(pylonsapp):' | |||
|
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 |
General Comments 0
You need to be logged in to leave comments.
Login now