From c58d8159d7bdee93a67a917e16b750fe99df9f99 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 31 May 2016 10:48:14 +0200 Subject: Create session tokens for apache auth users --- .../Token/DefaultTokenProviderTest.php | 11 +++++++ tests/lib/User/SessionTest.php | 38 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'tests') diff --git a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php index e04424e4628..98cee208065 100644 --- a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php +++ b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php @@ -134,6 +134,17 @@ class DefaultTokenProviderTest extends TestCase { $this->assertEquals('passme', $actual); } + /** + * @expectedException \OC\Authentication\Exceptions\PasswordlessTokenException + */ + public function testGetPasswordPasswordLessToken() { + $token = 'token1234'; + $tk = new DefaultToken(); + $tk->setPassword(null); + + $this->tokenProvider->getPassword($tk, $token); + } + /** * @expectedException \OC\Authentication\Exceptions\InvalidTokenException */ diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php index 5ff2a16acb9..36f14e85492 100644 --- a/tests/lib/User/SessionTest.php +++ b/tests/lib/User/SessionTest.php @@ -621,4 +621,42 @@ class SessionTest extends \Test\TestCase { $this->invokePrivate($userSession, 'validateSession', [$user]); } + 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 = $this->getMock('\OC\Authentication\Token\IToken'); + + $session->expects($this->once()) + ->method('getId') + ->will($this->returnValue('sessionid')); + $tokenProvider->expects($this->once()) + ->method('getToken') + ->with('sessionid') + ->will($this->returnValue($token)); + $session->expects($this->once()) + ->method('get') + ->with('last_login_check') + ->will($this->returnValue(1000)); + $timeFactory->expects($this->once()) + ->method('getTime') + ->will($this->returnValue(5000)); + $tokenProvider->expects($this->once()) + ->method('getPassword') + ->with($token, 'sessionid') + ->will($this->throwException(new \OC\Authentication\Exceptions\PasswordlessTokenException())); + $session->expects($this->once()) + ->method('set') + ->with('last_login_check', 5000); + + $this->invokePrivate($userSession, 'validateSession', [$user]); + } + } -- cgit v1.2.3