Show More
@@ -341,10 +341,7 b' def LdapSettingsForm(tls_reqcert_choices' | |||||
341 | ldap_base_dn = v.UnicodeString(strip=True,) |
|
341 | ldap_base_dn = v.UnicodeString(strip=True,) | |
342 | ldap_filter = v.UnicodeString(strip=True,) |
|
342 | ldap_filter = v.UnicodeString(strip=True,) | |
343 | ldap_search_scope = v.OneOf(search_scope_choices) |
|
343 | ldap_search_scope = v.OneOf(search_scope_choices) | |
344 |
ldap_attr_login = |
|
344 | ldap_attr_login = v.AttrLoginValidator()(not_empty=True) | |
345 | v.AttrLoginValidator(), |
|
|||
346 | v.UnicodeString(strip=True,) |
|
|||
347 | ) |
|
|||
348 | ldap_attr_firstname = v.UnicodeString(strip=True,) |
|
345 | ldap_attr_firstname = v.UnicodeString(strip=True,) | |
349 | ldap_attr_lastname = v.UnicodeString(strip=True,) |
|
346 | ldap_attr_lastname = v.UnicodeString(strip=True,) | |
350 | ldap_attr_email = v.UnicodeString(strip=True,) |
|
347 | ldap_attr_email = v.UnicodeString(strip=True,) |
@@ -723,13 +723,7 b' def AttrLoginValidator():' | |||||
723 | 'this is the name of the attribute that is equivalent ' |
|
723 | 'this is the name of the attribute that is equivalent ' | |
724 | 'to "username"') |
|
724 | 'to "username"') | |
725 | } |
|
725 | } | |
726 |
|
726 | messages['empty'] = messages['invalid_cn'] | ||
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 | ) |
|
|||
733 |
|
727 | |||
734 | return _validator |
|
728 | return _validator | |
735 |
|
729 |
@@ -52,7 +52,7 b' log = logging.getLogger(__name__)' | |||||
52 |
|
52 | |||
53 | __all__ = [ |
|
53 | __all__ = [ | |
54 | 'parameterized', 'environ', 'url', 'get_new_dir', 'TestController', |
|
54 | 'parameterized', 'environ', 'url', 'get_new_dir', 'TestController', | |
55 | 'SkipTest', |
|
55 | 'SkipTest', 'ldap_lib_installed', | |
56 | 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', |
|
56 | 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', | |
57 | 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS', |
|
57 | 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS', | |
58 | 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS', |
|
58 | 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS', | |
@@ -117,6 +117,15 b" TEST_REPO_PREFIX = 'vcs-test'" | |||||
117 | GIT_REMOTE_REPO = jn(TESTS_TMP_PATH, GIT_REPO) |
|
117 | GIT_REMOTE_REPO = jn(TESTS_TMP_PATH, GIT_REPO) | |
118 | HG_REMOTE_REPO = jn(TESTS_TMP_PATH, HG_REPO) |
|
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 | def get_new_dir(title): |
|
130 | def get_new_dir(title): | |
122 | """ |
|
131 | """ |
@@ -1,15 +1,6 b'' | |||||
1 | from rhodecode.tests import * |
|
1 | from rhodecode.tests import * | |
2 | from rhodecode.model.db import RhodeCodeSetting |
|
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 | class TestLdapSettingsController(TestController): |
|
4 | class TestLdapSettingsController(TestController): | |
14 |
|
5 | |||
15 | def test_index(self): |
|
6 | def test_index(self): | |
@@ -20,26 +11,26 b' class TestLdapSettingsController(TestCon' | |||||
20 |
|
11 | |||
21 | def test_ldap_save_settings(self): |
|
12 | def test_ldap_save_settings(self): | |
22 | self.log_user() |
|
13 | self.log_user() | |
23 |
if |
|
14 | if ldap_lib_installed: | |
24 | raise SkipTest('skipping due to missing ldap lib') |
|
15 | raise SkipTest('skipping due to missing ldap lib') | |
25 |
|
16 | |||
26 | test_url = url(controller='admin/ldap_settings', |
|
17 | test_url = url(controller='admin/ldap_settings', | |
27 | action='ldap_settings') |
|
18 | action='ldap_settings') | |
28 |
|
19 | |||
29 | response = self.app.post(url=test_url, |
|
20 | response = self.app.post(url=test_url, | |
30 |
params={'ldap_host' |
|
21 | params={'ldap_host': u'dc.example.com', | |
31 |
'ldap_port' |
|
22 | 'ldap_port': '999', | |
32 |
'ldap_tls_kind' |
|
23 | 'ldap_tls_kind': 'PLAIN', | |
33 |
'ldap_tls_reqcert' |
|
24 | 'ldap_tls_reqcert': 'NEVER', | |
34 | 'ldap_dn_user':'test_user', |
|
25 | 'ldap_dn_user': 'test_user', | |
35 | 'ldap_dn_pass':'test_pass', |
|
26 | 'ldap_dn_pass': 'test_pass', | |
36 | 'ldap_base_dn':'test_base_dn', |
|
27 | 'ldap_base_dn': 'test_base_dn', | |
37 | 'ldap_filter':'test_filter', |
|
28 | 'ldap_filter': 'test_filter', | |
38 | 'ldap_search_scope':'BASE', |
|
29 | 'ldap_search_scope': 'BASE', | |
39 | 'ldap_attr_login':'test_attr_login', |
|
30 | 'ldap_attr_login': 'test_attr_login', | |
40 | 'ldap_attr_firstname':'ima', |
|
31 | 'ldap_attr_firstname': 'ima', | |
41 | 'ldap_attr_lastname':'tester', |
|
32 | 'ldap_attr_lastname': 'tester', | |
42 | 'ldap_attr_email':'test@example.com' }) |
|
33 | 'ldap_attr_email': 'test@example.com' }) | |
43 |
|
34 | |||
44 | new_settings = RhodeCodeSetting.get_ldap_settings() |
|
35 | new_settings = RhodeCodeSetting.get_ldap_settings() | |
45 | self.assertEqual(new_settings['ldap_host'], u'dc.example.com', |
|
36 | self.assertEqual(new_settings['ldap_host'], u'dc.example.com', | |
@@ -48,36 +39,58 b' class TestLdapSettingsController(TestCon' | |||||
48 | self.checkSessionFlash(response, |
|
39 | self.checkSessionFlash(response, | |
49 | 'LDAP settings updated successfully') |
|
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 | self.log_user() |
|
43 | self.log_user() | |
53 |
if |
|
44 | if ldap_lib_installed: | |
54 | raise SkipTest('skipping due to missing ldap lib') |
|
45 | raise SkipTest('skipping due to missing ldap lib') | |
55 |
|
46 | |||
56 | test_url = url(controller='admin/ldap_settings', |
|
47 | test_url = url(controller='admin/ldap_settings', | |
57 | action='ldap_settings') |
|
48 | action='ldap_settings') | |
58 |
|
49 | |||
59 | response = self.app.post(url=test_url, |
|
50 | response = self.app.post(url=test_url, | |
60 |
params={'ldap_host' |
|
51 | params={'ldap_host': '', | |
61 |
'ldap_port' |
|
52 | 'ldap_port': 'i-should-be-number', # bad port num | |
62 |
'ldap_tls_kind' |
|
53 | 'ldap_tls_kind': 'PLAIN', | |
63 |
'ldap_tls_reqcert' |
|
54 | 'ldap_tls_reqcert': 'NEVER', | |
64 | 'ldap_dn_user':'', |
|
55 | 'ldap_dn_user': '', | |
65 | 'ldap_dn_pass':'', |
|
56 | 'ldap_dn_pass': '', | |
66 | 'ldap_base_dn':'', |
|
57 | 'ldap_base_dn': '', | |
67 | 'ldap_filter':'', |
|
58 | 'ldap_filter': '', | |
68 | 'ldap_search_scope':'BASE', |
|
59 | 'ldap_search_scope': 'BASE', | |
69 |
'ldap_attr_login':'', |
|
60 | 'ldap_attr_login': '', | |
70 | 'ldap_attr_firstname':'', |
|
61 | 'ldap_attr_firstname': '', | |
71 | 'ldap_attr_lastname':'', |
|
62 | 'ldap_attr_lastname': '', | |
72 |
'ldap_attr_email':'' |
|
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 | response.mustcontain("""<span class="error-message">The LDAP Login""" |
|
91 | response.mustcontain("""<span class="error-message">The LDAP Login""" | |
75 | """ attribute of the CN must be specified""") |
|
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 | def test_ldap_login(self): |
|
94 | def test_ldap_login(self): | |
82 | pass |
|
95 | pass | |
83 |
|
96 |
@@ -220,12 +220,16 b' class TestReposGroups(unittest.TestCase)' | |||||
220 | self.assertRaises(formencode.Invalid, validator.to_python, 'err') |
|
220 | self.assertRaises(formencode.Invalid, validator.to_python, 'err') | |
221 |
|
221 | |||
222 | def test_LdapLibValidator(self): |
|
222 | def test_LdapLibValidator(self): | |
223 | validator = v.LdapLibValidator() |
|
223 | if ldap_lib_installed: | |
224 | self.assertRaises(v.LdapImportError, validator.to_python, 'err') |
|
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 | def test_AttrLoginValidator(self): |
|
230 | def test_AttrLoginValidator(self): | |
227 | validator = v.AttrLoginValidator() |
|
231 | validator = v.AttrLoginValidator() | |
228 |
self.assert |
|
232 | self.assertEqual('DN_attr', validator.to_python('DN_attr')) | |
229 |
|
233 | |||
230 | def test_NotReviewedRevisions(self): |
|
234 | def test_NotReviewedRevisions(self): | |
231 | repo_id = Repository.get_by_repo_name(HG_REPO).repo_id |
|
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