Passed
Push — master ( f80f70...56399a )
by Thomas Mauro
03:05 queued 10s
created

RPUserInfoSigEncTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 48
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTestId() 0 3 1
A execute() 0 41 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\ConformanceTest\RpTest\UserInfoEndpoint;
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 Facile\OpenIDClient\Service\UserInfoService;
16
use function Facile\OpenIDClient\base64url_encode;
17
use function json_decode;
18
use function json_encode;
19
20
/**
21
 * Request signed UserInfo.
22
 *
23
 * A UserInfo Response.
24
 */
25
class RPUserInfoSigEncTest extends AbstractRpTest
26
{
27
    public function getTestId(): string
28
    {
29
        return 'rp-userinfo-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(static function (JWK $jwk) {
39
            return $jwk->toPublic();
40
        }, $jwks->all()));
41
42
        $client = $this->registerClient($testInfo, [
43
            'userinfo_signed_response_alg' => 'RS256',
44
            'userinfo_encrypted_response_alg' => 'RSA1_5',
45
            'jwks' => json_decode(json_encode($publicJwks), true),
46
        ], $jwks);
47
48
        Assert::assertSame('RS256', $client->getMetadata()->get('userinfo_signed_response_alg'));
49
        Assert::assertSame('RSA1_5', $client->getMetadata()->get('userinfo_encrypted_response_alg'));
50
        Assert::assertSame('A128CBC-HS256', $client->getMetadata()->get('userinfo_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
        $userInfoService = new UserInfoService();
0 ignored issues
show
Bug introduced by
The call to Facile\OpenIDClient\Serv...oService::__construct() has too few arguments starting with userInfoVerifierBuilder. ( Ignorable by Annotation )

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

54
        $userInfoService = /** @scrutinizer ignore-call */ new UserInfoService();

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...
55
56
        $authSession = AuthSession::fromArray([
57
            'nonce' => base64url_encode(\random_bytes(32)),
58
        ]);
59
        $uri = $authorizationService->getAuthorizationUri($client, [
60
            'response_type' => $testInfo->getResponseType(),
61
            'nonce' => $authSession->getNonce(),
62
        ]);
63
64
        // Simulate a redirect and create the server request
65
        $serverRequest = $this->simulateAuthRedirect($uri);
66
67
        $params = $authorizationService->getCallbackParams($serverRequest, $client);
68
        $tokenSet = $authorizationService->callback($client, $params, null, $authSession);
69
70
        $userInfo = $userInfoService->getUserInfo($client, $tokenSet);
71
72
        Assert::assertArrayHasKey('sub', $userInfo);
73
    }
74
}
75