Show More
@@ -1,142 +1,142 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2018 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | |
|
22 | 22 | import pytest |
|
23 | 23 | |
|
24 | 24 | import rhodecode |
|
25 | 25 | from rhodecode.model.db import Repository |
|
26 | 26 | from rhodecode.model.meta import Session |
|
27 | 27 | from rhodecode.model.repo import RepoModel |
|
28 | 28 | from rhodecode.model.repo_group import RepoGroupModel |
|
29 | 29 | from rhodecode.model.settings import SettingsModel |
|
30 | 30 | from rhodecode.tests import TestController |
|
31 | 31 | from rhodecode.tests.fixture import Fixture |
|
32 | 32 | from rhodecode.lib import helpers as h |
|
33 | 33 | |
|
34 | 34 | fixture = Fixture() |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | def route_path(name, **kwargs): |
|
38 | 38 | return { |
|
39 | 39 | 'home': '/', |
|
40 | 40 | 'repo_group_home': '/{repo_group_name}' |
|
41 | 41 | }[name].format(**kwargs) |
|
42 | 42 | |
|
43 | 43 | |
|
44 | 44 | class TestHomeController(TestController): |
|
45 | 45 | |
|
46 | 46 | def test_index(self): |
|
47 | 47 | self.log_user() |
|
48 | 48 | response = self.app.get(route_path('home')) |
|
49 | 49 | # if global permission is set |
|
50 | 50 | response.mustcontain('Add Repository') |
|
51 | 51 | |
|
52 | 52 | # search for objects inside the JavaScript JSON |
|
53 | 53 | for repo in Repository.getAll(): |
|
54 | 54 | response.mustcontain('"name_raw": "%s"' % repo.repo_name) |
|
55 | 55 | |
|
56 | 56 | def test_index_contains_statics_with_ver(self): |
|
57 | 57 | from rhodecode.lib.base import calculate_version_hash |
|
58 | 58 | |
|
59 | 59 | self.log_user() |
|
60 | 60 | response = self.app.get(route_path('home')) |
|
61 | 61 | |
|
62 | 62 | rhodecode_version_hash = calculate_version_hash( |
|
63 | {'beaker.session.secret':'test-rc-uytcxaz'}) | |
|
63 | {'beaker.session.secret': 'test-rc-uytcxaz'}) | |
|
64 | 64 | response.mustcontain('style.css?ver={0}'.format(rhodecode_version_hash)) |
|
65 |
response.mustcontain(' |
|
|
66 | rhodecode_version_hash)) | |
|
65 | response.mustcontain('scripts.js?ver={0}'.format(rhodecode_version_hash)) | |
|
66 | response.mustcontain('hodecode-components.html?ver={0}'.format(rhodecode_version_hash)) | |
|
67 | 67 | |
|
68 | 68 | def test_index_contains_backend_specific_details(self, backend): |
|
69 | 69 | self.log_user() |
|
70 | 70 | response = self.app.get(route_path('home')) |
|
71 | 71 | tip = backend.repo.get_commit().raw_id |
|
72 | 72 | |
|
73 | 73 | # html in javascript variable: |
|
74 | 74 | response.mustcontain(r'<i class=\"icon-%s\"' % (backend.alias, )) |
|
75 | 75 | response.mustcontain(r'href=\"/%s\"' % (backend.repo_name, )) |
|
76 | 76 | |
|
77 | 77 | response.mustcontain("""/%s/changeset/%s""" % (backend.repo_name, tip)) |
|
78 | 78 | response.mustcontain("""Added a symlink""") |
|
79 | 79 | |
|
80 | 80 | def test_index_with_anonymous_access_disabled(self): |
|
81 | 81 | with fixture.anon_access(False): |
|
82 | 82 | response = self.app.get(route_path('home'), status=302) |
|
83 | 83 | assert 'login' in response.location |
|
84 | 84 | |
|
85 | 85 | def test_index_page_on_groups(self, autologin_user, repo_group): |
|
86 | 86 | response = self.app.get(route_path('repo_group_home', repo_group_name='gr1')) |
|
87 | 87 | response.mustcontain("gr1/repo_in_group") |
|
88 | 88 | |
|
89 | 89 | def test_index_page_on_group_with_trailing_slash( |
|
90 | 90 | self, autologin_user, repo_group): |
|
91 | 91 | response = self.app.get(route_path('repo_group_home', repo_group_name='gr1') + '/') |
|
92 | 92 | response.mustcontain("gr1/repo_in_group") |
|
93 | 93 | |
|
94 | 94 | @pytest.fixture(scope='class') |
|
95 | 95 | def repo_group(self, request): |
|
96 | 96 | gr = fixture.create_repo_group('gr1') |
|
97 | 97 | fixture.create_repo(name='gr1/repo_in_group', repo_group=gr) |
|
98 | 98 | |
|
99 | 99 | @request.addfinalizer |
|
100 | 100 | def cleanup(): |
|
101 | 101 | RepoModel().delete('gr1/repo_in_group') |
|
102 | 102 | RepoGroupModel().delete(repo_group='gr1', force_delete=True) |
|
103 | 103 | Session().commit() |
|
104 | 104 | |
|
105 | 105 | def test_index_with_name_with_tags(self, user_util, autologin_user): |
|
106 | 106 | user = user_util.create_user() |
|
107 | 107 | username = user.username |
|
108 | 108 | user.name = '<img src="/image1" onload="alert(\'Hello, World!\');">' |
|
109 | 109 | user.lastname = '#"><img src=x onerror=prompt(document.cookie);>' |
|
110 | 110 | |
|
111 | 111 | Session().add(user) |
|
112 | 112 | Session().commit() |
|
113 | 113 | user_util.create_repo(owner=username) |
|
114 | 114 | |
|
115 | 115 | response = self.app.get(route_path('home')) |
|
116 | 116 | response.mustcontain(h.html_escape(user.first_name)) |
|
117 | 117 | response.mustcontain(h.html_escape(user.last_name)) |
|
118 | 118 | |
|
119 | 119 | @pytest.mark.parametrize("name, state", [ |
|
120 | 120 | ('Disabled', False), |
|
121 | 121 | ('Enabled', True), |
|
122 | 122 | ]) |
|
123 | 123 | def test_index_show_version(self, autologin_user, name, state): |
|
124 | 124 | version_string = 'RhodeCode Enterprise %s' % rhodecode.__version__ |
|
125 | 125 | |
|
126 | 126 | sett = SettingsModel().create_or_update_setting( |
|
127 | 127 | 'show_version', state, 'bool') |
|
128 | 128 | Session().add(sett) |
|
129 | 129 | Session().commit() |
|
130 | 130 | SettingsModel().invalidate_settings_cache() |
|
131 | 131 | |
|
132 | 132 | response = self.app.get(route_path('home')) |
|
133 | 133 | if state is True: |
|
134 | 134 | response.mustcontain(version_string) |
|
135 | 135 | if state is False: |
|
136 | 136 | response.mustcontain(no=[version_string]) |
|
137 | 137 | |
|
138 | 138 | def test_logout_form_contains_csrf(self, autologin_user, csrf_token): |
|
139 | 139 | response = self.app.get(route_path('home')) |
|
140 | 140 | assert_response = response.assert_response() |
|
141 | 141 | element = assert_response.get_element('.logout #csrf_token') |
|
142 | 142 | assert element.value == csrf_token |
General Comments 0
You need to be logged in to leave comments.
Login now