public function testAuthenticateInvalidPassword() { $share = $this->getMock('\\OC\\Share20\\IShare'); $share->method('getId')->willReturn(42); $this->shareManager->expects($this->once())->method('getShareByToken')->with('token')->willReturn($share); $this->shareManager->expects($this->once())->method('checkPassword')->with($share, 'invalidpassword')->willReturn(false); $this->session->expects($this->never())->method('set'); $response = $this->shareController->authenticate('token', 'invalidpassword'); $expectedResponse = new TemplateResponse($this->appName, 'authenticate', array('wrongpw' => true), 'guest'); $this->assertEquals($expectedResponse, $response); }
public function testAuthenticate() { // Test without a not existing token $response = $this->shareController->authenticate('ThisTokenShouldHopefullyNeverExistSoThatTheUnitTestWillAlwaysPass :)'); $expectedResponse = new TemplateResponse('core', '404', array(), 'guest'); $this->assertEquals($expectedResponse, $response); // Test with a valid password $response = $this->shareController->authenticate($this->token, 'IAmPasswordProtected!'); $expectedResponse = new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.showShare', array('token' => $this->token))); $this->assertEquals($expectedResponse, $response); // Test with a invalid password $response = $this->shareController->authenticate($this->token, 'WrongPw!'); $expectedResponse = new TemplateResponse($this->container['AppName'], 'authenticate', array('wrongpw' => true), 'guest'); $this->assertEquals($expectedResponse, $response); }
public function testAuthenticateInvalidPassword() { $share = \OC::$server->getShareManager()->newShare(); $share->setNodeId(100)->setNodeType('file')->setToken('token')->setSharedBy('initiator')->setId(42); $this->shareManager->expects($this->once())->method('getShareByToken')->with('token')->willReturn($share); $this->shareManager->expects($this->once())->method('checkPassword')->with($share, 'invalidpassword')->willReturn(false); $this->session->expects($this->never())->method('set'); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['access'])->getMock(); \OCP\Util::connectHook('OCP\\Share', 'share_link_access', $hookListner, 'access'); $hookListner->expects($this->once())->method('access')->with($this->callback(function (array $data) { return $data['itemType'] === 'file' && $data['itemSource'] === 100 && $data['uidOwner'] === 'initiator' && $data['token'] === 'token' && $data['errorCode'] === 403 && $data['errorMessage'] === 'Wrong password'; })); $response = $this->shareController->authenticate('token', 'invalidpassword'); $expectedResponse = new TemplateResponse($this->appName, 'authenticate', array('wrongpw' => true), 'guest'); $this->assertEquals($expectedResponse, $response); }