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')); }
public function testCheckPasswordUpdateShare() { $share = $this->manager->newShare(); $share->setShareType(\OCP\Share::SHARE_TYPE_LINK)->setPassword('passwordHash'); $this->hasher->method('verify')->with('password', 'passwordHash', '')->will($this->returnCallback(function ($pass, $hash, &$newHash) { $newHash = 'newHash'; return true; })); $this->defaultProvider->expects($this->once())->method('update')->with($this->callback(function (\OCP\Share\IShare $share) { return $share->getPassword() === 'newHash'; })); $this->assertTrue($this->manager->checkPassword($share, 'password')); }
/** * Authenticate a link item with the given password. * Or use the session if no password is provided. * * This is a modified version of Helper::authenticate * TODO: Try to merge back eventually with Helper::authenticate * * @param \OCP\Share\IShare $share * @param string|null $password * @return bool */ private function linkShareAuth(\OCP\Share\IShare $share, $password = null) { if ($password !== null) { if ($this->shareManager->checkPassword($share, $password)) { $this->session->set('public_link_authenticated', (string) $share->getId()); } else { return false; } } else { // not authenticated ? if (!$this->session->exists('public_link_authenticated') || $this->session->get('public_link_authenticated') !== (string) $share->getId()) { return false; } } return true; }