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

RpUserInfoBearerBodyTest::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
nc 1
nop 1
dl 0
loc 24
rs 9.8333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\ConformanceTest\RpTest\UserInfoEndpoint;
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 Facile\OpenIDClient\Service\UserInfoService;
13
use function Facile\OpenIDClient\base64url_encode;
14
15
/**
16
 * Pass the access token as a form-encoded body parameter while doing the UserInfo Request.
17
 *
18
 * A UserInfo Response.
19
 */
20
class RpUserInfoBearerBodyTest extends AbstractRpTest
21
{
22
23
    public function getTestId(): string
24
    {
25
        return 'rp-userinfo-bearer-body';
26
    }
27
28
    public function execute(TestInfo $testInfo): void
29
    {
30
        $client = $this->registerClient($testInfo);
31
32
        $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

32
        $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...
33
        $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

33
        $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...
34
35
        $authSession = AuthSession::fromArray([
36
            'nonce' => base64url_encode(\random_bytes(32)),
37
        ]);
38
        $uri = $authorizationService->getAuthorizationUri($client, [
39
            'response_type' => $testInfo->getResponseType(),
40
            'nonce' => $authSession->getNonce(),
41
        ]);
42
43
        // Simulate a redirect and create the server request
44
        $serverRequest = $this->simulateAuthRedirect($uri);
45
46
        $params = $authorizationService->getCallbackParams($serverRequest, $client);
47
        $tokenSet = $authorizationService->callback($client, $params, null, $authSession);
48
49
        $userInfo = $userInfoService->getUserInfo($client, $tokenSet, true);
50
51
        Assert::assertArrayHasKey('sub', $userInfo);
52
    }
53
}
54