summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-06-26 12:55:05 +0200
committerLukas Reschke <lukas@owncloud.com>2016-06-26 12:55:05 +0200
commit7a9d60d87eb8e4414e5fe05830b088d426ff810d (patch)
tree0fc97a7eacfd071475afd8bc6d4372babacb5740 /tests
parent5387b942c44e05b87ba2a0fd54168f5278a31344 (diff)
parent52eab2a61a5d27b64fcd0440b91f854c052933a9 (diff)
downloadnextcloud-server-7a9d60d87eb8e4414e5fe05830b088d426ff810d.tar.gz
nextcloud-server-7a9d60d87eb8e4414e5fe05830b088d426ff810d.zip
Merge remote-tracking branch 'upstream/master' into master-upstream-sync
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Controller/OccControllerTest.php143
-rw-r--r--tests/lib/Authentication/Token/DefaultTokenMapperTest.php4
-rw-r--r--tests/lib/Authentication/Token/DefaultTokenProviderTest.php72
-rw-r--r--tests/lib/User/SessionTest.php226
4 files changed, 338 insertions, 107 deletions
diff --git a/tests/Core/Controller/OccControllerTest.php b/tests/Core/Controller/OccControllerTest.php
new file mode 100644
index 00000000000..682d9170096
--- /dev/null
+++ b/tests/Core/Controller/OccControllerTest.php
@@ -0,0 +1,143 @@
+<?php
+/**
+ * @author Victor Dubiniuk <dubiniuk@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace Tests\Core\Controller;
+
+use OC\Console\Application;
+use OC\Core\Controller\OccController;
+use OCP\IConfig;
+use Symfony\Component\Console\Output\Output;
+use Test\TestCase;
+
+/**
+ * Class OccControllerTest
+ *
+ * @package OC\Core\Controller
+ */
+class OccControllerTest extends TestCase {
+
+ const TEMP_SECRET = 'test';
+
+ /** @var \OC\AppFramework\Http\Request | \PHPUnit_Framework_MockObject_MockObject */
+ private $request;
+ /** @var \OC\Core\Controller\OccController | \PHPUnit_Framework_MockObject_MockObject */
+ private $controller;
+ /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
+ private $config;
+ /** @var Application | \PHPUnit_Framework_MockObject_MockObject */
+ private $console;
+
+ public function testFromInvalidLocation(){
+ $this->getControllerMock('example.org');
+
+ $response = $this->controller->execute('status', '');
+ $responseData = $response->getData();
+
+ $this->assertArrayHasKey('exitCode', $responseData);
+ $this->assertEquals(126, $responseData['exitCode']);
+
+ $this->assertArrayHasKey('details', $responseData);
+ $this->assertEquals('Web executor is not allowed to run from a different host', $responseData['details']);
+ }
+
+ public function testNotWhiteListedCommand(){
+ $this->getControllerMock('localhost');
+
+ $response = $this->controller->execute('missing_command', '');
+ $responseData = $response->getData();
+
+ $this->assertArrayHasKey('exitCode', $responseData);
+ $this->assertEquals(126, $responseData['exitCode']);
+
+ $this->assertArrayHasKey('details', $responseData);
+ $this->assertEquals('Command "missing_command" is not allowed to run via web request', $responseData['details']);
+ }
+
+ public function testWrongToken(){
+ $this->getControllerMock('localhost');
+
+ $response = $this->controller->execute('status', self::TEMP_SECRET . '-');
+ $responseData = $response->getData();
+
+ $this->assertArrayHasKey('exitCode', $responseData);
+ $this->assertEquals(126, $responseData['exitCode']);
+
+ $this->assertArrayHasKey('details', $responseData);
+ $this->assertEquals('updater.secret does not match the provided token', $responseData['details']);
+ }
+
+ public function testSuccess(){
+ $this->getControllerMock('localhost');
+ $this->console->expects($this->once())->method('run')
+ ->willReturnCallback(
+ function ($input, $output) {
+ /** @var Output $output */
+ $output->writeln('{"installed":true,"version":"9.1.0.8","versionstring":"9.1.0 beta 2","edition":""}');
+ return 0;
+ }
+ );
+
+ $response = $this->controller->execute('status', self::TEMP_SECRET, ['--output'=>'json']);
+ $responseData = $response->getData();
+
+ $this->assertArrayHasKey('exitCode', $responseData);
+ $this->assertEquals(0, $responseData['exitCode']);
+
+ $this->assertArrayHasKey('response', $responseData);
+ $decoded = json_decode($responseData['response'], true);
+
+ $this->assertArrayHasKey('installed', $decoded);
+ $this->assertEquals(true, $decoded['installed']);
+ }
+
+ private function getControllerMock($host){
+ $this->request = $this->getMockBuilder('OC\AppFramework\Http\Request')
+ ->setConstructorArgs([
+ ['server' => []],
+ \OC::$server->getSecureRandom(),
+ \OC::$server->getConfig()
+ ])
+ ->setMethods(['getRemoteAddress'])
+ ->getMock();
+
+ $this->request->expects($this->any())->method('getRemoteAddress')
+ ->will($this->returnValue($host));
+
+ $this->config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->config->expects($this->any())->method('getSystemValue')
+ ->with('updater.secret')
+ ->willReturn(password_hash(self::TEMP_SECRET, PASSWORD_DEFAULT));
+
+ $this->console = $this->getMockBuilder('\OC\Console\Application')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->controller = new OccController(
+ 'core',
+ $this->request,
+ $this->config,
+ $this->console
+ );
+ }
+
+}
diff --git a/tests/lib/Authentication/Token/DefaultTokenMapperTest.php b/tests/lib/Authentication/Token/DefaultTokenMapperTest.php
index 5d49f75aaa4..6b73cab5ed0 100644
--- a/tests/lib/Authentication/Token/DefaultTokenMapperTest.php
+++ b/tests/lib/Authentication/Token/DefaultTokenMapperTest.php
@@ -63,6 +63,7 @@ class DefaultTokenMapperTest extends TestCase {
'token' => $qb->createNamedParameter('9c5a2e661482b65597408a6bb6c4a3d1af36337381872ac56e445a06cdb7fea2b1039db707545c11027a4966919918b19d875a8b774840b18c6cbb7ae56fe206'),
'type' => $qb->createNamedParameter(IToken::TEMPORARY_TOKEN),
'last_activity' => $qb->createNamedParameter($this->time - 120, IQueryBuilder::PARAM_INT), // Two minutes ago
+ 'last_check' => $this->time - 60 * 10, // 10mins ago
])->execute();
$qb->insert('authtoken')->values([
'uid' => $qb->createNamedParameter('user2'),
@@ -72,6 +73,7 @@ class DefaultTokenMapperTest extends TestCase {
'token' => $qb->createNamedParameter('1504445f1524fc801035448a95681a9378ba2e83930c814546c56e5d6ebde221198792fd900c88ed5ead0555780dad1ebce3370d7e154941cd5de87eb419899b'),
'type' => $qb->createNamedParameter(IToken::TEMPORARY_TOKEN),
'last_activity' => $qb->createNamedParameter($this->time - 60 * 60 * 24 * 3, IQueryBuilder::PARAM_INT), // Three days ago
+ 'last_check' => $this->time - 10, // 10secs ago
])->execute();
$qb->insert('authtoken')->values([
'uid' => $qb->createNamedParameter('user1'),
@@ -81,6 +83,7 @@ class DefaultTokenMapperTest extends TestCase {
'token' => $qb->createNamedParameter('47af8697ba590fb82579b5f1b3b6e8066773a62100abbe0db09a289a62f5d980dc300fa3d98b01d7228468d1ab05c1aa14c8d14bd5b6eee9cdf1ac14864680c3'),
'type' => $qb->createNamedParameter(IToken::TEMPORARY_TOKEN),
'last_activity' => $qb->createNamedParameter($this->time - 120, IQueryBuilder::PARAM_INT), // Two minutes ago
+ 'last_check' => $this->time - 60 * 10, // 10mins ago
])->execute();
}
@@ -127,6 +130,7 @@ class DefaultTokenMapperTest extends TestCase {
$token->setToken('1504445f1524fc801035448a95681a9378ba2e83930c814546c56e5d6ebde221198792fd900c88ed5ead0555780dad1ebce3370d7e154941cd5de87eb419899b');
$token->setType(IToken::TEMPORARY_TOKEN);
$token->setLastActivity($this->time - 60 * 60 * 24 * 3);
+ $token->setLastCheck($this->time - 10);
$dbToken = $this->mapper->getToken($token->getToken());
diff --git a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
index 98cee208065..28a59529dec 100644
--- a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
+++ b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
@@ -97,14 +97,25 @@ class DefaultTokenProviderTest extends TestCase {
public function testUpdateToken() {
$tk = new DefaultToken();
+ $tk->setLastActivity($this->time - 200);
$this->mapper->expects($this->once())
->method('update')
->with($tk);
- $this->tokenProvider->updateToken($tk);
+ $this->tokenProvider->updateTokenActivity($tk);
$this->assertEquals($this->time, $tk->getLastActivity());
}
+
+ public function testUpdateTokenDebounce() {
+ $tk = new DefaultToken();
+ $tk->setLastActivity($this->time - 30);
+ $this->mapper->expects($this->never())
+ ->method('update')
+ ->with($tk);
+
+ $this->tokenProvider->updateTokenActivity($tk);
+ }
public function testGetTokenByUser() {
$user = $this->getMock('\OCP\IUser');
@@ -175,6 +186,39 @@ class DefaultTokenProviderTest extends TestCase {
$tokenProvider->getPassword($tk, $token);
}
+ public function testSetPassword() {
+ $token = new DefaultToken();
+ $tokenId = 'token123';
+ $password = '123456';
+
+ $this->config->expects($this->once())
+ ->method('getSystemValue')
+ ->with('secret')
+ ->will($this->returnValue('ocsecret'));
+ $this->crypto->expects($this->once())
+ ->method('encrypt')
+ ->with($password, $tokenId . 'ocsecret')
+ ->will($this->returnValue('encryptedpassword'));
+ $this->mapper->expects($this->once())
+ ->method('update')
+ ->with($token);
+
+ $this->tokenProvider->setPassword($token, $tokenId, $password);
+
+ $this->assertEquals('encryptedpassword', $token->getPassword());
+ }
+
+ /**
+ * @expectedException \OC\Authentication\Exceptions\InvalidTokenException
+ */
+ public function testSetPasswordInvalidToken() {
+ $token = $this->getMock('\OC\Authentication\Token\IToken');
+ $tokenId = 'token123';
+ $password = '123456';
+
+ $this->tokenProvider->setPassword($token, $tokenId, $password);
+ }
+
public function testInvalidateToken() {
$this->mapper->expects($this->once())
->method('invalidate')
@@ -207,30 +251,4 @@ class DefaultTokenProviderTest extends TestCase {
$this->tokenProvider->invalidateOldTokens();
}
- public function testValidateToken() {
- $token = 'sometoken';
- $dbToken = new DefaultToken();
- $this->mapper->expects($this->once())
- ->method('getToken')
- ->with(hash('sha512', $token))
- ->will($this->returnValue($dbToken));
-
- $actual = $this->tokenProvider->validateToken($token);
-
- $this->assertEquals($dbToken, $actual);
- }
-
- /**
- * @expectedException \OC\Authentication\Exceptions\InvalidTokenException
- */
- public function testValidateInvalidToken() {
- $token = 'sometoken';
- $this->mapper->expects($this->once())
- ->method('getToken')
- ->with(hash('sha512', $token))
- ->will($this->throwException(new DoesNotExistException('')));
-
- $this->tokenProvider->validateToken($token);
- }
-
}
diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php
index 7a34d42a2bc..eef4c7ff5ea 100644
--- a/tests/lib/User/SessionTest.php
+++ b/tests/lib/User/SessionTest.php
@@ -41,6 +41,7 @@ class SessionTest extends \Test\TestCase {
public function testGetUser() {
$token = new \OC\Authentication\Token\DefaultToken();
$token->setLoginName('User123');
+ $token->setLastCheck(200);
$expectedUser = $this->getMock('\OCP\IUser');
$expectedUser->expects($this->any())
@@ -56,41 +57,32 @@ class SessionTest extends \Test\TestCase {
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
->getMock();
+ $session->expects($this->at(1))
+ ->method('get')
+ ->with('app_password')
+ ->will($this->returnValue(null)); // No password set -> browser session
$session->expects($this->once())
->method('getId')
->will($this->returnValue($sessionId));
$this->tokenProvider->expects($this->once())
->method('getToken')
+ ->with($sessionId)
->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'));
+ ->will($this->returnValue('passme'));
$manager->expects($this->once())
->method('checkPassword')
- ->with('User123', 'password123')
+ ->with('User123', 'passme')
->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')
+ ->method('updateTokenActivity')
->with($token);
- $session->expects($this->at(5))
- ->method('set')
- ->with('last_token_update', $this->equalTo(10000));
$manager->expects($this->any())
->method('get')
@@ -100,6 +92,7 @@ class SessionTest extends \Test\TestCase {
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
$user = $userSession->getUser();
$this->assertSame($expectedUser, $user);
+ $this->assertSame(10000, $token->getLastCheck());
}
public function isLoggedInData() {
@@ -155,6 +148,10 @@ class SessionTest extends \Test\TestCase {
$session = $this->getMock('\OC\Session\Memory', array(), array(''));
$session->expects($this->once())
->method('regenerateId');
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('bar')
+ ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
$session->expects($this->exactly(2))
->method('set')
->with($this->callback(function ($key) {
@@ -219,6 +216,10 @@ class SessionTest extends \Test\TestCase {
->method('set');
$session->expects($this->once())
->method('regenerateId');
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('bar')
+ ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
$managerMethods = get_class_methods('\OC\User\Manager');
//keep following methods intact in order to ensure hooks are
@@ -252,11 +253,6 @@ class SessionTest extends \Test\TestCase {
public function testLoginInvalidPassword() {
$session = $this->getMock('\OC\Session\Memory', array(), array(''));
- $session->expects($this->never())
- ->method('set');
- $session->expects($this->once())
- ->method('regenerateId');
-
$managerMethods = get_class_methods('\OC\User\Manager');
//keep following methods intact in order to ensure hooks are
//working
@@ -268,10 +264,20 @@ class SessionTest extends \Test\TestCase {
}
}
$manager = $this->getMock('\OC\User\Manager', $managerMethods, array());
-
$backend = $this->getMock('\Test\Util\User\Dummy');
+ $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
$user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+
+ $session->expects($this->never())
+ ->method('set');
+ $session->expects($this->once())
+ ->method('regenerateId');
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('bar')
+ ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
+
$user->expects($this->never())
->method('isEnabled');
$user->expects($this->never())
@@ -282,27 +288,29 @@ class SessionTest extends \Test\TestCase {
->with('foo', 'bar')
->will($this->returnValue(false));
- $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
$userSession->login('foo', 'bar');
}
public function testLoginNonExisting() {
$session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $manager = $this->getMock('\OC\User\Manager');
+ $backend = $this->getMock('\Test\Util\User\Dummy');
+ $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
+
$session->expects($this->never())
->method('set');
$session->expects($this->once())
->method('regenerateId');
-
- $manager = $this->getMock('\OC\User\Manager');
-
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('bar')
+ ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
$manager->expects($this->once())
->method('checkPassword')
->with('foo', 'bar')
->will($this->returnValue(false));
- $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
$userSession->login('foo', 'bar');
}
@@ -354,24 +362,14 @@ class SessionTest extends \Test\TestCase {
->will($this->returnValue(true));
$userSession->expects($this->once())
->method('login')
- ->with('john', 'doe')
+ ->with('john', 'I-AM-AN-APP-PASSWORD')
->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));
+ $session->expects($this->once())
+ ->method('set')
+ ->with('app_password', 'I-AM-AN-APP-PASSWORD');
+
+ $this->assertTrue($userSession->logClientIn('john', 'I-AM-AN-APP-PASSWORD', $request));
}
/**
@@ -706,9 +704,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())
@@ -716,15 +720,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')
@@ -744,40 +745,40 @@ class SessionTest extends \Test\TestCase {
->getMock();
$user = $this->getMock('\OCP\IUser');
- $token = $this->getMock('\OC\Authentication\Token\IToken');
+ $token = new \OC\Authentication\Token\DefaultToken();
+ $token->setLoginName('susan');
+ $token->setLastCheck(20);
$session->expects($this->once())
- ->method('getId')
- ->will($this->returnValue('sessionid'));
+ ->method('get')
+ ->with('app_password')
+ ->will($this->returnValue('APP-PASSWORD'));
$tokenProvider->expects($this->once())
->method('getToken')
- ->with('sessionid')
+ ->with('APP-PASSWORD')
->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));
+ ->will($this->returnValue(1000)); // more than 5min since last check
$tokenProvider->expects($this->once())
->method('getPassword')
- ->with($token, 'sessionid')
+ ->with($token, 'APP-PASSWORD')
->will($this->returnValue('123456'));
- $token->expects($this->once())
- ->method('getLoginName')
- ->will($this->returnValue('User5'));
$userManager->expects($this->once())
->method('checkPassword')
- ->with('User5', '123456')
+ ->with('susan', '123456')
->will($this->returnValue(true));
$user->expects($this->once())
->method('isEnabled')
->will($this->returnValue(false));
+ $tokenProvider->expects($this->once())
+ ->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() {
@@ -791,31 +792,96 @@ class SessionTest extends \Test\TestCase {
->getMock();
$user = $this->getMock('\OCP\IUser');
- $token = $this->getMock('\OC\Authentication\Token\IToken');
+ $token = new \OC\Authentication\Token\DefaultToken();
+ $token->setLastCheck(20);
$session->expects($this->once())
- ->method('getId')
- ->will($this->returnValue('sessionid'));
+ ->method('get')
+ ->with('app_password')
+ ->will($this->returnValue('APP-PASSWORD'));
$tokenProvider->expects($this->once())
->method('getToken')
- ->with('sessionid')
+ ->with('APP-PASSWORD')
->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));
+ ->will($this->returnValue(1000)); // more than 5min since last check
$tokenProvider->expects($this->once())
->method('getPassword')
- ->with($token, 'sessionid')
+ ->with($token, 'APP-PASSWORD')
->will($this->throwException(new \OC\Authentication\Exceptions\PasswordlessTokenException()));
- $session->expects($this->once())
- ->method('set')
- ->with('last_login_check', 5000);
+ $tokenProvider->expects($this->once())
+ ->method('updateToken')
+ ->with($token);
$this->invokePrivate($userSession, 'validateSession', [$user]);
+
+ $this->assertEquals(1000, $token->getLastCheck());
+ }
+
+ public function testUpdateSessionTokenPassword() {
+ $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 = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config);
+
+ $password = '123456';
+ $sessionId ='session1234';
+ $token = new \OC\Authentication\Token\DefaultToken();
+
+ $session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue($sessionId));
+ $tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with($sessionId)
+ ->will($this->returnValue($token));
+ $tokenProvider->expects($this->once())
+ ->method('setPassword')
+ ->with($token, $sessionId, $password);
+
+ $userSession->updateSessionTokenPassword($password);
+ }
+
+ public function testUpdateSessionTokenPasswordNoSessionAvailable() {
+ $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 = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config);
+
+ $session->expects($this->once())
+ ->method('getId')
+ ->will($this->throwException(new \OCP\Session\Exceptions\SessionNotAvailableException()));
+
+ $userSession->updateSessionTokenPassword('1234');
+ }
+
+ public function testUpdateSessionTokenPasswordInvalidTokenException() {
+ $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 = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config);
+
+ $password = '123456';
+ $sessionId ='session1234';
+ $token = new \OC\Authentication\Token\DefaultToken();
+
+ $session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue($sessionId));
+ $tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with($sessionId)
+ ->will($this->returnValue($token));
+ $tokenProvider->expects($this->once())
+ ->method('setPassword')
+ ->with($token, $sessionId, $password)
+ ->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
+
+ $userSession->updateSessionTokenPassword($password);
}
}