summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@owncloud.com>2016-05-08 19:31:42 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2016-05-11 13:36:46 +0200
commit69dafd727dc848e3be541ae15bd88d01037cfab0 (patch)
tree31b717a904e28969091b881316b267babd27c0c8 /tests
parentaf707fba41634b70115d47de86efe2ce2bf3d3b6 (diff)
downloadnextcloud-server-69dafd727dc848e3be541ae15bd88d01037cfab0.tar.gz
nextcloud-server-69dafd727dc848e3be541ae15bd88d01037cfab0.zip
delete the token in case an exception is thrown when decrypting the password
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/authentication/token/defaulttokenprovidertest.php33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/lib/authentication/token/defaulttokenprovidertest.php b/tests/lib/authentication/token/defaulttokenprovidertest.php
index 567068ef06a..5ee33d0ec11 100644
--- a/tests/lib/authentication/token/defaulttokenprovidertest.php
+++ b/tests/lib/authentication/token/defaulttokenprovidertest.php
@@ -54,7 +54,8 @@ class DefaultTokenProviderTest extends TestCase {
->method('getTime')
->will($this->returnValue($this->time));
- $this->tokenProvider = new DefaultTokenProvider($this->mapper, $this->crypto, $this->config, $this->logger, $this->timeFactory);
+ $this->tokenProvider = new DefaultTokenProvider($this->mapper, $this->crypto, $this->config, $this->logger,
+ $this->timeFactory);
}
public function testGenerateToken() {
@@ -118,6 +119,36 @@ class DefaultTokenProviderTest extends TestCase {
$this->assertEquals('passme', $actual);
}
+ /**
+ * @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);
+ }
+
public function testInvalidateToken() {
$this->mapper->expects($this->once())
->method('invalidate')