fix unit test warning/errors
This commit is contained in:
parent
fb36fd495b
commit
56199eba37
2 changed files with 26 additions and 27 deletions
|
@ -550,14 +550,12 @@ class Session implements IUserSession, Emitter {
|
|||
$pwd = $this->tokenProvider->getPassword($dbToken, $token);
|
||||
} catch (InvalidTokenException $ex) {
|
||||
// An invalid token password was used -> log user out
|
||||
$this->logout();
|
||||
return false;
|
||||
} catch (PasswordlessTokenException $ex) {
|
||||
// Token has no password
|
||||
|
||||
if (!is_null($this->activeUser) && !$this->activeUser->isEnabled()) {
|
||||
$this->tokenProvider->invalidateToken($token);
|
||||
$this->logout();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -570,7 +568,6 @@ class Session implements IUserSession, Emitter {
|
|||
|| (!is_null($this->activeUser) && !$this->activeUser->isEnabled())) {
|
||||
$this->tokenProvider->invalidateToken($token);
|
||||
// Password has changed or user was disabled -> log user out
|
||||
$this->logout();
|
||||
return false;
|
||||
}
|
||||
$dbToken->setLastCheck($now);
|
||||
|
@ -613,20 +610,21 @@ class Session implements IUserSession, Emitter {
|
|||
if (strpos($authHeader, 'token ') === false) {
|
||||
// No auth header, let's try session id
|
||||
try {
|
||||
$sessionId = $this->session->getId();
|
||||
$token = $this->session->getId();
|
||||
} catch (SessionNotAvailableException $ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->validateToken($sessionId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->loginWithToken($sessionId);
|
||||
} else {
|
||||
$token = substr($authHeader, 6);
|
||||
return $this->validateToken($token);
|
||||
}
|
||||
|
||||
if (!$this->loginWithToken($token)) {
|
||||
return false;
|
||||
}
|
||||
if(!$this->validateToken($token)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -151,7 +151,7 @@ class SessionTest extends \Test\TestCase {
|
|||
$this->tokenProvider->expects($this->once())
|
||||
->method('getToken')
|
||||
->with('bar')
|
||||
->will($this->throwException('\OC\Authentication\Exceptions\InvalidTokenException'));
|
||||
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
|
||||
$session->expects($this->exactly(2))
|
||||
->method('set')
|
||||
->with($this->callback(function ($key) {
|
||||
|
@ -698,9 +698,15 @@ class SessionTest extends \Test\TestCase {
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$session = new Memory('');
|
||||
$token = $this->getMock('\OC\Authentication\Token\IToken');
|
||||
$token = new \OC\Authentication\Token\DefaultToken();
|
||||
$token->setLoginName('fritz');
|
||||
$token->setUid('fritz0');
|
||||
$token->setLastCheck(100); // Needs check
|
||||
$user = $this->getMock('\OCP\IUser');
|
||||
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
|
||||
$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())
|
||||
|
@ -708,15 +714,12 @@ class SessionTest extends \Test\TestCase {
|
|||
->with('Authorization')
|
||||
->will($this->returnValue('token xxxxx'));
|
||||
$this->tokenProvider->expects($this->once())
|
||||
->method('validateToken')
|
||||
->method('getToken')
|
||||
->with('xxxxx')
|
||||
->will($this->returnValue($token));
|
||||
$token->expects($this->once())
|
||||
->method('getUID')
|
||||
->will($this->returnValue('user123'));
|
||||
$manager->expects($this->once())
|
||||
->method('get')
|
||||
->with('user123')
|
||||
->with('fritz0')
|
||||
->will($this->returnValue($user));
|
||||
$user->expects($this->once())
|
||||
->method('isEnabled')
|
||||
|
@ -762,16 +765,14 @@ class SessionTest extends \Test\TestCase {
|
|||
$user->expects($this->once())
|
||||
->method('isEnabled')
|
||||
->will($this->returnValue(false));
|
||||
$this->tokenProvider->expects($this->once())
|
||||
->method('invalidateToken')
|
||||
->with($token);
|
||||
$session->expects($this->once())
|
||||
->method('logout');
|
||||
$tokenProvider->expects($this->once())
|
||||
->method('updateToken')
|
||||
->with($token);
|
||||
->method('invalidateToken')
|
||||
->with('APP-PASSWORD');
|
||||
$userSession->expects($this->once())
|
||||
->method('logout');
|
||||
|
||||
$this->invokePrivate($userSession, 'validateSession', [$user]);
|
||||
$userSession->setUser($user);
|
||||
$this->invokePrivate($userSession, 'validateSession');
|
||||
}
|
||||
|
||||
public function testValidateSessionNoPassword() {
|
||||
|
|
Loading…
Reference in a new issue