Show More
@@ -1,89 +1,91 | |||
|
1 | 1 | # Copyright (C) 2010-2024 RhodeCode GmbH |
|
2 | 2 | # |
|
3 | 3 | # This program is free software: you can redistribute it and/or modify |
|
4 | 4 | # it under the terms of the GNU Affero General Public License, version 3 |
|
5 | 5 | # (only), as published by the Free Software Foundation. |
|
6 | 6 | # |
|
7 | 7 | # This program is distributed in the hope that it will be useful, |
|
8 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 | 10 | # GNU General Public License for more details. |
|
11 | 11 | # |
|
12 | 12 | # You should have received a copy of the GNU Affero General Public License |
|
13 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
14 | 14 | # |
|
15 | 15 | # This program is dual-licensed. If you wish to learn more about the |
|
16 | 16 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
17 | 17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
18 | 18 | |
|
19 | 19 | """ |
|
20 | 20 | Test suite for making push/pull operations, on specially modified INI files |
|
21 | 21 | """ |
|
22 | 22 | |
|
23 | 23 | import pytest |
|
24 | from importlib.metadata import version | |
|
24 | 25 | |
|
25 | 26 | from rhodecode.model.meta import Session |
|
26 | 27 | from rhodecode.model.settings import SettingsModel |
|
27 | 28 | |
|
28 | 29 | from rhodecode.tests import GIT_REPO, HG_REPO |
|
29 | 30 | from rhodecode.tests.vcs_operations import Command, _add_files_and_push |
|
30 | 31 | |
|
31 | 32 | |
|
32 | 33 | @pytest.fixture() |
|
33 | 34 | def bad_client_setter_factory(request): |
|
34 | 35 | def _factory(client_type, client_str_val): |
|
35 | 36 | # set allowed clients |
|
36 | 37 | setting = SettingsModel().create_or_update_setting(name=f"{client_type}_allowed_clients", val=client_str_val) |
|
37 | 38 | Session().add(setting) |
|
38 | 39 | Session().commit() |
|
39 | 40 | |
|
40 | 41 | @request.addfinalizer |
|
41 | 42 | def cleanup(): |
|
42 | 43 | setting2 = SettingsModel().create_or_update_setting(name=f"{client_type}_allowed_clients", val="*") |
|
43 | 44 | Session().add(setting2) |
|
44 | 45 | Session().commit() |
|
45 | 46 | |
|
46 | 47 | return _factory |
|
47 | 48 | |
|
48 | 49 | |
|
49 | 50 | @pytest.mark.usefixtures( |
|
50 | 51 | "init_pyramid_app", |
|
51 | 52 | "repo_group_repos", |
|
52 | 53 | "disable_anonymous_user", |
|
53 | 54 | "disable_locking", |
|
54 | 55 | ) |
|
55 | 56 | class TestVCSOperationsOnUsingBadClient(object): |
|
56 | 57 | def test_push_with_bad_client_repo_by_other_user_hg(self, rcstack, tmpdir): |
|
57 | 58 | clone_url = rcstack.repo_clone_url(HG_REPO) |
|
58 | 59 | stdout, stderr = Command(tmpdir.strpath).execute("hg clone", clone_url, tmpdir.strpath) |
|
59 | 60 | |
|
60 | 61 | # set allowed clients |
|
61 | 62 | setting = SettingsModel().create_or_update_setting(name=f"hg_allowed_clients", val="0.0.0") |
|
62 | 63 | Session().add(setting) |
|
63 | 64 | Session().commit() |
|
64 | 65 | |
|
65 | 66 | # push fails repo is locked by other user ! |
|
66 | 67 | push_url = rcstack.repo_clone_url(HG_REPO) |
|
67 | 68 | stdout, stderr = _add_files_and_push("hg", tmpdir.strpath, clone_url=push_url) |
|
68 | msg = "Your hg client (version=mercurial/proto-1.0 (Mercurial 6.7.4)) is forbidden by security rules" | |
|
69 | current_version = version('mercurial') | |
|
70 | msg = f"Your hg client (version=mercurial/proto-1.0 (Mercurial {current_version})) is forbidden by security rules" | |
|
69 | 71 | assert msg in stderr |
|
70 | 72 | |
|
71 | 73 | def test_push_with_bad_client_repo_by_other_user_git(self, rcstack, tmpdir): |
|
72 | 74 | clone_url = rcstack.repo_clone_url(GIT_REPO) |
|
73 | 75 | stdout, stderr = Command(tmpdir.strpath).execute("git clone", clone_url, tmpdir.strpath) |
|
74 | 76 | |
|
75 | 77 | # set allowed clients |
|
76 | 78 | setting = SettingsModel().create_or_update_setting(name=f"git_allowed_clients", val="0.0.0") |
|
77 | 79 | Session().add(setting) |
|
78 | 80 | Session().commit() |
|
79 | 81 | |
|
80 | 82 | # push fails repo is locked by other user! |
|
81 | 83 | push_url = rcstack.repo_clone_url(GIT_REPO) |
|
82 | 84 | stdout, stderr = _add_files_and_push("git", tmpdir.strpath, clone_url=push_url) |
|
83 | 85 | |
|
84 | 86 | err = "Your git client (version=git/2.45.2) is forbidden by security rules" |
|
85 | 87 | assert err in stderr |
|
86 | 88 | |
|
87 | 89 | @pytest.mark.xfail(reason="Lack of proper SVN support of cloning") |
|
88 | 90 | def test_push_with_bad_client_repo_by_other_user_svn(self, rcstack, tmpdir): |
|
89 | 91 | raise NotImplementedError("lacks svn support") |
General Comments 0
You need to be logged in to leave comments.
Login now