Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Make sure hidden trash collection is not exposed in sync report results.

  • Loading branch information
cyrusdaboo committed May 22, 2015
1 parent 2a20a4e commit 1532efeb39bb7ca166c5b4c6f19b4153cf1320ce
Showing with 113 additions and 0 deletions.
  1. +101 −0 txdav/caldav/datastore/test/test_sql.py
  2. +12 −0 txdav/common/datastore/sql.py
@@ -2348,6 +2348,107 @@ def test_removeAfterRevisionCleanup(self):
yield self.commit()


@inlineCallbacks
def test_homeSyncTokenWithTrash_Visible(self):
"""
L{ICalendarHome.resourceNamesSinceToken} will return the names of
calendar objects created since L{ICalendarHome.syncToken} last returned
a particular value.
"""

self.patch(config, "EnableTrashCollection", True)
self.patch(config, "ExposeTrashCollection", True)

home = yield self.homeUnderTest()
cal = yield self.calendarUnderTest()
st = yield home.syncToken()
yield cal.createCalendarObjectWithName("new.ics", Component.fromString(
test_event_text
))

obj1 = yield cal.calendarObjectWithName("2.ics")
yield obj1.remove()
yield home.createCalendarWithName("other-calendar")
st2 = yield home.syncToken()
self.failIfEquals(st, st2)

home = yield self.homeUnderTest()

expected = [
"calendar_1/",
"calendar_1/new.ics",
"calendar_1/2.ics",
"other-calendar/"
]

trash = yield home.getTrash()
if trash is not None:
trashed = yield trash.calendarObjects()
expected.extend([
"{}/".format(trash.name()),
"{}/{}".format(trash.name(), trashed[0].name()),
])

changed, deleted, invalid = yield home.resourceNamesSinceToken(
self.token2revision(st), "infinity")

self.assertEquals(set(changed), set(expected))
self.assertEquals(set(deleted), set(["calendar_1/2.ics"]))
self.assertEquals(invalid, [])

changed, deleted, invalid = yield home.resourceNamesSinceToken(
self.token2revision(st2), "infinity")
self.assertEquals(changed, [])
self.assertEquals(deleted, [])
self.assertEquals(invalid, [])


@inlineCallbacks
def test_homeSyncTokenWithTrash_Invisible(self):
"""
L{ICalendarHome.resourceNamesSinceToken} will return the names of
calendar objects created since L{ICalendarHome.syncToken} last returned
a particular value.
"""

self.patch(config, "EnableTrashCollection", True)

home = yield self.homeUnderTest()
cal = yield self.calendarUnderTest()
st = yield home.syncToken()
yield cal.createCalendarObjectWithName("new.ics", Component.fromString(
test_event_text
))

obj1 = yield cal.calendarObjectWithName("2.ics")
yield obj1.remove()
yield home.createCalendarWithName("other-calendar")
st2 = yield home.syncToken()
self.failIfEquals(st, st2)

home = yield self.homeUnderTest()

expected = [
"calendar_1/",
"calendar_1/new.ics",
"calendar_1/2.ics",
"other-calendar/"
]

changed, deleted, invalid = yield home.resourceNamesSinceToken(
self.token2revision(st), "infinity")

self.assertEquals(set(changed), set(expected))
self.assertEquals(set(deleted), set(["calendar_1/2.ics"]))
self.assertEquals(invalid, [])

changed, deleted, invalid = yield home.resourceNamesSinceToken(
self.token2revision(st2), "infinity")
self.assertEquals(changed, [])
self.assertEquals(deleted, [])
self.assertEquals(invalid, [])



class SchedulingTests(CommonCommonTests, unittest.TestCase):
"""
@@ -2610,11 +2610,22 @@ def resourceNamesSinceRevision(self, revision, depth):
(yield self.doChangesQuery(revision))
]

if not config.ExposeTrashCollection:
trash = yield self.getTrash(create=False)
trashName = trash.name() if trash else None
else:
trashName = None

changed = set()
deleted = set()
invalid = set()
deleted_collections = set()
for path, name, wasdeleted in results:

# Don't report the trash if it is hidden
if trashName and path == trashName:
continue

if wasdeleted:
if name:
# Resource deleted - for depth "1" report collection as changed,
@@ -3154,6 +3165,7 @@ def recoverTrash(self, mode, recoveryID):
yield collection.fromTrash(restoreChildren=True)



class CommonHomeChild(FancyEqMixin, Memoizable, _SharedSyncLogic, HomeChildBase, SharingMixIn):
"""
Common ancestor class of AddressBooks and Calendars.

0 comments on commit 1532efe

Please sign in to comment.
You can’t perform that action at this time.