diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-11-02 13:37:39 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-11-02 13:39:17 +0100 |
commit | 9d6e01ef40f7f4d2acab653b33e1af026bcde6c7 (patch) | |
tree | 45c98681e5fd2671bba975a56bc75185b08d0f9a /tests/lib/Authentication | |
parent | 271f2a4cfff2be6f25d4bc546040613fdb2e70bf (diff) | |
download | nextcloud-server-9d6e01ef40f7f4d2acab653b33e1af026bcde6c7.tar.gz nextcloud-server-9d6e01ef40f7f4d2acab653b33e1af026bcde6c7.zip |
Add missing tests and fix PHPDoc
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'tests/lib/Authentication')
-rw-r--r-- | tests/lib/Authentication/Token/DefaultTokenProviderTest.php | 118 |
1 files changed, 116 insertions, 2 deletions
diff --git a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php index cd6bf7bad57..5e4d4f94366 100644 --- a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php +++ b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php @@ -1,8 +1,8 @@ <?php - /** * @author Christoph Wurst <christoph@owncloud.com> * + * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch> * @copyright Copyright (c) 2016, ownCloud, Inc. * @license AGPL-3.0 * @@ -25,6 +25,7 @@ namespace Test\Authentication\Token; use OC\Authentication\Token\DefaultToken; use OC\Authentication\Token\DefaultTokenProvider; use OC\Authentication\Token\IToken; +use OCP\AppFramework\Db\Mapper; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IConfig; use OCP\ILogger; @@ -34,13 +35,19 @@ use Test\TestCase; class DefaultTokenProviderTest extends TestCase { - /** @var DefaultTokenProvider */ + /** @var DefaultTokenProvider|\PHPUnit_Framework_MockObject_MockObject */ private $tokenProvider; + /** @var Mapper|\PHPUnit_Framework_MockObject_MockObject */ private $mapper; + /** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */ private $crypto; + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ private $config; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ private $logger; + /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */ private $timeFactory; + /** @var int */ private $time; protected function setUp() { @@ -262,4 +269,111 @@ class DefaultTokenProviderTest extends TestCase { $this->tokenProvider->invalidateOldTokens(); } + public function testRenewSessionTokenWithoutPassword() { + $token = $this->getMockBuilder(DefaultToken::class) + ->disableOriginalConstructor() + ->setMethods(['getUID', 'getLoginName', 'getPassword', 'getName']) + ->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'); + $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); + $newToken->setLastActivity(1313131); + $this->mapper + ->expects($this->at(1)) + ->method('insert') + ->with($newToken); + + $this->tokenProvider->renewSessionToken('oldId', 'newId'); + } + + public function testRenewSessionTokenWithPassword() { + $token = $this->getMockBuilder(DefaultToken::class) + ->disableOriginalConstructor() + ->setMethods(['getUID', 'getLoginName', 'getPassword', 'getName']) + ->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'); + $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); + $newToken->setLastActivity(1313131); + $newToken->setPassword('EncryptedPassword'); + $this->mapper + ->expects($this->at(1)) + ->method('insert') + ->with($newToken); + + $this->tokenProvider->renewSessionToken('oldId', 'newId'); + } + } |