13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Component \HttpFoundation \Request ;
16
- use Symfony \Component \HttpFoundation \Response ;
17
16
use Symfony \Component \Security \Http \Authentication \DefaultAuthenticationSuccessHandler ;
18
17
use Symfony \Component \Security \Http \HttpUtils ;
19
18
@@ -24,7 +23,9 @@ class DefaultAuthenticationSuccessHandlerTest extends TestCase
24
23
*/
25
24
public function testRequestRedirections (Request $ request , $ options , $ redirectedUrl )
26
25
{
27
- $ httpUtils = new HttpUtils ();
26
+ $ urlGenerator = $ this ->getMockBuilder ('Symfony\Component\Routing\Generator\UrlGeneratorInterface ' )->getMock ();
27
+ $ urlGenerator ->expects ($ this ->any ())->method ('generate ' )->will ($ this ->returnValue ('http://localhost/login ' ));
28
+ $ httpUtils = new HttpUtils ($ urlGenerator );
28
29
$ token = $ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' )->getMock ();
29
30
$ handler = new DefaultAuthenticationSuccessHandler ($ httpUtils , $ options );
30
31
if ($ request ->hasSession ()) {
@@ -73,25 +74,30 @@ public function getRequestRedirections()
73
74
'/admin/dashboard ' ,
74
75
),
75
76
'target path as referer ' => array (
76
- Request::create ('/ ' , 'GET ' , array (), array (), array (), array ('HTTP_REFERER ' => 'http://localhost/dashboard ' )),
77
+ Request::create ('/ ' , 'GET ' , array (), array (), array (), array ('HTTP_REFERER ' => 'http://localhost/dashboard ' )),
77
78
array ('use_referer ' => true ),
78
79
'/dashboard ' ,
79
80
),
80
81
'target path as referer is ignored if not configured ' => array (
81
- Request::create ('/ ' , 'GET ' , array (), array (), array (), array ('HTTP_REFERER ' => 'http://localhost/dashboard ' )),
82
+ Request::create ('/ ' , 'GET ' , array (), array (), array (), array ('HTTP_REFERER ' => 'http://localhost/dashboard ' )),
82
83
array (),
83
84
'/ ' ,
84
85
),
85
86
'target path should be different than login URL ' => array (
86
- Request::create ('/ ' , 'GET ' , array (), array (), array (), array ('HTTP_REFERER ' => 'http://localhost/login ' )),
87
+ Request::create ('/ ' , 'GET ' , array (), array (), array (), array ('HTTP_REFERER ' => 'http://localhost/login ' )),
87
88
array ('use_referer ' => true , 'login_path ' => '/login ' ),
88
89
'/ ' ,
89
90
),
90
91
'target path should be different than login URL (query string does not matter) ' => array (
91
- Request::create ('/ ' , 'GET ' , array (), array (), array (), array ('HTTP_REFERER ' => 'http://localhost/login?t=1&p=2 ' )),
92
+ Request::create ('/ ' , 'GET ' , array (), array (), array (), array ('HTTP_REFERER ' => 'http://localhost/login?t=1&p=2 ' )),
92
93
array ('use_referer ' => true , 'login_path ' => '/login ' ),
93
94
'/ ' ,
94
95
),
96
+ 'target path should be different than login URL (login_path as a route) ' => array (
97
+ Request::create ('/ ' , 'GET ' , array (), array (), array (), array ('HTTP_REFERER ' => 'http://localhost/login?t=1&p=2 ' )),
98
+ array ('use_referer ' => true , 'login_path ' => 'login_route ' ),
99
+ '/ ' ,
100
+ ),
95
101
);
96
102
}
97
103
}
0 commit comments