Show More
@@ -1,373 +1,376 b'' | |||||
1 |
|
1 | |||
2 | # Copyright (C) 2010-2023 RhodeCode GmbH |
|
2 | # Copyright (C) 2010-2023 RhodeCode GmbH | |
3 | # |
|
3 | # | |
4 | # This program is free software: you can redistribute it and/or modify |
|
4 | # This program is free software: you can redistribute it and/or modify | |
5 | # it under the terms of the GNU Affero General Public License, version 3 |
|
5 | # it under the terms of the GNU Affero General Public License, version 3 | |
6 | # (only), as published by the Free Software Foundation. |
|
6 | # (only), as published by the Free Software Foundation. | |
7 | # |
|
7 | # | |
8 | # This program is distributed in the hope that it will be useful, |
|
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. |
|
11 | # GNU General Public License for more details. | |
12 | # |
|
12 | # | |
13 | # You should have received a copy of the GNU Affero General Public License |
|
13 | # You should have received a copy of the GNU Affero General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | # |
|
15 | # | |
16 | # This program is dual-licensed. If you wish to learn more about the |
|
16 | # This program is dual-licensed. If you wish to learn more about the | |
17 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
17 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
18 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
18 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
19 |
|
19 | |||
20 | """ |
|
20 | """ | |
21 | Test suite for making push/pull operations, on specially modified INI files |
|
21 | Test suite for making push/pull operations, on specially modified INI files | |
22 |
|
22 | |||
23 | .. important:: |
|
23 | .. important:: | |
24 |
|
24 | |||
25 | You must have git >= 1.8.5 for tests to work fine. With 68b939b git started |
|
25 | You must have git >= 1.8.5 for tests to work fine. With 68b939b git started | |
26 | to redirect things to stderr instead of stdout. |
|
26 | to redirect things to stderr instead of stdout. | |
27 | """ |
|
27 | """ | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | import time |
|
30 | import time | |
31 | import logging |
|
31 | import logging | |
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 | from rhodecode.tests.utils import assert_message_in_log |
|
42 | from rhodecode.tests.utils import assert_message_in_log | |
43 |
|
43 | |||
44 | from rhodecode.tests.vcs_operations import ( |
|
44 | from rhodecode.tests.vcs_operations import ( | |
45 | Command, _check_proper_clone, _check_proper_git_push, |
|
45 | Command, _check_proper_clone, _check_proper_git_push, | |
46 | _add_files_and_push, HG_REPO_WITH_GROUP, GIT_REPO_WITH_GROUP) |
|
46 | _add_files_and_push, HG_REPO_WITH_GROUP, GIT_REPO_WITH_GROUP) | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user") |
|
49 | @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user") | |
50 | class TestVCSOperations(object): |
|
50 | class TestVCSOperations(object): | |
51 |
|
51 | |||
52 | def test_clone_hg_repo_by_admin(self, rc_web_server, tmpdir): |
|
52 | def test_clone_hg_repo_by_admin(self, rc_web_server, tmpdir): | |
53 | clone_url = rc_web_server.repo_clone_url(HG_REPO) |
|
53 | clone_url = rc_web_server.repo_clone_url(HG_REPO) | |
54 | stdout, stderr = Command('/tmp').execute( |
|
54 | stdout, stderr = Command('/tmp').execute( | |
55 | 'hg clone', clone_url, tmpdir.strpath) |
|
55 | 'hg clone', clone_url, tmpdir.strpath) | |
56 | _check_proper_clone(stdout, stderr, 'hg') |
|
56 | _check_proper_clone(stdout, stderr, 'hg') | |
57 |
|
57 | |||
58 | def test_clone_hg_repo_by_admin_pull_protocol(self, rc_web_server, tmpdir): |
|
58 | def test_clone_hg_repo_by_admin_pull_protocol(self, rc_web_server, tmpdir): | |
59 | clone_url = rc_web_server.repo_clone_url(HG_REPO) |
|
59 | clone_url = rc_web_server.repo_clone_url(HG_REPO) | |
60 | stdout, stderr = Command('/tmp').execute( |
|
60 | stdout, stderr = Command('/tmp').execute( | |
61 | 'hg clone --pull', clone_url, tmpdir.strpath) |
|
61 | 'hg clone --pull', clone_url, tmpdir.strpath) | |
62 | _check_proper_clone(stdout, stderr, 'hg') |
|
62 | _check_proper_clone(stdout, stderr, 'hg') | |
63 |
|
63 | |||
64 | def test_clone_hg_repo_by_admin_pull_stream_protocol(self, rc_web_server, tmpdir): |
|
64 | def test_clone_hg_repo_by_admin_pull_stream_protocol(self, rc_web_server, tmpdir): | |
65 | clone_url = rc_web_server.repo_clone_url(HG_REPO) |
|
65 | clone_url = rc_web_server.repo_clone_url(HG_REPO) | |
66 | stdout, stderr = Command('/tmp').execute( |
|
66 | stdout, stderr = Command('/tmp').execute( | |
67 | 'hg clone --pull --stream', clone_url, tmpdir.strpath) |
|
67 | 'hg clone --pull --stream', clone_url, tmpdir.strpath) | |
68 | assert 'files to transfer,' in stdout |
|
68 | assert 'files to transfer,' in stdout | |
69 | assert 'transferred 1.' in stdout |
|
69 | assert 'transferred 1.' in stdout | |
70 | assert '114 files updated,' in stdout |
|
70 | assert '114 files updated,' in stdout | |
71 |
|
71 | |||
72 | def test_clone_git_repo_by_admin(self, rc_web_server, tmpdir): |
|
72 | def test_clone_git_repo_by_admin(self, rc_web_server, tmpdir): | |
73 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) |
|
73 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) | |
74 | cmd = Command('/tmp') |
|
74 | cmd = Command('/tmp') | |
75 | stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) |
|
75 | stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) | |
76 | _check_proper_clone(stdout, stderr, 'git') |
|
76 | _check_proper_clone(stdout, stderr, 'git') | |
77 | cmd.assert_returncode_success() |
|
77 | cmd.assert_returncode_success() | |
78 |
|
78 | |||
79 | def test_clone_git_repo_by_admin_with_git_suffix(self, rc_web_server, tmpdir): |
|
79 | def test_clone_git_repo_by_admin_with_git_suffix(self, rc_web_server, tmpdir): | |
80 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) |
|
80 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) | |
81 | cmd = Command('/tmp') |
|
81 | cmd = Command('/tmp') | |
82 | stdout, stderr = cmd.execute('git clone', clone_url+".git", tmpdir.strpath) |
|
82 | stdout, stderr = cmd.execute('git clone', clone_url+".git", tmpdir.strpath) | |
83 | _check_proper_clone(stdout, stderr, 'git') |
|
83 | _check_proper_clone(stdout, stderr, 'git') | |
84 | cmd.assert_returncode_success() |
|
84 | cmd.assert_returncode_success() | |
85 |
|
85 | |||
86 | def test_clone_hg_repo_by_id_by_admin(self, rc_web_server, tmpdir): |
|
86 | def test_clone_hg_repo_by_id_by_admin(self, rc_web_server, tmpdir): | |
87 | repo_id = Repository.get_by_repo_name(HG_REPO).repo_id |
|
87 | repo_id = Repository.get_by_repo_name(HG_REPO).repo_id | |
88 | clone_url = rc_web_server.repo_clone_url('_%s' % repo_id) |
|
88 | clone_url = rc_web_server.repo_clone_url('_%s' % repo_id) | |
89 | stdout, stderr = Command('/tmp').execute( |
|
89 | stdout, stderr = Command('/tmp').execute( | |
90 | 'hg clone', clone_url, tmpdir.strpath) |
|
90 | 'hg clone', clone_url, tmpdir.strpath) | |
91 | _check_proper_clone(stdout, stderr, 'hg') |
|
91 | _check_proper_clone(stdout, stderr, 'hg') | |
92 |
|
92 | |||
93 | def test_clone_git_repo_by_id_by_admin(self, rc_web_server, tmpdir): |
|
93 | def test_clone_git_repo_by_id_by_admin(self, rc_web_server, tmpdir): | |
94 | repo_id = Repository.get_by_repo_name(GIT_REPO).repo_id |
|
94 | repo_id = Repository.get_by_repo_name(GIT_REPO).repo_id | |
95 | clone_url = rc_web_server.repo_clone_url('_%s' % repo_id) |
|
95 | clone_url = rc_web_server.repo_clone_url('_%s' % repo_id) | |
96 | cmd = Command('/tmp') |
|
96 | cmd = Command('/tmp') | |
97 | stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) |
|
97 | stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) | |
98 | _check_proper_clone(stdout, stderr, 'git') |
|
98 | _check_proper_clone(stdout, stderr, 'git') | |
99 | cmd.assert_returncode_success() |
|
99 | cmd.assert_returncode_success() | |
100 |
|
100 | |||
101 | def test_clone_hg_repo_with_group_by_admin(self, rc_web_server, tmpdir): |
|
101 | def test_clone_hg_repo_with_group_by_admin(self, rc_web_server, tmpdir): | |
102 | clone_url = rc_web_server.repo_clone_url(HG_REPO_WITH_GROUP) |
|
102 | clone_url = rc_web_server.repo_clone_url(HG_REPO_WITH_GROUP) | |
103 | stdout, stderr = Command('/tmp').execute( |
|
103 | stdout, stderr = Command('/tmp').execute( | |
104 | 'hg clone', clone_url, tmpdir.strpath) |
|
104 | 'hg clone', clone_url, tmpdir.strpath) | |
105 | _check_proper_clone(stdout, stderr, 'hg') |
|
105 | _check_proper_clone(stdout, stderr, 'hg') | |
106 |
|
106 | |||
107 | def test_clone_git_repo_with_group_by_admin(self, rc_web_server, tmpdir): |
|
107 | def test_clone_git_repo_with_group_by_admin(self, rc_web_server, tmpdir): | |
108 | clone_url = rc_web_server.repo_clone_url(GIT_REPO_WITH_GROUP) |
|
108 | clone_url = rc_web_server.repo_clone_url(GIT_REPO_WITH_GROUP) | |
109 | cmd = Command('/tmp') |
|
109 | cmd = Command('/tmp') | |
110 | stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) |
|
110 | stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) | |
111 | _check_proper_clone(stdout, stderr, 'git') |
|
111 | _check_proper_clone(stdout, stderr, 'git') | |
112 | cmd.assert_returncode_success() |
|
112 | cmd.assert_returncode_success() | |
113 |
|
113 | |||
114 | def test_clone_git_repo_shallow_by_admin(self, rc_web_server, tmpdir): |
|
114 | def test_clone_git_repo_shallow_by_admin(self, rc_web_server, tmpdir): | |
115 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) |
|
115 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) | |
116 | cmd = Command('/tmp') |
|
116 | cmd = Command('/tmp') | |
117 | stdout, stderr = cmd.execute( |
|
117 | stdout, stderr = cmd.execute( | |
118 | 'git clone --depth=1', clone_url, tmpdir.strpath) |
|
118 | 'git clone --depth=1', clone_url, tmpdir.strpath) | |
119 |
|
119 | |||
120 | assert '' == stdout |
|
120 | assert '' == stdout | |
121 | assert 'Cloning into' in stderr |
|
121 | assert 'Cloning into' in stderr | |
122 | cmd.assert_returncode_success() |
|
122 | cmd.assert_returncode_success() | |
123 |
|
123 | |||
124 | def test_clone_wrong_credentials_hg(self, rc_web_server, tmpdir): |
|
124 | def test_clone_wrong_credentials_hg(self, rc_web_server, tmpdir): | |
125 | clone_url = rc_web_server.repo_clone_url(HG_REPO, passwd='bad!') |
|
125 | clone_url = rc_web_server.repo_clone_url(HG_REPO, passwd='bad!') | |
126 | stdout, stderr = Command('/tmp').execute( |
|
126 | stdout, stderr = Command('/tmp').execute( | |
127 | 'hg clone', clone_url, tmpdir.strpath) |
|
127 | 'hg clone', clone_url, tmpdir.strpath) | |
128 | assert 'abort: authorization failed' in stderr |
|
128 | assert 'abort: authorization failed' in stderr | |
129 |
|
129 | |||
130 | def test_clone_wrong_credentials_git(self, rc_web_server, tmpdir): |
|
130 | def test_clone_wrong_credentials_git(self, rc_web_server, tmpdir): | |
131 | clone_url = rc_web_server.repo_clone_url(GIT_REPO, passwd='bad!') |
|
131 | clone_url = rc_web_server.repo_clone_url(GIT_REPO, passwd='bad!') | |
132 | stdout, stderr = Command('/tmp').execute( |
|
132 | stdout, stderr = Command('/tmp').execute( | |
133 | 'git clone', clone_url, tmpdir.strpath) |
|
133 | 'git clone', clone_url, tmpdir.strpath) | |
134 | assert 'fatal: Authentication failed' in stderr |
|
134 | assert 'fatal: Authentication failed' in stderr | |
135 |
|
135 | |||
136 | def test_clone_git_dir_as_hg(self, rc_web_server, tmpdir): |
|
136 | def test_clone_git_dir_as_hg(self, rc_web_server, tmpdir): | |
137 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) |
|
137 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) | |
138 | stdout, stderr = Command('/tmp').execute( |
|
138 | stdout, stderr = Command('/tmp').execute( | |
139 | 'hg clone', clone_url, tmpdir.strpath) |
|
139 | 'hg clone', clone_url, tmpdir.strpath) | |
140 | assert 'HTTP Error 404: Not Found' in stderr |
|
140 | assert 'HTTP Error 404: Not Found' in stderr | |
141 |
|
141 | |||
142 | def test_clone_hg_repo_as_git(self, rc_web_server, tmpdir): |
|
142 | def test_clone_hg_repo_as_git(self, rc_web_server, tmpdir): | |
143 | clone_url = rc_web_server.repo_clone_url(HG_REPO) |
|
143 | clone_url = rc_web_server.repo_clone_url(HG_REPO) | |
144 | stdout, stderr = Command('/tmp').execute( |
|
144 | stdout, stderr = Command('/tmp').execute( | |
145 | 'git clone', clone_url, tmpdir.strpath) |
|
145 | 'git clone', clone_url, tmpdir.strpath) | |
146 | assert 'not found' in stderr |
|
146 | assert 'not found' in stderr | |
147 |
|
147 | |||
148 | def test_clone_non_existing_path_hg(self, rc_web_server, tmpdir): |
|
148 | def test_clone_non_existing_path_hg(self, rc_web_server, tmpdir): | |
149 | clone_url = rc_web_server.repo_clone_url('trololo') |
|
149 | clone_url = rc_web_server.repo_clone_url('trololo') | |
150 | stdout, stderr = Command('/tmp').execute( |
|
150 | stdout, stderr = Command('/tmp').execute( | |
151 | 'hg clone', clone_url, tmpdir.strpath) |
|
151 | 'hg clone', clone_url, tmpdir.strpath) | |
152 | assert 'HTTP Error 404: Not Found' in stderr |
|
152 | assert 'HTTP Error 404: Not Found' in stderr | |
153 |
|
153 | |||
154 | def test_clone_non_existing_path_git(self, rc_web_server, tmpdir): |
|
154 | def test_clone_non_existing_path_git(self, rc_web_server, tmpdir): | |
155 | clone_url = rc_web_server.repo_clone_url('trololo') |
|
155 | clone_url = rc_web_server.repo_clone_url('trololo') | |
156 | stdout, stderr = Command('/tmp').execute('git clone', clone_url) |
|
156 | stdout, stderr = Command('/tmp').execute('git clone', clone_url) | |
157 | assert 'not found' in stderr |
|
157 | assert 'not found' in stderr | |
158 |
|
158 | |||
159 | def test_clone_hg_with_slashes(self, rc_web_server, tmpdir): |
|
159 | def test_clone_hg_with_slashes(self, rc_web_server, tmpdir): | |
160 | clone_url = rc_web_server.repo_clone_url('//' + HG_REPO) |
|
160 | clone_url = rc_web_server.repo_clone_url('//' + HG_REPO) | |
161 | stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) |
|
161 | stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) | |
162 | assert 'HTTP Error 404: Not Found' in stderr |
|
162 | assert 'HTTP Error 404: Not Found' in stderr | |
163 |
|
163 | |||
164 | def test_clone_git_with_slashes(self, rc_web_server, tmpdir): |
|
164 | def test_clone_git_with_slashes(self, rc_web_server, tmpdir): | |
165 | clone_url = rc_web_server.repo_clone_url('//' + GIT_REPO) |
|
165 | clone_url = rc_web_server.repo_clone_url('//' + GIT_REPO) | |
166 | stdout, stderr = Command('/tmp').execute('git clone', clone_url) |
|
166 | stdout, stderr = Command('/tmp').execute('git clone', clone_url) | |
167 | assert 'not found' in stderr |
|
167 | assert 'not found' in stderr | |
168 |
|
168 | |||
169 | def test_clone_existing_path_hg_not_in_database( |
|
169 | def test_clone_existing_path_hg_not_in_database( | |
170 | self, rc_web_server, tmpdir, fs_repo_only): |
|
170 | self, rc_web_server, tmpdir, fs_repo_only): | |
171 |
|
171 | |||
172 | db_name = fs_repo_only('not-in-db-hg', repo_type='hg') |
|
172 | db_name = fs_repo_only('not-in-db-hg', repo_type='hg') | |
173 | clone_url = rc_web_server.repo_clone_url(db_name) |
|
173 | clone_url = rc_web_server.repo_clone_url(db_name) | |
174 | stdout, stderr = Command('/tmp').execute( |
|
174 | stdout, stderr = Command('/tmp').execute( | |
175 | 'hg clone', clone_url, tmpdir.strpath) |
|
175 | 'hg clone', clone_url, tmpdir.strpath) | |
176 | assert 'HTTP Error 404: Not Found' in stderr |
|
176 | assert 'HTTP Error 404: Not Found' in stderr | |
177 |
|
177 | |||
178 | def test_clone_existing_path_git_not_in_database( |
|
178 | def test_clone_existing_path_git_not_in_database( | |
179 | self, rc_web_server, tmpdir, fs_repo_only): |
|
179 | self, rc_web_server, tmpdir, fs_repo_only): | |
180 | db_name = fs_repo_only('not-in-db-git', repo_type='git') |
|
180 | db_name = fs_repo_only('not-in-db-git', repo_type='git') | |
181 | clone_url = rc_web_server.repo_clone_url(db_name) |
|
181 | clone_url = rc_web_server.repo_clone_url(db_name) | |
182 | stdout, stderr = Command('/tmp').execute( |
|
182 | stdout, stderr = Command('/tmp').execute( | |
183 | 'git clone', clone_url, tmpdir.strpath) |
|
183 | 'git clone', clone_url, tmpdir.strpath) | |
184 | assert 'not found' in stderr |
|
184 | assert 'not found' in stderr | |
185 |
|
185 | |||
186 | def test_clone_existing_path_hg_not_in_database_different_scm( |
|
186 | def test_clone_existing_path_hg_not_in_database_different_scm( | |
187 | self, rc_web_server, tmpdir, fs_repo_only): |
|
187 | self, rc_web_server, tmpdir, fs_repo_only): | |
188 | db_name = fs_repo_only('not-in-db-git', repo_type='git') |
|
188 | db_name = fs_repo_only('not-in-db-git', repo_type='git') | |
189 | clone_url = rc_web_server.repo_clone_url(db_name) |
|
189 | clone_url = rc_web_server.repo_clone_url(db_name) | |
190 | stdout, stderr = Command('/tmp').execute( |
|
190 | stdout, stderr = Command('/tmp').execute( | |
191 | 'hg clone', clone_url, tmpdir.strpath) |
|
191 | 'hg clone', clone_url, tmpdir.strpath) | |
192 | assert 'HTTP Error 404: Not Found' in stderr |
|
192 | assert 'HTTP Error 404: Not Found' in stderr | |
193 |
|
193 | |||
194 | def test_clone_existing_path_git_not_in_database_different_scm( |
|
194 | def test_clone_existing_path_git_not_in_database_different_scm( | |
195 | self, rc_web_server, tmpdir, fs_repo_only): |
|
195 | self, rc_web_server, tmpdir, fs_repo_only): | |
196 | db_name = fs_repo_only('not-in-db-hg', repo_type='hg') |
|
196 | db_name = fs_repo_only('not-in-db-hg', repo_type='hg') | |
197 | clone_url = rc_web_server.repo_clone_url(db_name) |
|
197 | clone_url = rc_web_server.repo_clone_url(db_name) | |
198 | stdout, stderr = Command('/tmp').execute( |
|
198 | stdout, stderr = Command('/tmp').execute( | |
199 | 'git clone', clone_url, tmpdir.strpath) |
|
199 | 'git clone', clone_url, tmpdir.strpath) | |
200 | assert 'not found' in stderr |
|
200 | assert 'not found' in stderr | |
201 |
|
201 | |||
202 | def test_clone_non_existing_store_path_hg(self, rc_web_server, tmpdir, user_util): |
|
202 | def test_clone_non_existing_store_path_hg(self, rc_web_server, tmpdir, user_util): | |
203 | repo = user_util.create_repo() |
|
203 | repo = user_util.create_repo() | |
204 | clone_url = rc_web_server.repo_clone_url(repo.repo_name) |
|
204 | clone_url = rc_web_server.repo_clone_url(repo.repo_name) | |
205 |
|
205 | |||
206 | # Damage repo by removing it's folder |
|
206 | # Damage repo by removing it's folder | |
207 | RepoModel()._delete_filesystem_repo(repo) |
|
207 | RepoModel()._delete_filesystem_repo(repo) | |
208 |
|
208 | |||
209 | stdout, stderr = Command('/tmp').execute( |
|
209 | stdout, stderr = Command('/tmp').execute( | |
210 | 'hg clone', clone_url, tmpdir.strpath) |
|
210 | 'hg clone', clone_url, tmpdir.strpath) | |
211 | assert 'HTTP Error 404: Not Found' in stderr |
|
211 | assert 'HTTP Error 404: Not Found' in stderr | |
212 |
|
212 | |||
213 | def test_clone_non_existing_store_path_git(self, rc_web_server, tmpdir, user_util): |
|
213 | def test_clone_non_existing_store_path_git(self, rc_web_server, tmpdir, user_util): | |
214 | repo = user_util.create_repo(repo_type='git') |
|
214 | repo = user_util.create_repo(repo_type='git') | |
215 | clone_url = rc_web_server.repo_clone_url(repo.repo_name) |
|
215 | clone_url = rc_web_server.repo_clone_url(repo.repo_name) | |
216 |
|
216 | |||
217 | # Damage repo by removing it's folder |
|
217 | # Damage repo by removing it's folder | |
218 | RepoModel()._delete_filesystem_repo(repo) |
|
218 | RepoModel()._delete_filesystem_repo(repo) | |
219 |
|
219 | |||
220 | stdout, stderr = Command('/tmp').execute( |
|
220 | stdout, stderr = Command('/tmp').execute( | |
221 | 'git clone', clone_url, tmpdir.strpath) |
|
221 | 'git clone', clone_url, tmpdir.strpath) | |
222 | assert 'not found' in stderr |
|
222 | assert 'not found' in stderr | |
223 |
|
223 | |||
224 | def test_push_new_file_hg(self, rc_web_server, tmpdir): |
|
224 | def test_push_new_file_hg(self, rc_web_server, tmpdir): | |
225 | clone_url = rc_web_server.repo_clone_url(HG_REPO) |
|
225 | clone_url = rc_web_server.repo_clone_url(HG_REPO) | |
226 | stdout, stderr = Command('/tmp').execute( |
|
226 | stdout, stderr = Command('/tmp').execute( | |
227 | 'hg clone', clone_url, tmpdir.strpath) |
|
227 | 'hg clone', clone_url, tmpdir.strpath) | |
228 |
|
228 | |||
229 | stdout, stderr = _add_files_and_push( |
|
229 | stdout, stderr = _add_files_and_push( | |
230 | 'hg', tmpdir.strpath, clone_url=clone_url) |
|
230 | 'hg', tmpdir.strpath, clone_url=clone_url) | |
231 |
|
231 | |||
232 | assert 'pushing to' in stdout |
|
232 | assert 'pushing to' in stdout | |
233 | assert 'size summary' in stdout |
|
233 | assert 'size summary' in stdout | |
234 |
|
234 | |||
235 | def test_push_new_file_git(self, rc_web_server, tmpdir): |
|
235 | def test_push_new_file_git(self, rc_web_server, tmpdir): | |
236 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) |
|
236 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) | |
237 | stdout, stderr = Command('/tmp').execute( |
|
237 | stdout, stderr = Command('/tmp').execute( | |
238 | 'git clone', clone_url, tmpdir.strpath) |
|
238 | 'git clone', clone_url, tmpdir.strpath) | |
239 |
|
239 | |||
240 | # commit some stuff into this repo |
|
240 | # commit some stuff into this repo | |
241 | stdout, stderr = _add_files_and_push( |
|
241 | stdout, stderr = _add_files_and_push( | |
242 | 'git', tmpdir.strpath, clone_url=clone_url) |
|
242 | 'git', tmpdir.strpath, clone_url=clone_url) | |
243 |
|
243 | |||
244 | _check_proper_git_push(stdout, stderr) |
|
244 | _check_proper_git_push(stdout, stderr) | |
245 |
|
245 | |||
246 | def test_push_invalidates_cache(self, rc_web_server, tmpdir): |
|
246 | def test_push_invalidates_cache(self, rc_web_server, tmpdir): | |
247 | hg_repo = Repository.get_by_repo_name(HG_REPO) |
|
247 | hg_repo = Repository.get_by_repo_name(HG_REPO) | |
248 |
|
248 | |||
249 | # init cache objects |
|
249 | # init cache objects | |
250 | CacheKey.delete_all_cache() |
|
250 | CacheKey.delete_all_cache() | |
251 | cache_namespace_uid = 'cache_push_test.{}'.format(hg_repo.repo_id) |
|
251 | ||
252 | repo_namespace_key = CacheKey.REPO_INVALIDATION_NAMESPACE.format(repo_id=hg_repo.repo_id) |
|
252 | repo_namespace_key = CacheKey.REPO_INVALIDATION_NAMESPACE.format(repo_id=hg_repo.repo_id) | |
253 |
|
253 | |||
254 | inv_context_manager = rc_cache.InvalidationContext(key=repo_namespace_key) |
|
254 | inv_context_manager = rc_cache.InvalidationContext(key=repo_namespace_key) | |
255 |
|
255 | |||
256 | with inv_context_manager as invalidation_context: |
|
256 | with inv_context_manager as invalidation_context: | |
257 | # __enter__ will create and register cache objects |
|
257 | # __enter__ will create and register cache objects | |
258 | pass |
|
258 | pass | |
259 |
|
259 | |||
|
260 | cache_keys = hg_repo.cache_keys | |||
|
261 | assert cache_keys != [] | |||
|
262 | old_ids = [x.cache_state_uid for x in cache_keys] | |||
|
263 | ||||
260 | # clone to init cache |
|
264 | # clone to init cache | |
261 | clone_url = rc_web_server.repo_clone_url(hg_repo.repo_name) |
|
265 | clone_url = rc_web_server.repo_clone_url(hg_repo.repo_name) | |
262 | stdout, stderr = Command('/tmp').execute( |
|
266 | stdout, stderr = Command('/tmp').execute( | |
263 | 'hg clone', clone_url, tmpdir.strpath) |
|
267 | 'hg clone', clone_url, tmpdir.strpath) | |
264 |
|
268 | |||
265 | cache_keys = hg_repo.cache_keys |
|
269 | cache_keys = hg_repo.cache_keys | |
266 | assert cache_keys != [] |
|
270 | assert cache_keys != [] | |
267 | for key in cache_keys: |
|
271 | for key in cache_keys: | |
268 | assert key.cache_active is True |
|
272 | assert key.cache_active is True | |
269 |
|
273 | |||
270 | # PUSH that should trigger invalidation cache |
|
274 | # PUSH that should trigger invalidation cache | |
271 | stdout, stderr = _add_files_and_push( |
|
275 | stdout, stderr = _add_files_and_push( | |
272 | 'hg', tmpdir.strpath, clone_url=clone_url, files_no=1) |
|
276 | 'hg', tmpdir.strpath, clone_url=clone_url, files_no=1) | |
273 |
|
277 | |||
274 | # flush... |
|
278 | # flush... | |
275 | Session().commit() |
|
279 | Session().commit() | |
276 | hg_repo = Repository.get_by_repo_name(HG_REPO) |
|
280 | hg_repo = Repository.get_by_repo_name(HG_REPO) | |
277 | cache_keys = hg_repo.cache_keys |
|
281 | cache_keys = hg_repo.cache_keys | |
278 | assert cache_keys != [] |
|
282 | assert cache_keys != [] | |
279 | for key in cache_keys: |
|
283 | new_ids = [x.cache_state_uid for x in cache_keys] | |
280 | # keys should be marked as not active |
|
284 | assert new_ids != old_ids | |
281 | assert key.cache_active is False |
|
|||
282 |
|
285 | |||
283 | def test_push_wrong_credentials_hg(self, rc_web_server, tmpdir): |
|
286 | def test_push_wrong_credentials_hg(self, rc_web_server, tmpdir): | |
284 | clone_url = rc_web_server.repo_clone_url(HG_REPO) |
|
287 | clone_url = rc_web_server.repo_clone_url(HG_REPO) | |
285 | stdout, stderr = Command('/tmp').execute( |
|
288 | stdout, stderr = Command('/tmp').execute( | |
286 | 'hg clone', clone_url, tmpdir.strpath) |
|
289 | 'hg clone', clone_url, tmpdir.strpath) | |
287 |
|
290 | |||
288 | push_url = rc_web_server.repo_clone_url( |
|
291 | push_url = rc_web_server.repo_clone_url( | |
289 | HG_REPO, user='bad', passwd='name') |
|
292 | HG_REPO, user='bad', passwd='name') | |
290 | stdout, stderr = _add_files_and_push( |
|
293 | stdout, stderr = _add_files_and_push( | |
291 | 'hg', tmpdir.strpath, clone_url=push_url) |
|
294 | 'hg', tmpdir.strpath, clone_url=push_url) | |
292 |
|
295 | |||
293 | assert 'abort: authorization failed' in stderr |
|
296 | assert 'abort: authorization failed' in stderr | |
294 |
|
297 | |||
295 | def test_push_wrong_credentials_git(self, rc_web_server, tmpdir): |
|
298 | def test_push_wrong_credentials_git(self, rc_web_server, tmpdir): | |
296 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) |
|
299 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) | |
297 | stdout, stderr = Command('/tmp').execute( |
|
300 | stdout, stderr = Command('/tmp').execute( | |
298 | 'git clone', clone_url, tmpdir.strpath) |
|
301 | 'git clone', clone_url, tmpdir.strpath) | |
299 |
|
302 | |||
300 | push_url = rc_web_server.repo_clone_url( |
|
303 | push_url = rc_web_server.repo_clone_url( | |
301 | GIT_REPO, user='bad', passwd='name') |
|
304 | GIT_REPO, user='bad', passwd='name') | |
302 | stdout, stderr = _add_files_and_push( |
|
305 | stdout, stderr = _add_files_and_push( | |
303 | 'git', tmpdir.strpath, clone_url=push_url) |
|
306 | 'git', tmpdir.strpath, clone_url=push_url) | |
304 |
|
307 | |||
305 | assert 'fatal: Authentication failed' in stderr |
|
308 | assert 'fatal: Authentication failed' in stderr | |
306 |
|
309 | |||
307 | def test_push_back_to_wrong_url_hg(self, rc_web_server, tmpdir): |
|
310 | def test_push_back_to_wrong_url_hg(self, rc_web_server, tmpdir): | |
308 | clone_url = rc_web_server.repo_clone_url(HG_REPO) |
|
311 | clone_url = rc_web_server.repo_clone_url(HG_REPO) | |
309 | stdout, stderr = Command('/tmp').execute( |
|
312 | stdout, stderr = Command('/tmp').execute( | |
310 | 'hg clone', clone_url, tmpdir.strpath) |
|
313 | 'hg clone', clone_url, tmpdir.strpath) | |
311 |
|
314 | |||
312 | stdout, stderr = _add_files_and_push( |
|
315 | stdout, stderr = _add_files_and_push( | |
313 | 'hg', tmpdir.strpath, |
|
316 | 'hg', tmpdir.strpath, | |
314 | clone_url=rc_web_server.repo_clone_url('not-existing')) |
|
317 | clone_url=rc_web_server.repo_clone_url('not-existing')) | |
315 |
|
318 | |||
316 | assert 'HTTP Error 404: Not Found' in stderr |
|
319 | assert 'HTTP Error 404: Not Found' in stderr | |
317 |
|
320 | |||
318 | def test_push_back_to_wrong_url_git(self, rc_web_server, tmpdir): |
|
321 | def test_push_back_to_wrong_url_git(self, rc_web_server, tmpdir): | |
319 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) |
|
322 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) | |
320 | stdout, stderr = Command('/tmp').execute( |
|
323 | stdout, stderr = Command('/tmp').execute( | |
321 | 'git clone', clone_url, tmpdir.strpath) |
|
324 | 'git clone', clone_url, tmpdir.strpath) | |
322 |
|
325 | |||
323 | stdout, stderr = _add_files_and_push( |
|
326 | stdout, stderr = _add_files_and_push( | |
324 | 'git', tmpdir.strpath, |
|
327 | 'git', tmpdir.strpath, | |
325 | clone_url=rc_web_server.repo_clone_url('not-existing')) |
|
328 | clone_url=rc_web_server.repo_clone_url('not-existing')) | |
326 |
|
329 | |||
327 | assert 'not found' in stderr |
|
330 | assert 'not found' in stderr | |
328 |
|
331 | |||
329 | def test_ip_restriction_hg(self, rc_web_server, tmpdir): |
|
332 | def test_ip_restriction_hg(self, rc_web_server, tmpdir): | |
330 | user_model = UserModel() |
|
333 | user_model = UserModel() | |
331 | try: |
|
334 | try: | |
332 | user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32') |
|
335 | user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32') | |
333 | Session().commit() |
|
336 | Session().commit() | |
334 | time.sleep(2) |
|
337 | time.sleep(2) | |
335 | clone_url = rc_web_server.repo_clone_url(HG_REPO) |
|
338 | clone_url = rc_web_server.repo_clone_url(HG_REPO) | |
336 | stdout, stderr = Command('/tmp').execute( |
|
339 | stdout, stderr = Command('/tmp').execute( | |
337 | 'hg clone', clone_url, tmpdir.strpath) |
|
340 | 'hg clone', clone_url, tmpdir.strpath) | |
338 | assert 'abort: HTTP Error 403: Forbidden' in stderr |
|
341 | assert 'abort: HTTP Error 403: Forbidden' in stderr | |
339 | finally: |
|
342 | finally: | |
340 | # release IP restrictions |
|
343 | # release IP restrictions | |
341 | for ip in UserIpMap.getAll(): |
|
344 | for ip in UserIpMap.getAll(): | |
342 | UserIpMap.delete(ip.ip_id) |
|
345 | UserIpMap.delete(ip.ip_id) | |
343 | Session().commit() |
|
346 | Session().commit() | |
344 |
|
347 | |||
345 | time.sleep(2) |
|
348 | time.sleep(2) | |
346 |
|
349 | |||
347 | stdout, stderr = Command('/tmp').execute( |
|
350 | stdout, stderr = Command('/tmp').execute( | |
348 | 'hg clone', clone_url, tmpdir.strpath) |
|
351 | 'hg clone', clone_url, tmpdir.strpath) | |
349 | _check_proper_clone(stdout, stderr, 'hg') |
|
352 | _check_proper_clone(stdout, stderr, 'hg') | |
350 |
|
353 | |||
351 | def test_ip_restriction_git(self, rc_web_server, tmpdir): |
|
354 | def test_ip_restriction_git(self, rc_web_server, tmpdir): | |
352 | user_model = UserModel() |
|
355 | user_model = UserModel() | |
353 | try: |
|
356 | try: | |
354 | user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32') |
|
357 | user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32') | |
355 | Session().commit() |
|
358 | Session().commit() | |
356 | time.sleep(2) |
|
359 | time.sleep(2) | |
357 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) |
|
360 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) | |
358 | stdout, stderr = Command('/tmp').execute( |
|
361 | stdout, stderr = Command('/tmp').execute( | |
359 | 'git clone', clone_url, tmpdir.strpath) |
|
362 | 'git clone', clone_url, tmpdir.strpath) | |
360 | msg = "The requested URL returned error: 403" |
|
363 | msg = "The requested URL returned error: 403" | |
361 | assert msg in stderr |
|
364 | assert msg in stderr | |
362 | finally: |
|
365 | finally: | |
363 | # release IP restrictions |
|
366 | # release IP restrictions | |
364 | for ip in UserIpMap.getAll(): |
|
367 | for ip in UserIpMap.getAll(): | |
365 | UserIpMap.delete(ip.ip_id) |
|
368 | UserIpMap.delete(ip.ip_id) | |
366 | Session().commit() |
|
369 | Session().commit() | |
367 |
|
370 | |||
368 | time.sleep(2) |
|
371 | time.sleep(2) | |
369 |
|
372 | |||
370 | cmd = Command('/tmp') |
|
373 | cmd = Command('/tmp') | |
371 | stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) |
|
374 | stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) | |
372 | cmd.assert_returncode_success() |
|
375 | cmd.assert_returncode_success() | |
373 | _check_proper_clone(stdout, stderr, 'git') |
|
376 | _check_proper_clone(stdout, stderr, 'git') |
General Comments 0
You need to be logged in to leave comments.
Login now