def test_cacheUsed(self): delegator = yield self.directory.recordWithUID(u"__wsanchez1__") delegate1 = yield self.directory.recordWithUID(u"__sagen1__") # Patch transaction so we can monitor whether cache is being used original_delegates = CommonStoreTransaction.delegates delegates_query = [0] def _delegates(self, delegator, readWrite, expanded=False): delegates_query[0] += 1 return original_delegates(self, delegator, readWrite, expanded) self.patch(CommonStoreTransaction, "delegates", _delegates) original_delegators = CommonStoreTransaction.delegators delegators_query = [0] def _delegators(self, delegate, readWrite): delegators_query[0] += 1 return original_delegators(self, delegate, readWrite) self.patch(CommonStoreTransaction, "delegators", _delegators) # Not used yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, True, False) self.assertEqual(delegates_query[0], 1) # Used yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, True, False) self.assertEqual(delegates_query[0], 1) # Not used yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, False, False) self.assertEqual(delegates_query[0], 2) # Used yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, False, False) self.assertEqual(delegates_query[0], 2) # Not used yield Delegates.delegatedTo(self.transactionUnderTest(), delegate1, True) self.assertEqual(delegators_query[0], 1) # Used yield Delegates.delegatedTo(self.transactionUnderTest(), delegate1, True) self.assertEqual(delegators_query[0], 1) # Not used yield Delegates.delegatedTo(self.transactionUnderTest(), delegate1, False) self.assertEqual(delegators_query[0], 2) # Used yield Delegates.delegatedTo(self.transactionUnderTest(), delegate1, False) self.assertEqual(delegators_query[0], 2)
def test_cacheUsed(self): delegator = yield self.directory.recordWithUID(u"__wsanchez1__") delegate1 = yield self.directory.recordWithUID(u"__sagen1__") # Patch transaction so we can monitor whether cache is being used original_delegates = CommonStoreTransaction.delegates delegates_query = [0] def _delegates(self, delegator, readWrite, expanded=False): delegates_query[0] += 1 return original_delegates(self, delegator, readWrite, expanded) self.patch(CommonStoreTransaction, "delegates", _delegates) original_delegators = CommonStoreTransaction.delegators delegators_query = [0] def _delegators(self, delegate, readWrite): delegators_query[0] += 1 return original_delegators(self, delegate, readWrite) self.patch(CommonStoreTransaction, "delegators", _delegators) # Not used yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, True, False) self.assertEqual(delegates_query[0], 1) # Used yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, True, False) self.assertEqual(delegates_query[0], 1) # Not used yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, False, False) self.assertEqual(delegates_query[0], 2) # Used yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, False, False) self.assertEqual(delegates_query[0], 2) # Not used yield Delegates.delegatedTo(self.transactionUnderTest(), delegate1, True) self.assertEqual(delegators_query[0], 1) # Used yield Delegates.delegatedTo(self.transactionUnderTest(), delegate1, True) self.assertEqual(delegators_query[0], 1) # Not used yield Delegates.delegatedTo(self.transactionUnderTest(), delegate1, False) self.assertEqual(delegators_query[0], 2) # Used yield Delegates.delegatedTo(self.transactionUnderTest(), delegate1, False) self.assertEqual(delegators_query[0], 2)
def _delegatesOfResults(self, delegator, readWrite, expanded, results): delegates = (yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, readWrite, expanded)) self.assertEquals( set([d.uid for d in delegates]), set([delegate.uid for delegate in results]), msg="uid:{}, rw={}, expanded={}".format(delegator.uid, readWrite, expanded) )
def _delegatesOfResults(self, delegator, readWrite, expanded, results): delegates = (yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, readWrite, expanded)) self.assertEquals( set([d.uid for d in delegates]), set([delegate.uid for delegate in results]), msg="uid:{}, rw={}, expanded={}".format(delegator.uid, readWrite, expanded) )
def test_migrateWiki(self): # Ensure the two records do not exist yet record = yield self.directory.recordWithUID(u"wiki-xyzzy") self.assertEquals(record, None) record = yield self.directory.recordWithUID(u"wiki-plugh") self.assertEquals(record, None) # We need to create the calendar homes, but we can't unless there are # records for these uids. Since we've disabled the wiki service above, # we're temporarily going to substitute a wiki directory service while # we create the calendar homes: realDirectory = self.store.directoryService() tmpWikiService = WikiDirectoryService("test", None) tmpWikiService.serversDB = lambda: None self.store._directoryService = tmpWikiService txn = self.store.newTransaction() yield txn.calendarHomeWithUID(u"wiki-xyzzy", create=True) yield txn.calendarHomeWithUID(u"wiki-plugh", create=True) yield txn.commit() self.store._directoryService = realDirectory # Migrate wiki principals to resources yield migrateWiki(self.store, "users:admin") txn = self.store.newTransaction() record = yield self.directory.recordWithUID(u"wiki-xyzzy") self.assertEquals(record.shortNames, [u"xyzzy"]) self.assertEquals(record.recordType, CalRecordType.resource) delegates = (yield Delegates.delegatesOf(txn, record, True)) self.assertEquals([u"admin"], [d.shortNames[0] for d in delegates]) record = yield self.directory.recordWithUID(u"wiki-plugh") self.assertEquals(record.shortNames, [u"plugh"]) self.assertEquals(record.recordType, CalRecordType.resource) delegates = (yield Delegates.delegatesOf(txn, record, True)) self.assertEquals([u"admin"], [d.shortNames[0] for d in delegates]) yield txn.commit()
def postCheck(self): """ Checks after migration is done """ # Check that the home has been moved home = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01") self.assertTrue(home.external()) home = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_NORMAL) self.assertTrue(home is None) home = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_EXTERNAL) self.assertTrue(home is not None) home = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_DISABLED) self.assertTrue(home is not None) home = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_MIGRATING) self.assertTrue(home is None) yield self.commitTransaction(0) home = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01") self.assertTrue(home.normal()) home = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_NORMAL) self.assertTrue(home is not None) home = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_EXTERNAL) self.assertTrue(home is None) home = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_DISABLED) self.assertTrue(home is not None) home = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_MIGRATING) self.assertTrue(home is None) yield self.commitTransaction(1) # Check that the notifications have been moved notifications = yield self.notificationCollectionUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_NORMAL) self.assertTrue(notifications is None) notifications = yield self.notificationCollectionUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_EXTERNAL) self.assertTrue(notifications is None) notifications = yield self.notificationCollectionUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_DISABLED) self.assertTrue(notifications is not None) yield self.commitTransaction(0) notifications = yield self.notificationCollectionUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_NORMAL) self.assertTrue(notifications is not None) notifications = yield self.notificationCollectionUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_EXTERNAL) self.assertTrue(notifications is None) notifications = yield self.notificationCollectionUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_DISABLED) self.assertTrue(notifications is not None) yield self.commitTransaction(1) # New pod data homes = {} homes["user01"] = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01") homes["user02"] = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user02") self.assertTrue(homes["user02"].external()) homes["user03"] = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user03") self.assertTrue(homes["user03"].external()) homes["puser01"] = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="puser01") self.assertTrue(homes["puser01"].normal()) homes["puser02"] = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="puser02") self.assertTrue(homes["puser02"].normal()) homes["puser03"] = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="puser03") self.assertTrue(homes["puser03"].normal()) # Check calendar data on new pod calendars = yield homes["user01"].loadChildren() calnames = dict([(calendar.name(), calendar) for calendar in calendars]) self.assertEqual( set(calnames.keys()), set(("calendar", "tasks", "inbox", self.stash["sharename_user02_to_user01"], self.stash["sharename_puser02_to_user01"],)) ) # Check shared-by user01 on new pod shared = calnames["calendar"] invitations = yield shared.sharingInvites() by_sharee = dict([(invitation.shareeUID, invitation) for invitation in invitations]) self.assertEqual(len(invitations), 2) self.assertEqual(set(by_sharee.keys()), set(("user03", "puser03",))) self.assertEqual(by_sharee["user03"].shareeHomeID, homes["user03"].id()) self.assertEqual(by_sharee["puser03"].shareeHomeID, homes["puser03"].id()) # Check shared-to user01 on new pod shared = calnames[self.stash["sharename_user02_to_user01"]] self.assertEqual(shared.ownerHome().uid(), "user02") self.assertEqual(shared.ownerHome().id(), homes["user02"].id()) shared = calnames[self.stash["sharename_puser02_to_user01"]] self.assertEqual(shared.ownerHome().uid(), "puser02") self.assertEqual(shared.ownerHome().id(), homes["puser02"].id()) shared = yield homes["puser02"].calendarWithName("calendar") invitations = yield shared.sharingInvites() self.assertEqual(len(invitations), 1) self.assertEqual(invitations[0].shareeHomeID, homes["user01"].id()) yield self.commitTransaction(1) # Old pod data homes = {} homes["user01"] = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01") homes["user02"] = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user02") self.assertTrue(homes["user02"].normal()) homes["user03"] = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user03") self.assertTrue(homes["user03"].normal()) homes["puser01"] = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="puser01") self.assertTrue(homes["puser01"] is None) homes["puser02"] = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="puser02") self.assertTrue(homes["puser02"].external()) homes["puser03"] = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="puser03") self.assertTrue(homes["puser03"].external()) # Check shared-by user01 on old pod shared = yield homes["user03"].calendarWithName(self.stash["sharename_user01_to_user03"]) self.assertEqual(shared.ownerHome().uid(), "user01") self.assertEqual(shared.ownerHome().id(), homes["user01"].id()) # Check shared-to user01 on old pod shared = yield homes["user02"].calendarWithName("calendar") invitations = yield shared.sharingInvites() self.assertEqual(len(invitations), 1) self.assertEqual(invitations[0].shareeHomeID, homes["user01"].id()) yield self.commitTransaction(0) # Delegates on each pod for pod in range(self.numberOfStores): txn = self.theTransactionUnderTest(pod) records = {} for ctr in range(10): uid = u"user{:02d}".format(ctr + 1) records[uid] = yield txn.directoryService().recordWithUID(uid) for ctr in range(10): uid = u"puser{:02d}".format(ctr + 1) records[uid] = yield txn.directoryService().recordWithUID(uid) for ctr in range(10): uid = u"group{:02d}".format(ctr + 1) records[uid] = yield txn.directoryService().recordWithUID(uid) delegates = yield Delegates.delegatesOf(txn, records["user01"], True, False) self.assertTrue(records["user02"] in delegates) self.assertTrue(records["group02"] in delegates) delegates = yield Delegates.delegatesOf(txn, records["user01"], True, True) self.assertTrue(records["user02"] in delegates) self.assertTrue(records["user06"] in delegates) self.assertTrue(records["user07"] in delegates) self.assertTrue(records["user08"] in delegates) delegates = yield Delegates.delegatesOf(txn, records["user01"], False, False) self.assertTrue(records["user03"] in delegates) self.assertTrue(records["group03"] in delegates) self.assertTrue(records["puser01"] in delegates) delegates = yield Delegates.delegatesOf(txn, records["user01"], False, True) self.assertTrue(records["user03"] in delegates) self.assertTrue(records["user07"] in delegates) self.assertTrue(records["user08"] in delegates) self.assertTrue(records["user09"] in delegates) self.assertTrue(records["puser01"] in delegates) # Attachments obj = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(1), name="01_3.ics", calendar_name="calendar", home="user01") attachment = yield obj.attachmentWithManagedID(self.stash["user01_attachment_mid"]) self.assertTrue(attachment is not None) self.assertEqual(attachment.md5(), self.stash["user01_attachment_md5"]) data = yield self.attachmentToString(attachment) self.assertEqual(data, "Here is some text #1.") # Check removal of data from new pod # Make sure all jobs are done yield JobItem.waitEmpty(self.theStoreUnderTest(1).newTransaction, reactor, 60) # No migration state data left txn = self.theTransactionUnderTest(1) for migrationType in (CalendarMigrationRecord, CalendarObjectMigrationRecord, AttachmentMigrationRecord,): records = yield migrationType.all(txn) self.assertEqual(len(records), 0, msg=migrationType.__name__) yield self.commitTransaction(1) # No homes txn = self.theTransactionUnderTest(1) oldhome = yield txn.calendarHomeWithUID("user01", status=_HOME_STATUS_DISABLED) self.assertTrue(oldhome is None) oldhome = yield txn.notificationsWithUID("user01", status=_HOME_STATUS_DISABLED) self.assertTrue(oldhome is None) # Check removal of data from old pod # Make sure all jobs are done yield JobItem.waitEmpty(self.theStoreUnderTest(0).newTransaction, reactor, 60) # No homes txn = self.theTransactionUnderTest(0) oldhome = yield txn.calendarHomeWithUID("user01", status=_HOME_STATUS_DISABLED) self.assertTrue(oldhome is None) oldhome = yield txn.notificationsWithUID("user01", status=_HOME_STATUS_DISABLED) self.assertTrue(oldhome is None) # No delegates for delegateType in (DelegateRecord, DelegateGroupsRecord, ExternalDelegateGroupsRecord): records = yield delegateType.query(txn, delegateType.delegator == "user01") self.assertEqual(len(records), 0, msg=delegateType.__name__) # No work items for workType in allScheduleWork: records = yield workType.query(txn, workType.homeResourceID == self.stash["user01_pod0_home_id"]) self.assertEqual(len(records), 0, msg=workType.__name__)
def postCheck(self): """ Checks after migration is done """ # Check that the home has been moved home = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01") self.assertTrue(home.external()) home = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_NORMAL) self.assertTrue(home is None) home = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_EXTERNAL) self.assertTrue(home is not None) home = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_DISABLED) self.assertTrue(home is not None) home = yield self.homeUnderTest(self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_MIGRATING) self.assertTrue(home is None) yield self.commitTransaction(0) home = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01") self.assertTrue(home.normal()) home = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_NORMAL) self.assertTrue(home is not None) home = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_EXTERNAL) self.assertTrue(home is None) home = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_DISABLED) self.assertTrue(home is not None) home = yield self.homeUnderTest(self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_MIGRATING) self.assertTrue(home is None) yield self.commitTransaction(1) # Check that the notifications have been moved notifications = yield self.notificationCollectionUnderTest( self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_NORMAL) self.assertTrue(notifications is None) notifications = yield self.notificationCollectionUnderTest( self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_EXTERNAL) self.assertTrue(notifications is None) notifications = yield self.notificationCollectionUnderTest( self.theTransactionUnderTest(0), name="user01", status=_HOME_STATUS_DISABLED) self.assertTrue(notifications is not None) yield self.commitTransaction(0) notifications = yield self.notificationCollectionUnderTest( self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_NORMAL) self.assertTrue(notifications is not None) notifications = yield self.notificationCollectionUnderTest( self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_EXTERNAL) self.assertTrue(notifications is None) notifications = yield self.notificationCollectionUnderTest( self.theTransactionUnderTest(1), name="user01", status=_HOME_STATUS_DISABLED) self.assertTrue(notifications is not None) yield self.commitTransaction(1) # New pod data homes = {} homes["user01"] = yield self.homeUnderTest( self.theTransactionUnderTest(1), name="user01") homes["user02"] = yield self.homeUnderTest( self.theTransactionUnderTest(1), name="user02") self.assertTrue(homes["user02"].external()) homes["user03"] = yield self.homeUnderTest( self.theTransactionUnderTest(1), name="user03") self.assertTrue(homes["user03"].external()) homes["puser01"] = yield self.homeUnderTest( self.theTransactionUnderTest(1), name="puser01") self.assertTrue(homes["puser01"].normal()) homes["puser02"] = yield self.homeUnderTest( self.theTransactionUnderTest(1), name="puser02") self.assertTrue(homes["puser02"].normal()) homes["puser03"] = yield self.homeUnderTest( self.theTransactionUnderTest(1), name="puser03") self.assertTrue(homes["puser03"].normal()) # Check calendar data on new pod calendars = yield homes["user01"].loadChildren() calnames = dict([(calendar.name(), calendar) for calendar in calendars]) self.assertEqual( set(calnames.keys()), set(( "calendar", "tasks", "inbox", self.stash["sharename_user02_to_user01"], self.stash["sharename_puser02_to_user01"], ))) # Check shared-by user01 on new pod shared = calnames["calendar"] invitations = yield shared.sharingInvites() by_sharee = dict([(invitation.shareeUID, invitation) for invitation in invitations]) self.assertEqual(len(invitations), 2) self.assertEqual(set(by_sharee.keys()), set(( "user03", "puser03", ))) self.assertEqual(by_sharee["user03"].shareeHomeID, homes["user03"].id()) self.assertEqual(by_sharee["puser03"].shareeHomeID, homes["puser03"].id()) # Check shared-to user01 on new pod shared = calnames[self.stash["sharename_user02_to_user01"]] self.assertEqual(shared.ownerHome().uid(), "user02") self.assertEqual(shared.ownerHome().id(), homes["user02"].id()) shared = calnames[self.stash["sharename_puser02_to_user01"]] self.assertEqual(shared.ownerHome().uid(), "puser02") self.assertEqual(shared.ownerHome().id(), homes["puser02"].id()) shared = yield homes["puser02"].calendarWithName("calendar") invitations = yield shared.sharingInvites() self.assertEqual(len(invitations), 1) self.assertEqual(invitations[0].shareeHomeID, homes["user01"].id()) yield self.commitTransaction(1) # Old pod data homes = {} homes["user01"] = yield self.homeUnderTest( self.theTransactionUnderTest(0), name="user01") homes["user02"] = yield self.homeUnderTest( self.theTransactionUnderTest(0), name="user02") self.assertTrue(homes["user02"].normal()) homes["user03"] = yield self.homeUnderTest( self.theTransactionUnderTest(0), name="user03") self.assertTrue(homes["user03"].normal()) homes["puser01"] = yield self.homeUnderTest( self.theTransactionUnderTest(0), name="puser01") self.assertTrue(homes["puser01"] is None) homes["puser02"] = yield self.homeUnderTest( self.theTransactionUnderTest(0), name="puser02") self.assertTrue(homes["puser02"].external()) homes["puser03"] = yield self.homeUnderTest( self.theTransactionUnderTest(0), name="puser03") self.assertTrue(homes["puser03"].external()) # Check shared-by user01 on old pod shared = yield homes["user03"].calendarWithName( self.stash["sharename_user01_to_user03"]) self.assertEqual(shared.ownerHome().uid(), "user01") self.assertEqual(shared.ownerHome().id(), homes["user01"].id()) # Check shared-to user01 on old pod shared = yield homes["user02"].calendarWithName("calendar") invitations = yield shared.sharingInvites() self.assertEqual(len(invitations), 1) self.assertEqual(invitations[0].shareeHomeID, homes["user01"].id()) yield self.commitTransaction(0) # Delegates on each pod for pod in range(self.numberOfStores): txn = self.theTransactionUnderTest(pod) records = {} for ctr in range(10): uid = u"user{:02d}".format(ctr + 1) records[uid] = yield txn.directoryService().recordWithUID(uid) for ctr in range(10): uid = u"puser{:02d}".format(ctr + 1) records[uid] = yield txn.directoryService().recordWithUID(uid) for ctr in range(10): uid = u"group{:02d}".format(ctr + 1) records[uid] = yield txn.directoryService().recordWithUID(uid) delegates = yield Delegates.delegatesOf(txn, records["user01"], True, False) self.assertTrue(records["user02"] in delegates) self.assertTrue(records["group02"] in delegates) delegates = yield Delegates.delegatesOf(txn, records["user01"], True, True) self.assertTrue(records["user02"] in delegates) self.assertTrue(records["user06"] in delegates) self.assertTrue(records["user07"] in delegates) self.assertTrue(records["user08"] in delegates) delegates = yield Delegates.delegatesOf(txn, records["user01"], False, False) self.assertTrue(records["user03"] in delegates) self.assertTrue(records["group03"] in delegates) self.assertTrue(records["puser01"] in delegates) delegates = yield Delegates.delegatesOf(txn, records["user01"], False, True) self.assertTrue(records["user03"] in delegates) self.assertTrue(records["user07"] in delegates) self.assertTrue(records["user08"] in delegates) self.assertTrue(records["user09"] in delegates) self.assertTrue(records["puser01"] in delegates) # Attachments obj = yield self.calendarObjectUnderTest( txn=self.theTransactionUnderTest(1), name="01_3.ics", calendar_name="calendar", home="user01") attachment = yield obj.attachmentWithManagedID( self.stash["user01_attachment_mid"]) self.assertTrue(attachment is not None) self.assertEqual(attachment.md5(), self.stash["user01_attachment_md5"]) data = yield self.attachmentToString(attachment) self.assertEqual(data, "Here is some text #1.") # Check removal of data from new pod # Make sure all jobs are done yield JobItem.waitEmpty( self.theStoreUnderTest(1).newTransaction, reactor, 60) # No migration state data left txn = self.theTransactionUnderTest(1) for migrationType in ( CalendarMigrationRecord, CalendarObjectMigrationRecord, AttachmentMigrationRecord, ): records = yield migrationType.all(txn) self.assertEqual(len(records), 0, msg=migrationType.__name__) yield self.commitTransaction(1) # No homes txn = self.theTransactionUnderTest(1) oldhome = yield txn.calendarHomeWithUID("user01", status=_HOME_STATUS_DISABLED) self.assertTrue(oldhome is None) oldhome = yield txn.notificationsWithUID("user01", status=_HOME_STATUS_DISABLED) self.assertTrue(oldhome is None) # Check removal of data from old pod # Make sure all jobs are done yield JobItem.waitEmpty( self.theStoreUnderTest(0).newTransaction, reactor, 60) # No homes txn = self.theTransactionUnderTest(0) oldhome = yield txn.calendarHomeWithUID("user01", status=_HOME_STATUS_DISABLED) self.assertTrue(oldhome is None) oldhome = yield txn.notificationsWithUID("user01", status=_HOME_STATUS_DISABLED) self.assertTrue(oldhome is None) # No delegates for delegateType in (DelegateRecord, DelegateGroupsRecord, ExternalDelegateGroupsRecord): records = yield delegateType.query( txn, delegateType.delegator == "user01") self.assertEqual(len(records), 0, msg=delegateType.__name__) # No work items for workType in allScheduleWork: records = yield workType.query( txn, workType.homeResourceID == self.stash["user01_pod0_home_id"]) self.assertEqual(len(records), 0, msg=workType.__name__)
def test_directDelegation(self): txn = self.store.newTransaction(label="test_directDelegation") delegator = yield self.directory.recordWithUID(u"__wsanchez1__") delegate1 = yield self.directory.recordWithUID(u"__sagen1__") delegate2 = yield self.directory.recordWithUID(u"__cdaboo1__") # Add 1 delegate yield Delegates.addDelegate(txn, delegator, delegate1, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals([u"__sagen1__"], [d.uid for d in delegates]) delegators = (yield Delegates.delegatedTo(txn, delegate1, True)) self.assertEquals([u"__wsanchez1__"], [d.uid for d in delegators]) yield txn.commit() # So delegateService will see the changes txn = self.store.newTransaction(label="test_directDelegation") # The "proxy-write" pseudoGroup will have one member pseudoGroup = yield self.directory.recordWithShortName( DelegateRecordType.writeDelegateGroup, u"__wsanchez1__" ) self.assertEquals(pseudoGroup.uid, u"__wsanchez1__#calendar-proxy-write") self.assertEquals( [r.uid for r in (yield pseudoGroup.members())], [u"__sagen1__"] ) # The "proxy-read" pseudoGroup will have no members pseudoGroup = yield self.directory.recordWithShortName( DelegateRecordType.readDelegateGroup, u"__wsanchez1__" ) self.assertEquals(pseudoGroup.uid, u"__wsanchez1__#calendar-proxy-read") self.assertEquals( [r.uid for r in (yield pseudoGroup.members())], [] ) # The "proxy-write-for" pseudoGroup will have one member pseudoGroup = yield self.directory.recordWithShortName( DelegateRecordType.writeDelegatorGroup, u"__sagen1__" ) self.assertEquals(pseudoGroup.uid, u"__sagen1__#calendar-proxy-write-for") self.assertEquals( [r.uid for r in (yield pseudoGroup.members())], [u"__wsanchez1__"] ) # The "proxy-read-for" pseudoGroup will have no members pseudoGroup = yield self.directory.recordWithShortName( DelegateRecordType.readDelegatorGroup, u"__sagen1__" ) self.assertEquals(pseudoGroup.uid, u"__sagen1__#calendar-proxy-read-for") self.assertEquals( [r.uid for r in (yield pseudoGroup.members())], [] ) # Add another delegate yield Delegates.addDelegate(txn, delegator, delegate2, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__"]), set([d.uid for d in delegates]) ) delegators = (yield Delegates.delegatedTo(txn, delegate2, True)) self.assertEquals([u"__wsanchez1__"], [d.uid for d in delegators]) # Remove 1 delegate yield Delegates.removeDelegate(txn, delegator, delegate1, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals([u"__cdaboo1__"], [d.uid for d in delegates]) delegators = (yield Delegates.delegatedTo(txn, delegate1, True)) self.assertEquals(0, len(delegators)) # Remove the other delegate yield Delegates.removeDelegate(txn, delegator, delegate2, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals(0, len(delegates)) delegators = (yield Delegates.delegatedTo(txn, delegate2, True)) self.assertEquals(0, len(delegators)) yield txn.commit() # So delegateService will see the changes # Now set delegate assignments by using pseudoGroup.setMembers() pseudoGroup = yield self.directory.recordWithShortName( DelegateRecordType.writeDelegateGroup, u"__wsanchez1__" ) yield pseudoGroup.setMembers([delegate1, delegate2]) # Verify the assignments were made txn = self.store.newTransaction(label="test_directDelegation") delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__"]), set([d.uid for d in delegates]) ) yield txn.commit() # Set a different group of assignments: yield pseudoGroup.setMembers([delegate2]) # Verify the assignments were made txn = self.store.newTransaction(label="test_directDelegation") delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals( set([u"__cdaboo1__"]), set([d.uid for d in delegates]) ) yield txn.commit()
def test_directoryBasedDelegationChanges(self): groupCacher = GroupCacher(self.directory) delegator = yield self.directory.recordWithUID(u"__wsanchez1__") groupRecord1 = yield self.directory.recordWithUID(u"__top_group_1__") group1 = yield self.transactionUnderTest().groupByUID("__top_group_1__") groupRecord2 = yield self.directory.recordWithUID(u"__sub_group_1__") group2 = yield self.transactionUnderTest().groupByUID("__sub_group_1__") groupRecord3 = yield self.directory.recordWithUID(u"left_coast") group3 = yield self.transactionUnderTest().groupByUID("left_coast") delegate = yield self.directory.recordWithUID(u"__sagen1__") # No delegates delegates = yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, False) self.assertEquals(len(delegates), 0) # No delegators to this group delegators = yield self.transactionUnderTest().delegatorsToGroup(group1.groupID, False) self.assertEquals(len(delegators), 0) # User is not a delegate delegators = yield Delegates.delegatedTo(self.transactionUnderTest(), delegate, True) self.assertEquals(len(delegators), 0) # Apply an external read-only assignment yield groupCacher.applyExternalAssignments( self.transactionUnderTest(), delegator.uid, groupRecord1.uid, None ) # Now there is a read-only delegate delegates = yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, False) self.assertEquals(len(delegates), 1) # Now this group is read-only delegated to delegators = yield self.transactionUnderTest().delegatorsToGroup(group1.groupID, False) self.assertEquals(len(delegators), 1) # Apply an external read-write assignment yield groupCacher.applyExternalAssignments( self.transactionUnderTest(), delegator.uid, groupRecord1.uid, groupRecord2.uid ) # Now there are read-only and read-write delegates delegates = yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, False) self.assertEquals(len(delegates), 1) self.assertEquals(delegates[0].uid, "__top_group_1__") delegates = yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, True) self.assertEquals(len(delegates), 1) self.assertEquals(delegates[0].uid, "__sub_group_1__") # Now both groups are delegated to delegators = yield self.transactionUnderTest().delegatorsToGroup(group1.groupID, False) self.assertEquals(len(delegators), 1) delegators = yield self.transactionUnderTest().delegatorsToGroup(group2.groupID, True) self.assertEquals(len(delegators), 1) # User is now a delegate (cache must have been invalidated properly) delegators = yield Delegates.delegatedTo(self.transactionUnderTest(), delegate, True) self.assertEquals(len(delegators), 1) # Change read-write assignment yield groupCacher.applyExternalAssignments( self.transactionUnderTest(), delegator.uid, groupRecord1.uid, groupRecord3.uid ) # Now this group is not delegated to delegators = yield self.transactionUnderTest().delegatorsToGroup(group2.groupID, True) self.assertEquals(len(delegators), 0) # ..but this group is delegated to delegators = yield self.transactionUnderTest().delegatorsToGroup(group3.groupID, True) self.assertEquals(len(delegators), 1) # Remove external read-write assignment yield groupCacher.applyExternalAssignments( self.transactionUnderTest(), delegator.uid, groupRecord1.uid, None ) # Now there is only a read-only delegate delegates = yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, False) self.assertEquals(len(delegates), 1) self.assertEquals(delegates[0].uid, "__top_group_1__") delegates = yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, True) self.assertEquals(len(delegates), 0) # Now this group is read-only delegated to delegators = yield self.transactionUnderTest().delegatorsToGroup(group1.groupID, False) self.assertEquals(len(delegators), 1) # Now this group is not delegated to delegators = yield self.transactionUnderTest().delegatorsToGroup(group3.groupID, True) self.assertEquals(len(delegators), 0) # User is not a delegate anymore (cache must have been invalidated properly) delegators = yield Delegates.delegatedTo(self.transactionUnderTest(), delegate, True) self.assertEquals(len(delegators), 0) # Remove external assignments altogether yield groupCacher.applyExternalAssignments( self.transactionUnderTest(), delegator.uid, None, None ) # Now there are no delegates delegates = yield Delegates.delegatesOf(self.transactionUnderTest(), delegator, False) self.assertEquals(len(delegates), 0) # No groups are delegated to delegators = yield self.transactionUnderTest().delegatorsToGroup(group1.groupID, False) self.assertEquals(len(delegators), 0) delegators = yield self.transactionUnderTest().delegatorsToGroup(group2.groupID, True) self.assertEquals(len(delegators), 0) delegators = yield self.transactionUnderTest().delegatorsToGroup(group3.groupID, True) self.assertEquals(len(delegators), 0)
def test_indirectDelegation(self): txn = self.store.newTransaction(label="test_indirectDelegation") delegator = yield self.directory.recordWithUID(u"__wsanchez1__") delegate1 = yield self.directory.recordWithUID(u"__sagen1__") group1 = yield self.directory.recordWithUID(u"__top_group_1__") group2 = yield self.directory.recordWithUID(u"__sub_group_1__") # Add group delegate yield Delegates.addDelegate(txn, delegator, group1, True) # Passing expanded=False will return the group delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=False)) self.assertEquals(1, len(delegates)) self.assertEquals(delegates[0].uid, u"__top_group_1__") # Passing expanded=True will return not the group -- it only returns # non-groups delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__", u"__glyph1__"]), set([d.uid for d in delegates]) ) delegators = (yield Delegates.delegatedTo(txn, delegate1, True)) self.assertEquals([u"__wsanchez1__"], [d.uid for d in delegators]) # Verify we can ask for all delegated-to groups yield Delegates.addDelegate(txn, delegator, group2, True) groups = (yield txn.allGroupDelegates()) self.assertEquals( set([u'__sub_group_1__', u'__top_group_1__']), set(groups) ) # Delegate to a user who is already indirectly delegated-to yield Delegates.addDelegate(txn, delegator, delegate1, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__", u"__glyph1__"]), set([d.uid for d in delegates]) ) # Add a member to the group; they become a delegate newSet = set() for name in (u"wsanchez1", u"cdaboo1", u"sagen1", u"glyph1", u"dre1"): record = ( yield self.directory.recordWithShortName(RecordType.user, name) ) newSet.add(record.uid) group = yield txn.groupByUID(group1.uid) _ignore_added, _ignore_removed = ( yield self.groupCacher.synchronizeMembers(txn, group.groupID, newSet) ) delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__", u"__glyph1__", u"__dre1__"]), set([d.uid for d in delegates]) ) # Remove delegate access from the top group yield Delegates.removeDelegate(txn, delegator, group1, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__"]), set([d.uid for d in delegates]) ) # Remove delegate access from the sub group yield Delegates.removeDelegate(txn, delegator, group2, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=True)) self.assertEquals( set([u"__sagen1__"]), set([d.uid for d in delegates]) ) yield txn.commit()
def test_directDelegation(self): txn = self.store.newTransaction(label="test_directDelegation") delegator = yield self.directory.recordWithUID(u"__wsanchez1__") delegate1 = yield self.directory.recordWithUID(u"__sagen1__") delegate2 = yield self.directory.recordWithUID(u"__cdaboo1__") # Add 1 delegate yield Delegates.addDelegate(txn, delegator, delegate1, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals([u"__sagen1__"], [d.uid for d in delegates]) delegators = (yield Delegates.delegatedTo(txn, delegate1, True)) self.assertEquals([u"__wsanchez1__"], [d.uid for d in delegators]) yield txn.commit() # So delegateService will see the changes txn = self.store.newTransaction(label="test_directDelegation") # The "proxy-write" pseudoGroup will have one member pseudoGroup = yield self.directory.recordWithShortName( DelegateRecordType.writeDelegateGroup, u"__wsanchez1__" ) self.assertEquals(pseudoGroup.uid, u"__wsanchez1__#calendar-proxy-write") self.assertEquals( [r.uid for r in (yield pseudoGroup.members())], [u"__sagen1__"] ) # The "proxy-read" pseudoGroup will have no members pseudoGroup = yield self.directory.recordWithShortName( DelegateRecordType.readDelegateGroup, u"__wsanchez1__" ) self.assertEquals(pseudoGroup.uid, u"__wsanchez1__#calendar-proxy-read") self.assertEquals( [r.uid for r in (yield pseudoGroup.members())], [] ) # The "proxy-write-for" pseudoGroup will have one member pseudoGroup = yield self.directory.recordWithShortName( DelegateRecordType.writeDelegatorGroup, u"__sagen1__" ) self.assertEquals(pseudoGroup.uid, u"__sagen1__#calendar-proxy-write-for") self.assertEquals( [r.uid for r in (yield pseudoGroup.members())], [u"__wsanchez1__"] ) # The "proxy-read-for" pseudoGroup will have no members pseudoGroup = yield self.directory.recordWithShortName( DelegateRecordType.readDelegatorGroup, u"__sagen1__" ) self.assertEquals(pseudoGroup.uid, u"__sagen1__#calendar-proxy-read-for") self.assertEquals( [r.uid for r in (yield pseudoGroup.members())], [] ) # Add another delegate yield Delegates.addDelegate(txn, delegator, delegate2, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__"]), set([d.uid for d in delegates]) ) delegators = (yield Delegates.delegatedTo(txn, delegate2, True)) self.assertEquals([u"__wsanchez1__"], [d.uid for d in delegators]) # Remove 1 delegate yield Delegates.removeDelegate(txn, delegator, delegate1, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals([u"__cdaboo1__"], [d.uid for d in delegates]) delegators = (yield Delegates.delegatedTo(txn, delegate1, True)) self.assertEquals(0, len(delegators)) # Remove the other delegate yield Delegates.removeDelegate(txn, delegator, delegate2, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals(0, len(delegates)) delegators = (yield Delegates.delegatedTo(txn, delegate2, True)) self.assertEquals(0, len(delegators)) yield txn.commit() # So delegateService will see the changes # Now set delegate assignments by using pseudoGroup.setMembers() pseudoGroup = yield self.directory.recordWithShortName( DelegateRecordType.writeDelegateGroup, u"__wsanchez1__" ) yield pseudoGroup.setMembers([delegate1, delegate2]) # Verify the assignments were made txn = self.store.newTransaction(label="test_directDelegation") delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__"]), set([d.uid for d in delegates]) ) yield txn.commit() # Set a different group of assignments: yield pseudoGroup.setMembers([delegate2]) # Verify the assignments were made txn = self.store.newTransaction(label="test_directDelegation") delegates = (yield Delegates.delegatesOf(txn, delegator, True)) self.assertEquals( set([u"__cdaboo1__"]), set([d.uid for d in delegates]) ) yield txn.commit()
def test_indirectDelegation(self): txn = self.store.newTransaction(label="test_indirectDelegation") delegator = yield self.directory.recordWithUID(u"__wsanchez1__") delegate1 = yield self.directory.recordWithUID(u"__sagen1__") group1 = yield self.directory.recordWithUID(u"__top_group_1__") group2 = yield self.directory.recordWithUID(u"__sub_group_1__") # Add group delegate yield Delegates.addDelegate(txn, delegator, group1, True) # Passing expanded=False will return the group delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=False)) self.assertEquals(1, len(delegates)) self.assertEquals(delegates[0].uid, u"__top_group_1__") # Passing expanded=True will return not the group -- it only returns # non-groups delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__", u"__glyph1__"]), set([d.uid for d in delegates]) ) delegators = (yield Delegates.delegatedTo(txn, delegate1, True)) self.assertEquals([u"__wsanchez1__"], [d.uid for d in delegators]) # Verify we can ask for all delegated-to groups yield Delegates.addDelegate(txn, delegator, group2, True) groups = (yield txn.allGroupDelegates()) self.assertEquals( set([u'__sub_group_1__', u'__top_group_1__']), set(groups) ) # Delegate to a user who is already indirectly delegated-to yield Delegates.addDelegate(txn, delegator, delegate1, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__", u"__glyph1__"]), set([d.uid for d in delegates]) ) # Add a member to the group; they become a delegate newSet = set() for name in (u"wsanchez1", u"cdaboo1", u"sagen1", u"glyph1", u"dre1"): record = ( yield self.directory.recordWithShortName(RecordType.user, name) ) newSet.add(record.uid) group = yield txn.groupByUID(group1.uid) _ignore_added, _ignore_removed = ( yield self.groupCacher.synchronizeMembers(txn, group.groupID, newSet) ) delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__", u"__glyph1__", u"__dre1__"]), set([d.uid for d in delegates]) ) # Remove delegate access from the top group yield Delegates.removeDelegate(txn, delegator, group1, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=True)) self.assertEquals( set([u"__sagen1__", u"__cdaboo1__"]), set([d.uid for d in delegates]) ) # Remove delegate access from the sub group yield Delegates.removeDelegate(txn, delegator, group2, True) delegates = (yield Delegates.delegatesOf(txn, delegator, True, expanded=True)) self.assertEquals( set([u"__sagen1__"]), set([d.uid for d in delegates]) ) yield txn.commit()