changeset 1425:3dedf3991d40 beta

fixes #173, many thanks for slestak for contributing into this one.
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 10 Jul 2011 15:50:31 +0200
parents ac0c4e600426
children 91708b96e991
files CONTRIBUTORS rhodecode/lib/auth.py rhodecode/tests/functional/test_admin_ldap_settings.py
diffstat 3 files changed, 64 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/CONTRIBUTORS	Sun Jul 10 13:15:23 2011 +0200
+++ b/CONTRIBUTORS	Sun Jul 10 15:50:31 2011 +0200
@@ -6,4 +6,5 @@
     cejones
     Lorenzo M. Catucci <lorenzo@sancho.ccd.uniroma2.it>
     Dmitri Kuznetsov
-    Jared Bunting <jared.bunting@peachjean.com>
\ No newline at end of file
+    Jared Bunting <jared.bunting@peachjean.com>
+    Steve Romanow <slestak989@gmail.com>
\ No newline at end of file
--- a/rhodecode/lib/auth.py	Sun Jul 10 13:15:23 2011 +0200
+++ b/rhodecode/lib/auth.py	Sun Jul 10 15:50:31 2011 +0200
@@ -41,7 +41,7 @@
 if __platform__ in PLATFORM_OTHERS:
     import bcrypt
 
-from rhodecode.lib import str2bool
+from rhodecode.lib import str2bool, safe_unicode
 from rhodecode.lib.exceptions import LdapPasswordError, LdapUsernameError
 from rhodecode.lib.utils import get_repo_slug
 from rhodecode.lib.auth_ldap import AuthLdap
@@ -207,10 +207,10 @@
                                                            .get(k), [''])[0]
 
                 user_attrs = {
-                    'name': get_ldap_attr('ldap_attr_firstname'),
-                    'lastname': get_ldap_attr('ldap_attr_lastname'),
-                    'email': get_ldap_attr('ldap_attr_email'),
-                    }
+                 'name': safe_unicode(get_ldap_attr('ldap_attr_firstname')),
+                 'lastname': safe_unicode(get_ldap_attr('ldap_attr_lastname')),
+                 'email': get_ldap_attr('ldap_attr_email'),
+                }
 
                 if user_model.create_ldap(username, password, user_dn,
                                           user_attrs):
--- a/rhodecode/tests/functional/test_admin_ldap_settings.py	Sun Jul 10 13:15:23 2011 +0200
+++ b/rhodecode/tests/functional/test_admin_ldap_settings.py	Sun Jul 10 15:50:31 2011 +0200
@@ -1,4 +1,11 @@
 from rhodecode.tests import *
+from rhodecode.model.db import RhodeCodeSettings
+
+try:
+    import ldap
+except ImportError:
+    # means that python-ldap is not installed
+    pass
 
 class TestLdapSettingsController(TestController):
 
@@ -6,13 +13,60 @@
         self.log_user()
         response = self.app.get(url(controller='admin/ldap_settings',
                                     action='index'))
-        # Test response...
+        self.assertTrue('LDAP administration' in response.body)
 
     def test_ldap_save_settings(self):
-        pass
+        self.log_user()
+        test_url = url(controller='admin/ldap_settings',
+                       action='ldap_settings')
+
+        response = self.app.post(url=test_url,
+            params={'ldap_host' : u'dc.example.com',
+                    'ldap_port' : '999',
+                    'ldap_tls_kind' : 'PLAIN',
+                    'ldap_tls_reqcert' : 'NEVER',
+                    'ldap_dn_user':'test_user',
+                    'ldap_dn_pass':'test_pass',
+                    'ldap_base_dn':'test_base_dn',
+                    'ldap_filter':'test_filter',
+                    'ldap_search_scope':'BASE',
+                    'ldap_attr_login':'test_attr_login',
+                    'ldap_attr_firstname':'ima',
+                    'ldap_attr_lastname':'tester',
+                    'ldap_attr_email':'test@example.com' })
+
+        new_settings = RhodeCodeSettings.get_ldap_settings()
+        self.assertEqual(new_settings['ldap_host'], u'dc.example.com',
+                         'fail db write compare')
+
+        self.checkSessionFlash(response,
+                               'Ldap settings updated successfully')
 
     def test_ldap_error_form(self):
-        pass
+        self.log_user()
+        test_url = url(controller='admin/ldap_settings',
+                       action='ldap_settings')
+
+        response = self.app.post(url=test_url,
+            params={'ldap_host' : '',
+                    'ldap_port' : 'i-should-be-number',
+                    'ldap_tls_kind' : 'PLAIN',
+                    'ldap_tls_reqcert' : 'NEVER',
+                    'ldap_dn_user':'',
+                    'ldap_dn_pass':'',
+                    'ldap_base_dn':'',
+                    'ldap_filter':'',
+                    'ldap_search_scope':'BASE',
+                    'ldap_attr_login':'', #  <----- missing required input
+                    'ldap_attr_firstname':'',
+                    'ldap_attr_lastname':'',
+                    'ldap_attr_email':'' })
+
+        self.assertTrue("""<span class="error-message">The LDAP Login"""
+                        """ attribute of the CN must be specified""" in
+                        response.body)
+        self.assertTrue("""<span class="error-message">Please """
+                        """enter a number</span>""" in response.body)
 
     def test_ldap_login(self):
         pass