##// END OF EJS Templates
tests: Adapt test to changed template.
johbo -
r89:2e1c9e51 default
parent child Browse files
Show More
@@ -1,199 +1,202 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2016 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 import pytest
22 22
23 from rhodecode.tests import assert_session_flash, url
23 from rhodecode.tests import assert_session_flash
24 from rhodecode.tests.utils import AssertResponse
24 25 from rhodecode.model.db import Session
25 26 from rhodecode.model.settings import SettingsModel
26 27
27 28
28 29 def assert_auth_settings_updated(response):
29 30 assert response.status_int == 302, 'Expected response HTTP Found 302'
30 31 assert_session_flash(response, 'Auth settings updated successfully')
31 32
32 33
33 34 @pytest.mark.usefixtures("autologin_user", "app")
34 35 class TestAuthSettingsController(object):
35 36
36 37 def _enable_plugins(self, plugins_list, csrf_token, override=None,
37 38 verify_response=False):
38 39 test_url = '/_admin/auth'
39 40 params = {
40 41 'auth_plugins': plugins_list,
41 42 'csrf_token': csrf_token,
42 43 }
43 44 if override:
44 45 params.update(override)
45 46 _enabled_plugins = []
46 47 for plugin in plugins_list.split(','):
47 48 plugin_name = plugin.partition('#')[-1]
48 49 enabled_plugin = '%s_enabled' % plugin_name
49 50 cache_ttl = '%s_auth_cache_ttl' % plugin_name
50 51
51 52 # default params that are needed for each plugin,
52 53 # `enabled` and `auth_cache_ttl`
53 54 params.update({
54 55 enabled_plugin: True,
55 56 cache_ttl: 0
56 57 })
57 58 _enabled_plugins.append(enabled_plugin)
58 59
59 60 # we need to clean any enabled plugin before, since they require
60 61 # form params to be present
61 62 db_plugin = SettingsModel().get_setting_by_name('auth_plugins')
62 63 db_plugin.app_settings_value = \
63 64 'egg:rhodecode-enterprise-ce#rhodecode'
64 65 Session().add(db_plugin)
65 66 Session().commit()
66 67 for _plugin in _enabled_plugins:
67 68 db_plugin = SettingsModel().get_setting_by_name(_plugin)
68 69 if db_plugin:
69 70 Session.delete(db_plugin)
70 71 Session().commit()
71 72
72 73 response = self.app.post(url=test_url, params=params)
73 74
74 75 if verify_response:
75 76 assert_auth_settings_updated(response)
76 77 return params
77 78
78 79 def _post_ldap_settings(self, params, override=None, force=False):
79 80
80 81 params.update({
81 82 'filter': 'user',
82 83 'user_member_of': '',
83 84 'user_search_base': '',
84 85 'user_search_filter': 'test_filter',
85 86
86 87 'host': 'dc.example.com',
87 88 'port': '999',
88 89 'tls_kind': 'PLAIN',
89 90 'tls_reqcert': 'NEVER',
90 91
91 92 'dn_user': 'test_user',
92 93 'dn_pass': 'test_pass',
93 94 'base_dn': 'test_base_dn',
94 95 'search_scope': 'BASE',
95 96 'attr_login': 'test_attr_login',
96 97 'attr_firstname': 'ima',
97 98 'attr_lastname': 'tester',
98 99 'attr_email': 'test@example.com',
99 100 'auth_cache_ttl': '0',
100 101 })
101 102 if force:
102 103 params = {}
103 104 params.update(override or {})
104 105
105 106 test_url = '/_admin/auth/ldap/'
106 107
107 108 response = self.app.post(url=test_url, params=params)
108 109 return response
109 110
110 111 def test_index(self):
111 112 response = self.app.get('/_admin/auth')
112 113 response.mustcontain('Authentication Plugins')
113 114
114 115 @pytest.mark.parametrize("disable_plugin, needs_import", [
115 116 pytest.mark.xfail(('egg:rhodecode-enterprise-ce#container', None),
116 117 reason="Migration of container plugin pending."),
117 118 ('egg:rhodecode-enterprise-ce#crowd', None),
118 119 ('egg:rhodecode-enterprise-ce#jasig_cas', None),
119 120 ('egg:rhodecode-enterprise-ce#ldap', None),
120 121 ('egg:rhodecode-enterprise-ce#pam', "pam"),
121 122 ])
122 123 def test_disable_plugin(self, csrf_token, disable_plugin, needs_import):
123 124 # TODO: johbo: "pam" is currently not available on darwin,
124 125 # although the docs state that it should work on darwin.
125 126 if needs_import:
126 127 pytest.importorskip(needs_import)
127 128
128 129 self._enable_plugins(
129 130 'egg:rhodecode-enterprise-ce#rhodecode,' + disable_plugin,
130 131 csrf_token, verify_response=True)
131 132
132 133 self._enable_plugins(
133 134 'egg:rhodecode-enterprise-ce#rhodecode', csrf_token,
134 135 verify_response=True)
135 136
136 137 def test_ldap_save_settings(self, csrf_token):
137 138 params = self._enable_plugins(
138 139 'egg:rhodecode-enterprise-ce#rhodecode,'
139 140 'egg:rhodecode-enterprise-ce#ldap',
140 141 csrf_token)
141 142 response = self._post_ldap_settings(params)
142 143 assert_auth_settings_updated(response)
143 144
144 145 new_settings = SettingsModel().get_auth_settings()
145 146 assert new_settings['auth_ldap_host'] == u'dc.example.com', \
146 147 'fail db write compare'
147 148
148 149 def test_ldap_error_form_wrong_port_number(self, csrf_token):
149 150 params = self._enable_plugins(
150 151 'egg:rhodecode-enterprise-ce#rhodecode,'
151 152 'egg:rhodecode-enterprise-ce#ldap',
152 153 csrf_token)
154 invalid_port_value = 'invalid-port-number'
153 155 response = self._post_ldap_settings(params, override={
154 'port': 'invalid-port-number',
156 'port': invalid_port_value,
155 157 })
156 response.mustcontain(
157 '<span class="error-message">&quot;invalid-port-number&quot;'
158 ' is not a number</span>')
158 assertr = AssertResponse(response)
159 assertr.element_contains(
160 '.form .field #port ~ .error-message',
161 invalid_port_value)
159 162
160 163 def test_ldap_error_form(self, csrf_token):
161 164 params = self._enable_plugins(
162 165 'egg:rhodecode-enterprise-ce#rhodecode,'
163 166 'egg:rhodecode-enterprise-ce#ldap',
164 167 csrf_token)
165 168 response = self._post_ldap_settings(params, override={
166 169 'attr_login': '',
167 170 })
168 171 response.mustcontain("""<span class="error-message">The LDAP Login"""
169 172 """ attribute of the CN must be specified""")
170 173
171 174 def test_post_ldap_group_settings(self, csrf_token):
172 175 params = self._enable_plugins(
173 176 'egg:rhodecode-enterprise-ce#rhodecode,'
174 177 'egg:rhodecode-enterprise-ce#ldap',
175 178 csrf_token)
176 179
177 180 response = self._post_ldap_settings(params, override={
178 181 'host': 'dc-legacy.example.com',
179 182 'port': '999',
180 183 'tls_kind': 'PLAIN',
181 184 'tls_reqcert': 'NEVER',
182 185 'dn_user': 'test_user',
183 186 'dn_pass': 'test_pass',
184 187 'base_dn': 'test_base_dn',
185 188 'filter': 'test_filter',
186 189 'search_scope': 'BASE',
187 190 'attr_login': 'test_attr_login',
188 191 'attr_firstname': 'ima',
189 192 'attr_lastname': 'tester',
190 193 'attr_email': 'test@example.com',
191 194 'auth_cache_ttl': '60',
192 195 'csrf_token': csrf_token,
193 196 }
194 197 )
195 198 assert_auth_settings_updated(response)
196 199
197 200 new_settings = SettingsModel().get_auth_settings()
198 201 assert new_settings['auth_ldap_host'] == u'dc-legacy.example.com', \
199 202 'fail db write compare'
General Comments 0
You need to be logged in to leave comments. Login now