diff options
Diffstat (limited to 'apps/dav/tests/unit')
-rw-r--r-- | apps/dav/tests/unit/carddav/birthdayservicetest.php | 49 | ||||
-rw-r--r-- | apps/dav/tests/unit/comments/commentsplugin.php | 10 | ||||
-rw-r--r-- | apps/dav/tests/unit/connector/publicauth.php | 170 | ||||
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/filesplugin.php | 10 |
4 files changed, 221 insertions, 18 deletions
diff --git a/apps/dav/tests/unit/carddav/birthdayservicetest.php b/apps/dav/tests/unit/carddav/birthdayservicetest.php index 2efb3c09aea..e15edd16c62 100644 --- a/apps/dav/tests/unit/carddav/birthdayservicetest.php +++ b/apps/dav/tests/unit/carddav/birthdayservicetest.php @@ -24,6 +24,7 @@ namespace OCA\DAV\Tests\Unit\CardDAV; use OCA\DAV\CalDAV\BirthdayService; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CardDAV\CardDavBackend; +use OCA\DAV\DAV\GroupPrincipalBackend; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; use Test\TestCase; @@ -36,14 +37,17 @@ class BirthdayServiceTest extends TestCase { private $calDav; /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject */ private $cardDav; + /** @var GroupPrincipalBackend | \PHPUnit_Framework_MockObject_MockObject */ + private $groupPrincialBackend; public function setUp() { parent::setUp(); $this->calDav = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock(); $this->cardDav = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')->disableOriginalConstructor()->getMock(); + $this->groupPrincialBackend = $this->getMockBuilder('OCA\DAV\DAV\GroupPrincipalBackend')->disableOriginalConstructor()->getMock(); - $this->service = new BirthdayService($this->calDav, $this->cardDav); + $this->service = new BirthdayService($this->calDav, $this->cardDav, $this->groupPrincialBackend); } /** @@ -77,6 +81,7 @@ class BirthdayServiceTest extends TestCase { 'id' => 1234 ]); $this->calDav->expects($this->once())->method('deleteCalendarObject')->with(1234, 'default-gump.vcf.ics'); + $this->cardDav->expects($this->once())->method('getShares')->willReturn([]); $this->service->onCardDeleted(666, 'gump.vcf'); } @@ -96,10 +101,11 @@ class BirthdayServiceTest extends TestCase { ->willReturn([ 'id' => 1234 ]); + $this->cardDav->expects($this->once())->method('getShares')->willReturn([]); /** @var BirthdayService | \PHPUnit_Framework_MockObject_MockObject $service */ $service = $this->getMock('\OCA\DAV\CalDAV\BirthdayService', - ['buildBirthdayFromContact', 'birthdayEvenChanged'], [$this->calDav, $this->cardDav]); + ['buildBirthdayFromContact', 'birthdayEvenChanged'], [$this->calDav, $this->cardDav, $this->groupPrincialBackend]); if ($expectedOp === 'delete') { $this->calDav->expects($this->once())->method('getCalendarObject')->willReturn(''); @@ -132,6 +138,45 @@ class BirthdayServiceTest extends TestCase { $this->assertEquals($expected, $this->service->birthdayEvenChanged($old, $new)); } + public function testGetAllAffectedPrincipals() { + $this->cardDav->expects($this->once())->method('getShares')->willReturn([ + [ + '{http://owncloud.org/ns}group-share' => false, + '{http://owncloud.org/ns}principal' => 'principals/users/user01' + ], + [ + '{http://owncloud.org/ns}group-share' => false, + '{http://owncloud.org/ns}principal' => 'principals/users/user01' + ], + [ + '{http://owncloud.org/ns}group-share' => false, + '{http://owncloud.org/ns}principal' => 'principals/users/user02' + ], + [ + '{http://owncloud.org/ns}group-share' => true, + '{http://owncloud.org/ns}principal' => 'principals/groups/users' + ], + ]); + $this->groupPrincialBackend->expects($this->once())->method('getGroupMemberSet') + ->willReturn([ + [ + 'uri' => 'principals/users/user01', + ], + [ + 'uri' => 'principals/users/user02', + ], + [ + 'uri' => 'principals/users/user03', + ], + ]); + $users = $this->invokePrivate($this->service, 'getAllAffectedPrincipals', [6666]); + $this->assertEquals([ + 'principals/users/user01', + 'principals/users/user02', + 'principals/users/user03' + ], $users); + } + public function providesBirthday() { return [ [true, diff --git a/apps/dav/tests/unit/comments/commentsplugin.php b/apps/dav/tests/unit/comments/commentsplugin.php index c7d073d1491..c909f6a61ab 100644 --- a/apps/dav/tests/unit/comments/commentsplugin.php +++ b/apps/dav/tests/unit/comments/commentsplugin.php @@ -449,16 +449,6 @@ class CommentsPlugin extends \Test\TestCase { ->with('users', 'alice', 'files', '42') ->will($this->returnValue($comment)); - $this->commentsManager->expects($this->any()) - ->method('setMessage') - ->with('') - ->will($this->throwException(new \InvalidArgumentException())); - - $this->commentsManager->expects($this->any()) - ->method('setVerb') - ->with('') - ->will($this->throwException(new \InvalidArgumentException())); - $this->userSession->expects($this->once()) ->method('getUser') ->will($this->returnValue($user)); diff --git a/apps/dav/tests/unit/connector/publicauth.php b/apps/dav/tests/unit/connector/publicauth.php new file mode 100644 index 00000000000..5f46651d372 --- /dev/null +++ b/apps/dav/tests/unit/connector/publicauth.php @@ -0,0 +1,170 @@ +<?php + +namespace OCA\DAV\Tests\Unit\Connector; + +use OCP\IRequest; +use OCP\ISession; +use OCP\Share\Exceptions\ShareNotFound; +use OCP\Share\IManager; + +class PublicAuth extends \Test\TestCase { + + /** @var ISession|\PHPUnit_Framework_MockObject_MockObject */ + private $session; + /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */ + private $request; + /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ + private $shareManager; + /** @var \OCA\DAV\Connector\PublicAuth */ + private $auth; + + /** @var string */ + private $oldUser; + + protected function setUp() { + parent::setUp(); + + $this->session = $this->getMock('\OCP\ISession'); + $this->request = $this->getMock('\OCP\IRequest'); + $this->shareManager = $this->getMock('\OCP\Share\IManager'); + + $this->auth = new \OCA\DAV\Connector\PublicAuth( + $this->request, + $this->shareManager, + $this->session + ); + + // Store current user + $this->oldUser = \OC_User::getUser(); + } + + protected function tearDown() { + \OC_User::setIncognitoMode(false); + + // Set old user + \OC_User::setUserId($this->oldUser); + \OC_Util::setupFS($this->oldUser); + + parent::tearDown(); + } + + public function testNoShare() { + $this->shareManager->expects($this->once()) + ->method('getShareByToken') + ->willThrowException(new ShareNotFound()); + + $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); + + $this->assertFalse($result); + } + + public function testShareNoPassword() { + $share = $this->getMock('OCP\Share\IShare'); + $share->method('getPassword')->willReturn(null); + + $this->shareManager->expects($this->once()) + ->method('getShareByToken') + ->willReturn($share); + + $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); + + $this->assertTrue($result); + } + + public function testSharePasswordFancyShareType() { + $share = $this->getMock('OCP\Share\IShare'); + $share->method('getPassword')->willReturn('password'); + $share->method('getShareType')->willReturn(42); + + $this->shareManager->expects($this->once()) + ->method('getShareByToken') + ->willReturn($share); + + $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); + + $this->assertFalse($result); + } + + + public function testSharePasswordRemote() { + $share = $this->getMock('OCP\Share\IShare'); + $share->method('getPassword')->willReturn('password'); + $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_REMOTE); + + $this->shareManager->expects($this->once()) + ->method('getShareByToken') + ->willReturn($share); + + $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); + + $this->assertTrue($result); + } + + public function testSharePasswordLinkValidPassword() { + $share = $this->getMock('OCP\Share\IShare'); + $share->method('getPassword')->willReturn('password'); + $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); + + $this->shareManager->expects($this->once()) + ->method('getShareByToken') + ->willReturn($share); + + $this->shareManager->expects($this->once()) + ->method('checkPassword')->with( + $this->equalTo($share), + $this->equalTo('password') + )->willReturn(true); + + $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); + + $this->assertTrue($result); + } + + public function testSharePasswordLinkValidSession() { + $share = $this->getMock('OCP\Share\IShare'); + $share->method('getPassword')->willReturn('password'); + $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); + $share->method('getId')->willReturn('42'); + + $this->shareManager->expects($this->once()) + ->method('getShareByToken') + ->willReturn($share); + + $this->shareManager->method('checkPassword') + ->with( + $this->equalTo($share), + $this->equalTo('password') + )->willReturn(false); + + $this->session->method('exists')->with('public_link_authenticated')->willReturn(true); + $this->session->method('get')->with('public_link_authenticated')->willReturn('42'); + + $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); + + $this->assertTrue($result); + } + + public function testSharePasswordLinkInvalidSession() { + $share = $this->getMock('OCP\Share\IShare'); + $share->method('getPassword')->willReturn('password'); + $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); + $share->method('getId')->willReturn('42'); + + $this->shareManager->expects($this->once()) + ->method('getShareByToken') + ->willReturn($share); + + $this->shareManager->method('checkPassword') + ->with( + $this->equalTo($share), + $this->equalTo('password') + )->willReturn(false); + + $this->session->method('exists')->with('public_link_authenticated')->willReturn(true); + $this->session->method('get')->with('public_link_authenticated')->willReturn('43'); + + $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); + + $this->assertFalse($result); + } +} diff --git a/apps/dav/tests/unit/connector/sabre/filesplugin.php b/apps/dav/tests/unit/connector/sabre/filesplugin.php index e88066a12da..fb08ee170c4 100644 --- a/apps/dav/tests/unit/connector/sabre/filesplugin.php +++ b/apps/dav/tests/unit/connector/sabre/filesplugin.php @@ -84,6 +84,7 @@ class FilesPlugin extends \Test\TestCase { $node = $this->getMockBuilder($class) ->disableOriginalConstructor() ->getMock(); + $node->expects($this->any()) ->method('getId') ->will($this->returnValue(123)); @@ -164,7 +165,9 @@ class FilesPlugin extends \Test\TestCase { } public function testGetPropertiesForFileHome() { - $node = $this->createTestNode('\OCA\DAV\Files\FilesHome'); + $node = $this->getMockBuilder('\OCA\DAV\Files\FilesHome') + ->disableOriginalConstructor() + ->getMock(); $propFind = new \Sabre\DAV\PropFind( '/dummyPath', @@ -185,9 +188,6 @@ class FilesPlugin extends \Test\TestCase { ->disableOriginalConstructor()->getMock(); $user->expects($this->never())->method('getUID'); $user->expects($this->never())->method('getDisplayName'); - $node->expects($this->never())->method('getDirectDownload'); - $node->expects($this->never())->method('getOwner'); - $node->expects($this->never())->method('getSize'); $this->plugin->handleGetProperties( $propFind, @@ -276,8 +276,6 @@ class FilesPlugin extends \Test\TestCase { 0 ); - $node->expects($this->never()) - ->method('getDirectDownload'); $node->expects($this->once()) ->method('getSize') ->will($this->returnValue(1025)); |