diff options
author | Julien Veyssier <julien-nc@posteo.net> | 2023-06-08 13:02:40 +0200 |
---|---|---|
committer | Julien Veyssier <julien-nc@posteo.net> | 2023-06-08 13:02:40 +0200 |
commit | 808819a4d0f87ba294b95e894b6db66872662208 (patch) | |
tree | 9a4d0e10856904ede6c58aa69dfa37b1bf21fa71 /apps/oauth2 | |
parent | 9ebeb5e736d8e4d189381ac845fbe841038ff2f7 (diff) | |
download | nextcloud-server-808819a4d0f87ba294b95e894b6db66872662208.tar.gz nextcloud-server-808819a4d0f87ba294b95e894b6db66872662208.zip |
fix oauth2 tests
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'apps/oauth2')
-rw-r--r-- | apps/oauth2/tests/Controller/OauthApiControllerTest.php | 68 | ||||
-rw-r--r-- | apps/oauth2/tests/Settings/AdminTest.php | 10 |
2 files changed, 53 insertions, 25 deletions
diff --git a/apps/oauth2/tests/Controller/OauthApiControllerTest.php b/apps/oauth2/tests/Controller/OauthApiControllerTest.php index 71294850f9d..eb9311dbbc7 100644 --- a/apps/oauth2/tests/Controller/OauthApiControllerTest.php +++ b/apps/oauth2/tests/Controller/OauthApiControllerTest.php @@ -203,16 +203,21 @@ class OauthApiControllerTest extends TestCase { $client = new Client(); $client->setClientIdentifier('clientId'); - $client->setSecret('clientSecret'); + $client->setSecret('encryptedClientSecret'); $this->clientMapper->method('getByUid') ->with(42) ->willReturn($client); - $this->crypto->method('decrypt') - ->with( - 'encryptedToken', - 'validrefresh' - )->willReturn('decryptedToken'); + $this->crypto + ->method('decrypt') + ->with($this->callback(function (string $text) { + return $text === 'encryptedClientSecret' || $text === 'encryptedToken'; + })) + ->willReturnCallback(function (string $text) { + return $text === 'encryptedClientSecret' + ? 'clientSecret' + : ($text === 'encryptedToken' ? 'decryptedToken' : ''); + }); $this->tokenProvider->method('getTokenById') ->with(1337) @@ -237,16 +242,21 @@ class OauthApiControllerTest extends TestCase { $client = new Client(); $client->setClientIdentifier('clientId'); - $client->setSecret('clientSecret'); + $client->setSecret('encryptedClientSecret'); $this->clientMapper->method('getByUid') ->with(42) ->willReturn($client); - $this->crypto->method('decrypt') - ->with( - 'encryptedToken', - 'validrefresh' - )->willReturn('decryptedToken'); + $this->crypto + ->method('decrypt') + ->with($this->callback(function (string $text) { + return $text === 'encryptedClientSecret' || $text === 'encryptedToken'; + })) + ->willReturnCallback(function (string $text) { + return $text === 'encryptedClientSecret' + ? 'clientSecret' + : ($text === 'encryptedToken' ? 'decryptedToken' : ''); + }); $appToken = new PublicKeyToken(); $appToken->setUid('userId'); @@ -329,16 +339,21 @@ class OauthApiControllerTest extends TestCase { $client = new Client(); $client->setClientIdentifier('clientId'); - $client->setSecret('clientSecret'); + $client->setSecret('encryptedClientSecret'); $this->clientMapper->method('getByUid') ->with(42) ->willReturn($client); - $this->crypto->method('decrypt') - ->with( - 'encryptedToken', - 'validrefresh' - )->willReturn('decryptedToken'); + $this->crypto + ->method('decrypt') + ->with($this->callback(function (string $text) { + return $text === 'encryptedClientSecret' || $text === 'encryptedToken'; + })) + ->willReturnCallback(function (string $text) { + return $text === 'encryptedClientSecret' + ? 'clientSecret' + : ($text === 'encryptedToken' ? 'decryptedToken' : ''); + }); $appToken = new PublicKeyToken(); $appToken->setUid('userId'); @@ -424,16 +439,21 @@ class OauthApiControllerTest extends TestCase { $client = new Client(); $client->setClientIdentifier('clientId'); - $client->setSecret('clientSecret'); + $client->setSecret('encryptedClientSecret'); $this->clientMapper->method('getByUid') ->with(42) ->willReturn($client); - $this->crypto->method('decrypt') - ->with( - 'encryptedToken', - 'validrefresh' - )->willReturn('decryptedToken'); + $this->crypto + ->method('decrypt') + ->with($this->callback(function (string $text) { + return $text === 'encryptedClientSecret' || $text === 'encryptedToken'; + })) + ->willReturnCallback(function (string $text) { + return $text === 'encryptedClientSecret' + ? 'clientSecret' + : ($text === 'encryptedToken' ? 'decryptedToken' : ''); + }); $appToken = new PublicKeyToken(); $appToken->setUid('userId'); diff --git a/apps/oauth2/tests/Settings/AdminTest.php b/apps/oauth2/tests/Settings/AdminTest.php index fc5ebbb8365..fb19a9fc6d1 100644 --- a/apps/oauth2/tests/Settings/AdminTest.php +++ b/apps/oauth2/tests/Settings/AdminTest.php @@ -28,7 +28,9 @@ use OCA\OAuth2\Settings\Admin; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; use OCP\IURLGenerator; +use OCP\Security\ICrypto; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; class AdminTest extends TestCase { @@ -48,7 +50,13 @@ class AdminTest extends TestCase { $this->initialState = $this->createMock(IInitialState::class); $this->clientMapper = $this->createMock(ClientMapper::class); - $this->admin = new Admin($this->initialState, $this->clientMapper, $this->createMock(IURLGenerator::class)); + $this->admin = new Admin( + $this->initialState, + $this->clientMapper, + $this->createMock(IURLGenerator::class), + $this->createMock(ICrypto::class), + $this->createMock(LoggerInterface::class) + ); } public function testGetForm() { |