1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Facile\OpenIDClient\ConformanceTest\RpTest\UserInfoEndpoint; |
6
|
|
|
|
7
|
|
|
use Jose\Component\Core\JWK; |
8
|
|
|
use Jose\Component\Core\JWKSet; |
9
|
|
|
use Jose\Component\KeyManagement\JWKFactory; |
10
|
|
|
use PHPUnit\Framework\Assert; |
11
|
|
|
use Facile\OpenIDClient\ConformanceTest\RpTest\AbstractRpTest; |
12
|
|
|
use Facile\OpenIDClient\ConformanceTest\TestInfo; |
13
|
|
|
use Facile\OpenIDClient\Session\AuthSession; |
14
|
|
|
use Facile\OpenIDClient\Service\AuthorizationService; |
15
|
|
|
use Facile\OpenIDClient\Service\UserInfoService; |
16
|
|
|
use function Facile\OpenIDClient\base64url_encode; |
17
|
|
|
use function json_decode; |
18
|
|
|
use function json_encode; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Request signed UserInfo. |
22
|
|
|
* |
23
|
|
|
* A UserInfo Response. |
24
|
|
|
*/ |
25
|
|
|
class RPUserInfoSigEncTest extends AbstractRpTest |
26
|
|
|
{ |
27
|
|
|
public function getTestId(): string |
28
|
|
|
{ |
29
|
|
|
return 'rp-userinfo-sig+enc'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function execute(TestInfo $testInfo): void |
33
|
|
|
{ |
34
|
|
|
$jwkSig = JWKFactory::createRSAKey(2048, ['alg' => 'RS256', 'use' => 'sig']); |
35
|
|
|
$jwkEncAlg = JWKFactory::createRSAKey(2048, ['alg' => 'RSA1_5', 'use' => 'enc']); |
36
|
|
|
|
37
|
|
|
$jwks = new JWKSet([$jwkSig, $jwkEncAlg]); |
38
|
|
|
$publicJwks = new JWKSet(\array_map(static function (JWK $jwk) { |
39
|
|
|
return $jwk->toPublic(); |
40
|
|
|
}, $jwks->all())); |
41
|
|
|
|
42
|
|
|
$client = $this->registerClient($testInfo, [ |
43
|
|
|
'userinfo_signed_response_alg' => 'RS256', |
44
|
|
|
'userinfo_encrypted_response_alg' => 'RSA1_5', |
45
|
|
|
'jwks' => json_decode(json_encode($publicJwks), true), |
46
|
|
|
], $jwks); |
47
|
|
|
|
48
|
|
|
Assert::assertSame('RS256', $client->getMetadata()->get('userinfo_signed_response_alg')); |
49
|
|
|
Assert::assertSame('RSA1_5', $client->getMetadata()->get('userinfo_encrypted_response_alg')); |
50
|
|
|
Assert::assertSame('A128CBC-HS256', $client->getMetadata()->get('userinfo_encrypted_response_enc')); |
51
|
|
|
|
52
|
|
|
// Get authorization redirect uri |
53
|
|
|
$authorizationService = new AuthorizationService(); |
|
|
|
|
54
|
|
|
$userInfoService = new UserInfoService(); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$authSession = AuthSession::fromArray([ |
57
|
|
|
'nonce' => base64url_encode(\random_bytes(32)), |
58
|
|
|
]); |
59
|
|
|
$uri = $authorizationService->getAuthorizationUri($client, [ |
60
|
|
|
'response_type' => $testInfo->getResponseType(), |
61
|
|
|
'nonce' => $authSession->getNonce(), |
62
|
|
|
]); |
63
|
|
|
|
64
|
|
|
// Simulate a redirect and create the server request |
65
|
|
|
$serverRequest = $this->simulateAuthRedirect($uri); |
66
|
|
|
|
67
|
|
|
$params = $authorizationService->getCallbackParams($serverRequest, $client); |
68
|
|
|
$tokenSet = $authorizationService->callback($client, $params, null, $authSession); |
69
|
|
|
|
70
|
|
|
$userInfo = $userInfoService->getUserInfo($client, $tokenSet); |
71
|
|
|
|
72
|
|
|
Assert::assertArrayHasKey('sub', $userInfo); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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.