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 );
@@ -85,8 +80,7 @@ public function testOnKernelRequestUserDataIsSetToScope($user): void
85
80
86
81
$ listener = new RequestListener (
87
82
$ this ->currentHub ->reveal (),
88
- $ tokenStorage ->reveal (),
89
- $ authorizationChecker ->reveal ()
83
+ $ tokenStorage ->reveal ()
90
84
);
91
85
92
86
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -113,7 +107,6 @@ public function userDataProvider(): \Generator
113
107
public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled (): void
114
108
{
115
109
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
116
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
117
110
$ event = $ this ->prophesize (GetResponseEvent::class);
118
111
119
112
$ event ->isMasterRequest ()
@@ -126,8 +119,7 @@ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
126
119
127
120
$ listener = new RequestListener (
128
121
$ this ->currentHub ->reveal (),
129
- $ tokenStorage ->reveal (),
130
- $ authorizationChecker ->reveal ()
122
+ $ tokenStorage ->reveal ()
131
123
);
132
124
133
125
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -138,7 +130,6 @@ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
138
130
public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent (): void
139
131
{
140
132
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
141
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
142
133
$ event = $ this ->prophesize (GetResponseEvent::class);
143
134
144
135
$ event ->isMasterRequest ()
@@ -151,8 +142,7 @@ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
151
142
152
143
$ listener = new RequestListener (
153
144
$ this ->currentHub ->reveal (),
154
- $ tokenStorage ->reveal (),
155
- $ authorizationChecker ->reveal ()
145
+ $ tokenStorage ->reveal ()
156
146
);
157
147
158
148
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -162,55 +152,19 @@ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
162
152
163
153
public function testOnKernelRequestUsernameIsNotSetIfTokenStorageIsAbsent (): void
164
154
{
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
155
$ event = $ this ->prophesize (GetResponseEvent::class);
198
156
$ request = $ this ->prophesize (Request::class);
199
157
200
158
$ event ->isMasterRequest ()
201
159
->willReturn (true );
202
160
203
- $ tokenStorage ->getToken ()
204
- ->willReturn ($ this ->prophesize (TokenInterface::class)->reveal ());
205
-
206
161
$ event ->getRequest ()
207
162
->willReturn ($ request ->reveal ());
208
163
$ request ->getClientIp ()
209
164
->willReturn ('1.2.3.4 ' );
210
165
211
166
$ listener = new RequestListener (
212
167
$ this ->currentHub ->reveal (),
213
- $ tokenStorage ->reveal (),
214
168
null
215
169
);
216
170
@@ -225,7 +179,6 @@ public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsen
225
179
public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent (): void
226
180
{
227
181
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
228
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
229
182
$ event = $ this ->prophesize (GetResponseEvent::class);
230
183
$ request = $ this ->prophesize (Request::class);
231
184
@@ -235,18 +188,14 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
235
188
$ tokenStorage ->getToken ()
236
189
->willReturn (null );
237
190
238
- $ authorizationChecker ->isGranted (AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED )
239
- ->shouldNotBeCalled ();
240
-
241
191
$ event ->getRequest ()
242
192
->willReturn ($ request ->reveal ());
243
193
$ request ->getClientIp ()
244
194
->willReturn ('1.2.3.4 ' );
245
195
246
196
$ listener = new RequestListener (
247
197
$ this ->currentHub ->reveal (),
248
- $ tokenStorage ->reveal (),
249
- $ authorizationChecker ->reveal ()
198
+ $ tokenStorage ->reveal ()
250
199
);
251
200
252
201
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -263,7 +212,6 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
263
212
public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated (): void
264
213
{
265
214
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
266
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
267
215
$ token = $ this ->prophesize (TokenInterface::class);
268
216
$ event = $ this ->prophesize (GetResponseEvent::class);
269
217
$ request = $ this ->prophesize (Request::class);
@@ -277,18 +225,14 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated():
277
225
$ token ->isAuthenticated ()
278
226
->willReturn (false );
279
227
280
- $ authorizationChecker ->isGranted (AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED )
281
- ->shouldNotBeCalled ();
282
-
283
228
$ event ->getRequest ()
284
229
->willReturn ($ request ->reveal ());
285
230
$ request ->getClientIp ()
286
231
->willReturn ('1.2.3.4 ' );
287
232
288
233
$ listener = new RequestListener (
289
234
$ this ->currentHub ->reveal (),
290
- $ tokenStorage ->reveal (),
291
- $ authorizationChecker ->reveal ()
235
+ $ tokenStorage ->reveal ()
292
236
);
293
237
294
238
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -302,7 +246,6 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated():
302
246
public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered (): void
303
247
{
304
248
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
305
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
306
249
$ event = $ this ->prophesize (GetResponseEvent::class);
307
250
$ request = $ this ->prophesize (Request::class);
308
251
@@ -312,18 +255,14 @@ public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered(): void
312
255
$ tokenStorage ->getToken ()
313
256
->willReturn (null );
314
257
315
- $ authorizationChecker ->isGranted (AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED )
316
- ->willReturn (false );
317
-
318
258
$ event ->getRequest ()
319
259
->willReturn ($ request ->reveal ());
320
260
$ request ->getClientIp ()
321
261
->willReturn ('1.2.3.4 ' );
322
262
323
263
$ listener = new RequestListener (
324
264
$ this ->currentHub ->reveal (),
325
- $ tokenStorage ->reveal (),
326
- $ authorizationChecker ->reveal ()
265
+ $ tokenStorage ->reveal ()
327
266
);
328
267
329
268
$ listener ->onKernelRequest ($ event ->reveal ());
@@ -347,8 +286,7 @@ public function testOnKernelControllerAddsRouteTag(): void
347
286
348
287
$ listener = new RequestListener (
349
288
$ this ->currentHub ->reveal (),
350
- $ this ->prophesize (TokenStorageInterface::class)->reveal (),
351
- $ this ->prophesize (AuthorizationCheckerInterface::class)->reveal ()
289
+ $ this ->prophesize (TokenStorageInterface::class)->reveal ()
352
290
);
353
291
354
292
$ listener ->onKernelController ($ event ->reveal ());
@@ -371,8 +309,7 @@ public function testOnKernelControllerRouteTagIsNotSetIfRequestDoesNotHaveARoute
371
309
372
310
$ listener = new RequestListener (
373
311
$ this ->currentHub ->reveal (),
374
- $ this ->prophesize (TokenStorageInterface::class)->reveal (),
375
- $ this ->prophesize (AuthorizationCheckerInterface::class)->reveal ()
312
+ $ this ->prophesize (TokenStorageInterface::class)->reveal ()
376
313
);
377
314
378
315
$ listener ->onKernelController ($ event ->reveal ());
@@ -384,7 +321,6 @@ public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest(): void
384
321
->shouldNotBeCalled ();
385
322
386
323
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
387
- $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
388
324
$ event = $ this ->prophesize (GetResponseEvent::class);
389
325
390
326
$ event ->isMasterRequest ()
@@ -393,13 +329,9 @@ public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest(): void
393
329
$ tokenStorage ->getToken ()
394
330
->shouldNotBeCalled ();
395
331
396
- $ authorizationChecker ->isGranted (AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED )
397
- ->shouldNotBeCalled ();
398
-
399
332
$ listener = new RequestListener (
400
333
$ this ->currentHub ->reveal (),
401
- $ tokenStorage ->reveal (),
402
- $ authorizationChecker ->reveal ()
334
+ $ tokenStorage ->reveal ()
403
335
);
404
336
405
337
$ listener ->onKernelRequest ($ event ->reveal ());
0 commit comments