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

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 28 09:28:17 PDT 2014


Revision: 13020
          http://trac.calendarserver.org//changeset/13020
Author:   sagen at apple.com
Date:     2014-03-28 09:28:17 -0700 (Fri, 28 Mar 2014)
Log Message:
-----------
Remove Lion wiki compatibility, remove old wiki test, add new wiki test

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py
    CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/stdconfig.py

Added Paths:
-----------
    CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_wiki.py

Removed Paths:
-------------
    CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_wiki.py

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py	2014-03-28 03:33:30 UTC (rev 13019)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py	2014-03-28 16:28:17 UTC (rev 13020)
@@ -21,12 +21,10 @@
 
 from calendarserver.platform.darwin.wiki import uidForAuthToken
 from twext.python.log import Logger
-from twext.who.idirectory import RecordType
 from twisted.cred.error import LoginFailed, UnauthorizedLogin
 from twisted.internet.defer import inlineCallbacks, returnValue, succeed
 from twisted.python.reflect import namedClass
 from twisted.web.error import Error as WebError
-from twisted.web.xmlrpc import Proxy
 from twistedcaldav.cache import DisabledCache
 from twistedcaldav.cache import MemcacheResponseCache, MemcacheChangeNotifier
 from twistedcaldav.cache import _CachedResponseResource
@@ -233,18 +231,9 @@
 
                     record = None
                     try:
-                        if wikiConfig.LionCompatibility:
+                        uid = (yield uidForAuthToken(token))
+                        if uid == "unauthenticated":
                             uid = None
-                            proxy = Proxy(wikiConfig["URL"])
-                            username = (yield proxy.callRemote(wikiConfig["UserMethod"], token))
-                            directory = request.site.resource.getDirectory()
-                            record = yield directory.recordWithShortName(RecordType.user, username)
-                            if record is not None:
-                                uid = record.uid
-                        else:
-                            uid = (yield uidForAuthToken(token))
-                            if uid == "unauthenticated":
-                                uid = None
 
                     except WebError, w:
                         uid = None

Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_wiki.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_wiki.py	2014-03-28 03:33:30 UTC (rev 13019)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_wiki.py	2014-03-28 16:28:17 UTC (rev 13020)
@@ -1,116 +0,0 @@
-##
-# Copyright (c) 2005-2014 Apple Inc. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-##
-
-from twistedcaldav.test.util import TestCase
-from twistedcaldav.directory.wiki import (
-    WikiDirectoryService, WikiDirectoryRecord, getWikiAccess
-)
-from twisted.internet.defer import inlineCallbacks, succeed
-from twisted.web.xmlrpc import Fault
-from txweb2.http import HTTPError
-from txweb2 import responsecode
-from twistedcaldav.config import config
-from twisted.web.error import Error as WebError
-
-class WikiTestCase(TestCase):
-    """
-    Test the Wiki Directory Service
-    """
-
-    def test_enabled(self):
-        service = WikiDirectoryService()
-        service.realmName = "Test"
-        record = WikiDirectoryRecord(service,
-            WikiDirectoryService.recordType_wikis,
-            "test",
-            None
-        )
-        self.assertTrue(record.enabled)
-        self.assertTrue(record.enabledForCalendaring)
-
-
-    @inlineCallbacks
-    def test_getWikiAccessLion(self):
-        """
-        XMLRPC Faults result in HTTPErrors
-        """
-        self.patch(config.Authentication.Wiki, "LionCompatibility", True)
-
-        def successful(self, user, wiki):
-            return succeed("read")
-
-        def fault2(self, user, wiki):
-            raise Fault(2, "Bad session")
-
-        def fault12(self, user, wiki):
-            raise Fault(12, "Non-existent wiki")
-
-        def fault13(self, user, wiki):
-            raise Fault(13, "Non-existent wiki")
-
-        access = (yield getWikiAccess("user", "wiki", method=successful))
-        self.assertEquals(access, "read")
-
-        for (method, code) in (
-            (fault2, responsecode.FORBIDDEN),
-            (fault12, responsecode.NOT_FOUND),
-            (fault13, responsecode.SERVICE_UNAVAILABLE),
-        ):
-            try:
-                access = (yield getWikiAccess("user", "wiki", method=method))
-            except HTTPError, e:
-                self.assertEquals(e.response.code, code)
-            except:
-                self.fail("Incorrect exception")
-            else:
-                self.fail("Didn't raise exception")
-
-
-    @inlineCallbacks
-    def test_getWikiAccess(self):
-        """
-        Non-200 GET responses result in HTTPErrors
-        """
-        self.patch(config.Authentication.Wiki, "LionCompatibility", False)
-
-        def successful(user, wiki, host=None, port=None):
-            return succeed("read")
-
-        def forbidden(user, wiki, host=None, port=None):
-            raise WebError(403, message="Unknown user")
-
-        def notFound(user, wiki, host=None, port=None):
-            raise WebError(404, message="Non-existent wiki")
-
-        def other(user, wiki, host=None, port=None):
-            raise WebError(500, "Error")
-
-        access = (yield getWikiAccess("user", "wiki", method=successful))
-        self.assertEquals(access, "read")
-
-        for (method, code) in (
-            (forbidden, responsecode.FORBIDDEN),
-            (notFound, responsecode.NOT_FOUND),
-            (other, responsecode.SERVICE_UNAVAILABLE),
-        ):
-            try:
-                access = (yield getWikiAccess("user", "wiki", method=method))
-            except HTTPError, e:
-                self.assertEquals(e.response.code, code)
-            except:
-                self.fail("Incorrect exception")
-            else:
-                self.fail("Didn't raise exception")

Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/stdconfig.py	2014-03-28 03:33:30 UTC (rev 13019)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/stdconfig.py	2014-03-28 16:28:17 UTC (rev 13020)
@@ -454,10 +454,6 @@
         "Wiki": {
             "Enabled": False,
             "Cookie": "cc.collabd_session_guid",
-            "URL": "http://127.0.0.1:8089/RPC2",
-            "UserMethod": "userForSession",
-            "WikiMethod": "accessLevelForUserWikiCalendar",
-            "LionCompatibility": False,
             "CollabHost": "localhost",
             "CollabPort": 4444,
         },

Added: CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_wiki.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_wiki.py	                        (rev 0)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_wiki.py	2014-03-28 16:28:17 UTC (rev 13020)
@@ -0,0 +1,116 @@
+##
+# Copyright (c) 2014 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from __future__ import print_function
+from __future__ import absolute_import
+
+"""
+Tests for L{txdav.who.wiki}.
+"""
+
+
+from twisted.trial import unittest
+from twisted.internet.defer import inlineCallbacks, succeed
+from twistedcaldav.test.util import StoreTestCase
+
+from ..wiki import DirectoryService, WikiAccessLevel
+import txdav.who.wiki
+
+
+class WikiIndividualServiceTestCase(unittest.TestCase):
+    """
+    Instantiate a wiki service directly
+    """
+
+    @inlineCallbacks
+    def test_service(self):
+        service = DirectoryService("realm", "localhost", 4444)
+        record = yield service.recordWithUID(u"[wiki]test")
+        self.assertEquals(
+            record.shortNames[0],
+            u"test"
+        )
+
+
+
+class WikiAggregateServiceTestCase(StoreTestCase):
+    """
+    Get a wiki service as part of directoryFromConfig
+    """
+
+    def configure(self):
+        """
+        Override configuration hook to turn on wiki service.
+        """
+        from twistedcaldav.config import config
+
+        super(WikiAggregateServiceTestCase, self).configure()
+        self.patch(config.Authentication.Wiki, "Enabled", True)
+
+
+    @inlineCallbacks
+    def test_service(self):
+        record = yield self.directory.recordWithUID(u"[wiki]test")
+        self.assertEquals(
+            record.shortNames[0],
+            u"test"
+        )
+
+
+
+class AccessForRecordTestCase(StoreTestCase):
+    """
+    Exercise accessForRecord
+    """
+
+    def configure(self):
+        """
+        Override configuration hook to turn on wiki service.
+        """
+        from twistedcaldav.config import config
+
+        super(AccessForRecordTestCase, self).configure()
+        self.patch(config.Authentication.Wiki, "Enabled", True)
+        self.patch(
+            txdav.who.wiki,
+            "accessForUserToWiki",
+            self.stubAccessForUserToWiki
+        )
+
+
+    def stubAccessForUserToWiki(self, *args, **kwds):
+        return succeed(self.access)
+
+
+    @inlineCallbacks
+    def test_accessForRecord(self):
+        record = yield self.directory.recordWithUID(u"[wiki]test")
+
+        self.access = "no-access"
+        access = yield record.accessForRecord(None)
+        self.assertEquals(access, WikiAccessLevel.none)
+
+        self.access = "read"
+        access = yield record.accessForRecord(None)
+        self.assertEquals(access, WikiAccessLevel.read)
+
+        self.access = "write"
+        access = yield record.accessForRecord(None)
+        self.assertEquals(access, WikiAccessLevel.write)
+
+        self.access = "admin"
+        access = yield record.accessForRecord(None)
+        self.assertEquals(access, WikiAccessLevel.write)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140328/8146d04d/attachment-0001.html>


More information about the calendarserver-changes mailing list