Skip to content

Commit

Permalink
Revert "no encryption on this grant"
Browse files Browse the repository at this point in the history
This reverts commit 7522a46.
  • Loading branch information
hafezdivandari committed Oct 28, 2024
1 parent 7522a46 commit b7751db
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/Grant/DeviceCodeGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use LeagueTests\Stubs\AccessTokenEntity;
use LeagueTests\Stubs\ClientEntity;
use LeagueTests\Stubs\CryptTraitStub;
use LeagueTests\Stubs\DeviceCodeEntity;
use LeagueTests\Stubs\RefreshTokenEntity;
use LeagueTests\Stubs\ScopeEntity;
Expand All @@ -35,6 +36,13 @@ class DeviceCodeGrantTest extends TestCase
private const DEFAULT_SCOPE = 'basic';
private const INTERVAL_RATE = 10;

protected CryptTraitStub $cryptStub;

public function setUp(): void
{
$this->cryptStub = new CryptTraitStub();
}

public function testGetIdentifier(): void
{
$deviceCodeRepositoryMock = $this->getMockBuilder(DeviceCodeRepositoryInterface::class)->getMock();
Expand Down Expand Up @@ -92,6 +100,7 @@ public function testRespondToDeviceAuthorizationRequest(): void

$grant->setClientRepository($clientRepositoryMock);
$grant->setDefaultScope(self::DEFAULT_SCOPE);
$grant->setEncryptionKey($this->cryptStub->getKey());
$grant->setScopeRepository($scopeRepositoryMock);

$request = (new ServerRequest())->withParsedBody([
Expand Down Expand Up @@ -136,6 +145,7 @@ public function testRespondToDeviceAuthorizationRequestWithVerificationUriComple

$grant->setClientRepository($clientRepositoryMock);
$grant->setDefaultScope(self::DEFAULT_SCOPE);
$grant->setEncryptionKey($this->cryptStub->getKey());
$grant->setScopeRepository($scopeRepositoryMock);

$request = (new ServerRequest())->withParsedBody([
Expand Down Expand Up @@ -262,6 +272,8 @@ public function testCompleteDeviceAuthorizationRequest(): void
'http://foo/bar',
);

$grant->setEncryptionKey($this->cryptStub->getKey());

$grant->completeDeviceAuthorizationRequest($deviceCode->getIdentifier(), 'userId', true);

$this::assertEquals('userId', $deviceCode->getUserIdentifier());
Expand Down Expand Up @@ -311,6 +323,8 @@ public function testDeviceAuthorizationResponse(): void
'http://foo/bar'
);

$deviceCodeGrant->setEncryptionKey($this->cryptStub->getKey());

$server->enableGrantType($deviceCodeGrant);

$response = $server->respondToDeviceAuthorizationRequest($serverRequest, new Response());
Expand Down Expand Up @@ -376,6 +390,7 @@ public function testRespondToAccessTokenRequest(): void
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
$grant->setScopeRepository($scopeRepositoryMock);
$grant->setDefaultScope(self::DEFAULT_SCOPE);
$grant->setEncryptionKey($this->cryptStub->getKey());
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));

$grant->completeDeviceAuthorizationRequest($deviceCodeEntity->getIdentifier(), 'baz', true);
Expand Down Expand Up @@ -454,6 +469,7 @@ public function testRespondToRequestMissingDeviceCode(): void
$grant->setClientRepository($clientRepositoryMock);
$grant->setScopeRepository($scopeRepositoryMock);
$grant->setDefaultScope(self::DEFAULT_SCOPE);
$grant->setEncryptionKey($this->cryptStub->getKey());
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));

$serverRequest = (new ServerRequest())->withParsedBody([
Expand Down Expand Up @@ -501,6 +517,7 @@ public function testIssueSlowDownError(): void
$grant->setClientRepository($clientRepositoryMock);
$grant->setScopeRepository($scopeRepositoryMock);
$grant->setDefaultScope(self::DEFAULT_SCOPE);
$grant->setEncryptionKey($this->cryptStub->getKey());
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));

$serverRequest = (new ServerRequest())->withParsedBody([
Expand Down Expand Up @@ -548,6 +565,7 @@ public function testIssueAuthorizationPendingError(): void
$grant->setClientRepository($clientRepositoryMock);
$grant->setScopeRepository($scopeRepositoryMock);
$grant->setDefaultScope(self::DEFAULT_SCOPE);
$grant->setEncryptionKey($this->cryptStub->getKey());
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));

$serverRequest = (new ServerRequest())->withParsedBody([
Expand Down Expand Up @@ -595,6 +613,7 @@ public function testIssueExpiredTokenError(): void
$grant->setClientRepository($clientRepositoryMock);
$grant->setScopeRepository($scopeRepositoryMock);
$grant->setDefaultScope(self::DEFAULT_SCOPE);
$grant->setEncryptionKey($this->cryptStub->getKey());
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));

$serverRequest = (new ServerRequest())->withParsedBody([
Expand Down Expand Up @@ -638,6 +657,7 @@ public function testSettingDeviceCodeIntervalRate(): void

$grant->setClientRepository($clientRepositoryMock);
$grant->setDefaultScope(self::DEFAULT_SCOPE);
$grant->setEncryptionKey($this->cryptStub->getKey());
$grant->setScopeRepository($scopeRepositoryMock);
$grant->setIntervalVisibility(true);

Expand Down Expand Up @@ -692,6 +712,7 @@ public function testIssueAccessDeniedError(): void
$grant->setClientRepository($clientRepositoryMock);
$grant->setScopeRepository($scopeRepositoryMock);
$grant->setDefaultScope(self::DEFAULT_SCOPE);
$grant->setEncryptionKey($this->cryptStub->getKey());
$grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));

$grant->completeDeviceAuthorizationRequest($deviceCode->getIdentifier(), '1', false);
Expand Down

0 comments on commit b7751db

Please sign in to comment.