|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Facile\OpenIDClientTest\Authorization; |
|
6
|
|
|
|
|
7
|
|
|
use Facile\OpenIDClient\Authorization\AuthRequest; |
|
8
|
|
|
use function json_decode; |
|
9
|
|
|
use function json_encode; |
|
10
|
|
|
use Facile\OpenIDClientTest\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
class AuthRequestTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testFromParams(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$authRequest = AuthRequest::fromParams([ |
|
17
|
|
|
'scope' => 'fooscope', |
|
18
|
|
|
'client_id' => 'foo', |
|
19
|
|
|
'redirect_uri' => 'bar', |
|
20
|
|
|
]); |
|
21
|
|
|
|
|
22
|
|
|
static::assertSame('foo', $authRequest->getClientId()); |
|
23
|
|
|
static::assertSame('bar', $authRequest->getRedirectUri()); |
|
24
|
|
|
static::assertSame('fooscope', $authRequest->getScope()); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testJsonSerialize(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$authRequest = AuthRequest::fromParams([ |
|
30
|
|
|
'client_id' => 'foo', |
|
31
|
|
|
'redirect_uri' => 'bar', |
|
32
|
|
|
]); |
|
33
|
|
|
|
|
34
|
|
|
$array = json_decode(json_encode($authRequest), true); |
|
35
|
|
|
|
|
36
|
|
|
static::assertSame('foo', $array['client_id']); |
|
37
|
|
|
static::assertSame('bar', $array['redirect_uri']); |
|
38
|
|
|
static::assertSame('openid', $array['scope']); |
|
39
|
|
|
static::assertSame('code', $array['response_type']); |
|
40
|
|
|
static::assertSame('query', $array['response_mode']); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testCreateParams(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$authRequest = AuthRequest::fromParams([ |
|
46
|
|
|
'client_id' => 'foo', |
|
47
|
|
|
'redirect_uri' => 'bar', |
|
48
|
|
|
]); |
|
49
|
|
|
|
|
50
|
|
|
$array = $authRequest->createParams(); |
|
51
|
|
|
|
|
52
|
|
|
static::assertSame('foo', $array['client_id']); |
|
53
|
|
|
static::assertSame('bar', $array['redirect_uri']); |
|
54
|
|
|
static::assertSame('openid', $array['scope']); |
|
55
|
|
|
static::assertSame('code', $array['response_type']); |
|
56
|
|
|
static::assertSame('query', $array['response_mode']); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testGetClientId(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
62
|
|
|
|
|
63
|
|
|
static::assertSame('foo', $authRequest->getClientId()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testGetUiLocales(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
69
|
|
|
|
|
70
|
|
|
static::assertNull($authRequest->getUiLocales()); |
|
71
|
|
|
|
|
72
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['ui_locales' => 'it_IT']); |
|
73
|
|
|
static::assertSame('it_IT', $authRequest->getUiLocales()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testGetRequest(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
79
|
|
|
|
|
80
|
|
|
static::assertNull($authRequest->getRequest()); |
|
81
|
|
|
|
|
82
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['request' => 'foo']); |
|
83
|
|
|
static::assertSame('foo', $authRequest->getRequest()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testWithParams(): void |
|
87
|
|
|
{ |
|
88
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
89
|
|
|
|
|
90
|
|
|
$authRequest2 = $authRequest->withParams(['request' => 'foo']); |
|
91
|
|
|
|
|
92
|
|
|
static::assertNotSame($authRequest2, $authRequest); |
|
93
|
|
|
static::assertNull($authRequest->getRequest()); |
|
94
|
|
|
static::assertSame('foo', $authRequest2->getRequest()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testGetCodeChallengeMethod(): void |
|
98
|
|
|
{ |
|
99
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
100
|
|
|
|
|
101
|
|
|
static::assertNull($authRequest->getCodeChallengeMethod()); |
|
102
|
|
|
|
|
103
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['code_challenge_method' => 'foo']); |
|
104
|
|
|
static::assertSame('foo', $authRequest->getCodeChallengeMethod()); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function testGetState(): void |
|
108
|
|
|
{ |
|
109
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
110
|
|
|
|
|
111
|
|
|
static::assertNull($authRequest->getState()); |
|
112
|
|
|
|
|
113
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['state' => 'foo']); |
|
114
|
|
|
static::assertSame('foo', $authRequest->getState()); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function testGetLoginHint(): void |
|
118
|
|
|
{ |
|
119
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
120
|
|
|
|
|
121
|
|
|
static::assertNull($authRequest->getLoginHint()); |
|
122
|
|
|
|
|
123
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['login_hint' => 'foo']); |
|
124
|
|
|
static::assertSame('foo', $authRequest->getLoginHint()); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function testGetDisplay(): void |
|
128
|
|
|
{ |
|
129
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
130
|
|
|
|
|
131
|
|
|
static::assertNull($authRequest->getDisplay()); |
|
132
|
|
|
|
|
133
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['display' => 'foo']); |
|
134
|
|
|
static::assertSame('foo', $authRequest->getDisplay()); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function testGetMaxAge(): void |
|
138
|
|
|
{ |
|
139
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
140
|
|
|
|
|
141
|
|
|
static::assertNull($authRequest->getMaxAge()); |
|
142
|
|
|
|
|
143
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['max_age' => 3]); |
|
144
|
|
|
static::assertSame(3, $authRequest->getMaxAge()); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function testGetRedirectUri(): void |
|
148
|
|
|
{ |
|
149
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
150
|
|
|
|
|
151
|
|
|
static::assertSame('bar', $authRequest->getRedirectUri()); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function testGetNonce(): void |
|
155
|
|
|
{ |
|
156
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
157
|
|
|
|
|
158
|
|
|
static::assertNull($authRequest->getNonce()); |
|
159
|
|
|
|
|
160
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['nonce' => 'foo']); |
|
161
|
|
|
static::assertSame('foo', $authRequest->getNonce()); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function testGetCodeChallenge(): void |
|
165
|
|
|
{ |
|
166
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
167
|
|
|
|
|
168
|
|
|
static::assertNull($authRequest->getCodeChallenge()); |
|
169
|
|
|
|
|
170
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['code_challenge' => 'foo']); |
|
171
|
|
|
static::assertSame('foo', $authRequest->getCodeChallenge()); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function testGetAcrValues(): void |
|
175
|
|
|
{ |
|
176
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
177
|
|
|
|
|
178
|
|
|
static::assertNull($authRequest->getAcrValues()); |
|
179
|
|
|
|
|
180
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['acr_values' => 'foo']); |
|
181
|
|
|
static::assertSame('foo', $authRequest->getAcrValues()); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
public function testGetScope(): void |
|
185
|
|
|
{ |
|
186
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
187
|
|
|
|
|
188
|
|
|
static::assertSame('openid', $authRequest->getScope()); |
|
189
|
|
|
|
|
190
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['scope' => 'foo']); |
|
191
|
|
|
static::assertSame('foo', $authRequest->getScope()); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function testGetResponseMode(): void |
|
195
|
|
|
{ |
|
196
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
197
|
|
|
|
|
198
|
|
|
static::assertSame('query', $authRequest->getResponseMode()); |
|
199
|
|
|
|
|
200
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['response_mode' => 'foo']); |
|
201
|
|
|
static::assertSame('foo', $authRequest->getResponseMode()); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
public function testGetPrompt(): void |
|
205
|
|
|
{ |
|
206
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
207
|
|
|
|
|
208
|
|
|
static::assertNull($authRequest->getPrompt()); |
|
209
|
|
|
|
|
210
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['prompt' => 'foo']); |
|
211
|
|
|
static::assertSame('foo', $authRequest->getPrompt()); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
public function testGetIdTokenHint(): void |
|
215
|
|
|
{ |
|
216
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
217
|
|
|
|
|
218
|
|
|
static::assertNull($authRequest->getIdTokenHint()); |
|
219
|
|
|
|
|
220
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['id_token_hint' => 'foo']); |
|
221
|
|
|
static::assertSame('foo', $authRequest->getIdTokenHint()); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
public function testGetResponseType(): void |
|
225
|
|
|
{ |
|
226
|
|
|
$authRequest = new AuthRequest('foo', 'bar'); |
|
227
|
|
|
|
|
228
|
|
|
static::assertSame('code', $authRequest->getResponseType()); |
|
229
|
|
|
|
|
230
|
|
|
$authRequest = new AuthRequest('foo', 'bar', ['response_type' => 'foo']); |
|
231
|
|
|
static::assertSame('foo', $authRequest->getResponseType()); |
|
232
|
|
|
} |
|
233
|
|
|
} |
|
234
|
|
|
|