diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-01-20 21:56:55 +0100 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-01-20 21:56:55 +0100 |
commit | 88bc8634d2076b7392c9ec214e414c558a6584d6 (patch) | |
tree | 343707517e56713337fc5540660a762f6a0479b0 /tests/lib/share20/managertest.php | |
parent | 18421e7e686a4ed90f276925322b5d168f347e30 (diff) | |
download | nextcloud-server-88bc8634d2076b7392c9ec214e414c558a6584d6.tar.gz nextcloud-server-88bc8634d2076b7392c9ec214e414c558a6584d6.zip |
Add Unit tests
Diffstat (limited to 'tests/lib/share20/managertest.php')
-rw-r--r-- | tests/lib/share20/managertest.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php index 92ebe1951b5..28303d3152f 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -1478,6 +1478,71 @@ class ManagerTest extends \Test\TestCase { $manager->createShare($share); } + + public function testGetShareByToken() { + $factory = $this->getMock('\OC\Share20\IProviderFactory'); + + $manager = new Manager( + $this->logger, + $this->config, + $this->secureRandom, + $this->hasher, + $this->mountManager, + $this->groupManager, + $this->l, + $factory + ); + + $share = $this->getMock('\OC\Share20\IShare'); + + $factory->expects($this->once()) + ->method('getProviderForType') + ->with(\OCP\Share::SHARE_TYPE_LINK) + ->willReturn($this->defaultProvider); + + $this->defaultProvider->expects($this->once()) + ->method('getShareByToken') + ->with('token') + ->willReturn($share); + + $ret = $manager->getShareByToken('token'); + $this->assertSame($share, $ret); + } + + public function testCheckPasswordNoLinkShare() { + $share = $this->getMock('\OC\Share20\IShare'); + $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); + $this->assertFalse($this->manager->checkPassword($share, 'password')); + } + + public function testCheckPasswordNoPassword() { + $share = $this->getMock('\OC\Share20\IShare'); + $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); + $this->assertFalse($this->manager->checkPassword($share, 'password')); + + $share->method('getPassword')->willReturn('password'); + $this->assertFalse($this->manager->checkPassword($share, null)); + } + + public function testCheckPasswordInvalidPassword() { + $share = $this->getMock('\OC\Share20\IShare'); + $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); + $share->method('getPassword')->willReturn('password'); + + $this->hasher->method('verify')->with('invalidpassword', 'password', '')->willReturn(false); + + $this->assertFalse($this->manager->checkPassword($share, 'invalidpassword')); + } + + public function testCheckPasswordValidPassword() { + $share = $this->getMock('\OC\Share20\IShare'); + $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); + $share->method('getPassword')->willReturn('passwordHash'); + + $this->hasher->method('verify')->with('password', 'passwordHash', '')->willReturn(true); + + $this->assertTrue($this->manager->checkPassword($share, 'password')); + } } class DummyPassword { |