[CalendarServer-changes] [12313] twext/trunk/twext/who/ldap

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:24:58 PDT 2014


Revision: 12313
          http://trac.calendarserver.org//changeset/12313
Author:   wsanchez at apple.com
Date:     2014-01-11 14:16:45 -0800 (Sat, 11 Jan 2014)
Log Message:
-----------
Add test_connect_withUsernamePassword_invalid.

Modified Paths:
--------------
    twext/trunk/twext/who/ldap/_service.py
    twext/trunk/twext/who/ldap/test/test_service.py

Modified: twext/trunk/twext/who/ldap/_service.py
===================================================================
--- twext/trunk/twext/who/ldap/_service.py	2014-01-11 22:00:27 UTC (rev 12312)
+++ twext/trunk/twext/who/ldap/_service.py	2014-01-11 22:16:45 UTC (rev 12313)
@@ -82,6 +82,13 @@
 
 
 
+class LDAPConnectionAuthError(LDAPConnectionError):
+    """
+    LDAP connection auth error.
+    """
+
+
+
 # class LDAPQueryError(LDAPError):
 #     """
 #     LDAP query error.
@@ -191,12 +198,16 @@
                             "Bound to LDAP as {credentials.username}",
                             credentials=self.credentials
                         )
-                    except ldap.INVALID_CREDENTIALS as e:
+                    except (
+                        ldap.INVALID_CREDENTIALS, ldap.INVALID_DN_SYNTAX
+                    ) as e:
                         self.log.error(
                             "Unable to bind to LDAP as {credentials.username}",
                             credentials=self.credentials
                         )
-                        raise LDAPConnectionError(str(e), e)
+                        raise LDAPConnectionAuthError(
+                            self.credentials.username, e
+                        )
 
                 else:
                     raise LDAPConnectionError(

Modified: twext/trunk/twext/who/ldap/test/test_service.py
===================================================================
--- twext/trunk/twext/who/ldap/test/test_service.py	2014-01-11 22:00:27 UTC (rev 12312)
+++ twext/trunk/twext/who/ldap/test/test_service.py	2014-01-11 22:16:45 UTC (rev 12313)
@@ -23,13 +23,19 @@
 
 from twisted.python.filepath import FilePath
 from twisted.internet.defer import inlineCallbacks
+from twisted.cred.credentials import UsernamePassword
 from twisted.trial import unittest
 
 # from ...expression import (
 #     CompoundExpression, Operand, MatchExpression, MatchType, MatchFlags
 # )
-from .._service import DirectoryService, DirectoryRecord, DEFAULT_URL
+from .._service import (
+    DEFAULT_URL,
+    LDAPConnectionAuthError,
+    DirectoryService, DirectoryRecord,
+)
 
+
 from ...test import test_directory
 
 
@@ -104,6 +110,18 @@
         self.assertFalse(connection.tls_enabled)
 
 
+    def test_connect_withUsernamePassword_invalid(self):
+        """
+        Connect with UsernamePassword credentials.
+        """
+        credentials = UsernamePassword(
+            "cn=wsanchez,ou=calendarserver,o=org",
+            "__password__"
+        )
+        service = self.service(credentials=credentials)
+        self.assertFailure(service._connect(), LDAPConnectionAuthError)
+
+
     @inlineCallbacks
     def test_connect_withOptions(self):
         """
@@ -132,17 +150,18 @@
         self.assertEquals(opt(ldap.OPT_X_TLS_CACERTDIR), "/path/to/certdir")
         self.assertEquals(opt(ldap.OPT_DEBUG_LEVEL), 255)
 
+        # Tested in test_connect_defaults, but test again here since we're
+        # setting SSL options and we want to be sure they don't somehow enable
+        # SSL implicitly.
         self.assertFalse(connection.tls_enabled)
 
 
     @inlineCallbacks
-    def test_connect_withSSL(self):
+    def test_connect_withTLS(self):
         """
-        Connect with SSL enabled.
+        Connect with TLS enabled.
         """
-        service = self.service(
-            useTLS=True,
-        )
+        service = self.service(useTLS=True)
         connection = yield service._connect()
 
         self.assertEquals(
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/3c04ccec/attachment.html>


More information about the calendarserver-changes mailing list