[CalendarServer-changes] [13026] CalendarServer/branches/users/sagen/move2who-4

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 28 12:08:49 PDT 2014


Revision: 13026
          http://trac.calendarserver.org//changeset/13026
Author:   sagen at apple.com
Date:     2014-03-28 12:08:49 -0700 (Fri, 28 Mar 2014)
Log Message:
-----------
Add tests to investigate recordsFromExpression failure over AMP

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml
    CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml
    CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py

Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml	2014-03-28 18:08:37 UTC (rev 13025)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml	2014-03-28 19:08:49 UTC (rev 13026)
@@ -242,6 +242,7 @@
 
   <record type="user">
     <uid>__sagen1__</uid>
+    <short-name>sagen</short-name>
     <short-name>sagen1</short-name>
     <full-name>Morgen Sagen</full-name>
     <password>negas</password>
@@ -259,6 +260,7 @@
   <record type="user">
     <uid>__dre1__</uid>
     <short-name>dre1</short-name>
+    <short-name>dre</short-name>
     <full-name>Andre LaBranche</full-name>
     <password>erd</password>
     <email>dre at bitbucket.calendarserver.org</email>

Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml	2014-03-28 18:08:37 UTC (rev 13025)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml	2014-03-28 19:08:49 UTC (rev 13026)
@@ -75,4 +75,9 @@
     <full-name>Disabled Record</full-name>
     <email>disabled at example.com</email>
   </record>
+  <record type="location">
+    <uid>__sanchezoffice__</uid>
+    <short-name>sanchezoffice</short-name>
+    <full-name>Sanchez Office</full-name>
+  </record>
 </directory>

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py	2014-03-28 18:08:37 UTC (rev 13025)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py	2014-03-28 19:08:49 UTC (rev 13026)
@@ -16,8 +16,10 @@
 
 import os
 
-from twext.who.expression import Operand, MatchType, MatchFlags
-from twext.who.idirectory import RecordType
+from twext.who.expression import (
+    Operand, MatchType, MatchFlags, MatchExpression, CompoundExpression
+)
+from twext.who.idirectory import RecordType, FieldName
 from twisted.cred.credentials import calcResponse, calcHA1, calcHA2
 from twisted.internet.defer import inlineCallbacks, succeed
 from twisted.protocols.amp import AMP
@@ -27,6 +29,8 @@
 from txdav.dps.client import DirectoryService
 from txdav.dps.server import DirectoryProxyAMPProtocol
 from txdav.who.directory import CalendarDirectoryServiceMixin
+from twistedcaldav.test.util import StoreTestCase
+from twistedcaldav.config import config
 
 
 testMode = "xml"  # "xml" or "od"
@@ -59,7 +63,7 @@
 
 
 
-class DPSClientTest(unittest.TestCase):
+class DPSClientSingleDirectoryTest(unittest.TestCase):
 
     def setUp(self):
 
@@ -204,6 +208,18 @@
 
 
     @inlineCallbacks
+    def test_recordsFromMatchExpression(self):
+        expression = MatchExpression(
+            FieldName.uid,
+            testUID,
+            MatchType.equals,
+            MatchFlags.none
+        )
+        records = yield self.directory.recordsFromExpression(expression)
+        self.assertEquals(len(records), 1)
+
+
+    @inlineCallbacks
     def test_verifyPlaintextPassword(self):
         expectations = (
             (testPassword, True),  # Correct
@@ -257,3 +273,223 @@
                     )
                 )
                 self.assertEquals(authenticated, answer)
+
+
+
+
+
+class DPSClientAugmentedAggregateDirectoryTest(StoreTestCase):
+
+    wsanchezUID = u"6423F94A-6B76-4A3A-815B-D52CFD77935D"
+
+    @inlineCallbacks
+    def setUp(self):
+        yield super(DPSClientAugmentedAggregateDirectoryTest, self).setUp()
+
+        # The "local" directory service
+        self.client = DirectoryService(None)
+
+        # The "remote" directory service
+        remoteDirectory = self.directory
+
+        # Connect the two services directly via an IOPump
+        client = AMP()
+        server = DirectoryProxyAMPProtocol(remoteDirectory)
+        pump = returnConnected(server, client)
+
+        # Replace the normal _getConnection method with one that bypasses any
+        # actual networking
+        self.patch(self.client, "_getConnection", lambda: succeed(client))
+
+        # Wrap the normal _call method with one that flushes the IOPump
+        # afterwards
+        origCall = self.client._call
+
+        def newCall(*args, **kwds):
+            d = origCall(*args, **kwds)
+            pump.flush()
+            return d
+
+        self.patch(self.client, "_call", newCall)
+
+
+    def configure(self):
+        """
+        Override configuration hook to turn on wiki.
+        """
+        super(DPSClientAugmentedAggregateDirectoryTest, self).configure()
+        self.patch(config.Authentication.Wiki, "Enabled", True)
+
+
+    @inlineCallbacks
+    def test_uid(self):
+        record = (yield self.client.recordWithUID(self.wsanchezUID))
+        self.assertTrue(u"wsanchez" in record.shortNames)
+
+
+    @inlineCallbacks
+    def test_shortName(self):
+        record = (yield self.client.recordWithShortName(
+            RecordType.user,
+            u"wsanchez"
+        ))
+        self.assertEquals(record.uid, self.wsanchezUID)
+
+
+    def test_guid(self):
+        record = yield self.client.recordWithGUID(self.wsanchezUID)
+        self.assertTrue(u"wsanchez" in record.shortNames)
+
+
+    @inlineCallbacks
+    def test_recordType(self):
+        records = (yield self.client.recordsWithRecordType(
+            RecordType.user
+        ))
+        self.assertEquals(len(records), 31)
+
+
+    @inlineCallbacks
+    def test_emailAddress(self):
+        records = (yield self.client.recordsWithEmailAddress(
+            u"wsanchez at example.com"
+        ))
+        self.assertEquals(len(records), 1)
+        self.assertEquals(records[0].shortNames, [u"wsanchez"])
+
+
+    @inlineCallbacks
+    def test_recordsMatchingTokens(self):
+        records = (yield self.client.recordsMatchingTokens(
+            [u"anche"]
+        ))
+        matchingShortNames = set()
+        for r in records:
+            for shortName in r.shortNames:
+                matchingShortNames.add(shortName)
+        self.assertTrue("dre" in matchingShortNames)
+        self.assertTrue("wsanchez" in matchingShortNames)
+
+
+    @inlineCallbacks
+    def test_recordsMatchingFields_anyType(self):
+        fields = (
+            (u"fullNames", "anche", MatchFlags.caseInsensitive, MatchType.contains),
+            (u"fullNames", "morgen", MatchFlags.caseInsensitive, MatchType.contains),
+        )
+        records = (yield self.client.recordsMatchingFields(
+            fields, operand=Operand.OR, recordType=None
+        ))
+        matchingShortNames = set()
+        for r in records:
+            for shortName in r.shortNames:
+                matchingShortNames.add(shortName)
+        self.assertTrue("sagen" in matchingShortNames)
+        self.assertTrue("dre" in matchingShortNames)
+        self.assertTrue("wsanchez" in matchingShortNames)
+        self.assertTrue("sanchezoffice" in matchingShortNames)
+
+
+    @inlineCallbacks
+    def test_recordsMatchingFields_oneType(self):
+        fields = (
+            (u"fullNames", "anche", MatchFlags.caseInsensitive, MatchType.contains),
+        )
+        records = (yield self.client.recordsMatchingFields(
+            fields, operand=Operand.OR, recordType=RecordType.user
+        ))
+        matchingShortNames = set()
+        for r in records:
+            for shortName in r.shortNames:
+                matchingShortNames.add(shortName)
+        self.assertTrue("dre" in matchingShortNames)
+        self.assertTrue("wsanchez" in matchingShortNames)
+        # This location should *not* appear in the results
+        self.assertFalse("sanchezoffice" in matchingShortNames)
+
+
+    @inlineCallbacks
+    def test_recordsMatchingFields_unsupportedField(self):
+        fields = (
+            (u"fullNames", "anche", MatchFlags.caseInsensitive, MatchType.contains),
+            # This should be ignored:
+            (u"foo", "bar", MatchFlags.caseInsensitive, MatchType.contains),
+        )
+        records = (yield self.client.recordsMatchingFields(
+            fields, operand=Operand.OR, recordType=None
+        ))
+        matchingShortNames = set()
+        for r in records:
+            for shortName in r.shortNames:
+                matchingShortNames.add(shortName)
+        self.assertTrue("dre" in matchingShortNames)
+        self.assertTrue("wsanchez" in matchingShortNames)
+        self.assertTrue("sanchezoffice" in matchingShortNames)
+
+
+    @inlineCallbacks
+    def test_recordsFromMatchExpression(self):
+        expression = MatchExpression(
+            FieldName.uid,
+            u"wsanchez",
+            MatchType.equals,
+            MatchFlags.none
+        )
+        records = yield self.client.recordsFromExpression(expression)
+        self.assertEquals(len(records), 1)
+
+
+    @inlineCallbacks
+    def test_verifyPlaintextPassword(self):
+        expectations = (
+            (u"zehcnasw", True),  # Correct
+            ("wrong", False)  # Incorrect
+        )
+        record = (
+            yield self.client.recordWithShortName(
+                RecordType.user,
+                u"wsanchez"
+            )
+        )
+
+        for password, answer in expectations:
+            authenticated = (yield record.verifyPlaintextPassword(password))
+            self.assertEquals(authenticated, answer)
+
+
+    @inlineCallbacks
+    def test_verifyHTTPDigest(self):
+        expectations = (
+            (u"zehcnasw", True),  # Correct
+            ("wrong", False)  # Incorrect
+        )
+        record = (
+            yield self.client.recordWithShortName(
+                RecordType.user,
+                u"wsanchez"
+            )
+        )
+
+        realm = "host.example.com"
+        nonce = "128446648710842461101646794502"
+        algorithm = "md5"
+        uri = "http://host.example.com"
+        method = "GET"
+
+        for password, answer in expectations:
+            for qop, nc, cnonce in (
+                ("", "", ""),
+                ("auth", "00000001", "/rrD6TqPA3lHRmg+fw/vyU6oWoQgzK7h9yWrsCmv/lE="),
+            ):
+                response = calcResponse(
+                    calcHA1(algorithm, u"wsanchez", realm, password, nonce, cnonce),
+                    calcHA2(algorithm, method, uri, qop, None),
+                    algorithm, nonce, nc, cnonce, qop)
+
+                authenticated = (
+                    yield record.verifyHTTPDigest(
+                        u"wsanchez", realm, uri, nonce, cnonce, algorithm, nc, qop,
+                        response, method
+                    )
+                )
+                self.assertEquals(authenticated, answer)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140328/7eeed33b/attachment-0001.html>


More information about the calendarserver-changes mailing list