Passed
Pull Request — master (#11)
by Pol
07:45
created

RpTokenEndpointPrivateKeyJwtTest::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
nc 1
nop 1
dl 0
loc 26
rs 9.7666
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\ConformanceTest\RpTest\ClientAuthentication;
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\Service\AuthorizationService;
14
use function Facile\OpenIDClient\base64url_encode;
15
use function json_decode;
16
use function json_encode;
17
18
/**
19
 * Use the 'private_key_jwt' method to authenticate at the Authorization Server when using the token endpoint.
20
 *
21
 * A Token Response, containing an ID token.
22
 */
23
class RpTokenEndpointPrivateKeyJwtTest extends AbstractRpTest
24
{
25
26
    public function getTestId(): string
27
    {
28
        return 'rp-token_endpoint-private_key_jwt';
29
    }
30
31
    public function execute(TestInfo $testInfo): void
32
    {
33
        $jwk = JWKFactory::createRSAKey(2048, ['use' => 'sig', 'alg' => 'RS256']);
34
        $jwks = new JWKSet([$jwk]);
35
        $publicJwks = new JWKSet([$jwk->toPublic()]);
36
37
        $client = $this->registerClient($testInfo, [
38
            'token_endpoint_auth_method' => 'private_key_jwt',
39
            'jwks' => json_decode(json_encode($publicJwks), true),
40
        ], $jwks);
41
42
        $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

42
        $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...
43
44
        $uri = $authorizationService->getAuthorizationUri($client, [
45
            'response_type' => $testInfo->getResponseType(),
46
            'nonce' => base64url_encode(\random_bytes(32)),
47
        ]);
48
49
        // Simulate a redirect and create the server request
50
        $serverRequest = $this->simulateAuthRedirect($uri);
51
52
        $params = $authorizationService->getCallbackParams($serverRequest, $client);
53
54
        $tokenSet = $authorizationService->callback($client, $params);
55
56
        Assert::assertNotNull($tokenSet->getIdToken());
57
    }
58
}
59