Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4b4f831

Browse filesBrowse files
committed
Merge branch '2.8' into 3.2
* 2.8: [Security] added more tests [Security] fixed default target path when referer contains a query string [Security] simplified tests [Security] refactored tests [VarDumper] Move locale sniffing to dump() time
2 parents 1375601 + ce12665 commit 4b4f831
Copy full SHA for 4b4f831

File tree

Expand file treeCollapse file tree

3 files changed

+91
-163
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+91
-163
lines changed

‎src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,14 @@ protected function determineTargetUrl(Request $request)
122122
return $targetUrl;
123123
}
124124

125-
if ($this->options['use_referer'] && ($targetUrl = $request->headers->get('Referer')) && $targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
126-
return $targetUrl;
125+
if ($this->options['use_referer']) {
126+
$targetUrl = $request->headers->get('Referer');
127+
if (false !== $pos = strpos($targetUrl, '?')) {
128+
$targetUrl = substr($targetUrl, 0, $pos);
129+
}
130+
if ($targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
131+
return $targetUrl;
132+
}
127133
}
128134

129135
return $this->options['default_target_path'];

‎src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php
+78-159Lines changed: 78 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -12,173 +12,92 @@
1212
namespace Symfony\Component\Security\Http\Tests\Authentication;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\HttpFoundation\Response;
15+
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
17+
use Symfony\Component\Security\Http\HttpUtils;
1718

1819
class DefaultAuthenticationSuccessHandlerTest extends TestCase
1920
{
20-
private $httpUtils = null;
21-
22-
private $request = null;
23-
24-
private $token = null;
25-
26-
protected function setUp()
21+
/**
22+
* @dataProvider getRequestRedirections
23+
*/
24+
public function testRequestRedirections(Request $request, $options, $redirectedUrl)
2725
{
28-
$this->httpUtils = $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')->getMock();
29-
$this->request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
30-
$this->request->headers = $this->getMockBuilder('Symfony\Component\HttpFoundation\HeaderBag')->getMock();
31-
$this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
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);
29+
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
30+
$handler = new DefaultAuthenticationSuccessHandler($httpUtils, $options);
31+
if ($request->hasSession()) {
32+
$handler->setProviderKey('admin');
33+
}
34+
$this->assertSame('http://localhost'.$redirectedUrl, $handler->onAuthenticationSuccess($request, $token)->getTargetUrl());
3235
}
3336

34-
public function testRequestIsRedirected()
35-
{
36-
$response = $this->expectRedirectResponse('/');
37-
38-
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
39-
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
40-
41-
$this->assertSame($response, $result);
42-
}
43-
44-
public function testDefaultTargetPathCanBeForced()
45-
{
46-
$options = array(
47-
'always_use_default_target_path' => true,
48-
'default_target_path' => '/dashboard',
49-
);
50-
51-
$response = $this->expectRedirectResponse('/dashboard');
52-
53-
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
54-
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
55-
56-
$this->assertSame($response, $result);
57-
}
58-
59-
public function testTargetPathIsPassedWithRequest()
60-
{
61-
$this->request->expects($this->once())
62-
->method('get')->with('_target_path')
63-
->will($this->returnValue('/dashboard'));
64-
65-
$response = $this->expectRedirectResponse('/dashboard');
66-
67-
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
68-
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
69-
70-
$this->assertSame($response, $result);
71-
}
72-
73-
public function testTargetPathIsPassedAsNestedParameterWithRequest()
74-
{
75-
$this->request->expects($this->once())
76-
->method('get')->with('_target_path')
77-
->will($this->returnValue(array('value' => '/dashboard')));
78-
79-
$response = $this->expectRedirectResponse('/dashboard');
80-
81-
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array('target_path_parameter' => '_target_path[value]'));
82-
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
83-
84-
$this->assertSame($response, $result);
85-
}
86-
87-
public function testTargetPathParameterIsCustomised()
88-
{
89-
$options = array('target_path_parameter' => '_my_target_path');
90-
91-
$this->request->expects($this->once())
92-
->method('get')->with('_my_target_path')
93-
->will($this->returnValue('/dashboard'));
94-
95-
$response = $this->expectRedirectResponse('/dashboard');
96-
97-
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
98-
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
99-
100-
$this->assertSame($response, $result);
101-
}
102-
103-
public function testTargetPathIsTakenFromTheSession()
37+
public function getRequestRedirections()
10438
{
10539
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock();
106-
$session->expects($this->once())
107-
->method('get')->with('_security.admin.target_path')
108-
->will($this->returnValue('/admin/dashboard'));
109-
$session->expects($this->once())
110-
->method('remove')->with('_security.admin.target_path');
111-
112-
$this->request->expects($this->any())
113-
->method('getSession')
114-
->will($this->returnValue($session));
115-
116-
$response = $this->expectRedirectResponse('/admin/dashboard');
117-
118-
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
119-
$handler->setProviderKey('admin');
120-
121-
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
122-
123-
$this->assertSame($response, $result);
124-
}
125-
126-
public function testTargetPathIsPassedAsReferer()
127-
{
128-
$options = array('use_referer' => true);
129-
130-
$this->request->headers->expects($this->once())
131-
->method('get')->with('Referer')
132-
->will($this->returnValue('/dashboard'));
133-
134-
$response = $this->expectRedirectResponse('/dashboard');
135-
136-
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
137-
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
138-
139-
$this->assertSame($response, $result);
140-
}
141-
142-
public function testRefererHasToBeDifferentThatLoginUrl()
143-
{
144-
$options = array('use_referer' => true);
145-
146-
$this->request->headers->expects($this->any())
147-
->method('get')->with('Referer')
148-
->will($this->returnValue('/login'));
149-
150-
$this->httpUtils->expects($this->once())
151-
->method('generateUri')->with($this->request, '/login')
152-
->will($this->returnValue('/login'));
153-
154-
$response = $this->expectRedirectResponse('/');
155-
156-
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
157-
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
158-
159-
$this->assertSame($response, $result);
160-
}
161-
162-
public function testRefererTargetPathIsIgnoredByDefault()
163-
{
164-
$this->request->headers->expects($this->never())->method('get');
165-
166-
$response = $this->expectRedirectResponse('/');
167-
168-
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
169-
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
170-
171-
$this->assertSame($response, $result);
172-
}
173-
174-
private function expectRedirectResponse($path)
175-
{
176-
$response = new Response();
177-
$this->httpUtils->expects($this->once())
178-
->method('createRedirectResponse')
179-
->with($this->request, $path)
180-
->will($this->returnValue($response));
181-
182-
return $response;
40+
$session->expects($this->once())->method('get')->with('_security.admin.target_path')->will($this->returnValue('/admin/dashboard'));
41+
$session->expects($this->once())->method('remove')->with('_security.admin.target_path');
42+
$requestWithSession = Request::create('/');
43+
$requestWithSession->setSession($session);
44+
45+
return array(
46+
'default' => array(
47+
Request::create('/'),
48+
array(),
49+
'/',
50+
),
51+
'forced target path' => array(
52+
Request::create('/'),
53+
array('always_use_default_target_path' => true, 'default_target_path' => '/dashboard'),
54+
'/dashboard',
55+
),
56+
'target path as query string' => array(
57+
Request::create('/?_target_path=/dashboard'),
58+
array(),
59+
'/dashboard',
60+
),
61+
'target path name as query string is customized' => array(
62+
Request::create('/?_my_target_path=/dashboard'),
63+
array('target_path_parameter' => '_my_target_path'),
64+
'/dashboard',
65+
),
66+
'target path name as query string is customized and nested' => array(
67+
Request::create('/?_target_path[value]=/dashboard'),
68+
array('target_path_parameter' => '_target_path[value]'),
69+
'/dashboard',
70+
),
71+
'target path in session' => array(
72+
$requestWithSession,
73+
array(),
74+
'/admin/dashboard',
75+
),
76+
'target path as referer' => array(
77+
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/dashboard')),
78+
array('use_referer' => true),
79+
'/dashboard',
80+
),
81+
'target path as referer is ignored if not configured' => array(
82+
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/dashboard')),
83+
array(),
84+
'/',
85+
),
86+
'target path should be different than login URL' => array(
87+
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login')),
88+
array('use_referer' => true, 'login_path' => '/login'),
89+
'/',
90+
),
91+
'target path should be different than login URL (query string does not matter)' => array(
92+
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login?t=1&p=2')),
93+
array('use_referer' => true, 'login_path' => '/login'),
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+
),
101+
);
183102
}
184103
}

‎src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public function __construct($output = null, $charset = null, $flags = 0)
4444
{
4545
$this->flags = (int) $flags;
4646
$this->setCharset($charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8');
47-
$this->decimalPoint = (string) 0.5;
48-
$this->decimalPoint = $this->decimalPoint[1];
47+
$this->decimalPoint = localeconv();
48+
$this->decimalPoint = $this->decimalPoint['decimal_point'];
4949
$this->setOutput($output ?: static::$defaultOutput);
5050
if (!$output && is_string(static::$defaultOutput)) {
5151
static::$defaultOutput = $this->outputStream;
@@ -121,6 +121,9 @@ public function setIndentPad($pad)
121121
*/
122122
public function dump(Data $data, $output = null)
123123
{
124+
$this->decimalPoint = localeconv();
125+
$this->decimalPoint = $this->decimalPoint['decimal_point'];
126+
124127
if ($returnDump = true === $output) {
125128
$output = fopen('php://memory', 'r+b');
126129
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.