public function testUnwrappingGet() { $unencryptedValue = 'foobar'; $encryptedValue = $this->crypto->encrypt($unencryptedValue); $this->wrappedSession->expects($this->once())->method('get')->with('encrypted_session_data')->willReturnCallback(function () use($encryptedValue) { return $encryptedValue; }); $this->assertSame($unencryptedValue, $this->wrappedSession->get('encrypted_session_data')); }
public function testShowLoginFormWithErrorsInSession() { $this->userSession->expects($this->once())->method('isLoggedIn')->willReturn(false); $this->session->expects($this->once())->method('get')->with('loginMessages')->willReturn([['ErrorArray1', 'ErrorArray2'], ['MessageArray1', 'MessageArray2']]); $expectedResponse = new TemplateResponse('core', 'login', ['ErrorArray1' => true, 'ErrorArray2' => true, 'messages' => ['MessageArray1', 'MessageArray2'], 'loginName' => '', 'user_autofocus' => true, 'canResetPassword' => true, 'alt_login' => [], 'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(), 'rememberLoginState' => 0], 'guest'); $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', '', '')); }
/** * */ protected function setUp() { parent::setUp(); $this->sessionMock = $this->getMock('OCP\\ISession'); $this->sessionMock->expects($this->any())->method('set')->will($this->returnCallback([$this, "setValueTester"])); $this->sessionMock->expects($this->any())->method('get')->will($this->returnCallback([$this, "getValueTester"])); $this->sessionMock->expects($this->any())->method('remove')->will($this->returnCallback([$this, "removeValueTester"])); $this->instance = new Session($this->sessionMock); }
public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjaxButUserIsStillLoggedIn() { /** @var \Sabre\HTTP\RequestInterface $httpRequest */ $httpRequest = $this->getMockBuilder('\\Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock(); /** @var \Sabre\HTTP\ResponseInterface $httpResponse */ $httpResponse = $this->getMockBuilder('\\Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock(); $this->userSession->expects($this->any())->method('isLoggedIn')->will($this->returnValue(true)); $this->session->expects($this->once())->method('get')->with('AUTHENTICATED_TO_DAV_BACKEND')->will($this->returnValue('MyTestUser')); $httpRequest->expects($this->once())->method('getHeader')->with('Authorization')->will($this->returnValue(null)); $this->auth->check($httpRequest, $httpResponse); }
public function testAuthenticateAlreadyLoggedIn() { $server = $this->getMockBuilder('\\Sabre\\DAV\\Server')->disableOriginalConstructor()->getMock(); $this->userSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true)); $this->session->expects($this->once())->method('get')->with('AUTHENTICATED_TO_DAV_BACKEND')->will($this->returnValue(null)); $user = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock(); $user->expects($this->once())->method('getUID')->will($this->returnValue('MyWrongDavUser')); $this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($user)); $this->session->expects($this->once())->method('close'); $this->assertTrue($this->auth->authenticate($server, 'TestRealm')); }
public function testAuthenticateAlreadyLoggedIn() { $request = $this->getMockBuilder('Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock(); $response = $this->getMockBuilder('Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock(); $this->userSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true)); $this->session->expects($this->once())->method('get')->with('AUTHENTICATED_TO_DAV_BACKEND')->will($this->returnValue(null)); $user = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock(); $user->expects($this->once())->method('getUID')->will($this->returnValue('MyWrongDavUser')); $this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($user)); $this->session->expects($this->once())->method('close'); $response = $this->auth->check($request, $response); $this->assertEquals([true, 'principals/users/MyWrongDavUser'], $response); }
/** * test updatePrivateKeyPassword() with the correct old and new password */ public function testUpdatePrivateKeyPassword() { $oldPassword = '******'; $newPassword = '******'; $this->ocSessionMock->expects($this->once())->method('get')->with('loginname')->willReturn('testUser'); $this->userManagerMock->expects($this->at(0))->method('checkPassword')->with('testUserUid', 'new')->willReturn(false); $this->userManagerMock->expects($this->at(1))->method('checkPassword')->with('testUser', 'new')->willReturn(true); $this->cryptMock->expects($this->once())->method('decryptPrivateKey')->willReturn('decryptedKey'); $this->cryptMock->expects($this->once())->method('encryptPrivateKey')->willReturn('encryptedKey'); $this->cryptMock->expects($this->once())->method('generateHeader')->willReturn('header.'); // methods which must be called after successful changing the key password $this->keyManagerMock->expects($this->once())->method('setPrivateKey')->with($this->equalTo('testUserUid'), $this->equalTo('header.encryptedKey')); $this->sessionMock->expects($this->once())->method('setPrivateKey')->with($this->equalTo('decryptedKey')); $this->sessionMock->expects($this->once())->method('setStatus')->with($this->equalTo(Session::INIT_SUCCESSFUL)); $result = $this->controller->updatePrivateKeyPassword($oldPassword, $newPassword); $data = $result->getData(); $this->assertSame(Http::STATUS_OK, $result->getStatus()); $this->assertSame('Private key password successfully updated.', $data['message']); }
/** * Mocks ISession->get('public_link_authenticated') * * @param int $linkItemId */ private function mockSessionWithLinkItemId($linkItemId) { $this->session->expects($this->once())->method('get')->with('public_link_authenticated')->willReturn($linkItemId); }
public function testPrepareTwoFactorLogin() { $this->user->expects($this->once())->method('getUID')->will($this->returnValue('ferdinand')); $this->session->expects($this->once())->method('set')->with('two_factor_auth_uid', 'ferdinand'); $this->manager->prepareTwoFactorLogin($this->user); }
public function testHasTokenWithoutExistingToken() { $this->session->expects($this->once())->method('exists')->with('requesttoken')->willReturn(false); $this->assertSame(false, $this->sessionStorage->hasToken()); }