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

RPKeyRotationOPSignKeyTest::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 19
nc 1
nop 1
dl 0
loc 37
rs 9.6333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\ConformanceTest\RpTest\KeyRotation;
6
7
use PHPUnit\Framework\Assert;
8
use Facile\OpenIDClient\ConformanceTest\RpTest\AbstractRpTest;
9
use Facile\OpenIDClient\ConformanceTest\TestInfo;
10
use Facile\OpenIDClient\Session\AuthSession;
11
use Facile\OpenIDClient\Service\AuthorizationService;
12
use function Facile\OpenIDClient\base64url_encode;
13
14
/**
15
 * Request an ID Token and verify its signature.
16
 * Will have to retrieve new keys from the OP to be able to verify the ID Token.
17
 *
18
 * Successfully verify the ID Token signature, fetching the rotated signing keys if the 'kid' claim in the
19
 * JOSE header is unknown.
20
 */
21
class RPKeyRotationOPSignKeyTest extends AbstractRpTest
22
{
23
24
    public function getTestId(): string
25
    {
26
        return 'rp-key-rotation-op-sign-key';
27
    }
28
29
    public function execute(TestInfo $testInfo): void
30
    {
31
        $client = $this->registerClient($testInfo);
32
33
        // Get authorization redirect uri
34
        $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

34
        $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...
35
36
        $authSession = AuthSession::fromArray([
37
            'state' => base64url_encode(\random_bytes(32)),
38
            'nonce' => base64url_encode(\random_bytes(32)),
39
        ]);
40
        $uri = $authorizationService->getAuthorizationUri($client, [
41
            'state' => $authSession->getState(),
42
            'nonce' => $authSession->getNonce(),
43
        ]);
44
45
        // Simulate a redirect and create the server request
46
        $serverRequest = $this->simulateAuthRedirect($uri);
47
48
        $params = $authorizationService->getCallbackParams($serverRequest, $client);
49
        $tokenSet = $authorizationService->callback($client, $params, null, $authSession);
50
51
        Assert::assertNotNull($tokenSet->getIdToken());
52
53
        // 2nd id_token
54
        $uri = $authorizationService->getAuthorizationUri($client, [
55
            'state' => $authSession->getState(),
56
            'nonce' => $authSession->getNonce(),
57
        ]);
58
59
        // Simulate a redirect and create the server request
60
        $serverRequest = $this->simulateAuthRedirect($uri);
61
62
        $params = $authorizationService->getCallbackParams($serverRequest, $client);
63
        $tokenSet = $authorizationService->callback($client, $params, null, $authSession);
64
65
        Assert::assertNotNull($tokenSet->getIdToken());
66
    }
67
}
68