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
|
|
|
* Request signed UserInfo. |
17
|
|
|
* |
18
|
|
|
* Successful signature verification of the UserInfo Response. |
19
|
|
|
*/ |
20
|
|
|
class RPUserInfoSigTest extends AbstractRpTest |
21
|
|
|
{ |
22
|
|
|
public function getTestId(): string |
23
|
|
|
{ |
24
|
|
|
return 'rp-userinfo-sig'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function execute(TestInfo $testInfo): void |
28
|
|
|
{ |
29
|
|
|
$client = $this->registerClient($testInfo, [ |
30
|
|
|
'userinfo_signed_response_alg' => 'RS256', |
31
|
|
|
]); |
32
|
|
|
|
33
|
|
|
Assert::assertSame('RS256', $client->getMetadata()->get('userinfo_signed_response_alg')); |
34
|
|
|
|
35
|
|
|
// Get authorization redirect uri |
36
|
|
|
$authorizationService = new AuthorizationService(); |
|
|
|
|
37
|
|
|
$userInfoService = new UserInfoService(); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$authSession = AuthSession::fromArray([ |
40
|
|
|
'nonce' => base64url_encode(\random_bytes(32)), |
41
|
|
|
]); |
42
|
|
|
$uri = $authorizationService->getAuthorizationUri($client, [ |
43
|
|
|
'response_type' => $testInfo->getResponseType(), |
44
|
|
|
'nonce' => $authSession->getNonce(), |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
// Simulate a redirect and create the server request |
48
|
|
|
$serverRequest = $this->simulateAuthRedirect($uri); |
49
|
|
|
|
50
|
|
|
$params = $authorizationService->getCallbackParams($serverRequest, $client); |
51
|
|
|
$tokenSet = $authorizationService->callback($client, $params, null, $authSession); |
52
|
|
|
|
53
|
|
|
$userInfo = $userInfoService->getUserInfo($client, $tokenSet); |
54
|
|
|
|
55
|
|
|
Assert::assertArrayHasKey('sub', $userInfo); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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.