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

RpNonceInvalidTest::execute()   A

Complexity

Conditions 3
Paths 6

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 19
nc 6
nop 1
dl 0
loc 29
rs 9.6333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\ConformanceTest\RpTest\NonceRequestParameter;
6
7
use PHPUnit\Framework\Assert;
8
use PHPUnit\Framework\AssertionFailedError;
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
16
class RpNonceInvalidTest extends AbstractRpTest
17
{
18
19
    public function getTestId(): string
20
    {
21
        return 'rp-nonce-invalid';
22
    }
23
24
    public function execute(TestInfo $testInfo): void
25
    {
26
        $client = $this->registerClient($testInfo);
27
28
        $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

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

29
        $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...
30
        $nonce = base64url_encode(\random_bytes(32));
31
        $authSession = AuthSession::fromArray(['nonce' => $nonce]);
32
33
        $uri = $authorizationService->getAuthorizationUri($client, [
34
            'response_type' => $testInfo->getResponseType(),
35
            'nonce' => $nonce,
36
        ]);
37
        // Simulate a redirect and create the server request
38
        $serverRequest = $this->simulateAuthRedirect($uri);
39
40
        try {
41
            $params = $authorizationService->getCallbackParams($serverRequest, $client);
42
            $tokenSet = $authorizationService->callback($client, $params, null, $authSession);
43
            $accessToken = $tokenSet->getAccessToken();
44
45
            if ($accessToken) {
46
                $userInfoService->getUserInfo($client, $tokenSet);
47
            }
48
49
            throw new AssertionFailedError('No assertion');
50
        } catch (\Throwable $e) {
51
            Assert::assertSame('Invalid token provided', $e->getMessage());
52
            Assert::assertRegExp('/Nonce mismatch.* got: 012345678/', $e->getPrevious()->getMessage());
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertRegExp() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/4086 ( Ignorable by Annotation )

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

52
            /** @scrutinizer ignore-deprecated */ Assert::assertRegExp('/Nonce mismatch.* got: 012345678/', $e->getPrevious()->getMessage());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
53
        }
54
    }
55
}
56