16
16
use Symfony \Component \HttpKernel \Event \GetResponseEvent ;
17
17
use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
18
18
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
19
- use Symfony \Component \Security \Core \Authorization \AuthorizationCheckerInterface ;
20
- use Symfony \Component \Security \Core \Authorization \Voter \AuthenticatedVoter ;
21
19
use Symfony \Component \Security \Core \User \UserInterface ;
22
20
23
21
class RequestListenerTest extends TestCase
@@ -59,7 +57,6 @@ protected function setUp()
59
57
public function testOnKernelRequestUserDataIsSetToScope ($ user ): void
60
58
{
61
59
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
62
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
63
60
$ event = $ this ->prophesize (GetResponseEvent::class);
64
61
$ request = $ this ->prophesize (Request::class);
65
62
$ token = $ this ->prophesize (TokenInterface::class);
@@ -72,8 +69,6 @@ public function testOnKernelRequestUserDataIsSetToScope($user): void
72
69
73
70
$ token ->isAuthenticated ()
74
71
->willReturn (true );
75
- $ authorizationChecker ->isGranted (AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED )
76
- ->willReturn (true );
77
72
78
73
$ token ->getUser ()
79
74
->willReturn ($ user );
@@ -113,7 +108,6 @@ public function userDataProvider(): \Generator
113
108
public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled (): void
114
109
{
115
110
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
116
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
117
111
$ event = $ this ->prophesize (GetResponseEvent::class);
118
112
119
113
$ event ->isMasterRequest ()
@@ -126,8 +120,7 @@ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
126
120
127
121
$ listener = new RequestListener (
128
122
$ this ->currentHub ->reveal (),
129
- $ tokenStorage ->reveal (),
130
- $ authorizationChecker ->reveal ()
123
+ $ tokenStorage ->reveal ()
131
124
);
132
125
133
126
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -138,7 +131,6 @@ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
138
131
public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent (): void
139
132
{
140
133
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
141
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
142
134
$ event = $ this ->prophesize (GetResponseEvent::class);
143
135
144
136
$ event ->isMasterRequest ()
@@ -151,8 +143,7 @@ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
151
143
152
144
$ listener = new RequestListener (
153
145
$ this ->currentHub ->reveal (),
154
- $ tokenStorage ->reveal (),
155
- $ authorizationChecker ->reveal ()
146
+ $ tokenStorage ->reveal ()
156
147
);
157
148
158
149
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -162,55 +153,19 @@ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
162
153
163
154
public function testOnKernelRequestUsernameIsNotSetIfTokenStorageIsAbsent (): void
164
155
{
165
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
166
- $ event = $ this ->prophesize (GetResponseEvent::class);
167
- $ request = $ this ->prophesize (Request::class);
168
-
169
- $ event ->isMasterRequest ()
170
- ->willReturn (true );
171
-
172
- $ authorizationChecker ->isGranted (AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED )
173
- ->shouldNotBeCalled ();
174
-
175
- $ event ->getRequest ()
176
- ->willReturn ($ request ->reveal ());
177
- $ request ->getClientIp ()
178
- ->willReturn ('1.2.3.4 ' );
179
-
180
- $ listener = new RequestListener (
181
- $ this ->currentHub ->reveal (),
182
- null ,
183
- $ authorizationChecker ->reveal ()
184
- );
185
-
186
- $ listener ->onKernelRequest ($ event ->reveal ());
187
-
188
- $ expectedUserData = [
189
- 'ip_address ' => '1.2.3.4 ' ,
190
- ];
191
- $ this ->assertEquals ($ expectedUserData , $ this ->getUserContext ($ this ->currentScope ));
192
- }
193
-
194
- public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsent (): void
195
- {
196
- $ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
197
156
$ event = $ this ->prophesize (GetResponseEvent::class);
198
157
$ request = $ this ->prophesize (Request::class);
199
158
200
159
$ event ->isMasterRequest ()
201
160
->willReturn (true );
202
161
203
- $ tokenStorage ->getToken ()
204
- ->willReturn ($ this ->prophesize (TokenInterface::class)->reveal ());
205
-
206
162
$ event ->getRequest ()
207
163
->willReturn ($ request ->reveal ());
208
164
$ request ->getClientIp ()
209
165
->willReturn ('1.2.3.4 ' );
210
166
211
167
$ listener = new RequestListener (
212
168
$ this ->currentHub ->reveal (),
213
- $ tokenStorage ->reveal (),
214
169
null
215
170
);
216
171
@@ -225,7 +180,6 @@ public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsen
225
180
public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent (): void
226
181
{
227
182
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
228
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
229
183
$ event = $ this ->prophesize (GetResponseEvent::class);
230
184
$ request = $ this ->prophesize (Request::class);
231
185
@@ -235,18 +189,14 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
235
189
$ tokenStorage ->getToken ()
236
190
->willReturn (null );
237
191
238
- $ authorizationChecker ->isGranted (AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED )
239
- ->shouldNotBeCalled ();
240
-
241
192
$ event ->getRequest ()
242
193
->willReturn ($ request ->reveal ());
243
194
$ request ->getClientIp ()
244
195
->willReturn ('1.2.3.4 ' );
245
196
246
197
$ listener = new RequestListener (
247
198
$ this ->currentHub ->reveal (),
248
- $ tokenStorage ->reveal (),
249
- $ authorizationChecker ->reveal ()
199
+ $ tokenStorage ->reveal ()
250
200
);
251
201
252
202
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -263,7 +213,6 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
263
213
public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated (): void
264
214
{
265
215
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
266
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
267
216
$ token = $ this ->prophesize (TokenInterface::class);
268
217
$ event = $ this ->prophesize (GetResponseEvent::class);
269
218
$ request = $ this ->prophesize (Request::class);
@@ -277,18 +226,14 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated():
277
226
$ token ->isAuthenticated ()
278
227
->willReturn (false );
279
228
280
- $ authorizationChecker ->isGranted (AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED )
281
- ->shouldNotBeCalled ();
282
-
283
229
$ event ->getRequest ()
284
230
->willReturn ($ request ->reveal ());
285
231
$ request ->getClientIp ()
286
232
->willReturn ('1.2.3.4 ' );
287
233
288
234
$ listener = new RequestListener (
289
235
$ this ->currentHub ->reveal (),
290
- $ tokenStorage ->reveal (),
291
- $ authorizationChecker ->reveal ()
236
+ $ tokenStorage ->reveal ()
292
237
);
293
238
294
239
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -302,7 +247,6 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated():
302
247
public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered (): void
303
248
{
304
249
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
305
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
306
250
$ event = $ this ->prophesize (GetResponseEvent::class);
307
251
$ request = $ this ->prophesize (Request::class);
308
252
@@ -312,18 +256,14 @@ public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered(): void
312
256
$ tokenStorage ->getToken ()
313
257
->willReturn (null );
314
258
315
- $ authorizationChecker ->isGranted (AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED )
316
- ->willReturn (false );
317
-
318
259
$ event ->getRequest ()
319
260
->willReturn ($ request ->reveal ());
320
261
$ request ->getClientIp ()
321
262
->willReturn ('1.2.3.4 ' );
322
263
323
264
$ listener = new RequestListener (
324
265
$ this ->currentHub ->reveal (),
325
- $ tokenStorage ->reveal (),
326
- $ authorizationChecker ->reveal ()
266
+ $ tokenStorage ->reveal ()
327
267
);
328
268
329
269
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -347,8 +287,7 @@ public function testOnKernelControllerAddsRouteTag(): void
347
287
348
288
$ listener = new RequestListener (
349
289
$ this ->currentHub ->reveal (),
350
- $ this ->prophesize (TokenStorageInterface::class)->reveal (),
351
- $ this ->prophesize (AuthorizationCheckerInterface::class)->reveal ()
290
+ $ this ->prophesize (TokenStorageInterface::class)->reveal ()
352
291
);
353
292
354
293
$ listener ->onKernelController ($ event ->reveal ());
@@ -371,8 +310,7 @@ public function testOnKernelControllerRouteTagIsNotSetIfRequestDoesNotHaveARoute
371
310
372
311
$ listener = new RequestListener (
373
312
$ this ->currentHub ->reveal (),
374
- $ this ->prophesize (TokenStorageInterface::class)->reveal (),
375
- $ this ->prophesize (AuthorizationCheckerInterface::class)->reveal ()
313
+ $ this ->prophesize (TokenStorageInterface::class)->reveal ()
376
314
);
377
315
378
316
$ listener ->onKernelController ($ event ->reveal ());
@@ -384,7 +322,6 @@ public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest(): void
384
322
->shouldNotBeCalled ();
385
323
386
324
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
387
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
388
325
$ event = $ this ->prophesize (GetResponseEvent::class);
389
326
390
327
$ event ->isMasterRequest ()
@@ -393,13 +330,9 @@ public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest(): void
393
330
$ tokenStorage ->getToken ()
394
331
->shouldNotBeCalled ();
395
332
396
- $ authorizationChecker ->isGranted (AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED )
397
- ->shouldNotBeCalled ();
398
-
399
333
$ listener = new RequestListener (
400
334
$ this ->currentHub ->reveal (),
401
- $ tokenStorage ->reveal (),
402
- $ authorizationChecker ->reveal ()
335
+ $ tokenStorage ->reveal ()
403
336
);
404
337
405
338
$ listener ->onKernelRequest ($ event ->reveal ());
0 commit comments