Add Unit tests
This commit is contained in:
parent
18421e7e68
commit
88bc8634d2
|
@ -721,4 +721,54 @@ class DefaultShareProviderTest extends \Test\TestCase {
|
|||
$this->assertSame('token', $share2->getToken());
|
||||
$this->assertEquals($expireDate, $share2->getExpirationDate());
|
||||
}
|
||||
|
||||
public function testGetShareByToken() {
|
||||
$qb = $this->dbConn->getQueryBuilder();
|
||||
|
||||
$qb->insert('share')
|
||||
->values([
|
||||
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
|
||||
'share_with' => $qb->expr()->literal('password'),
|
||||
'uid_owner' => $qb->expr()->literal('shareOwner'),
|
||||
'uid_initiator' => $qb->expr()->literal('sharedBy'),
|
||||
'item_type' => $qb->expr()->literal('file'),
|
||||
'file_source' => $qb->expr()->literal(42),
|
||||
'file_target' => $qb->expr()->literal('myTarget'),
|
||||
'permissions' => $qb->expr()->literal(13),
|
||||
'token' => $qb->expr()->literal('secrettoken'),
|
||||
]);
|
||||
$qb->execute();
|
||||
$id = $qb->getLastInsertId();
|
||||
|
||||
$owner = $this->getMock('\OCP\IUser');
|
||||
$owner->method('getUID')->willReturn('shareOwner');
|
||||
$initiator = $this->getMock('\OCP\IUser');
|
||||
$initiator->method('getUID')->willReturn('sharedBy');
|
||||
|
||||
$this->userManager->method('get')
|
||||
->will($this->returnValueMap([
|
||||
['sharedBy', $initiator],
|
||||
['shareOwner', $owner],
|
||||
]));
|
||||
|
||||
$file = $this->getMock('\OCP\Files\File');
|
||||
|
||||
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
|
||||
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
|
||||
|
||||
$share = $this->provider->getShareByToken('secrettoken');
|
||||
$this->assertEquals($id, $share->getId());
|
||||
$this->assertSame($owner, $share->getShareOwner());
|
||||
$this->assertSame($initiator, $share->getSharedBy());
|
||||
$this->assertSame('secrettoken', $share->getToken());
|
||||
$this->assertSame('password', $share->getPassword());
|
||||
$this->assertSame(null, $share->getSharedWith());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OC\Share20\Exception\ShareNotFound
|
||||
*/
|
||||
public function testGetShareByTokenNotFound() {
|
||||
$this->provider->getShareByToken('invalidtoken');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue