Passed
Pull Request — master (#11)
by Pol
02:31
created

RpIdTokenSigEncTest::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
nc 1
nop 1
dl 0
loc 38
rs 9.52
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\ConformanceTest\RpTest\IdToken;
6
7
use Jose\Component\Core\JWK;
8
use Jose\Component\Core\JWKSet;
9
use Jose\Component\KeyManagement\JWKFactory;
10
use PHPUnit\Framework\Assert;
11
use Facile\OpenIDClient\ConformanceTest\RpTest\AbstractRpTest;
12
use Facile\OpenIDClient\ConformanceTest\TestInfo;
13
use Facile\OpenIDClient\Session\AuthSession;
14
use Facile\OpenIDClient\Service\AuthorizationService;
15
use function Facile\OpenIDClient\base64url_encode;
16
use function json_decode;
17
use function json_encode;
18
19
/**
20
 * Request an signed ID Token. Verify the signature on the ID Token using the keys published by the Issuer.
21
 *
22
 * Accept the ID Token after doing ID Token validation.
23
 */
24
class RpIdTokenSigEncTest extends AbstractRpTest
25
{
26
27
    public function getTestId(): string
28
    {
29
        return 'rp-id_token-sig+enc';
30
    }
31
32
    public function execute(TestInfo $testInfo): void
33
    {
34
        $jwkSig = JWKFactory::createRSAKey(2048, ['alg' => 'RS256', 'use' => 'sig']);
35
        $jwkEncAlg = JWKFactory::createRSAKey(2048, ['alg' => 'RSA1_5', 'use' => 'enc']);
36
37
        $jwks = new JWKSet([$jwkSig, $jwkEncAlg]);
38
        $publicJwks = new JWKSet(\array_map(function (JWK $jwk) {
39
            return $jwk->toPublic();
40
        }, $jwks->all()));
41
42
        $client = $this->registerClient($testInfo, [
43
            'id_token_signed_response_alg' => 'RS256',
44
            'id_token_encrypted_response_alg' => 'RSA1_5',
45
            'jwks' => json_decode(json_encode($publicJwks), true),
46
        ], $jwks);
47
48
        Assert::assertSame('RS256', $client->getMetadata()->get('id_token_signed_response_alg'));
49
        Assert::assertSame('RSA1_5', $client->getMetadata()->get('id_token_encrypted_response_alg'));
50
        Assert::assertSame('A128CBC-HS256', $client->getMetadata()->get('id_token_encrypted_response_enc'));
51
52
        // Get authorization redirect uri
53
        $authorizationService = new AuthorizationService();
0 ignored issues
show
Bug introduced by
The call to Facile\OpenIDClient\Serv...nService::__construct() has too few arguments starting with tokenSetFactory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $authorizationService = /** @scrutinizer ignore-call */ new AuthorizationService();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
54
        $authSession = AuthSession::fromArray([
55
            'nonce' => base64url_encode(\random_bytes(32)),
56
        ]);
57
        $uri = $authorizationService->getAuthorizationUri($client, [
58
            'response_type' => $testInfo->getResponseType(),
59
            'nonce' => $authSession->getNonce(),
60
        ]);
61
62
        // Simulate a redirect and create the server request
63
        $serverRequest = $this->simulateAuthRedirect($uri);
64
        $params = $authorizationService->getCallbackParams($serverRequest, $client);
65
66
        $tokenSet = $authorizationService->callback($client, $params, null, $authSession);
67
68
        Assert::assertNotNull($tokenSet->getIdToken());
69
        Assert::arrayHasKey('email', $tokenSet->claims());
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit\Framework\Assert::arrayHasKey() has too many arguments starting with $tokenSet->claims(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        Assert::/** @scrutinizer ignore-call */ 
70
                arrayHasKey('email', $tokenSet->claims());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
70
    }
71
}
72