diff options
author | Joas Schilling <coding@schilljs.com> | 2017-10-05 12:32:46 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-10-05 12:48:10 +0200 |
commit | 3b4ab6560b1195a8ebd1d0627e142e440b644f1a (patch) | |
tree | 0948dd837b8e6464b8e2bfa9db83796757f74fbd /apps/dav/tests | |
parent | 9ba51247f0ab65e8e92763508a9ba3c53f275fab (diff) | |
download | nextcloud-server-3b4ab6560b1195a8ebd1d0627e142e440b644f1a.tar.gz nextcloud-server-3b4ab6560b1195a8ebd1d0627e142e440b644f1a.zip |
Check if the user/group exists for dav shares
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php (renamed from apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php) | 8 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/CalDavBackendTest.php | 10 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php | 5 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/CardDavBackendTest.php | 44 |
4 files changed, 53 insertions, 14 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php index a7bf4432c64..3f3b744e5ab 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php @@ -24,6 +24,7 @@ namespace OCA\DAV\Tests\unit\CalDAV; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\Connector\Sabre\Principal; +use OCP\IGroupManager; use OCP\IUserManager; use OCP\Security\ISecureRandom; use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet; @@ -37,7 +38,7 @@ use Test\TestCase; * * @package OCA\DAV\Tests\unit\CalDAV */ -abstract class AbstractCalDavBackendTest extends TestCase { +abstract class AbstractCalDavBackend extends TestCase { /** @var CalDavBackend */ protected $backend; @@ -46,6 +47,8 @@ abstract class AbstractCalDavBackendTest extends TestCase { protected $principal; /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ protected $userManager; + /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ + protected $groupManager; /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $dispatcher; @@ -61,6 +64,7 @@ abstract class AbstractCalDavBackendTest extends TestCase { parent::setUp(); $this->userManager = $this->createMock(IUserManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); $this->dispatcher = $this->createMock(EventDispatcherInterface::class); $this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal') ->disableOriginalConstructor() @@ -77,7 +81,7 @@ abstract class AbstractCalDavBackendTest extends TestCase { $db = \OC::$server->getDatabaseConnection(); $this->random = \OC::$server->getSecureRandom(); - $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->random, $this->dispatcher); + $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->groupManager, $this->random, $this->dispatcher); $this->cleanUpBackend(); } diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index fa298282d7e..95ea09148be 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -42,7 +42,7 @@ use Sabre\DAVACL\IACL; * * @package OCA\DAV\Tests\unit\CalDAV */ -class CalDavBackendTest extends AbstractCalDavBackendTest { +class CalDavBackendTest extends AbstractCalDavBackend { public function testCalendarOperations() { @@ -130,6 +130,14 @@ class CalDavBackendTest extends AbstractCalDavBackendTest { return vsprintf($text, $parameters); })); + $this->userManager->expects($this->any()) + ->method('userExists') + ->willReturn(true); + + $this->userManager->expects($this->any()) + ->method('groupExists') + ->willReturn(true); + $calendarId = $this->createTestCalendar(); $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $this->assertCount(1, $calendars); diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php index eb9f9cd10d7..ec767f3dbd8 100644 --- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php +++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php @@ -5,6 +5,7 @@ namespace OCA\DAV\Tests\unit\CalDAV; use OCA\DAV\CalDAV\Calendar; use OCA\DAV\CalDAV\PublicCalendar; use OCA\DAV\Connector\Sabre\Principal; +use OCP\IGroupManager; use OCP\IL10N; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\PublicCalendarRoot; @@ -33,6 +34,8 @@ class PublicCalendarRootTest extends TestCase { private $principal; /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ protected $userManager; + /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ + protected $groupManager; /** @var ISecureRandom */ private $random; @@ -43,6 +46,7 @@ class PublicCalendarRootTest extends TestCase { $db = \OC::$server->getDatabaseConnection(); $this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal'); $this->userManager = $this->createMock(IUserManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); $this->random = \OC::$server->getSecureRandom(); $dispatcher = $this->createMock(EventDispatcherInterface::class); @@ -54,6 +58,7 @@ class PublicCalendarRootTest extends TestCase { $db, $this->principal, $this->userManager, + $this->groupManager, $this->random, $dispatcher ); diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php index 8ca7e8a33b1..992445392d5 100644 --- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php +++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php @@ -33,6 +33,7 @@ use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\Connector\Sabre\Principal; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +use OCP\IGroupManager; use OCP\IL10N; use OCP\IUserManager; use Sabre\DAV\PropPatch; @@ -60,6 +61,9 @@ class CardDavBackendTest extends TestCase { /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ private $userManager; + /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ + private $groupManager; + /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ private $dispatcher; @@ -80,6 +84,7 @@ class CardDavBackendTest extends TestCase { parent::setUp(); $this->userManager = $this->createMock(IUserManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); $this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal') ->disableOriginalConstructor() ->setMethods(['getPrincipalByPath', 'getGroupMembership']) @@ -96,7 +101,7 @@ class CardDavBackendTest extends TestCase { $this->db = \OC::$server->getDatabaseConnection(); - $this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, $this->dispatcher); + $this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher); // start every test with a empty cards_properties and cards table $query = $this->db->getQueryBuilder(); $query->delete('cards_properties')->execute(); @@ -154,6 +159,14 @@ class CardDavBackendTest extends TestCase { public function testAddressBookSharing() { + $this->userManager->expects($this->any()) + ->method('userExists') + ->willReturn(true); + + $this->groupManager->expects($this->any()) + ->method('groupExists') + ->willReturn(true); + $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []); $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); $this->assertEquals(1, count($books)); @@ -180,7 +193,7 @@ class CardDavBackendTest extends TestCase { /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $backend */ $backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) ->setMethods(['updateProperties', 'purgeProperties'])->getMock(); // create a new address book @@ -253,7 +266,7 @@ class CardDavBackendTest extends TestCase { public function testMultiCard() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) ->setMethods(['updateProperties'])->getMock(); // create a new address book @@ -299,7 +312,7 @@ class CardDavBackendTest extends TestCase { public function testDeleteWithoutCard() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) ->setMethods([ 'getCardId', 'addChange', @@ -339,7 +352,7 @@ class CardDavBackendTest extends TestCase { public function testSyncSupport() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) ->setMethods(['updateProperties'])->getMock(); // create a new address book @@ -362,32 +375,41 @@ class CardDavBackendTest extends TestCase { } public function testSharing() { + + $this->userManager->expects($this->any()) + ->method('userExists') + ->willReturn(true); + + $this->groupManager->expects($this->any()) + ->method('groupExists') + ->willReturn(true); + $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []); $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); $this->assertEquals(1, count($books)); $l = $this->createMock(IL10N::class); $exampleBook = new AddressBook($this->backend, $books[0], $l); - $this->backend->updateShares($exampleBook, [['href' => 'principal:principals/best-friend']], []); + $this->backend->updateShares($exampleBook, [['href' => 'principal:' . self::UNIT_TEST_USER1]], []); $shares = $this->backend->getShares($exampleBook->getResourceId()); $this->assertEquals(1, count($shares)); // adding the same sharee again has no effect - $this->backend->updateShares($exampleBook, [['href' => 'principal:principals/best-friend']], []); + $this->backend->updateShares($exampleBook, [['href' => 'principal:' . self::UNIT_TEST_USER1]], []); $shares = $this->backend->getShares($exampleBook->getResourceId()); $this->assertEquals(1, count($shares)); - $books = $this->backend->getAddressBooksForUser('principals/best-friend'); + $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER1); $this->assertEquals(1, count($books)); - $this->backend->updateShares($exampleBook, [], ['principal:principals/best-friend']); + $this->backend->updateShares($exampleBook, [], ['principal:' . self::UNIT_TEST_USER1]); $shares = $this->backend->getShares($exampleBook->getResourceId()); $this->assertEquals(0, count($shares)); - $books = $this->backend->getAddressBooksForUser('principals/best-friend'); + $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER1); $this->assertEquals(0, count($books)); } @@ -398,7 +420,7 @@ class CardDavBackendTest extends TestCase { $cardId = 2; $backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher]) ->setMethods(['getCardId'])->getMock(); $backend->expects($this->any())->method('getCardId')->willReturn($cardId); |