diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-05-31 22:56:26 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-06-18 22:11:55 +0200 |
commit | 9e7a95fe58ee8ace0ae30ff2ebda993018542187 (patch) | |
tree | 09f31b9e28ff4052d82254c87cba342aa9979b98 /lib | |
parent | 1999f7ce7bd438f9b545fff8956ea4ed24d3dc8d (diff) | |
download | nextcloud-server-9e7a95fe58ee8ace0ae30ff2ebda993018542187.tar.gz nextcloud-server-9e7a95fe58ee8ace0ae30ff2ebda993018542187.zip |
Add more tests
* Add a lot of tests
* Fixes related to those tests
* Fix tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Authentication/Token/Manager.php | 12 | ||||
-rw-r--r-- | lib/private/Authentication/Token/PublicKeyTokenMapper.php | 2 | ||||
-rw-r--r-- | lib/private/Authentication/Token/PublicKeyTokenProvider.php | 3 |
3 files changed, 14 insertions, 3 deletions
diff --git a/lib/private/Authentication/Token/Manager.php b/lib/private/Authentication/Token/Manager.php index e4f0ead862b..5e30afbc92e 100644 --- a/lib/private/Authentication/Token/Manager.php +++ b/lib/private/Authentication/Token/Manager.php @@ -144,7 +144,7 @@ class Manager implements IProvider { */ public function getTokenById(int $tokenId): IToken { try { - $this->publicKeyTokenProvider->getTokenById($tokenId); + return $this->publicKeyTokenProvider->getTokenById($tokenId); } catch (InvalidTokenException $e) { return $this->defaultTokenProvider->getTokenById($tokenId); } @@ -178,16 +178,22 @@ class Manager implements IProvider { if ($savedToken instanceof PublicKeyToken) { return $this->publicKeyTokenProvider->getPassword($savedToken, $tokenId); } + + throw new InvalidTokenException(); } public function setPassword(IToken $token, string $tokenId, string $password) { if ($token instanceof DefaultToken) { $this->defaultTokenProvider->setPassword($token, $tokenId, $password); + return; } - if ($tokenId instanceof PublicKeyToken) { + if ($token instanceof PublicKeyToken) { $this->publicKeyTokenProvider->setPassword($token, $tokenId, $password); + return; } + + throw new InvalidTokenException(); } public function invalidateToken(string $token) { @@ -219,6 +225,8 @@ class Manager implements IProvider { if ($token instanceof PublicKeyToken) { return $this->publicKeyTokenProvider->rotate($token, $oldTokenId, $newTokenId); } + + throw new InvalidTokenException(); } diff --git a/lib/private/Authentication/Token/PublicKeyTokenMapper.php b/lib/private/Authentication/Token/PublicKeyTokenMapper.php index 30349fba31a..23982c6ba09 100644 --- a/lib/private/Authentication/Token/PublicKeyTokenMapper.php +++ b/lib/private/Authentication/Token/PublicKeyTokenMapper.php @@ -166,5 +166,7 @@ class PublicKeyTokenMapper extends QBMapper { ->where($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN))) ->andWhere($qb->expr()->neq('id', $qb->createNamedParameter($except->getId()))) ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(2, IQueryBuilder::PARAM_INT))); + + $qb->execute(); } } diff --git a/lib/private/Authentication/Token/PublicKeyTokenProvider.php b/lib/private/Authentication/Token/PublicKeyTokenProvider.php index e512133a962..ca7a7e37e1e 100644 --- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php +++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php @@ -196,7 +196,7 @@ class PublicKeyTokenProvider implements IProvider { // Update the password for all tokens $tokens = $this->mapper->getTokenByUser($token->getUID()); foreach ($tokens as $t) { - $publicKey = $token->getPublicKey(); + $publicKey = $t->getPublicKey(); $t->setPassword($this->encryptPassword($password, $publicKey)); $this->updateToken($t); } @@ -271,6 +271,7 @@ class PublicKeyTokenProvider implements IProvider { $defaultToken->getRemember() ); + $pkToken->setExpires($defaultToken->getExpires()); $pkToken->setId($defaultToken->getId()); return $this->mapper->update($pkToken); |