Пример #1
0
 public function testGetUser()
 {
     $token = new \OC\Authentication\Token\DefaultToken();
     $token->setLoginName('User123');
     $expectedUser = $this->getMock('\\OCP\\IUser');
     $expectedUser->expects($this->any())->method('getUID')->will($this->returnValue('user123'));
     $session = $this->getMock('\\OC\\Session\\Memory', array(), array(''));
     $session->expects($this->at(0))->method('get')->with('user_id')->will($this->returnValue($expectedUser->getUID()));
     $sessionId = 'abcdef12345';
     $manager = $this->getMockBuilder('\\OC\\User\\Manager')->disableOriginalConstructor()->getMock();
     $session->expects($this->once())->method('getId')->will($this->returnValue($sessionId));
     $this->tokenProvider->expects($this->once())->method('getToken')->will($this->returnValue($token));
     $session->expects($this->at(2))->method('get')->with('last_login_check')->will($this->returnValue(null));
     // No check has been run yet
     $this->tokenProvider->expects($this->once())->method('getPassword')->with($token, $sessionId)->will($this->returnValue('password123'));
     $manager->expects($this->once())->method('checkPassword')->with('User123', 'password123')->will($this->returnValue(true));
     $expectedUser->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
     $session->expects($this->at(3))->method('set')->with('last_login_check', 10000);
     $session->expects($this->at(4))->method('get')->with('last_token_update')->will($this->returnValue(null));
     // No check run so far
     $this->tokenProvider->expects($this->once())->method('updateToken')->with($token);
     $session->expects($this->at(5))->method('set')->with('last_token_update', $this->equalTo(10000));
     $manager->expects($this->any())->method('get')->with($expectedUser->getUID())->will($this->returnValue($expectedUser));
     $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
     $user = $userSession->getUser();
     $this->assertSame($expectedUser, $user);
 }
Пример #2
0
 public function testValidateSessionNoPassword()
 {
     $userManager = $this->getMock('\\OCP\\IUserManager');
     $session = $this->getMock('\\OCP\\ISession');
     $timeFactory = $this->getMock('\\OCP\\AppFramework\\Utility\\ITimeFactory');
     $tokenProvider = $this->getMock('\\OC\\Authentication\\Token\\IProvider');
     $userSession = $this->getMockBuilder('\\OC\\User\\Session')->setConstructorArgs([$userManager, $session, $timeFactory, $tokenProvider, $this->config])->setMethods(['logout'])->getMock();
     $user = $this->getMock('\\OCP\\IUser');
     $token = new \OC\Authentication\Token\DefaultToken();
     $token->setLastCheck(20);
     $session->expects($this->once())->method('get')->with('app_password')->will($this->returnValue('APP-PASSWORD'));
     $tokenProvider->expects($this->once())->method('getToken')->with('APP-PASSWORD')->will($this->returnValue($token));
     $timeFactory->expects($this->once())->method('getTime')->will($this->returnValue(1000));
     // more than 5min since last check
     $tokenProvider->expects($this->once())->method('getPassword')->with($token, 'APP-PASSWORD')->will($this->throwException(new \OC\Authentication\Exceptions\PasswordlessTokenException()));
     $tokenProvider->expects($this->once())->method('updateToken')->with($token);
     $this->invokePrivate($userSession, 'validateSession', [$user]);
     $this->assertEquals(1000, $token->getLastCheck());
 }