/** * @dataProvider providesSharingData */ public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add) { /** @var IL10N | \PHPUnit_Framework_MockObject_MockObject $l10n */ $l10n = $this->getMockBuilder('\\OCP\\IL10N')->disableOriginalConstructor()->getMock(); $l10n->expects($this->any())->method('t')->will($this->returnCallback(function ($text, $parameters = array()) { return vsprintf($text, $parameters); })); $calendarId = $this->createTestCalendar(); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $this->assertEquals(1, count($books)); $calendar = new Calendar($this->backend, $books[0], $l10n); $this->backend->updateShares($calendar, $add, []); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1); $this->assertEquals(1, count($books)); $calendar = new Calendar($this->backend, $books[0], $l10n); $acl = $calendar->getACL(); $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl); $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl); $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl); $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl); $this->assertAccess($groupCanRead, self::UNIT_TEST_GROUP, '{DAV:}read', $acl); $this->assertAccess($groupCanWrite, self::UNIT_TEST_GROUP, '{DAV:}write', $acl); $this->assertEquals(self::UNIT_TEST_USER, $calendar->getOwner()); // test acls on the child $uri = $this->getUniqueID('calobj'); $calData = <<<'EOD' BEGIN:VCALENDAR VERSION:2.0 PRODID:ownCloud Calendar BEGIN:VEVENT CREATED;VALUE=DATE-TIME:20130910T125139Z UID:47d15e3ec8 LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z DTSTAMP;VALUE=DATE-TIME:20130910T125139Z SUMMARY:Test Event DTSTART;VALUE=DATE-TIME:20130912T130000Z DTEND;VALUE=DATE-TIME:20130912T140000Z CLASS:PUBLIC END:VEVENT END:VCALENDAR EOD; $this->backend->createCalendarObject($calendarId, $uri, $calData); /** @var IACL $child */ $child = $calendar->getChild($uri); $acl = $child->getACL(); $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl); $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl); $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl); $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl); $this->assertAccess($groupCanRead, self::UNIT_TEST_GROUP, '{DAV:}read', $acl); $this->assertAccess($groupCanWrite, self::UNIT_TEST_GROUP, '{DAV:}write', $acl); // delete the address book $this->backend->deleteCalendar($books[0]['id']); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $this->assertEquals(0, count($books)); }
/** * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testDeleteFromGroup() { /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder('OCA\\DAV\\CalDAV\\CalDavBackend')->disableOriginalConstructor()->getMock(); $backend->expects($this->never())->method('updateShares'); $backend->method('getShares')->willReturn([['href' => 'principal:group2']]); $calendarInfo = ['{http://owncloud.org/ns}owner-principal' => 'user1', 'principaluri' => 'user2', 'id' => 666]; $c = new Calendar($backend, $calendarInfo); $c->delete(); }
/** * @dataProvider dataPropPatch */ public function testPropPatch($mutations, $throws) { /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder('OCA\\DAV\\CalDAV\\CalDavBackend')->disableOriginalConstructor()->getMock(); $calendarInfo = ['{http://owncloud.org/ns}owner-principal' => 'user1', 'principaluri' => 'user2', 'id' => 666]; $c = new Calendar($backend, $calendarInfo); if ($throws) { $this->setExpectedException('\\Sabre\\DAV\\Exception\\Forbidden'); } $c->propPatch(new PropPatch($mutations)); if (!$throws) { $this->assertTrue(true); } }
/** * @dataProvider providesSharingData */ public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add) { $calendarId = $this->createTestCalendar(); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $this->assertEquals(1, count($books)); $calendar = new Calendar($this->backend, $books[0]); $this->backend->updateShares($calendar, $add, []); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1); $this->assertEquals(1, count($books)); $calendar = new Calendar($this->backend, $books[0]); $acl = $calendar->getACL(); $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl); $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl); $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl); $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl); $this->assertAccess($groupCanRead, self::UNIT_TEST_GROUP, '{DAV:}read', $acl); $this->assertAccess($groupCanWrite, self::UNIT_TEST_GROUP, '{DAV:}write', $acl); $this->assertEquals(self::UNIT_TEST_USER, $calendar->getOwner()); // test acls on the child $uri = $this->getUniqueID('calobj'); $calData = <<<'EOD' BEGIN:VCALENDAR VERSION:2.0 PRODID:ownCloud Calendar BEGIN:VEVENT CREATED;VALUE=DATE-TIME:20130910T125139Z UID:47d15e3ec8 LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z DTSTAMP;VALUE=DATE-TIME:20130910T125139Z SUMMARY:Test Event DTSTART;VALUE=DATE-TIME:20130912T130000Z DTEND;VALUE=DATE-TIME:20130912T140000Z CLASS:PUBLIC END:VEVENT END:VCALENDAR EOD; $this->backend->createCalendarObject($calendarId, $uri, $calData); /** @var IACL $child */ $child = $calendar->getChild($uri); $acl = $child->getACL(); $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl); $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl); $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl); $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl); $this->assertAccess($groupCanRead, self::UNIT_TEST_GROUP, '{DAV:}read', $acl); $this->assertAccess($groupCanWrite, self::UNIT_TEST_GROUP, '{DAV:}write', $acl); // delete the address book $this->backend->deleteCalendar($books[0]['id']); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $this->assertEquals(0, count($books)); }
/** * @dataProvider providesConfidentialClassificationData * @param $expectedChildren * @param $isShared */ public function testConfidentialClassification($expectedChildren, $isShared) { $start = '20160609'; $end = '20160610'; $calData = <<<EOD BEGIN:VCALENDAR PRODID:-//ownCloud calendar v1.2.2 BEGIN:VEVENT CREATED:20160602T133732 DTSTAMP:20160602T133732 LAST-MODIFIED:20160602T133732 UID:wej2z68l9h SUMMARY:Test Event LOCATION:Somewhere ... ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;CUTYPE=INDIVIDUAL;CN=de epdiver:MAILTO:thomas.mueller@tmit.eu ORGANIZER;CN=deepdiver:MAILTO:thomas.mueller@tmit.eu DESCRIPTION:maybe .... DTSTART;TZID=Europe/Berlin;VALUE=DATE:{$start} DTEND;TZID=Europe/Berlin;VALUE=DATE:{$end} RRULE:FREQ=DAILY BEGIN:VALARM ACTION:AUDIO TRIGGER:-PT15M END:VALARM END:VEVENT BEGIN:VTIMEZONE TZID:Europe/Berlin BEGIN:DAYLIGHT DTSTART:19810329T020000 RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU TZNAME:MESZ TZOFFSETFROM:+0100 TZOFFSETTO:+0200 END:DAYLIGHT BEGIN:STANDARD DTSTART:19961027T030000 RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU TZNAME:MEZ TZOFFSETFROM:+0200 TZOFFSETTO:+0100 END:STANDARD END:VTIMEZONE END:VCALENDAR EOD; $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder('OCA\\DAV\\CalDAV\\CalDavBackend')->disableOriginalConstructor()->getMock(); $backend->expects($this->any())->method('getCalendarObjects')->willReturn([$calObject0, $calObject1, $calObject2]); $backend->expects($this->any())->method('getMultipleCalendarObjects')->with(666, ['event-0', 'event-1', 'event-2'])->willReturn([$calObject0, $calObject1, $calObject2]); $backend->expects($this->any())->method('getCalendarObject')->willReturn($calObject1)->with(666, 'event-1'); $calendarInfo = ['principaluri' => 'user2', 'id' => 666, 'uri' => 'cal']; if ($isShared) { $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; } $c = new Calendar($backend, $calendarInfo, $this->l10n); // test private event $privateEvent = $c->getChild('event-1'); $calData = $privateEvent->get(); $event = Reader::read($calData); $this->assertEquals($start, $event->VEVENT->DTSTART->getValue()); $this->assertEquals($end, $event->VEVENT->DTEND->getValue()); if ($isShared) { $this->assertEquals('Busy', $event->VEVENT->SUMMARY->getValue()); $this->assertArrayNotHasKey('ATTENDEE', $event->VEVENT); $this->assertArrayNotHasKey('LOCATION', $event->VEVENT); $this->assertArrayNotHasKey('DESCRIPTION', $event->VEVENT); $this->assertArrayNotHasKey('ORGANIZER', $event->VEVENT); } else { $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue()); } }
/** * @dataProvider providesReadOnlyInfo */ public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet, $uri = 'default') { /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder('OCA\\DAV\\CalDAV\\CalDavBackend')->disableOriginalConstructor()->getMock(); $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); $calendarInfo = ['principaluri' => 'user2', 'id' => 666, 'uri' => $uri]; if (!is_null($readOnlyValue)) { $calendarInfo['{http://owncloud.org/ns}read-only'] = $readOnlyValue; } if ($hasOwnerSet) { $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; } $c = new Calendar($backend, $calendarInfo, $this->l10n); $acl = $c->getACL(); $childAcl = $c->getChildACL(); $expectedAcl = [['privilege' => '{DAV:}read', 'principal' => $hasOwnerSet ? 'user1' : 'user2', 'protected' => true], ['privilege' => '{DAV:}write', 'principal' => $hasOwnerSet ? 'user1' : 'user2', 'protected' => true]]; if ($uri === BirthdayService::BIRTHDAY_CALENDAR_URI) { $expectedAcl = [['privilege' => '{DAV:}read', 'principal' => $hasOwnerSet ? 'user1' : 'user2', 'protected' => true]]; } if ($hasOwnerSet) { $expectedAcl[] = ['privilege' => '{DAV:}read', 'principal' => 'user2', 'protected' => true]; if ($expectsWrite) { $expectedAcl[] = ['privilege' => '{DAV:}write', 'principal' => 'user2', 'protected' => true]; } } $this->assertEquals($expectedAcl, $acl); $this->assertEquals($expectedAcl, $childAcl); }