public function testInvalidateOldTokens() { $defaultSessionLifetime = 60 * 60 * 24; $this->config->expects($this->once())->method('getSystemValue')->with('session_lifetime', $defaultSessionLifetime)->will($this->returnValue(150)); $this->mapper->expects($this->once())->method('invalidateOld')->with($this->time - 150); $this->tokenProvider->invalidateOldTokens(); }
public function testTryTokenLoginWithDisabledUser() { $manager = $this->getMockBuilder('\\OC\\User\\Manager')->disableOriginalConstructor()->getMock(); $session = new Memory(''); $token = $this->getMock('\\OC\\Authentication\\Token\\IToken'); $user = $this->getMock('\\OCP\\IUser'); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config); $request = $this->getMock('\\OCP\\IRequest'); $request->expects($this->once())->method('getHeader')->with('Authorization')->will($this->returnValue('token xxxxx')); $this->tokenProvider->expects($this->once())->method('validateToken')->with('xxxxx')->will($this->returnValue($token)); $token->expects($this->once())->method('getUID')->will($this->returnValue('user123')); $manager->expects($this->once())->method('get')->with('user123')->will($this->returnValue($user)); $user->expects($this->once())->method('isEnabled')->will($this->returnValue(false)); $this->assertFalse($userSession->tryTokenLogin($request)); }
/** * @expectedException \OC\User\LoginException */ public function testTryTokenLoginWithDisabledUser() { $manager = $this->getMockBuilder('\\OC\\User\\Manager')->disableOriginalConstructor()->getMock(); $session = new Memory(''); $token = new \OC\Authentication\Token\DefaultToken(); $token->setLoginName('fritz'); $token->setUid('fritz0'); $token->setLastCheck(100); // Needs check $user = $this->getMock('\\OCP\\IUser'); $userSession = $this->getMockBuilder('\\OC\\User\\Session')->setMethods(['logout'])->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config])->getMock(); $request = $this->getMock('\\OCP\\IRequest'); $request->expects($this->once())->method('getHeader')->with('Authorization')->will($this->returnValue('token xxxxx')); $this->tokenProvider->expects($this->once())->method('getToken')->with('xxxxx')->will($this->returnValue($token)); $manager->expects($this->once())->method('get')->with('fritz0')->will($this->returnValue($user)); $user->expects($this->once())->method('isEnabled')->will($this->returnValue(false)); $userSession->tryTokenLogin($request); }
/** * @expectedException \OC\Authentication\Exceptions\InvalidTokenException */ public function testValidateInvalidToken() { $token = 'sometoken'; $this->mapper->expects($this->once())->method('getToken')->with(hash('sha512', $token))->will($this->throwException(new DoesNotExistException(''))); $this->tokenProvider->validateToken($token); }