summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@owncloud.com>2016-06-20 10:41:23 +0200
committerChristoph Wurst <christoph@owncloud.com>2016-06-20 10:41:23 +0200
commit56199eba376e044f65e9e02844a9d98e524340b4 (patch)
treede818c6f4b21243cda9e5d8e35a9889165285406
parentfb36fd495b2b97063a13239f214909011d0b1385 (diff)
downloadnextcloud-server-56199eba376e044f65e9e02844a9d98e524340b4.tar.gz
nextcloud-server-56199eba376e044f65e9e02844a9d98e524340b4.zip
fix unit test warning/errors
-rw-r--r--lib/private/User/Session.php20
-rw-r--r--tests/lib/User/SessionTest.php31
2 files changed, 25 insertions, 26 deletions
diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php
index 07235c1b42b..aedb308539a 100644
--- a/lib/private/User/Session.php
+++ b/lib/private/User/Session.php
@@ -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;
}
/**
diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php
index 974b5d3fd88..6b72cf81bc9 100644
--- a/tests/lib/User/SessionTest.php
+++ b/tests/lib/User/SessionTest.php
@@ -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())
+ $tokenProvider->expects($this->once())
->method('invalidateToken')
- ->with($token);
- $session->expects($this->once())
+ ->with('APP-PASSWORD');
+ $userSession->expects($this->once())
->method('logout');
- $tokenProvider->expects($this->once())
- ->method('updateToken')
- ->with($token);
- $this->invokePrivate($userSession, 'validateSession', [$user]);
+ $userSession->setUser($user);
+ $this->invokePrivate($userSession, 'validateSession');
}
public function testValidateSessionNoPassword() {