Show More
@@ -341,10 +341,7 b' def LdapSettingsForm(tls_reqcert_choices' | |||
|
341 | 341 | ldap_base_dn = v.UnicodeString(strip=True,) |
|
342 | 342 | ldap_filter = v.UnicodeString(strip=True,) |
|
343 | 343 | ldap_search_scope = v.OneOf(search_scope_choices) |
|
344 |
ldap_attr_login = |
|
|
345 | v.AttrLoginValidator(), | |
|
346 | v.UnicodeString(strip=True,) | |
|
347 | ) | |
|
344 | ldap_attr_login = v.AttrLoginValidator()(not_empty=True) | |
|
348 | 345 | ldap_attr_firstname = v.UnicodeString(strip=True,) |
|
349 | 346 | ldap_attr_lastname = v.UnicodeString(strip=True,) |
|
350 | 347 | ldap_attr_email = v.UnicodeString(strip=True,) |
@@ -723,13 +723,7 b' def AttrLoginValidator():' | |||
|
723 | 723 | 'this is the name of the attribute that is equivalent ' |
|
724 | 724 | 'to "username"') |
|
725 | 725 | } |
|
726 | ||
|
727 | def validate_python(self, value, state): | |
|
728 | if not value or not isinstance(value, (str, unicode)): | |
|
729 | msg = M(self, 'invalid_cn', state) | |
|
730 | raise formencode.Invalid(msg, value, state, | |
|
731 | error_dict=dict(ldap_attr_login=msg) | |
|
732 | ) | |
|
726 | messages['empty'] = messages['invalid_cn'] | |
|
733 | 727 | |
|
734 | 728 | return _validator |
|
735 | 729 |
@@ -52,7 +52,7 b' log = logging.getLogger(__name__)' | |||
|
52 | 52 | |
|
53 | 53 | __all__ = [ |
|
54 | 54 | 'parameterized', 'environ', 'url', 'get_new_dir', 'TestController', |
|
55 | 'SkipTest', | |
|
55 | 'SkipTest', 'ldap_lib_installed', | |
|
56 | 56 | 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', |
|
57 | 57 | 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS', |
|
58 | 58 | 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS', |
@@ -117,6 +117,15 b" TEST_REPO_PREFIX = 'vcs-test'" | |||
|
117 | 117 | GIT_REMOTE_REPO = jn(TESTS_TMP_PATH, GIT_REPO) |
|
118 | 118 | HG_REMOTE_REPO = jn(TESTS_TMP_PATH, HG_REPO) |
|
119 | 119 | |
|
120 | #skip ldap tests if LDAP lib is not installed | |
|
121 | ldap_lib_installed = False | |
|
122 | try: | |
|
123 | import ldap | |
|
124 | ldap_lib_installed = True | |
|
125 | except ImportError: | |
|
126 | # means that python-ldap is not installed | |
|
127 | pass | |
|
128 | ||
|
120 | 129 | |
|
121 | 130 | def get_new_dir(title): |
|
122 | 131 | """ |
@@ -1,15 +1,6 b'' | |||
|
1 | 1 | from rhodecode.tests import * |
|
2 | 2 | from rhodecode.model.db import RhodeCodeSetting |
|
3 | 3 | |
|
4 | skip_ldap_test = False | |
|
5 | try: | |
|
6 | import ldap | |
|
7 | except ImportError: | |
|
8 | # means that python-ldap is not installed | |
|
9 | skip_ldap_test = True | |
|
10 | pass | |
|
11 | ||
|
12 | ||
|
13 | 4 | class TestLdapSettingsController(TestController): |
|
14 | 5 | |
|
15 | 6 | def test_index(self): |
@@ -20,26 +11,26 b' class TestLdapSettingsController(TestCon' | |||
|
20 | 11 | |
|
21 | 12 | def test_ldap_save_settings(self): |
|
22 | 13 | self.log_user() |
|
23 |
if |
|
|
14 | if ldap_lib_installed: | |
|
24 | 15 | raise SkipTest('skipping due to missing ldap lib') |
|
25 | 16 | |
|
26 | 17 | test_url = url(controller='admin/ldap_settings', |
|
27 | 18 | action='ldap_settings') |
|
28 | 19 | |
|
29 | 20 | response = self.app.post(url=test_url, |
|
30 |
params={'ldap_host' |
|
|
31 |
'ldap_port' |
|
|
32 |
'ldap_tls_kind' |
|
|
33 |
'ldap_tls_reqcert' |
|
|
34 | 'ldap_dn_user':'test_user', | |
|
35 | 'ldap_dn_pass':'test_pass', | |
|
36 | 'ldap_base_dn':'test_base_dn', | |
|
37 | 'ldap_filter':'test_filter', | |
|
38 | 'ldap_search_scope':'BASE', | |
|
39 | 'ldap_attr_login':'test_attr_login', | |
|
40 | 'ldap_attr_firstname':'ima', | |
|
41 | 'ldap_attr_lastname':'tester', | |
|
42 | 'ldap_attr_email':'test@example.com' }) | |
|
21 | params={'ldap_host': u'dc.example.com', | |
|
22 | 'ldap_port': '999', | |
|
23 | 'ldap_tls_kind': 'PLAIN', | |
|
24 | 'ldap_tls_reqcert': 'NEVER', | |
|
25 | 'ldap_dn_user': 'test_user', | |
|
26 | 'ldap_dn_pass': 'test_pass', | |
|
27 | 'ldap_base_dn': 'test_base_dn', | |
|
28 | 'ldap_filter': 'test_filter', | |
|
29 | 'ldap_search_scope': 'BASE', | |
|
30 | 'ldap_attr_login': 'test_attr_login', | |
|
31 | 'ldap_attr_firstname': 'ima', | |
|
32 | 'ldap_attr_lastname': 'tester', | |
|
33 | 'ldap_attr_email': 'test@example.com' }) | |
|
43 | 34 | |
|
44 | 35 | new_settings = RhodeCodeSetting.get_ldap_settings() |
|
45 | 36 | self.assertEqual(new_settings['ldap_host'], u'dc.example.com', |
@@ -48,36 +39,58 b' class TestLdapSettingsController(TestCon' | |||
|
48 | 39 | self.checkSessionFlash(response, |
|
49 | 40 | 'LDAP settings updated successfully') |
|
50 | 41 | |
|
51 | def test_ldap_error_form(self): | |
|
42 | def test_ldap_error_form_wrong_port_number(self): | |
|
52 | 43 | self.log_user() |
|
53 |
if |
|
|
44 | if ldap_lib_installed: | |
|
54 | 45 | raise SkipTest('skipping due to missing ldap lib') |
|
55 | 46 | |
|
56 | 47 | test_url = url(controller='admin/ldap_settings', |
|
57 | 48 | action='ldap_settings') |
|
58 | 49 | |
|
59 | 50 | response = self.app.post(url=test_url, |
|
60 |
params={'ldap_host' |
|
|
61 |
'ldap_port' |
|
|
62 |
'ldap_tls_kind' |
|
|
63 |
'ldap_tls_reqcert' |
|
|
64 | 'ldap_dn_user':'', | |
|
65 | 'ldap_dn_pass':'', | |
|
66 | 'ldap_base_dn':'', | |
|
67 | 'ldap_filter':'', | |
|
68 | 'ldap_search_scope':'BASE', | |
|
69 |
'ldap_attr_login':'', |
|
|
70 | 'ldap_attr_firstname':'', | |
|
71 | 'ldap_attr_lastname':'', | |
|
72 |
'ldap_attr_email':'' |
|
|
51 | params={'ldap_host': '', | |
|
52 | 'ldap_port': 'i-should-be-number', # bad port num | |
|
53 | 'ldap_tls_kind': 'PLAIN', | |
|
54 | 'ldap_tls_reqcert': 'NEVER', | |
|
55 | 'ldap_dn_user': '', | |
|
56 | 'ldap_dn_pass': '', | |
|
57 | 'ldap_base_dn': '', | |
|
58 | 'ldap_filter': '', | |
|
59 | 'ldap_search_scope': 'BASE', | |
|
60 | 'ldap_attr_login': '', | |
|
61 | 'ldap_attr_firstname': '', | |
|
62 | 'ldap_attr_lastname': '', | |
|
63 | 'ldap_attr_email': ''}) | |
|
64 | ||
|
65 | response.mustcontain("""<span class="error-message">""" | |
|
66 | """Please enter a number</span><br />""") | |
|
67 | ||
|
68 | def test_ldap_error_form(self): | |
|
69 | self.log_user() | |
|
70 | if ldap_lib_installed: | |
|
71 | raise SkipTest('skipping due to missing ldap lib') | |
|
72 | ||
|
73 | test_url = url(controller='admin/ldap_settings', | |
|
74 | action='ldap_settings') | |
|
75 | ||
|
76 | response = self.app.post(url=test_url, | |
|
77 | params={'ldap_host': 'Host', | |
|
78 | 'ldap_port': '123', | |
|
79 | 'ldap_tls_kind': 'PLAIN', | |
|
80 | 'ldap_tls_reqcert': 'NEVER', | |
|
81 | 'ldap_dn_user': '', | |
|
82 | 'ldap_dn_pass': '', | |
|
83 | 'ldap_base_dn': '', | |
|
84 | 'ldap_filter': '', | |
|
85 | 'ldap_search_scope': 'BASE', | |
|
86 | 'ldap_attr_login': '', # <----- missing required input | |
|
87 | 'ldap_attr_firstname': '', | |
|
88 | 'ldap_attr_lastname': '', | |
|
89 | 'ldap_attr_email': ''}) | |
|
73 | 90 | |
|
74 | 91 | response.mustcontain("""<span class="error-message">The LDAP Login""" |
|
75 | 92 | """ attribute of the CN must be specified""") |
|
76 | 93 | |
|
77 | ||
|
78 | response.mustcontain("""<span class="error-message">Please """ | |
|
79 | """enter a number</span>""") | |
|
80 | ||
|
81 | 94 | def test_ldap_login(self): |
|
82 | 95 | pass |
|
83 | 96 |
@@ -220,12 +220,16 b' class TestReposGroups(unittest.TestCase)' | |||
|
220 | 220 | self.assertRaises(formencode.Invalid, validator.to_python, 'err') |
|
221 | 221 | |
|
222 | 222 | def test_LdapLibValidator(self): |
|
223 | validator = v.LdapLibValidator() | |
|
224 | self.assertRaises(v.LdapImportError, validator.to_python, 'err') | |
|
223 | if ldap_lib_installed: | |
|
224 | validator = v.LdapLibValidator() | |
|
225 | self.assertEqual("DN", validator.to_python('DN')) | |
|
226 | else: | |
|
227 | validator = v.LdapLibValidator() | |
|
228 | self.assertRaises(v.LdapImportError, validator.to_python, 'err') | |
|
225 | 229 | |
|
226 | 230 | def test_AttrLoginValidator(self): |
|
227 | 231 | validator = v.AttrLoginValidator() |
|
228 |
self.assert |
|
|
232 | self.assertEqual('DN_attr', validator.to_python('DN_attr')) | |
|
229 | 233 | |
|
230 | 234 | def test_NotReviewedRevisions(self): |
|
231 | 235 | repo_id = Repository.get_by_repo_name(HG_REPO).repo_id |
General Comments 0
You need to be logged in to leave comments.
Login now