##// END OF EJS Templates
tests: marked some xfail tests that are now working
marcink -
r450:b574cb7c default
parent child Browse files
Show More
@@ -1,202 +1,201 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2016 RhodeCode GmbH
3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import pytest
21 import pytest
22
22
23 from rhodecode.tests import assert_session_flash
23 from rhodecode.tests import assert_session_flash
24 from rhodecode.tests.utils import AssertResponse
24 from rhodecode.tests.utils import AssertResponse
25 from rhodecode.model.db import Session
25 from rhodecode.model.db import Session
26 from rhodecode.model.settings import SettingsModel
26 from rhodecode.model.settings import SettingsModel
27
27
28
28
29 def assert_auth_settings_updated(response):
29 def assert_auth_settings_updated(response):
30 assert response.status_int == 302, 'Expected response HTTP Found 302'
30 assert response.status_int == 302, 'Expected response HTTP Found 302'
31 assert_session_flash(response, 'Auth settings updated successfully')
31 assert_session_flash(response, 'Auth settings updated successfully')
32
32
33
33
34 @pytest.mark.usefixtures("autologin_user", "app")
34 @pytest.mark.usefixtures("autologin_user", "app")
35 class TestAuthSettingsController(object):
35 class TestAuthSettingsController(object):
36
36
37 def _enable_plugins(self, plugins_list, csrf_token, override=None,
37 def _enable_plugins(self, plugins_list, csrf_token, override=None,
38 verify_response=False):
38 verify_response=False):
39 test_url = '/_admin/auth'
39 test_url = '/_admin/auth'
40 params = {
40 params = {
41 'auth_plugins': plugins_list,
41 'auth_plugins': plugins_list,
42 'csrf_token': csrf_token,
42 'csrf_token': csrf_token,
43 }
43 }
44 if override:
44 if override:
45 params.update(override)
45 params.update(override)
46 _enabled_plugins = []
46 _enabled_plugins = []
47 for plugin in plugins_list.split(','):
47 for plugin in plugins_list.split(','):
48 plugin_name = plugin.partition('#')[-1]
48 plugin_name = plugin.partition('#')[-1]
49 enabled_plugin = '%s_enabled' % plugin_name
49 enabled_plugin = '%s_enabled' % plugin_name
50 cache_ttl = '%s_auth_cache_ttl' % plugin_name
50 cache_ttl = '%s_auth_cache_ttl' % plugin_name
51
51
52 # default params that are needed for each plugin,
52 # default params that are needed for each plugin,
53 # `enabled` and `auth_cache_ttl`
53 # `enabled` and `auth_cache_ttl`
54 params.update({
54 params.update({
55 enabled_plugin: True,
55 enabled_plugin: True,
56 cache_ttl: 0
56 cache_ttl: 0
57 })
57 })
58 _enabled_plugins.append(enabled_plugin)
58 _enabled_plugins.append(enabled_plugin)
59
59
60 # we need to clean any enabled plugin before, since they require
60 # we need to clean any enabled plugin before, since they require
61 # form params to be present
61 # form params to be present
62 db_plugin = SettingsModel().get_setting_by_name('auth_plugins')
62 db_plugin = SettingsModel().get_setting_by_name('auth_plugins')
63 db_plugin.app_settings_value = \
63 db_plugin.app_settings_value = \
64 'egg:rhodecode-enterprise-ce#rhodecode'
64 'egg:rhodecode-enterprise-ce#rhodecode'
65 Session().add(db_plugin)
65 Session().add(db_plugin)
66 Session().commit()
66 Session().commit()
67 for _plugin in _enabled_plugins:
67 for _plugin in _enabled_plugins:
68 db_plugin = SettingsModel().get_setting_by_name(_plugin)
68 db_plugin = SettingsModel().get_setting_by_name(_plugin)
69 if db_plugin:
69 if db_plugin:
70 Session.delete(db_plugin)
70 Session.delete(db_plugin)
71 Session().commit()
71 Session().commit()
72
72
73 response = self.app.post(url=test_url, params=params)
73 response = self.app.post(url=test_url, params=params)
74
74
75 if verify_response:
75 if verify_response:
76 assert_auth_settings_updated(response)
76 assert_auth_settings_updated(response)
77 return params
77 return params
78
78
79 def _post_ldap_settings(self, params, override=None, force=False):
79 def _post_ldap_settings(self, params, override=None, force=False):
80
80
81 params.update({
81 params.update({
82 'filter': 'user',
82 'filter': 'user',
83 'user_member_of': '',
83 'user_member_of': '',
84 'user_search_base': '',
84 'user_search_base': '',
85 'user_search_filter': 'test_filter',
85 'user_search_filter': 'test_filter',
86
86
87 'host': 'dc.example.com',
87 'host': 'dc.example.com',
88 'port': '999',
88 'port': '999',
89 'tls_kind': 'PLAIN',
89 'tls_kind': 'PLAIN',
90 'tls_reqcert': 'NEVER',
90 'tls_reqcert': 'NEVER',
91
91
92 'dn_user': 'test_user',
92 'dn_user': 'test_user',
93 'dn_pass': 'test_pass',
93 'dn_pass': 'test_pass',
94 'base_dn': 'test_base_dn',
94 'base_dn': 'test_base_dn',
95 'search_scope': 'BASE',
95 'search_scope': 'BASE',
96 'attr_login': 'test_attr_login',
96 'attr_login': 'test_attr_login',
97 'attr_firstname': 'ima',
97 'attr_firstname': 'ima',
98 'attr_lastname': 'tester',
98 'attr_lastname': 'tester',
99 'attr_email': 'test@example.com',
99 'attr_email': 'test@example.com',
100 'auth_cache_ttl': '0',
100 'auth_cache_ttl': '0',
101 })
101 })
102 if force:
102 if force:
103 params = {}
103 params = {}
104 params.update(override or {})
104 params.update(override or {})
105
105
106 test_url = '/_admin/auth/ldap/'
106 test_url = '/_admin/auth/ldap/'
107
107
108 response = self.app.post(url=test_url, params=params)
108 response = self.app.post(url=test_url, params=params)
109 return response
109 return response
110
110
111 def test_index(self):
111 def test_index(self):
112 response = self.app.get('/_admin/auth')
112 response = self.app.get('/_admin/auth')
113 response.mustcontain('Authentication Plugins')
113 response.mustcontain('Authentication Plugins')
114
114
115 @pytest.mark.parametrize("disable_plugin, needs_import", [
115 @pytest.mark.parametrize("disable_plugin, needs_import", [
116 pytest.mark.xfail(('egg:rhodecode-enterprise-ce#container', None),
116 ('egg:rhodecode-enterprise-ce#headers', None),
117 reason="Migration of container plugin pending."),
118 ('egg:rhodecode-enterprise-ce#crowd', None),
117 ('egg:rhodecode-enterprise-ce#crowd', None),
119 ('egg:rhodecode-enterprise-ce#jasig_cas', None),
118 ('egg:rhodecode-enterprise-ce#jasig_cas', None),
120 ('egg:rhodecode-enterprise-ce#ldap', None),
119 ('egg:rhodecode-enterprise-ce#ldap', None),
121 ('egg:rhodecode-enterprise-ce#pam', "pam"),
120 ('egg:rhodecode-enterprise-ce#pam', "pam"),
122 ])
121 ])
123 def test_disable_plugin(self, csrf_token, disable_plugin, needs_import):
122 def test_disable_plugin(self, csrf_token, disable_plugin, needs_import):
124 # TODO: johbo: "pam" is currently not available on darwin,
123 # TODO: johbo: "pam" is currently not available on darwin,
125 # although the docs state that it should work on darwin.
124 # although the docs state that it should work on darwin.
126 if needs_import:
125 if needs_import:
127 pytest.importorskip(needs_import)
126 pytest.importorskip(needs_import)
128
127
129 self._enable_plugins(
128 self._enable_plugins(
130 'egg:rhodecode-enterprise-ce#rhodecode,' + disable_plugin,
129 'egg:rhodecode-enterprise-ce#rhodecode,' + disable_plugin,
131 csrf_token, verify_response=True)
130 csrf_token, verify_response=True)
132
131
133 self._enable_plugins(
132 self._enable_plugins(
134 'egg:rhodecode-enterprise-ce#rhodecode', csrf_token,
133 'egg:rhodecode-enterprise-ce#rhodecode', csrf_token,
135 verify_response=True)
134 verify_response=True)
136
135
137 def test_ldap_save_settings(self, csrf_token):
136 def test_ldap_save_settings(self, csrf_token):
138 params = self._enable_plugins(
137 params = self._enable_plugins(
139 'egg:rhodecode-enterprise-ce#rhodecode,'
138 'egg:rhodecode-enterprise-ce#rhodecode,'
140 'egg:rhodecode-enterprise-ce#ldap',
139 'egg:rhodecode-enterprise-ce#ldap',
141 csrf_token)
140 csrf_token)
142 response = self._post_ldap_settings(params)
141 response = self._post_ldap_settings(params)
143 assert_auth_settings_updated(response)
142 assert_auth_settings_updated(response)
144
143
145 new_settings = SettingsModel().get_auth_settings()
144 new_settings = SettingsModel().get_auth_settings()
146 assert new_settings['auth_ldap_host'] == u'dc.example.com', \
145 assert new_settings['auth_ldap_host'] == u'dc.example.com', \
147 'fail db write compare'
146 'fail db write compare'
148
147
149 def test_ldap_error_form_wrong_port_number(self, csrf_token):
148 def test_ldap_error_form_wrong_port_number(self, csrf_token):
150 params = self._enable_plugins(
149 params = self._enable_plugins(
151 'egg:rhodecode-enterprise-ce#rhodecode,'
150 'egg:rhodecode-enterprise-ce#rhodecode,'
152 'egg:rhodecode-enterprise-ce#ldap',
151 'egg:rhodecode-enterprise-ce#ldap',
153 csrf_token)
152 csrf_token)
154 invalid_port_value = 'invalid-port-number'
153 invalid_port_value = 'invalid-port-number'
155 response = self._post_ldap_settings(params, override={
154 response = self._post_ldap_settings(params, override={
156 'port': invalid_port_value,
155 'port': invalid_port_value,
157 })
156 })
158 assertr = AssertResponse(response)
157 assertr = AssertResponse(response)
159 assertr.element_contains(
158 assertr.element_contains(
160 '.form .field #port ~ .error-message',
159 '.form .field #port ~ .error-message',
161 invalid_port_value)
160 invalid_port_value)
162
161
163 def test_ldap_error_form(self, csrf_token):
162 def test_ldap_error_form(self, csrf_token):
164 params = self._enable_plugins(
163 params = self._enable_plugins(
165 'egg:rhodecode-enterprise-ce#rhodecode,'
164 'egg:rhodecode-enterprise-ce#rhodecode,'
166 'egg:rhodecode-enterprise-ce#ldap',
165 'egg:rhodecode-enterprise-ce#ldap',
167 csrf_token)
166 csrf_token)
168 response = self._post_ldap_settings(params, override={
167 response = self._post_ldap_settings(params, override={
169 'attr_login': '',
168 'attr_login': '',
170 })
169 })
171 response.mustcontain("""<span class="error-message">The LDAP Login"""
170 response.mustcontain("""<span class="error-message">The LDAP Login"""
172 """ attribute of the CN must be specified""")
171 """ attribute of the CN must be specified""")
173
172
174 def test_post_ldap_group_settings(self, csrf_token):
173 def test_post_ldap_group_settings(self, csrf_token):
175 params = self._enable_plugins(
174 params = self._enable_plugins(
176 'egg:rhodecode-enterprise-ce#rhodecode,'
175 'egg:rhodecode-enterprise-ce#rhodecode,'
177 'egg:rhodecode-enterprise-ce#ldap',
176 'egg:rhodecode-enterprise-ce#ldap',
178 csrf_token)
177 csrf_token)
179
178
180 response = self._post_ldap_settings(params, override={
179 response = self._post_ldap_settings(params, override={
181 'host': 'dc-legacy.example.com',
180 'host': 'dc-legacy.example.com',
182 'port': '999',
181 'port': '999',
183 'tls_kind': 'PLAIN',
182 'tls_kind': 'PLAIN',
184 'tls_reqcert': 'NEVER',
183 'tls_reqcert': 'NEVER',
185 'dn_user': 'test_user',
184 'dn_user': 'test_user',
186 'dn_pass': 'test_pass',
185 'dn_pass': 'test_pass',
187 'base_dn': 'test_base_dn',
186 'base_dn': 'test_base_dn',
188 'filter': 'test_filter',
187 'filter': 'test_filter',
189 'search_scope': 'BASE',
188 'search_scope': 'BASE',
190 'attr_login': 'test_attr_login',
189 'attr_login': 'test_attr_login',
191 'attr_firstname': 'ima',
190 'attr_firstname': 'ima',
192 'attr_lastname': 'tester',
191 'attr_lastname': 'tester',
193 'attr_email': 'test@example.com',
192 'attr_email': 'test@example.com',
194 'auth_cache_ttl': '60',
193 'auth_cache_ttl': '60',
195 'csrf_token': csrf_token,
194 'csrf_token': csrf_token,
196 }
195 }
197 )
196 )
198 assert_auth_settings_updated(response)
197 assert_auth_settings_updated(response)
199
198
200 new_settings = SettingsModel().get_auth_settings()
199 new_settings = SettingsModel().get_auth_settings()
201 assert new_settings['auth_ldap_host'] == u'dc-legacy.example.com', \
200 assert new_settings['auth_ldap_host'] == u'dc-legacy.example.com', \
202 'fail db write compare'
201 'fail db write compare'
General Comments 0
You need to be logged in to leave comments. Login now