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