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

RPUserInfoEncTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
dl 0
loc 45
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 38 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 encrypted UserInfo. Decrypt the UserInfo Response.
22
 *
23
 * A UserInfo Response.
24
 */
25
class RPUserInfoEncTest extends AbstractRpTest
26
{
27
    public function getTestId(): string
28
    {
29
        return 'rp-userinfo-enc';
30
    }
31
32
    public function execute(TestInfo $testInfo): void
33
    {
34
        $jwkEncAlg = JWKFactory::createRSAKey(2048, ['alg' => 'RSA1_5', 'use' => 'enc']);
35
36
        $jwks = new JWKSet([$jwkEncAlg]);
37
        $publicJwks = new JWKSet(\array_map(static function (JWK $jwk) {
38
            return $jwk->toPublic();
39
        }, $jwks->all()));
40
41
        $client = $this->registerClient($testInfo, [
42
            'userinfo_signed_response_alg' => 'none',
43
            'userinfo_encrypted_response_alg' => 'RSA1_5',
44
            'jwks' => json_decode(json_encode($publicJwks), true),
45
        ], $jwks);
46
47
        Assert::assertSame('none', $client->getMetadata()->get('userinfo_signed_response_alg'));
48
        Assert::assertSame('RSA1_5', $client->getMetadata()->get('userinfo_encrypted_response_alg'));
49
50
        // Get authorization redirect uri
51
        $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

51
        $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...
52
        $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

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