##// END OF EJS Templates
tests: protocol ops, added --pull and --pull --stream clone tests
dan -
r3525:442219c2 default
parent child Browse files
Show More
@@ -1,469 +1,483 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2019 RhodeCode GmbH
3 # Copyright (C) 2010-2019 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 """
21 """
22 Test suite for making push/pull operations, on specially modified INI files
22 Test suite for making push/pull operations, on specially modified INI files
23
23
24 .. important::
24 .. important::
25
25
26 You must have git >= 1.8.5 for tests to work fine. With 68b939b git started
26 You must have git >= 1.8.5 for tests to work fine. With 68b939b git started
27 to redirect things to stderr instead of stdout.
27 to redirect things to stderr instead of stdout.
28 """
28 """
29
29
30
30
31 import time
31 import time
32
32
33 import pytest
33 import pytest
34
34
35 from rhodecode.lib import rc_cache
35 from rhodecode.lib import rc_cache
36 from rhodecode.model.auth_token import AuthTokenModel
36 from rhodecode.model.auth_token import AuthTokenModel
37 from rhodecode.model.db import Repository, UserIpMap, CacheKey
37 from rhodecode.model.db import Repository, UserIpMap, CacheKey
38 from rhodecode.model.meta import Session
38 from rhodecode.model.meta import Session
39 from rhodecode.model.repo import RepoModel
39 from rhodecode.model.repo import RepoModel
40 from rhodecode.model.user import UserModel
40 from rhodecode.model.user import UserModel
41 from rhodecode.tests import (GIT_REPO, HG_REPO, TEST_USER_ADMIN_LOGIN)
41 from rhodecode.tests import (GIT_REPO, HG_REPO, TEST_USER_ADMIN_LOGIN)
42
42
43 from rhodecode.tests.vcs_operations import (
43 from rhodecode.tests.vcs_operations import (
44 Command, _check_proper_clone, _check_proper_git_push,
44 Command, _check_proper_clone, _check_proper_git_push,
45 _add_files_and_push, HG_REPO_WITH_GROUP, GIT_REPO_WITH_GROUP)
45 _add_files_and_push, HG_REPO_WITH_GROUP, GIT_REPO_WITH_GROUP)
46
46
47
47
48 @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user")
48 @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user")
49 class TestVCSOperations(object):
49 class TestVCSOperations(object):
50
50
51 def test_clone_hg_repo_by_admin(self, rc_web_server, tmpdir):
51 def test_clone_hg_repo_by_admin(self, rc_web_server, tmpdir):
52 clone_url = rc_web_server.repo_clone_url(HG_REPO)
52 clone_url = rc_web_server.repo_clone_url(HG_REPO)
53 stdout, stderr = Command('/tmp').execute(
53 stdout, stderr = Command('/tmp').execute(
54 'hg clone', clone_url, tmpdir.strpath)
54 'hg clone', clone_url, tmpdir.strpath)
55 _check_proper_clone(stdout, stderr, 'hg')
55 _check_proper_clone(stdout, stderr, 'hg')
56
56
57 def test_clone_hg_repo_by_admin_pull_protocol(self, rc_web_server, tmpdir):
58 clone_url = rc_web_server.repo_clone_url(HG_REPO)
59 stdout, stderr = Command('/tmp').execute(
60 'hg clone --pull', clone_url, tmpdir.strpath)
61 _check_proper_clone(stdout, stderr, 'hg')
62
63 def test_clone_hg_repo_by_admin_pull_stream_protocol(self, rc_web_server, tmpdir):
64 clone_url = rc_web_server.repo_clone_url(HG_REPO)
65 stdout, stderr = Command('/tmp').execute(
66 'hg clone --pull --stream', clone_url, tmpdir.strpath)
67 assert '225 files to transfer, 1.04 MB of data' in stdout
68 assert 'transferred 1.04 MB' in stdout
69 assert '114 files updated,' in stdout
70
57 def test_clone_git_repo_by_admin(self, rc_web_server, tmpdir):
71 def test_clone_git_repo_by_admin(self, rc_web_server, tmpdir):
58 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
72 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
59 cmd = Command('/tmp')
73 cmd = Command('/tmp')
60 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
74 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
61 _check_proper_clone(stdout, stderr, 'git')
75 _check_proper_clone(stdout, stderr, 'git')
62 cmd.assert_returncode_success()
76 cmd.assert_returncode_success()
63
77
64 def test_clone_git_repo_by_admin_with_git_suffix(self, rc_web_server, tmpdir):
78 def test_clone_git_repo_by_admin_with_git_suffix(self, rc_web_server, tmpdir):
65 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
79 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
66 cmd = Command('/tmp')
80 cmd = Command('/tmp')
67 stdout, stderr = cmd.execute('git clone', clone_url+".git", tmpdir.strpath)
81 stdout, stderr = cmd.execute('git clone', clone_url+".git", tmpdir.strpath)
68 _check_proper_clone(stdout, stderr, 'git')
82 _check_proper_clone(stdout, stderr, 'git')
69 cmd.assert_returncode_success()
83 cmd.assert_returncode_success()
70
84
71 def test_clone_hg_repo_by_id_by_admin(self, rc_web_server, tmpdir):
85 def test_clone_hg_repo_by_id_by_admin(self, rc_web_server, tmpdir):
72 repo_id = Repository.get_by_repo_name(HG_REPO).repo_id
86 repo_id = Repository.get_by_repo_name(HG_REPO).repo_id
73 clone_url = rc_web_server.repo_clone_url('_%s' % repo_id)
87 clone_url = rc_web_server.repo_clone_url('_%s' % repo_id)
74 stdout, stderr = Command('/tmp').execute(
88 stdout, stderr = Command('/tmp').execute(
75 'hg clone', clone_url, tmpdir.strpath)
89 'hg clone', clone_url, tmpdir.strpath)
76 _check_proper_clone(stdout, stderr, 'hg')
90 _check_proper_clone(stdout, stderr, 'hg')
77
91
78 def test_clone_git_repo_by_id_by_admin(self, rc_web_server, tmpdir):
92 def test_clone_git_repo_by_id_by_admin(self, rc_web_server, tmpdir):
79 repo_id = Repository.get_by_repo_name(GIT_REPO).repo_id
93 repo_id = Repository.get_by_repo_name(GIT_REPO).repo_id
80 clone_url = rc_web_server.repo_clone_url('_%s' % repo_id)
94 clone_url = rc_web_server.repo_clone_url('_%s' % repo_id)
81 cmd = Command('/tmp')
95 cmd = Command('/tmp')
82 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
96 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
83 _check_proper_clone(stdout, stderr, 'git')
97 _check_proper_clone(stdout, stderr, 'git')
84 cmd.assert_returncode_success()
98 cmd.assert_returncode_success()
85
99
86 def test_clone_hg_repo_with_group_by_admin(self, rc_web_server, tmpdir):
100 def test_clone_hg_repo_with_group_by_admin(self, rc_web_server, tmpdir):
87 clone_url = rc_web_server.repo_clone_url(HG_REPO_WITH_GROUP)
101 clone_url = rc_web_server.repo_clone_url(HG_REPO_WITH_GROUP)
88 stdout, stderr = Command('/tmp').execute(
102 stdout, stderr = Command('/tmp').execute(
89 'hg clone', clone_url, tmpdir.strpath)
103 'hg clone', clone_url, tmpdir.strpath)
90 _check_proper_clone(stdout, stderr, 'hg')
104 _check_proper_clone(stdout, stderr, 'hg')
91
105
92 def test_clone_git_repo_with_group_by_admin(self, rc_web_server, tmpdir):
106 def test_clone_git_repo_with_group_by_admin(self, rc_web_server, tmpdir):
93 clone_url = rc_web_server.repo_clone_url(GIT_REPO_WITH_GROUP)
107 clone_url = rc_web_server.repo_clone_url(GIT_REPO_WITH_GROUP)
94 cmd = Command('/tmp')
108 cmd = Command('/tmp')
95 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
109 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
96 _check_proper_clone(stdout, stderr, 'git')
110 _check_proper_clone(stdout, stderr, 'git')
97 cmd.assert_returncode_success()
111 cmd.assert_returncode_success()
98
112
99 def test_clone_git_repo_shallow_by_admin(self, rc_web_server, tmpdir):
113 def test_clone_git_repo_shallow_by_admin(self, rc_web_server, tmpdir):
100 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
114 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
101 cmd = Command('/tmp')
115 cmd = Command('/tmp')
102 stdout, stderr = cmd.execute(
116 stdout, stderr = cmd.execute(
103 'git clone --depth=1', clone_url, tmpdir.strpath)
117 'git clone --depth=1', clone_url, tmpdir.strpath)
104
118
105 assert '' == stdout
119 assert '' == stdout
106 assert 'Cloning into' in stderr
120 assert 'Cloning into' in stderr
107 cmd.assert_returncode_success()
121 cmd.assert_returncode_success()
108
122
109 def test_clone_wrong_credentials_hg(self, rc_web_server, tmpdir):
123 def test_clone_wrong_credentials_hg(self, rc_web_server, tmpdir):
110 clone_url = rc_web_server.repo_clone_url(HG_REPO, passwd='bad!')
124 clone_url = rc_web_server.repo_clone_url(HG_REPO, passwd='bad!')
111 stdout, stderr = Command('/tmp').execute(
125 stdout, stderr = Command('/tmp').execute(
112 'hg clone', clone_url, tmpdir.strpath)
126 'hg clone', clone_url, tmpdir.strpath)
113 assert 'abort: authorization failed' in stderr
127 assert 'abort: authorization failed' in stderr
114
128
115 def test_clone_wrong_credentials_git(self, rc_web_server, tmpdir):
129 def test_clone_wrong_credentials_git(self, rc_web_server, tmpdir):
116 clone_url = rc_web_server.repo_clone_url(GIT_REPO, passwd='bad!')
130 clone_url = rc_web_server.repo_clone_url(GIT_REPO, passwd='bad!')
117 stdout, stderr = Command('/tmp').execute(
131 stdout, stderr = Command('/tmp').execute(
118 'git clone', clone_url, tmpdir.strpath)
132 'git clone', clone_url, tmpdir.strpath)
119 assert 'fatal: Authentication failed' in stderr
133 assert 'fatal: Authentication failed' in stderr
120
134
121 def test_clone_git_dir_as_hg(self, rc_web_server, tmpdir):
135 def test_clone_git_dir_as_hg(self, rc_web_server, tmpdir):
122 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
136 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
123 stdout, stderr = Command('/tmp').execute(
137 stdout, stderr = Command('/tmp').execute(
124 'hg clone', clone_url, tmpdir.strpath)
138 'hg clone', clone_url, tmpdir.strpath)
125 assert 'HTTP Error 404: Not Found' in stderr
139 assert 'HTTP Error 404: Not Found' in stderr
126
140
127 def test_clone_hg_repo_as_git(self, rc_web_server, tmpdir):
141 def test_clone_hg_repo_as_git(self, rc_web_server, tmpdir):
128 clone_url = rc_web_server.repo_clone_url(HG_REPO)
142 clone_url = rc_web_server.repo_clone_url(HG_REPO)
129 stdout, stderr = Command('/tmp').execute(
143 stdout, stderr = Command('/tmp').execute(
130 'git clone', clone_url, tmpdir.strpath)
144 'git clone', clone_url, tmpdir.strpath)
131 assert 'not found' in stderr
145 assert 'not found' in stderr
132
146
133 def test_clone_non_existing_path_hg(self, rc_web_server, tmpdir):
147 def test_clone_non_existing_path_hg(self, rc_web_server, tmpdir):
134 clone_url = rc_web_server.repo_clone_url('trololo')
148 clone_url = rc_web_server.repo_clone_url('trololo')
135 stdout, stderr = Command('/tmp').execute(
149 stdout, stderr = Command('/tmp').execute(
136 'hg clone', clone_url, tmpdir.strpath)
150 'hg clone', clone_url, tmpdir.strpath)
137 assert 'HTTP Error 404: Not Found' in stderr
151 assert 'HTTP Error 404: Not Found' in stderr
138
152
139 def test_clone_non_existing_path_git(self, rc_web_server, tmpdir):
153 def test_clone_non_existing_path_git(self, rc_web_server, tmpdir):
140 clone_url = rc_web_server.repo_clone_url('trololo')
154 clone_url = rc_web_server.repo_clone_url('trololo')
141 stdout, stderr = Command('/tmp').execute('git clone', clone_url)
155 stdout, stderr = Command('/tmp').execute('git clone', clone_url)
142 assert 'not found' in stderr
156 assert 'not found' in stderr
143
157
144 def test_clone_hg_with_slashes(self, rc_web_server, tmpdir):
158 def test_clone_hg_with_slashes(self, rc_web_server, tmpdir):
145 clone_url = rc_web_server.repo_clone_url('//' + HG_REPO)
159 clone_url = rc_web_server.repo_clone_url('//' + HG_REPO)
146 stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath)
160 stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath)
147 assert 'HTTP Error 404: Not Found' in stderr
161 assert 'HTTP Error 404: Not Found' in stderr
148
162
149 def test_clone_git_with_slashes(self, rc_web_server, tmpdir):
163 def test_clone_git_with_slashes(self, rc_web_server, tmpdir):
150 clone_url = rc_web_server.repo_clone_url('//' + GIT_REPO)
164 clone_url = rc_web_server.repo_clone_url('//' + GIT_REPO)
151 stdout, stderr = Command('/tmp').execute('git clone', clone_url)
165 stdout, stderr = Command('/tmp').execute('git clone', clone_url)
152 assert 'not found' in stderr
166 assert 'not found' in stderr
153
167
154 def test_clone_existing_path_hg_not_in_database(
168 def test_clone_existing_path_hg_not_in_database(
155 self, rc_web_server, tmpdir, fs_repo_only):
169 self, rc_web_server, tmpdir, fs_repo_only):
156
170
157 db_name = fs_repo_only('not-in-db-hg', repo_type='hg')
171 db_name = fs_repo_only('not-in-db-hg', repo_type='hg')
158 clone_url = rc_web_server.repo_clone_url(db_name)
172 clone_url = rc_web_server.repo_clone_url(db_name)
159 stdout, stderr = Command('/tmp').execute(
173 stdout, stderr = Command('/tmp').execute(
160 'hg clone', clone_url, tmpdir.strpath)
174 'hg clone', clone_url, tmpdir.strpath)
161 assert 'HTTP Error 404: Not Found' in stderr
175 assert 'HTTP Error 404: Not Found' in stderr
162
176
163 def test_clone_existing_path_git_not_in_database(
177 def test_clone_existing_path_git_not_in_database(
164 self, rc_web_server, tmpdir, fs_repo_only):
178 self, rc_web_server, tmpdir, fs_repo_only):
165 db_name = fs_repo_only('not-in-db-git', repo_type='git')
179 db_name = fs_repo_only('not-in-db-git', repo_type='git')
166 clone_url = rc_web_server.repo_clone_url(db_name)
180 clone_url = rc_web_server.repo_clone_url(db_name)
167 stdout, stderr = Command('/tmp').execute(
181 stdout, stderr = Command('/tmp').execute(
168 'git clone', clone_url, tmpdir.strpath)
182 'git clone', clone_url, tmpdir.strpath)
169 assert 'not found' in stderr
183 assert 'not found' in stderr
170
184
171 def test_clone_existing_path_hg_not_in_database_different_scm(
185 def test_clone_existing_path_hg_not_in_database_different_scm(
172 self, rc_web_server, tmpdir, fs_repo_only):
186 self, rc_web_server, tmpdir, fs_repo_only):
173 db_name = fs_repo_only('not-in-db-git', repo_type='git')
187 db_name = fs_repo_only('not-in-db-git', repo_type='git')
174 clone_url = rc_web_server.repo_clone_url(db_name)
188 clone_url = rc_web_server.repo_clone_url(db_name)
175 stdout, stderr = Command('/tmp').execute(
189 stdout, stderr = Command('/tmp').execute(
176 'hg clone', clone_url, tmpdir.strpath)
190 'hg clone', clone_url, tmpdir.strpath)
177 assert 'HTTP Error 404: Not Found' in stderr
191 assert 'HTTP Error 404: Not Found' in stderr
178
192
179 def test_clone_existing_path_git_not_in_database_different_scm(
193 def test_clone_existing_path_git_not_in_database_different_scm(
180 self, rc_web_server, tmpdir, fs_repo_only):
194 self, rc_web_server, tmpdir, fs_repo_only):
181 db_name = fs_repo_only('not-in-db-hg', repo_type='hg')
195 db_name = fs_repo_only('not-in-db-hg', repo_type='hg')
182 clone_url = rc_web_server.repo_clone_url(db_name)
196 clone_url = rc_web_server.repo_clone_url(db_name)
183 stdout, stderr = Command('/tmp').execute(
197 stdout, stderr = Command('/tmp').execute(
184 'git clone', clone_url, tmpdir.strpath)
198 'git clone', clone_url, tmpdir.strpath)
185 assert 'not found' in stderr
199 assert 'not found' in stderr
186
200
187 def test_clone_non_existing_store_path_hg(self, rc_web_server, tmpdir, user_util):
201 def test_clone_non_existing_store_path_hg(self, rc_web_server, tmpdir, user_util):
188 repo = user_util.create_repo()
202 repo = user_util.create_repo()
189 clone_url = rc_web_server.repo_clone_url(repo.repo_name)
203 clone_url = rc_web_server.repo_clone_url(repo.repo_name)
190
204
191 # Damage repo by removing it's folder
205 # Damage repo by removing it's folder
192 RepoModel()._delete_filesystem_repo(repo)
206 RepoModel()._delete_filesystem_repo(repo)
193
207
194 stdout, stderr = Command('/tmp').execute(
208 stdout, stderr = Command('/tmp').execute(
195 'hg clone', clone_url, tmpdir.strpath)
209 'hg clone', clone_url, tmpdir.strpath)
196 assert 'HTTP Error 404: Not Found' in stderr
210 assert 'HTTP Error 404: Not Found' in stderr
197
211
198 def test_clone_non_existing_store_path_git(self, rc_web_server, tmpdir, user_util):
212 def test_clone_non_existing_store_path_git(self, rc_web_server, tmpdir, user_util):
199 repo = user_util.create_repo(repo_type='git')
213 repo = user_util.create_repo(repo_type='git')
200 clone_url = rc_web_server.repo_clone_url(repo.repo_name)
214 clone_url = rc_web_server.repo_clone_url(repo.repo_name)
201
215
202 # Damage repo by removing it's folder
216 # Damage repo by removing it's folder
203 RepoModel()._delete_filesystem_repo(repo)
217 RepoModel()._delete_filesystem_repo(repo)
204
218
205 stdout, stderr = Command('/tmp').execute(
219 stdout, stderr = Command('/tmp').execute(
206 'git clone', clone_url, tmpdir.strpath)
220 'git clone', clone_url, tmpdir.strpath)
207 assert 'not found' in stderr
221 assert 'not found' in stderr
208
222
209 def test_push_new_file_hg(self, rc_web_server, tmpdir):
223 def test_push_new_file_hg(self, rc_web_server, tmpdir):
210 clone_url = rc_web_server.repo_clone_url(HG_REPO)
224 clone_url = rc_web_server.repo_clone_url(HG_REPO)
211 stdout, stderr = Command('/tmp').execute(
225 stdout, stderr = Command('/tmp').execute(
212 'hg clone', clone_url, tmpdir.strpath)
226 'hg clone', clone_url, tmpdir.strpath)
213
227
214 stdout, stderr = _add_files_and_push(
228 stdout, stderr = _add_files_and_push(
215 'hg', tmpdir.strpath, clone_url=clone_url)
229 'hg', tmpdir.strpath, clone_url=clone_url)
216
230
217 assert 'pushing to' in stdout
231 assert 'pushing to' in stdout
218 assert 'size summary' in stdout
232 assert 'size summary' in stdout
219
233
220 def test_push_new_file_git(self, rc_web_server, tmpdir):
234 def test_push_new_file_git(self, rc_web_server, tmpdir):
221 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
235 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
222 stdout, stderr = Command('/tmp').execute(
236 stdout, stderr = Command('/tmp').execute(
223 'git clone', clone_url, tmpdir.strpath)
237 'git clone', clone_url, tmpdir.strpath)
224
238
225 # commit some stuff into this repo
239 # commit some stuff into this repo
226 stdout, stderr = _add_files_and_push(
240 stdout, stderr = _add_files_and_push(
227 'git', tmpdir.strpath, clone_url=clone_url)
241 'git', tmpdir.strpath, clone_url=clone_url)
228
242
229 _check_proper_git_push(stdout, stderr)
243 _check_proper_git_push(stdout, stderr)
230
244
231 def test_push_invalidates_cache(self, rc_web_server, tmpdir):
245 def test_push_invalidates_cache(self, rc_web_server, tmpdir):
232 hg_repo = Repository.get_by_repo_name(HG_REPO)
246 hg_repo = Repository.get_by_repo_name(HG_REPO)
233
247
234 # init cache objects
248 # init cache objects
235 CacheKey.delete_all_cache()
249 CacheKey.delete_all_cache()
236 cache_namespace_uid = 'cache_push_test.{}'.format(hg_repo.repo_id)
250 cache_namespace_uid = 'cache_push_test.{}'.format(hg_repo.repo_id)
237 invalidation_namespace = CacheKey.REPO_INVALIDATION_NAMESPACE.format(
251 invalidation_namespace = CacheKey.REPO_INVALIDATION_NAMESPACE.format(
238 repo_id=hg_repo.repo_id)
252 repo_id=hg_repo.repo_id)
239
253
240 inv_context_manager = rc_cache.InvalidationContext(
254 inv_context_manager = rc_cache.InvalidationContext(
241 uid=cache_namespace_uid, invalidation_namespace=invalidation_namespace)
255 uid=cache_namespace_uid, invalidation_namespace=invalidation_namespace)
242
256
243 with inv_context_manager as invalidation_context:
257 with inv_context_manager as invalidation_context:
244 # __enter__ will create and register cache objects
258 # __enter__ will create and register cache objects
245 pass
259 pass
246
260
247 # clone to init cache
261 # clone to init cache
248 clone_url = rc_web_server.repo_clone_url(hg_repo.repo_name)
262 clone_url = rc_web_server.repo_clone_url(hg_repo.repo_name)
249 stdout, stderr = Command('/tmp').execute(
263 stdout, stderr = Command('/tmp').execute(
250 'hg clone', clone_url, tmpdir.strpath)
264 'hg clone', clone_url, tmpdir.strpath)
251
265
252 cache_keys = hg_repo.cache_keys
266 cache_keys = hg_repo.cache_keys
253 assert cache_keys != []
267 assert cache_keys != []
254 for key in cache_keys:
268 for key in cache_keys:
255 assert key.cache_active is True
269 assert key.cache_active is True
256
270
257 # PUSH that should trigger invalidation cache
271 # PUSH that should trigger invalidation cache
258 stdout, stderr = _add_files_and_push(
272 stdout, stderr = _add_files_and_push(
259 'hg', tmpdir.strpath, clone_url=clone_url, files_no=1)
273 'hg', tmpdir.strpath, clone_url=clone_url, files_no=1)
260
274
261 # flush...
275 # flush...
262 Session().commit()
276 Session().commit()
263 hg_repo = Repository.get_by_repo_name(HG_REPO)
277 hg_repo = Repository.get_by_repo_name(HG_REPO)
264 cache_keys = hg_repo.cache_keys
278 cache_keys = hg_repo.cache_keys
265 assert cache_keys != []
279 assert cache_keys != []
266 for key in cache_keys:
280 for key in cache_keys:
267 # keys should be marked as not active
281 # keys should be marked as not active
268 assert key.cache_active is False
282 assert key.cache_active is False
269
283
270 def test_push_wrong_credentials_hg(self, rc_web_server, tmpdir):
284 def test_push_wrong_credentials_hg(self, rc_web_server, tmpdir):
271 clone_url = rc_web_server.repo_clone_url(HG_REPO)
285 clone_url = rc_web_server.repo_clone_url(HG_REPO)
272 stdout, stderr = Command('/tmp').execute(
286 stdout, stderr = Command('/tmp').execute(
273 'hg clone', clone_url, tmpdir.strpath)
287 'hg clone', clone_url, tmpdir.strpath)
274
288
275 push_url = rc_web_server.repo_clone_url(
289 push_url = rc_web_server.repo_clone_url(
276 HG_REPO, user='bad', passwd='name')
290 HG_REPO, user='bad', passwd='name')
277 stdout, stderr = _add_files_and_push(
291 stdout, stderr = _add_files_and_push(
278 'hg', tmpdir.strpath, clone_url=push_url)
292 'hg', tmpdir.strpath, clone_url=push_url)
279
293
280 assert 'abort: authorization failed' in stderr
294 assert 'abort: authorization failed' in stderr
281
295
282 def test_push_wrong_credentials_git(self, rc_web_server, tmpdir):
296 def test_push_wrong_credentials_git(self, rc_web_server, tmpdir):
283 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
297 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
284 stdout, stderr = Command('/tmp').execute(
298 stdout, stderr = Command('/tmp').execute(
285 'git clone', clone_url, tmpdir.strpath)
299 'git clone', clone_url, tmpdir.strpath)
286
300
287 push_url = rc_web_server.repo_clone_url(
301 push_url = rc_web_server.repo_clone_url(
288 GIT_REPO, user='bad', passwd='name')
302 GIT_REPO, user='bad', passwd='name')
289 stdout, stderr = _add_files_and_push(
303 stdout, stderr = _add_files_and_push(
290 'git', tmpdir.strpath, clone_url=push_url)
304 'git', tmpdir.strpath, clone_url=push_url)
291
305
292 assert 'fatal: Authentication failed' in stderr
306 assert 'fatal: Authentication failed' in stderr
293
307
294 def test_push_back_to_wrong_url_hg(self, rc_web_server, tmpdir):
308 def test_push_back_to_wrong_url_hg(self, rc_web_server, tmpdir):
295 clone_url = rc_web_server.repo_clone_url(HG_REPO)
309 clone_url = rc_web_server.repo_clone_url(HG_REPO)
296 stdout, stderr = Command('/tmp').execute(
310 stdout, stderr = Command('/tmp').execute(
297 'hg clone', clone_url, tmpdir.strpath)
311 'hg clone', clone_url, tmpdir.strpath)
298
312
299 stdout, stderr = _add_files_and_push(
313 stdout, stderr = _add_files_and_push(
300 'hg', tmpdir.strpath,
314 'hg', tmpdir.strpath,
301 clone_url=rc_web_server.repo_clone_url('not-existing'))
315 clone_url=rc_web_server.repo_clone_url('not-existing'))
302
316
303 assert 'HTTP Error 404: Not Found' in stderr
317 assert 'HTTP Error 404: Not Found' in stderr
304
318
305 def test_push_back_to_wrong_url_git(self, rc_web_server, tmpdir):
319 def test_push_back_to_wrong_url_git(self, rc_web_server, tmpdir):
306 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
320 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
307 stdout, stderr = Command('/tmp').execute(
321 stdout, stderr = Command('/tmp').execute(
308 'git clone', clone_url, tmpdir.strpath)
322 'git clone', clone_url, tmpdir.strpath)
309
323
310 stdout, stderr = _add_files_and_push(
324 stdout, stderr = _add_files_and_push(
311 'git', tmpdir.strpath,
325 'git', tmpdir.strpath,
312 clone_url=rc_web_server.repo_clone_url('not-existing'))
326 clone_url=rc_web_server.repo_clone_url('not-existing'))
313
327
314 assert 'not found' in stderr
328 assert 'not found' in stderr
315
329
316 def test_ip_restriction_hg(self, rc_web_server, tmpdir):
330 def test_ip_restriction_hg(self, rc_web_server, tmpdir):
317 user_model = UserModel()
331 user_model = UserModel()
318 try:
332 try:
319 user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
333 user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
320 Session().commit()
334 Session().commit()
321 time.sleep(2)
335 time.sleep(2)
322 clone_url = rc_web_server.repo_clone_url(HG_REPO)
336 clone_url = rc_web_server.repo_clone_url(HG_REPO)
323 stdout, stderr = Command('/tmp').execute(
337 stdout, stderr = Command('/tmp').execute(
324 'hg clone', clone_url, tmpdir.strpath)
338 'hg clone', clone_url, tmpdir.strpath)
325 assert 'abort: HTTP Error 403: Forbidden' in stderr
339 assert 'abort: HTTP Error 403: Forbidden' in stderr
326 finally:
340 finally:
327 # release IP restrictions
341 # release IP restrictions
328 for ip in UserIpMap.getAll():
342 for ip in UserIpMap.getAll():
329 UserIpMap.delete(ip.ip_id)
343 UserIpMap.delete(ip.ip_id)
330 Session().commit()
344 Session().commit()
331
345
332 time.sleep(2)
346 time.sleep(2)
333
347
334 stdout, stderr = Command('/tmp').execute(
348 stdout, stderr = Command('/tmp').execute(
335 'hg clone', clone_url, tmpdir.strpath)
349 'hg clone', clone_url, tmpdir.strpath)
336 _check_proper_clone(stdout, stderr, 'hg')
350 _check_proper_clone(stdout, stderr, 'hg')
337
351
338 def test_ip_restriction_git(self, rc_web_server, tmpdir):
352 def test_ip_restriction_git(self, rc_web_server, tmpdir):
339 user_model = UserModel()
353 user_model = UserModel()
340 try:
354 try:
341 user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
355 user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
342 Session().commit()
356 Session().commit()
343 time.sleep(2)
357 time.sleep(2)
344 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
358 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
345 stdout, stderr = Command('/tmp').execute(
359 stdout, stderr = Command('/tmp').execute(
346 'git clone', clone_url, tmpdir.strpath)
360 'git clone', clone_url, tmpdir.strpath)
347 msg = "The requested URL returned error: 403"
361 msg = "The requested URL returned error: 403"
348 assert msg in stderr
362 assert msg in stderr
349 finally:
363 finally:
350 # release IP restrictions
364 # release IP restrictions
351 for ip in UserIpMap.getAll():
365 for ip in UserIpMap.getAll():
352 UserIpMap.delete(ip.ip_id)
366 UserIpMap.delete(ip.ip_id)
353 Session().commit()
367 Session().commit()
354
368
355 time.sleep(2)
369 time.sleep(2)
356
370
357 cmd = Command('/tmp')
371 cmd = Command('/tmp')
358 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
372 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
359 cmd.assert_returncode_success()
373 cmd.assert_returncode_success()
360 _check_proper_clone(stdout, stderr, 'git')
374 _check_proper_clone(stdout, stderr, 'git')
361
375
362 def test_clone_by_auth_token(
376 def test_clone_by_auth_token(
363 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
377 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
364 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
378 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
365 'egg:rhodecode-enterprise-ce#rhodecode'])
379 'egg:rhodecode-enterprise-ce#rhodecode'])
366
380
367 user = user_util.create_user()
381 user = user_util.create_user()
368 token = user.auth_tokens[1]
382 token = user.auth_tokens[1]
369
383
370 clone_url = rc_web_server.repo_clone_url(
384 clone_url = rc_web_server.repo_clone_url(
371 HG_REPO, user=user.username, passwd=token)
385 HG_REPO, user=user.username, passwd=token)
372
386
373 stdout, stderr = Command('/tmp').execute(
387 stdout, stderr = Command('/tmp').execute(
374 'hg clone', clone_url, tmpdir.strpath)
388 'hg clone', clone_url, tmpdir.strpath)
375 _check_proper_clone(stdout, stderr, 'hg')
389 _check_proper_clone(stdout, stderr, 'hg')
376
390
377 def test_clone_by_auth_token_expired(
391 def test_clone_by_auth_token_expired(
378 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
392 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
379 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
393 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
380 'egg:rhodecode-enterprise-ce#rhodecode'])
394 'egg:rhodecode-enterprise-ce#rhodecode'])
381
395
382 user = user_util.create_user()
396 user = user_util.create_user()
383 auth_token = AuthTokenModel().create(
397 auth_token = AuthTokenModel().create(
384 user.user_id, 'test-token', -10, AuthTokenModel.cls.ROLE_VCS)
398 user.user_id, 'test-token', -10, AuthTokenModel.cls.ROLE_VCS)
385 token = auth_token.api_key
399 token = auth_token.api_key
386
400
387 clone_url = rc_web_server.repo_clone_url(
401 clone_url = rc_web_server.repo_clone_url(
388 HG_REPO, user=user.username, passwd=token)
402 HG_REPO, user=user.username, passwd=token)
389
403
390 stdout, stderr = Command('/tmp').execute(
404 stdout, stderr = Command('/tmp').execute(
391 'hg clone', clone_url, tmpdir.strpath)
405 'hg clone', clone_url, tmpdir.strpath)
392 assert 'abort: authorization failed' in stderr
406 assert 'abort: authorization failed' in stderr
393
407
394 def test_clone_by_auth_token_bad_role(
408 def test_clone_by_auth_token_bad_role(
395 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
409 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
396 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
410 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
397 'egg:rhodecode-enterprise-ce#rhodecode'])
411 'egg:rhodecode-enterprise-ce#rhodecode'])
398
412
399 user = user_util.create_user()
413 user = user_util.create_user()
400 auth_token = AuthTokenModel().create(
414 auth_token = AuthTokenModel().create(
401 user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_API)
415 user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_API)
402 token = auth_token.api_key
416 token = auth_token.api_key
403
417
404 clone_url = rc_web_server.repo_clone_url(
418 clone_url = rc_web_server.repo_clone_url(
405 HG_REPO, user=user.username, passwd=token)
419 HG_REPO, user=user.username, passwd=token)
406
420
407 stdout, stderr = Command('/tmp').execute(
421 stdout, stderr = Command('/tmp').execute(
408 'hg clone', clone_url, tmpdir.strpath)
422 'hg clone', clone_url, tmpdir.strpath)
409 assert 'abort: authorization failed' in stderr
423 assert 'abort: authorization failed' in stderr
410
424
411 def test_clone_by_auth_token_user_disabled(
425 def test_clone_by_auth_token_user_disabled(
412 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
426 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
413 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
427 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
414 'egg:rhodecode-enterprise-ce#rhodecode'])
428 'egg:rhodecode-enterprise-ce#rhodecode'])
415 user = user_util.create_user()
429 user = user_util.create_user()
416 user.active = False
430 user.active = False
417 Session().add(user)
431 Session().add(user)
418 Session().commit()
432 Session().commit()
419 token = user.auth_tokens[1]
433 token = user.auth_tokens[1]
420
434
421 clone_url = rc_web_server.repo_clone_url(
435 clone_url = rc_web_server.repo_clone_url(
422 HG_REPO, user=user.username, passwd=token)
436 HG_REPO, user=user.username, passwd=token)
423
437
424 stdout, stderr = Command('/tmp').execute(
438 stdout, stderr = Command('/tmp').execute(
425 'hg clone', clone_url, tmpdir.strpath)
439 'hg clone', clone_url, tmpdir.strpath)
426 assert 'abort: authorization failed' in stderr
440 assert 'abort: authorization failed' in stderr
427
441
428 def test_clone_by_auth_token_with_scope(
442 def test_clone_by_auth_token_with_scope(
429 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
443 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
430 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
444 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
431 'egg:rhodecode-enterprise-ce#rhodecode'])
445 'egg:rhodecode-enterprise-ce#rhodecode'])
432 user = user_util.create_user()
446 user = user_util.create_user()
433 auth_token = AuthTokenModel().create(
447 auth_token = AuthTokenModel().create(
434 user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_VCS)
448 user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_VCS)
435 token = auth_token.api_key
449 token = auth_token.api_key
436
450
437 # manually set scope
451 # manually set scope
438 auth_token.repo = Repository.get_by_repo_name(HG_REPO)
452 auth_token.repo = Repository.get_by_repo_name(HG_REPO)
439 Session().add(auth_token)
453 Session().add(auth_token)
440 Session().commit()
454 Session().commit()
441
455
442 clone_url = rc_web_server.repo_clone_url(
456 clone_url = rc_web_server.repo_clone_url(
443 HG_REPO, user=user.username, passwd=token)
457 HG_REPO, user=user.username, passwd=token)
444
458
445 stdout, stderr = Command('/tmp').execute(
459 stdout, stderr = Command('/tmp').execute(
446 'hg clone', clone_url, tmpdir.strpath)
460 'hg clone', clone_url, tmpdir.strpath)
447 _check_proper_clone(stdout, stderr, 'hg')
461 _check_proper_clone(stdout, stderr, 'hg')
448
462
449 def test_clone_by_auth_token_with_wrong_scope(
463 def test_clone_by_auth_token_with_wrong_scope(
450 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
464 self, rc_web_server, tmpdir, user_util, enable_auth_plugins):
451 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
465 enable_auth_plugins(['egg:rhodecode-enterprise-ce#token',
452 'egg:rhodecode-enterprise-ce#rhodecode'])
466 'egg:rhodecode-enterprise-ce#rhodecode'])
453 user = user_util.create_user()
467 user = user_util.create_user()
454 auth_token = AuthTokenModel().create(
468 auth_token = AuthTokenModel().create(
455 user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_VCS)
469 user.user_id, 'test-token', -1, AuthTokenModel.cls.ROLE_VCS)
456 token = auth_token.api_key
470 token = auth_token.api_key
457
471
458 # manually set scope
472 # manually set scope
459 auth_token.repo = Repository.get_by_repo_name(GIT_REPO)
473 auth_token.repo = Repository.get_by_repo_name(GIT_REPO)
460 Session().add(auth_token)
474 Session().add(auth_token)
461 Session().commit()
475 Session().commit()
462
476
463 clone_url = rc_web_server.repo_clone_url(
477 clone_url = rc_web_server.repo_clone_url(
464 HG_REPO, user=user.username, passwd=token)
478 HG_REPO, user=user.username, passwd=token)
465
479
466 stdout, stderr = Command('/tmp').execute(
480 stdout, stderr = Command('/tmp').execute(
467 'hg clone', clone_url, tmpdir.strpath)
481 'hg clone', clone_url, tmpdir.strpath)
468 assert 'abort: authorization failed' in stderr
482 assert 'abort: authorization failed' in stderr
469
483
General Comments 0
You need to be logged in to leave comments. Login now