diff options
Diffstat (limited to 'apps/oauth2/tests')
-rw-r--r-- | apps/oauth2/tests/Controller/OauthApiControllerTest.php | 5 | ||||
-rw-r--r-- | apps/oauth2/tests/Controller/SettingsControllerTest.php | 17 |
2 files changed, 19 insertions, 3 deletions
diff --git a/apps/oauth2/tests/Controller/OauthApiControllerTest.php b/apps/oauth2/tests/Controller/OauthApiControllerTest.php index 8977f6a2b66..71294850f9d 100644 --- a/apps/oauth2/tests/Controller/OauthApiControllerTest.php +++ b/apps/oauth2/tests/Controller/OauthApiControllerTest.php @@ -43,6 +43,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\IRequest; use OCP\Security\ICrypto; use OCP\Security\ISecureRandom; +use Psr\Log\LoggerInterface; use Test\TestCase; /* We have to use this to add a property to the mocked request and avoid warnings about dynamic properties on PHP>=8.2 */ @@ -67,6 +68,8 @@ class OauthApiControllerTest extends TestCase { private $time; /** @var Throttler|\PHPUnit\Framework\MockObject\MockObject */ private $throttler; + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $logger; /** @var OauthApiController */ private $oauthApiController; @@ -81,6 +84,7 @@ class OauthApiControllerTest extends TestCase { $this->secureRandom = $this->createMock(ISecureRandom::class); $this->time = $this->createMock(ITimeFactory::class); $this->throttler = $this->createMock(Throttler::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->oauthApiController = new OauthApiController( 'oauth2', @@ -91,6 +95,7 @@ class OauthApiControllerTest extends TestCase { $this->tokenProvider, $this->secureRandom, $this->time, + $this->logger, $this->throttler ); } diff --git a/apps/oauth2/tests/Controller/SettingsControllerTest.php b/apps/oauth2/tests/Controller/SettingsControllerTest.php index e79d7cbe34e..817747599b7 100644 --- a/apps/oauth2/tests/Controller/SettingsControllerTest.php +++ b/apps/oauth2/tests/Controller/SettingsControllerTest.php @@ -38,6 +38,7 @@ use OCP\IL10N; use OCP\IRequest; use OCP\IUser; use OCP\IUserManager; +use OCP\Security\ICrypto; use OCP\Security\ISecureRandom; use Test\TestCase; @@ -61,6 +62,8 @@ class SettingsControllerTest extends TestCase { private $settingsController; /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ private $l; + /** @var ICrypto|\PHPUnit\Framework\MockObject\MockObject */ + private $crypto; protected function setUp(): void { parent::setUp(); @@ -71,6 +74,7 @@ class SettingsControllerTest extends TestCase { $this->accessTokenMapper = $this->createMock(AccessTokenMapper::class); $this->authTokenProvider = $this->createMock(IAuthTokenProvider::class); $this->userManager = $this->createMock(IUserManager::class); + $this->crypto = $this->createMock(ICrypto::class); $this->l = $this->createMock(IL10N::class); $this->l->method('t') ->willReturnArgument(0); @@ -82,7 +86,8 @@ class SettingsControllerTest extends TestCase { $this->accessTokenMapper, $this->l, $this->authTokenProvider, - $this->userManager + $this->userManager, + $this->crypto ); } @@ -96,6 +101,11 @@ class SettingsControllerTest extends TestCase { 'MySecret', 'MyClientIdentifier'); + $this->crypto + ->expects($this->once()) + ->method('encrypt') + ->willReturn('MyEncryptedSecret'); + $client = new Client(); $client->setName('My Client Name'); $client->setRedirectUri('https://example.com/'); @@ -108,7 +118,7 @@ class SettingsControllerTest extends TestCase { ->with($this->callback(function (Client $c) { return $c->getName() === 'My Client Name' && $c->getRedirectUri() === 'https://example.com/' && - $c->getSecret() === 'MySecret' && + $c->getSecret() === 'MyEncryptedSecret' && $c->getClientIdentifier() === 'MyClientIdentifier'; }))->willReturnCallback(function (Client $c) { $c->setId(42); @@ -175,7 +185,8 @@ class SettingsControllerTest extends TestCase { $this->accessTokenMapper, $this->l, $tokenProviderMock, - $userManager + $userManager, + $this->crypto ); $result = $settingsController->deleteClient(123); |