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

RpIdTokenBadSigHS256Test   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 23 2
A getTestId() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\ConformanceTest\RpTest\IdToken;
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\Service\AuthorizationService;
12
use function Facile\OpenIDClient\base64url_encode;
13
14
/**
15
 * Request an ID token and verify its signature using the 'client_secret' as MAC key.
16
 *
17
 * Identify the invalid signature and reject the ID Token after doing ID Token validation.
18
 */
19
class RpIdTokenBadSigHS256Test extends AbstractRpTest
20
{
21
22
    public function getTestId(): string
23
    {
24
        return 'rp-id_token-bad-sig-hs256';
25
    }
26
27
    public function execute(TestInfo $testInfo): void
28
    {
29
        $client = $this->registerClient($testInfo, ['id_token_signed_response_alg' => 'HS256']);
30
31
        Assert::assertSame('HS256', $client->getMetadata()->get('id_token_signed_response_alg'));
32
33
        // Get authorization redirect uri
34
        $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

34
        $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...
35
        $uri = $authorizationService->getAuthorizationUri($client, [
36
            'response_type' => $testInfo->getResponseType(),
37
            'nonce' => base64url_encode(\random_bytes(32)),
38
        ]);
39
40
        // Simulate a redirect and create the server request
41
        $serverRequest = $this->simulateAuthRedirect($uri);
42
        $params = $authorizationService->getCallbackParams($serverRequest, $client);
43
44
        try {
45
            $authorizationService->callback($client, $params);
46
            throw new AssertionFailedError('No assertions');
47
        } catch (\Throwable $e) {
48
            Assert::assertSame('Invalid token provided', $e->getMessage());
49
            Assert::assertRegExp('/Invalid signature/', $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

49
            /** @scrutinizer ignore-deprecated */ Assert::assertRegExp('/Invalid signature/', $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...
50
        }
51
    }
52
}
53