-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerTest.php
More file actions
125 lines (102 loc) · 4.35 KB
/
ServerTest.php
File metadata and controls
125 lines (102 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace Pdsinterop\Solid\Auth\Config;
use ArgumentCountError;
use Pdsinterop\Solid\Auth\Enum\OpenId\OpenIdConnectMetadata as OidcMeta;
use Pdsinterop\Solid\Auth\Exception\LogicException;
use PHPUnit\Framework\TestCase;
/**
* @coversNothing
*/
class ServerTest extends TestCase
{
final public function testServerConfigShouldComplainWhenInstantiatedWithoutData() : void
{
$this->expectException(ArgumentCountError::class);
$this->expectExceptionMessage('Too few arguments to function');
/** @noinspection PhpParamsInspection */
new Server();
}
final public function testServerConfigShouldInstantiatedWhenGivenData() : void
{
$actual = new Server([]);
$expected = Server::class;
self::assertInstanceOf($expected, $actual);
}
final public function testServerConfigShouldProvideRequiredPropertiesWhenAskedForRequiredProperties() : void
{
$server = new Server([]);
$actual = $server->getRequired();
$expected = [
OidcMeta::AUTHORIZATION_ENDPOINT,
OidcMeta::ID_TOKEN_SIGNING_ALG_VALUES_SUPPORTED,
OidcMeta::ISSUER,
OidcMeta::JWKS_URI,
OidcMeta::RESPONSE_TYPES_SUPPORTED,
OidcMeta::SUBJECT_TYPES_SUPPORTED,
];
self::assertEquals($expected, $actual);
}
final public function testServerConfigShouldNotBeValidWhenMissingRequiredProperties() : void
{
$server = new Server([]);
$actual = $server->validate();
self::assertFalse($actual);
}
final public function testServerConfigShouldBeValidWhenGivenAllRequiredProperties() : void
{
$required = (new Server([]))->getRequired();
$data = array_combine($required, $required);
$server = new Server($data);
$server->getRequired();
$actual = $server->validate();
self::assertTrue($actual);
}
final public function testServerConfigShouldComplainWhenSerializedWithRequiredKeysMissing() : void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Required properties have not been set: authorization_endpoint, issuer, jwks_uri');
$server = new Server([]);
$server->jsonSerialize();
}
final public function testServerConfigShouldReturnArrayWhenSerializedWithRequiredKeysPresent() : array
{
$data = [
OidcMeta::AUTHORIZATION_ENDPOINT => 'https://server/authorize',
OidcMeta::ISSUER => 'https://server/identifier',
OidcMeta::JWKS_URI => 'https://server/jwk'
];
$server = new Server($data);
$actual = $server->jsonSerialize();
self::assertIsArray($actual);
return $actual;
}
/**
* @depends testServerConfigShouldReturnArrayWhenSerializedWithRequiredKeysPresent
*/
final public function testServerConfigShouldReturnExpectedValuesWhenSerializedWithRequiredKeysPresent(array $actual)
{
self::assertEquals([
'authorization_endpoint' => 'https://server/authorize',
'id_token_signing_alg_values_supported' => ['RS256'],
'issuer' => 'https://server/identifier',
'jwks_uri' => 'https://server/jwk',
'response_types_supported' => ['code', 'code token', 'code id_token', 'id_token code', 'id_token', 'id_token token', 'code id_token token', 'none'],
'subject_types_supported' => ['public'],
'token_types_supported' => ['legacyPop','dpop'],
'response_modes_supported' => ['query', 'fragment'],
'grant_types_supported' => ['authorization_code', 'implicit', 'refresh_token', 'client_credentials'],
'token_endpoint_auth_methods_supported' => ['client_secret_basic'],
'token_endpoint_auth_signing_alg_values_supported' => ['RS256'],
'display_values_supported' => [],
'claim_types_supported' => ['normal'],
'claims_supported' => ['webid'],
'claims_parameter_supported' => false,
'request_parameter_supported' => true,
'request_uri_parameter_supported' => false,
'require_request_uri_registration' => false,
'code_challenge_methods_supported' => ['S256'],
'dpop_signing_alg_values_supported' => ['RS256'],
'scopes_supported' => ['webid']
], $actual);
}
}