RpScopeUserinfoClaimsTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTestId() 0 3 1
A execute() 0 32 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\ConformanceTest\RpTest\ScopeRequestParameter;
6
7
use PHPUnit\Framework\Assert;
8
use function Facile\OpenIDClient\base64url_decode;
9
use Facile\OpenIDClient\ConformanceTest\RpTest\AbstractRpTest;
10
use Facile\OpenIDClient\ConformanceTest\TestInfo;
11
use Facile\OpenIDClient\Session\AuthSession;
12
use Facile\OpenIDClient\Service\AuthorizationService;
13
use Facile\OpenIDClient\Service\UserInfoService;
14
use function Facile\OpenIDClient\base64url_encode;
15
use function var_dump;
16
17
class RpScopeUserinfoClaimsTest extends AbstractRpTest
18
{
19
20
    public function getTestId(): string
21
    {
22
        return 'rp-scope-userinfo-claims';
23
    }
24
25
    public function execute(TestInfo $testInfo): void
26
    {
27
        $client = $this->registerClient($testInfo);
28
29
        $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

29
        $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...
30
        $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

30
        $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...
31
32
        $authSession = AuthSession::fromArray([
33
            'nonce' => base64url_encode(\random_bytes(32)),
34
        ]);
35
        $uri = $authorizationService->getAuthorizationUri($client, [
36
            'scope' => 'openid email',
37
            'response_type' => $testInfo->getResponseType(),
38
            'nonce' => $authSession->getNonce(),
39
        ]);
40
41
        // Simulate a redirect and create the server request
42
        $serverRequest = $this->simulateAuthRedirect($uri);
43
44
        $params = $authorizationService->getCallbackParams($serverRequest, $client);
45
46
        $tokenSet = $authorizationService->callback($client, $params, null, $authSession);
47
48
        $accessToken = $tokenSet->getAccessToken();
49
50
        if ($accessToken) {
51
            $userInfo = $userInfoService->getUserInfo($client, $tokenSet);
52
        } else {
53
            $userInfo = \json_decode(base64url_decode(\explode('.', $tokenSet->getIdToken())[1]), true);
0 ignored issues
show
Bug introduced by
It seems like $tokenSet->getIdToken() can also be of type null; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

53
            $userInfo = \json_decode(base64url_decode(\explode('.', /** @scrutinizer ignore-type */ $tokenSet->getIdToken())[1]), true);
Loading history...
54
        }
55
56
        Assert::assertArrayHasKey('email', $userInfo);
57
    }
58
}
59