diff options
author | Christoph Wurst <christoph@owncloud.com> | 2016-06-13 16:00:49 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@owncloud.com> | 2016-06-13 19:44:05 +0200 |
commit | 465807490d7648e5675f1cdbc5b1d232cda4feee (patch) | |
tree | b00e74e21eef32523bc3ff63247865daa087a94e /tests | |
parent | 331d88bcabd4a66b0efc89fa28b90d26e88f4637 (diff) | |
download | nextcloud-server-465807490d7648e5675f1cdbc5b1d232cda4feee.tar.gz nextcloud-server-465807490d7648e5675f1cdbc5b1d232cda4feee.zip |
create session token only for clients that support cookies
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/User/SessionTest.php | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php index eac38ebba16..28f6b6a5377 100644 --- a/tests/lib/User/SessionTest.php +++ b/tests/lib/User/SessionTest.php @@ -311,11 +311,13 @@ class SessionTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $session = $this->getMock('\OCP\ISession'); + $request = $this->getMock('\OCP\IRequest'); + $user = $this->getMock('\OCP\IUser'); /** @var \OC\User\Session $userSession */ $userSession = $this->getMockBuilder('\OC\User\Session') ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config]) - ->setMethods(['login']) + ->setMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser']) ->getMock(); $this->tokenProvider->expects($this->once()) @@ -327,7 +329,46 @@ class SessionTest extends \Test\TestCase { ->with('token_auth_enforced', false) ->will($this->returnValue(true)); - $this->assertFalse($userSession->logClientIn('john', 'doe')); + $this->assertFalse($userSession->logClientIn('john', 'doe', $request)); + } + + public function testLogClientInWithTokenPassword() { + $manager = $this->getMockBuilder('\OC\User\Manager') + ->disableOriginalConstructor() + ->getMock(); + $session = $this->getMock('\OCP\ISession'); + $request = $this->getMock('\OCP\IRequest'); + $user = $this->getMock('\OCP\IUser'); + + /** @var \OC\User\Session $userSession */ + $userSession = $this->getMockBuilder('\OC\User\Session') + ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config]) + ->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser']) + ->getMock(); + + $userSession->expects($this->once()) + ->method('isTokenPassword') + ->will($this->returnValue(true)); + $userSession->expects($this->once()) + ->method('login') + ->with('john', 'doe') + ->will($this->returnValue(true)); + + $userSession->expects($this->once()) + ->method('supportsCookies') + ->with($request) + ->will($this->returnValue(true)); + $userSession->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($user)); + $user->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('user123')); + $userSession->expects($this->once()) + ->method('createSessionToken') + ->with($request, 'user123', 'john', 'doe'); + + $this->assertTrue($userSession->logClientIn('john', 'doe', $request)); } public function testLogClientInNoTokenPasswordNo2fa() { @@ -336,6 +377,7 @@ class SessionTest extends \Test\TestCase { ->getMock(); $session = $this->getMock('\OCP\ISession'); $user = $this->getMock('\OCP\IUser'); + $request = $this->getMock('\OCP\IRequest'); /** @var \OC\User\Session $userSession */ $userSession = $this->getMockBuilder('\OC\User\Session') @@ -357,7 +399,7 @@ class SessionTest extends \Test\TestCase { ->with('john') ->will($this->returnValue(true)); - $this->assertFalse($userSession->logClientIn('john', 'doe')); + $this->assertFalse($userSession->logClientIn('john', 'doe', $request)); } public function testRememberLoginValidToken() { |