2016-04-29 14:31:27 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
|
|
|
*
|
2016-11-02 12:37:39 +00:00
|
|
|
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
|
2016-04-29 14:31:27 +00:00
|
|
|
* @copyright Copyright (c) 2016, 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 Test\Authentication\Token;
|
|
|
|
|
2016-11-11 08:25:42 +00:00
|
|
|
use OC\Authentication\Exceptions\InvalidTokenException;
|
2016-04-29 14:31:27 +00:00
|
|
|
use OC\Authentication\Token\DefaultToken;
|
2018-05-15 08:56:40 +00:00
|
|
|
use OC\Authentication\Token\DefaultTokenMapper;
|
2016-04-29 14:31:27 +00:00
|
|
|
use OC\Authentication\Token\DefaultTokenProvider;
|
|
|
|
use OC\Authentication\Token\IToken;
|
2016-11-11 08:25:42 +00:00
|
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
2016-09-02 09:07:26 +00:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\Security\ICrypto;
|
2016-04-29 14:31:27 +00:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class DefaultTokenProviderTest extends TestCase {
|
|
|
|
|
2016-11-02 12:37:39 +00:00
|
|
|
/** @var DefaultTokenProvider|\PHPUnit_Framework_MockObject_MockObject */
|
2016-04-29 14:31:27 +00:00
|
|
|
private $tokenProvider;
|
2018-05-15 08:56:40 +00:00
|
|
|
/** @var DefaultTokenMapper|\PHPUnit_Framework_MockObject_MockObject */
|
2016-04-29 14:31:27 +00:00
|
|
|
private $mapper;
|
2016-11-02 12:37:39 +00:00
|
|
|
/** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */
|
2016-04-29 14:31:27 +00:00
|
|
|
private $crypto;
|
2016-11-02 12:37:39 +00:00
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
2016-04-29 14:31:27 +00:00
|
|
|
private $config;
|
2016-11-02 12:37:39 +00:00
|
|
|
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
2016-04-29 14:31:27 +00:00
|
|
|
private $logger;
|
2016-11-02 12:37:39 +00:00
|
|
|
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
|
2016-05-06 14:31:40 +00:00
|
|
|
private $timeFactory;
|
2016-11-02 12:37:39 +00:00
|
|
|
/** @var int */
|
2016-05-06 14:31:40 +00:00
|
|
|
private $time;
|
2016-04-29 14:31:27 +00:00
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2018-05-15 08:56:40 +00:00
|
|
|
$this->mapper = $this->createMock(DefaultTokenMapper::class);
|
2016-09-02 09:07:26 +00:00
|
|
|
$this->crypto = $this->createMock(ICrypto::class);
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
2016-05-06 14:31:40 +00:00
|
|
|
$this->time = 1313131;
|
|
|
|
$this->timeFactory->expects($this->any())
|
|
|
|
->method('getTime')
|
|
|
|
->will($this->returnValue($this->time));
|
2016-04-29 14:31:27 +00:00
|
|
|
|
2016-05-08 17:31:42 +00:00
|
|
|
$this->tokenProvider = new DefaultTokenProvider($this->mapper, $this->crypto, $this->config, $this->logger,
|
|
|
|
$this->timeFactory);
|
2016-04-29 14:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGenerateToken() {
|
|
|
|
$token = 'token';
|
|
|
|
$uid = 'user';
|
2016-05-24 08:50:18 +00:00
|
|
|
$user = 'User';
|
2016-04-29 14:31:27 +00:00
|
|
|
$password = 'passme';
|
2016-05-12 09:19:17 +00:00
|
|
|
$name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'
|
|
|
|
. 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'
|
|
|
|
. 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'
|
|
|
|
. 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12';
|
2016-04-29 14:31:27 +00:00
|
|
|
$type = IToken::PERMANENT_TOKEN;
|
|
|
|
|
|
|
|
$toInsert = new DefaultToken();
|
|
|
|
$toInsert->setUid($uid);
|
2016-05-24 08:50:18 +00:00
|
|
|
$toInsert->setLoginName($user);
|
2016-04-29 14:31:27 +00:00
|
|
|
$toInsert->setPassword('encryptedpassword');
|
|
|
|
$toInsert->setName($name);
|
2016-05-06 14:31:40 +00:00
|
|
|
$toInsert->setToken(hash('sha512', $token . '1f4h9s'));
|
2016-04-29 14:31:27 +00:00
|
|
|
$toInsert->setType($type);
|
2016-09-06 19:41:15 +00:00
|
|
|
$toInsert->setRemember(IToken::DO_NOT_REMEMBER);
|
2016-05-06 14:31:40 +00:00
|
|
|
$toInsert->setLastActivity($this->time);
|
2017-11-27 08:25:03 +00:00
|
|
|
$toInsert->setLastCheck($this->time);
|
2016-04-29 14:31:27 +00:00
|
|
|
|
2016-05-06 14:31:40 +00:00
|
|
|
$this->config->expects($this->any())
|
2016-04-29 14:31:27 +00:00
|
|
|
->method('getSystemValue')
|
|
|
|
->with('secret')
|
|
|
|
->will($this->returnValue('1f4h9s'));
|
|
|
|
$this->crypto->expects($this->once())
|
|
|
|
->method('encrypt')
|
|
|
|
->with($password, $token . '1f4h9s')
|
|
|
|
->will($this->returnValue('encryptedpassword'));
|
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('insert')
|
|
|
|
->with($this->equalTo($toInsert));
|
|
|
|
|
2016-09-06 19:41:15 +00:00
|
|
|
$actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER);
|
2016-04-29 14:31:27 +00:00
|
|
|
|
|
|
|
$this->assertEquals($toInsert, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateToken() {
|
2016-05-06 14:31:40 +00:00
|
|
|
$tk = new DefaultToken();
|
2016-06-17 10:08:48 +00:00
|
|
|
$tk->setLastActivity($this->time - 200);
|
2016-04-29 14:31:27 +00:00
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('update')
|
|
|
|
->with($tk);
|
|
|
|
|
2016-06-17 10:08:48 +00:00
|
|
|
$this->tokenProvider->updateTokenActivity($tk);
|
2016-05-06 14:31:40 +00:00
|
|
|
|
|
|
|
$this->assertEquals($this->time, $tk->getLastActivity());
|
2016-04-29 14:31:27 +00:00
|
|
|
}
|
2016-06-17 10:08:48 +00:00
|
|
|
|
|
|
|
public function testUpdateTokenDebounce() {
|
|
|
|
$tk = new DefaultToken();
|
|
|
|
$tk->setLastActivity($this->time - 30);
|
|
|
|
$this->mapper->expects($this->never())
|
|
|
|
->method('update')
|
|
|
|
->with($tk);
|
|
|
|
|
|
|
|
$this->tokenProvider->updateTokenActivity($tk);
|
|
|
|
}
|
2016-05-18 09:33:56 +00:00
|
|
|
|
|
|
|
public function testGetTokenByUser() {
|
2016-09-02 09:07:26 +00:00
|
|
|
$user = $this->createMock(IUser::class);
|
2016-05-18 09:33:56 +00:00
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('getTokenByUser')
|
|
|
|
->with($user)
|
|
|
|
->will($this->returnValue(['token']));
|
|
|
|
|
|
|
|
$this->assertEquals(['token'], $this->tokenProvider->getTokenByUser($user));
|
|
|
|
}
|
2016-04-29 14:31:27 +00:00
|
|
|
|
|
|
|
public function testGetPassword() {
|
|
|
|
$token = 'token1234';
|
2016-05-06 14:31:40 +00:00
|
|
|
$tk = new DefaultToken();
|
|
|
|
$tk->setPassword('someencryptedvalue');
|
2016-04-29 14:31:27 +00:00
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
|
|
|
->with('secret')
|
|
|
|
->will($this->returnValue('1f4h9s'));
|
|
|
|
$this->crypto->expects($this->once())
|
|
|
|
->method('decrypt')
|
|
|
|
->with('someencryptedvalue', $token . '1f4h9s')
|
|
|
|
->will($this->returnValue('passme'));
|
|
|
|
|
|
|
|
$actual = $this->tokenProvider->getPassword($tk, $token);
|
|
|
|
|
|
|
|
$this->assertEquals('passme', $actual);
|
|
|
|
}
|
|
|
|
|
2016-05-31 08:48:14 +00:00
|
|
|
/**
|
|
|
|
* @expectedException \OC\Authentication\Exceptions\PasswordlessTokenException
|
|
|
|
*/
|
|
|
|
public function testGetPasswordPasswordLessToken() {
|
|
|
|
$token = 'token1234';
|
|
|
|
$tk = new DefaultToken();
|
|
|
|
$tk->setPassword(null);
|
|
|
|
|
|
|
|
$this->tokenProvider->getPassword($tk, $token);
|
|
|
|
}
|
|
|
|
|
2016-05-08 17:31:42 +00:00
|
|
|
/**
|
|
|
|
* @expectedException \OC\Authentication\Exceptions\InvalidTokenException
|
|
|
|
*/
|
|
|
|
public function testGetPasswordDeletesInvalidToken() {
|
|
|
|
$token = 'token1234';
|
|
|
|
$tk = new DefaultToken();
|
|
|
|
$tk->setPassword('someencryptedvalue');
|
|
|
|
/* @var $tokenProvider DefaultTokenProvider */
|
|
|
|
$tokenProvider = $this->getMockBuilder('\OC\Authentication\Token\DefaultTokenProvider')
|
|
|
|
->setMethods([
|
|
|
|
'invalidateToken'
|
|
|
|
])
|
|
|
|
->setConstructorArgs([$this->mapper, $this->crypto, $this->config, $this->logger,
|
|
|
|
$this->timeFactory])
|
|
|
|
->getMock();
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
|
|
|
->with('secret')
|
|
|
|
->will($this->returnValue('1f4h9s'));
|
|
|
|
$this->crypto->expects($this->once())
|
|
|
|
->method('decrypt')
|
|
|
|
->with('someencryptedvalue', $token . '1f4h9s')
|
|
|
|
->will($this->throwException(new \Exception('some crypto error occurred')));
|
|
|
|
$tokenProvider->expects($this->once())
|
|
|
|
->method('invalidateToken')
|
|
|
|
->with($token);
|
|
|
|
|
|
|
|
$tokenProvider->getPassword($tk, $token);
|
|
|
|
}
|
|
|
|
|
2016-06-21 08:23:50 +00:00
|
|
|
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() {
|
2016-09-02 09:07:26 +00:00
|
|
|
$token = $this->createMock(IToken::class);
|
2016-06-21 08:23:50 +00:00
|
|
|
$tokenId = 'token123';
|
|
|
|
$password = '123456';
|
|
|
|
|
|
|
|
$this->tokenProvider->setPassword($token, $tokenId, $password);
|
|
|
|
}
|
|
|
|
|
2016-04-29 14:31:27 +00:00
|
|
|
public function testInvalidateToken() {
|
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('invalidate')
|
|
|
|
->with(hash('sha512', 'token7'));
|
|
|
|
|
|
|
|
$this->tokenProvider->invalidateToken('token7');
|
|
|
|
}
|
|
|
|
|
2016-05-19 09:20:22 +00:00
|
|
|
public function testInvaildateTokenById() {
|
|
|
|
$id = 123;
|
2016-09-02 09:07:26 +00:00
|
|
|
$user = $this->createMock(IUser::class);
|
2016-05-19 09:20:22 +00:00
|
|
|
|
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('deleteById')
|
|
|
|
->with($user, $id);
|
|
|
|
|
|
|
|
$this->tokenProvider->invalidateTokenById($user, $id);
|
|
|
|
}
|
|
|
|
|
2016-04-29 14:31:27 +00:00
|
|
|
public function testInvalidateOldTokens() {
|
|
|
|
$defaultSessionLifetime = 60 * 60 * 24;
|
2016-09-06 19:41:15 +00:00
|
|
|
$defaultRememberMeLifetime = 60 * 60 * 24 * 15;
|
|
|
|
$this->config->expects($this->exactly(2))
|
2016-04-29 14:31:27 +00:00
|
|
|
->method('getSystemValue')
|
2016-09-06 19:41:15 +00:00
|
|
|
->will($this->returnValueMap([
|
|
|
|
['session_lifetime', $defaultSessionLifetime, 150],
|
|
|
|
['remember_login_cookie_lifetime', $defaultRememberMeLifetime, 300],
|
|
|
|
]));
|
|
|
|
$this->mapper->expects($this->at(0))
|
2016-04-29 14:31:27 +00:00
|
|
|
->method('invalidateOld')
|
2016-05-06 14:31:40 +00:00
|
|
|
->with($this->time - 150);
|
2016-09-06 19:41:15 +00:00
|
|
|
$this->mapper->expects($this->at(1))
|
|
|
|
->method('invalidateOld')
|
|
|
|
->with($this->time - 300);
|
2016-04-29 14:31:27 +00:00
|
|
|
|
|
|
|
$this->tokenProvider->invalidateOldTokens();
|
|
|
|
}
|
|
|
|
|
2016-11-02 12:37:39 +00:00
|
|
|
public function testRenewSessionTokenWithoutPassword() {
|
|
|
|
$token = $this->getMockBuilder(DefaultToken::class)
|
|
|
|
->disableOriginalConstructor()
|
2017-04-20 10:37:59 +00:00
|
|
|
->setMethods(['getUID', 'getLoginName', 'getPassword', 'getName', 'getRemember'])
|
2016-11-02 12:37:39 +00:00
|
|
|
->getMock();
|
|
|
|
$token
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('UserUid');
|
|
|
|
$token
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getLoginName')
|
|
|
|
->willReturn('UserLoginName');
|
|
|
|
$token
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getPassword')
|
|
|
|
->willReturn(null);
|
|
|
|
$token
|
|
|
|
->expects($this->at(3))
|
|
|
|
->method('getName')
|
|
|
|
->willReturn('MyTokenName');
|
2016-11-27 13:19:57 +00:00
|
|
|
$token
|
2017-04-20 10:37:59 +00:00
|
|
|
->expects($this->at(4))
|
2017-02-28 09:26:19 +00:00
|
|
|
->method('getRemember')
|
2016-11-27 13:19:57 +00:00
|
|
|
->willReturn(IToken::DO_NOT_REMEMBER);
|
2016-11-02 12:37:39 +00:00
|
|
|
$this->config
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('getSystemValue')
|
|
|
|
->with('secret')
|
|
|
|
->willReturn('MyInstanceSecret');
|
|
|
|
$this->mapper
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getToken')
|
|
|
|
->with(hash('sha512', 'oldId' . 'MyInstanceSecret'))
|
|
|
|
->willReturn($token);
|
|
|
|
$newToken = new DefaultToken();
|
|
|
|
$newToken->setUid('UserUid');
|
|
|
|
$newToken->setLoginName('UserLoginName');
|
|
|
|
$newToken->setName('MyTokenName');
|
|
|
|
$newToken->setToken(hash('sha512', 'newId' . 'MyInstanceSecret'));
|
|
|
|
$newToken->setType(IToken::TEMPORARY_TOKEN);
|
2016-11-27 13:19:57 +00:00
|
|
|
$newToken->setRemember(IToken::DO_NOT_REMEMBER);
|
2016-11-02 12:37:39 +00:00
|
|
|
$newToken->setLastActivity(1313131);
|
|
|
|
$this->mapper
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('insert')
|
|
|
|
->with($newToken);
|
2017-09-18 08:33:19 +00:00
|
|
|
$this->mapper
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('delete')
|
|
|
|
->with($token);
|
2016-11-02 12:37:39 +00:00
|
|
|
|
|
|
|
$this->tokenProvider->renewSessionToken('oldId', 'newId');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenewSessionTokenWithPassword() {
|
|
|
|
$token = $this->getMockBuilder(DefaultToken::class)
|
|
|
|
->disableOriginalConstructor()
|
2017-04-20 10:37:59 +00:00
|
|
|
->setMethods(['getUID', 'getLoginName', 'getPassword', 'getName', 'getRemember'])
|
2016-11-02 12:37:39 +00:00
|
|
|
->getMock();
|
|
|
|
$token
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('UserUid');
|
|
|
|
$token
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getLoginName')
|
|
|
|
->willReturn('UserLoginName');
|
|
|
|
$token
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getPassword')
|
|
|
|
->willReturn('EncryptedPassword');
|
|
|
|
$token
|
|
|
|
->expects($this->at(3))
|
|
|
|
->method('getPassword')
|
|
|
|
->willReturn('EncryptedPassword');
|
|
|
|
$token
|
|
|
|
->expects($this->at(4))
|
|
|
|
->method('getName')
|
|
|
|
->willReturn('MyTokenName');
|
2016-11-27 13:19:57 +00:00
|
|
|
$token
|
2017-04-20 10:37:59 +00:00
|
|
|
->expects($this->at(5))
|
2017-02-28 09:26:19 +00:00
|
|
|
->method('getRemember')
|
2016-11-27 13:19:57 +00:00
|
|
|
->willReturn(IToken::REMEMBER);
|
2016-11-02 12:37:39 +00:00
|
|
|
$this->crypto
|
|
|
|
->expects($this->any(0))
|
|
|
|
->method('decrypt')
|
|
|
|
->with('EncryptedPassword', 'oldIdMyInstanceSecret')
|
|
|
|
->willReturn('ClearTextPassword');
|
|
|
|
$this->crypto
|
|
|
|
->expects($this->any(1))
|
|
|
|
->method('encrypt')
|
|
|
|
->with('ClearTextPassword', 'newIdMyInstanceSecret')
|
|
|
|
->willReturn('EncryptedPassword');
|
|
|
|
$this->config
|
|
|
|
->expects($this->exactly(4))
|
|
|
|
->method('getSystemValue')
|
|
|
|
->with('secret')
|
|
|
|
->willReturn('MyInstanceSecret');
|
|
|
|
$this->mapper
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getToken')
|
|
|
|
->with(hash('sha512', 'oldId' . 'MyInstanceSecret'))
|
|
|
|
->willReturn($token);
|
|
|
|
$newToken = new DefaultToken();
|
|
|
|
$newToken->setUid('UserUid');
|
|
|
|
$newToken->setLoginName('UserLoginName');
|
|
|
|
$newToken->setName('MyTokenName');
|
|
|
|
$newToken->setToken(hash('sha512', 'newId' . 'MyInstanceSecret'));
|
|
|
|
$newToken->setType(IToken::TEMPORARY_TOKEN);
|
2016-11-27 13:19:57 +00:00
|
|
|
$newToken->setRemember(IToken::REMEMBER);
|
2016-11-02 12:37:39 +00:00
|
|
|
$newToken->setLastActivity(1313131);
|
|
|
|
$newToken->setPassword('EncryptedPassword');
|
|
|
|
$this->mapper
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('insert')
|
2016-11-27 13:19:57 +00:00
|
|
|
->with($this->equalTo($newToken));
|
2017-09-18 08:33:19 +00:00
|
|
|
$this->mapper
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('delete')
|
|
|
|
->with($token);
|
2016-11-02 12:37:39 +00:00
|
|
|
|
|
|
|
$this->tokenProvider->renewSessionToken('oldId', 'newId');
|
|
|
|
}
|
|
|
|
|
2016-11-11 08:25:42 +00:00
|
|
|
public function testGetTokenById() {
|
|
|
|
$token = $this->createMock(DefaultToken::class);
|
|
|
|
|
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('getTokenById')
|
|
|
|
->with($this->equalTo(42))
|
|
|
|
->willReturn($token);
|
|
|
|
|
|
|
|
$this->assertSame($token, $this->tokenProvider->getTokenById(42));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetInvalidTokenById() {
|
|
|
|
$this->expectException(InvalidTokenException::class);
|
|
|
|
|
|
|
|
$this->mapper->expects($this->once())
|
|
|
|
->method('getTokenById')
|
|
|
|
->with($this->equalTo(42))
|
|
|
|
->willThrowException(new DoesNotExistException('nope'));
|
|
|
|
|
|
|
|
$this->tokenProvider->getTokenById(42);
|
|
|
|
}
|
2016-04-29 14:31:27 +00:00
|
|
|
}
|