8000 Merge branch '2.0' into 2.1 · symfony/symfony@922c201 · GitHub
[go: up one dir, main page]

Skip to content

Commit 922c201

Browse files
committed
Merge branch '2.0' into 2.1
* 2.0: [DependencyInjection] fixed composer.json [Form] Updated checks for the ICU version from 4.5+ to 4.7+ due to test failures with ICU 4.6 fixed CS small fix of #5984 when the container param is not set fixed CS Use better default ports in urlRedirectAction Add tests for urlRedirectAction Update src/Symfony/Component/DomCrawler/Tests/FormTest.php Update src/Symfony/Component/DomCrawler/Form.php [Security] remove escape charters from username provided by Digest DigestAuthenticationListener [Security] added test extra for digest authentication fixed CS [Security] Fixed digest authentication [Security] Fixed digest authentication [SecurityBundle] Convert Http method to uppercase in the config Use Norm Data instead of Data Conflicts: src/Symfony/Bridge/Doctrine/Form/EventListener/MergeCollectionListener.php src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php src/Symfony/Component/DependencyInjection/composer.json
2 parents ed6a345 + fc89d6b commit 922c201

File tree

12 files changed

+393
-40
lines changed

12 files changed

+393
-40
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public function redirectAction($route, $permanent = false)
5757
* In case the path is empty, the status code will be 404 when permanent is false
5858
* and 410 otherwise.
5959
*
60-
* @param string $path The absolute path or URL to redirect to
61-
* @param Boolean $permanent Whether the redirection is permanent
62-
* @param Boolean $scheme The URL scheme (null to keep the current one)
63-
* @param integer $httpPort The HTTP port
64-
* @param integer $httpsPort The HTTPS port
60+
* @param string $path The absolute path or URL to redirect to
61+
* @param Boolean $permanent Whether the redirect is permanent or not
62+
* @param string|null $scheme The URL scheme (null to keep the current one)
63+
* @param integer|null $httpPort The HTTP port (null to keep the current one for the same scheme or the configured port in the container)
64+
* @param integer|null $httpsPort The HTTPS port (null to keep the current one for the same scheme or the configured port in the container)
6565
*
6666
* @return Response A Response instance
6767
*/
68-
public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443)
68+
public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = null, $httpsPort = null)
6969
{
7070
if ('' == $path) {
7171
return new Response(null, $permanent ? 410 : 404);
@@ -89,10 +89,30 @@ public function urlRedirectAction($path, $permanent = false, $scheme = null, $ht
8989
}
9090

9191
$port = '';
92-
if ('http' === $scheme && 80 != $httpPort) {
93-
$port = ':'.$httpPort;
94-
} elseif ('https' === $scheme && 443 != $httpsPort) {
95-
$port = ':'.$httpsPort;
92+
if ('http' === $scheme) {
93+
if (null === $httpPort) {
94+
if ('http' === $request->getScheme()) {
95+
$httpPort = $request->getPort();
96+
} elseif ($this->container->hasParameter('request_listener.http_port')) {
97+
$httpPort = $this->container->getParameter('request_listener.http_port');
98+
}
99+
}
100+
101+
if (null !== $httpPort && 80 != $httpPort) {
102+
$port = ":$httpPort";
103+
}
104+
} elseif ('https' === $scheme) {
105+
if (null === $httpsPort) {
106+
if ('https' === $request->getScheme()) {
107+
$httpsPort = $request->getPort();
108+
} elseif ($this->container->hasParameter('request_listener.https_port')) {
109+
$httpsPort = $this->container->getParameter('request_listener.https_port');
110+
}
111+
}
112+
113+
if (null !== $httpsPort && 443 != $httpsPort) {
114+
$port = ":$httpsPort";
115+
}
96116
}
97117

98118
$url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$path.$qs;

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php

Lines changed: 138 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ public function testRoute($permanent, $expectedCode)
8787

8888
$returnResponse = $controller->redirectAction($route, $permanent);
8989

90-
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
91-
92-
$this->assertTrue($returnResponse->isRedirect($url));
90+
$this->assertRedirectUrl($returnResponse, $url);
9391
$this->assertEquals($expectedCode, $returnResponse->getStatusCode());
9492
}
9593

@@ -119,9 +117,143 @@ public function testFullURL()
119117
$controller = new RedirectController();
120118
$returnResponse = $controller->urlRedirectAction('http://foo.bar/');
121119

122-
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
123-
124-
$this->assertEquals('http://foo.bar/', $returnResponse->headers->get('Location'));
120+
$this->assertRedirectUrl($returnResponse, 'http://foo.bar/');
125121
$this->assertEquals(302, $returnResponse->getStatusCode());
126122
}
123+
124+
public function testUrlRedirectDefaultPortParameters()
125+
{
126+
$host = 'www.example.com';
127+
$baseUrl = '/base';
128+
$path = '/redirect-path';
129+
$httpPort = 1080;
130+
$httpsPort = 1443;
131+
132+
$expectedUrl = "https://$host:$httpsPort$baseUrl$path";
133+
$request = $this->createRequestObject('http', $host, $httpPort, $baseUrl);
134+
$controller = $this->createRedirectController($request, null, $httpsPort);
135+
$returnValue = $controller->urlRedirectAction($path, false, 'https');
136+
$this->assertRedirectUrl($returnValue, $expectedUrl);
137+
138+
$expectedUrl = "http://$host:$httpPort$baseUrl$path";
139+
$request = $this->createRequestObject('https', $host, $httpPort, $baseUrl);
140+
$controller = $this->createRedirectController($request, $httpPort);
141+
$returnValue = $controller->urlRedirectAction($path, false, 'http');
142+
$this->assertRedirectUrl($returnValue, $expectedUrl);
143+
}
144+
145+
public function urlRedirectProvider()
146+
{
147+
return array(
148+
// Standard ports
149+
array('http', null, null, 'http', 80, ""),
150+
array('http', 80, null, 'http', 80, ""),
151+
array('https', null, null, 'http', 80, ""),
152+
array('https', 80, null, 'http', 80, ""),
153+
154+
array('http', null, null, 'https', 443, ""),
155+
array('http', null, 443, 'https', 443, ""),
156+
array('https', null, null, 'https', 443, ""),
157+
array('https', null, 443, 'https', 443, ""),
158+
159+
// Non-standard ports
160+
array('http', null, null, 'http', 8080, ":8080"),
161+
array('http', 4080, null, 'http', 8080, ":4080"),
162+
array('http', 80, null, 'http', 8080, ""),
163+
array('https', null, null, 'http', 8080, ""),
164+
array('https', null, 8443, 'http', 8080, ":8443"),
165+
array('https', null, 443, 'http', 8080, ""),
166+
167+
array('https', null, null, 'https', 8443, ":8443"),
168+
array('https', null, 4443, 'https', 8443, ":4443"),
169+
array('https', null, 443, 'https', 8443, ""),
170+
array('http', null, null, 'https', 8443, ""),
171+
array('http', 8080, 4443, 'https', 8443, ":8080"),
172+
array('http', 80, 4443, 'https', 8443, ""),
173+
);
174+
}
175+
176+
/**
177+
* @dataProvider urlRedirectProvider
178+
*/
179+
public function testUrlRedirect($scheme, $httpPort, $httpsPort, $requestScheme, $requestPort, $expectedPort)
180+
{
181+
$host = 'www.example.com';
182+
$baseUrl = '/base';
183+
$path = '/redirect-path';
184+
$expectedUrl = "$scheme://$host$expectedPort$baseUrl$path";
185+
186+
$request = $this->createRequestObject($requestScheme, $host, $requestPort, $baseUrl);
187+
$controller = $this->createRedirectController($request);
188+
189+
$returnValue = $controller->urlRedirectAction($path, false, $scheme, $httpPort, $httpsPort);
190+
$this->assertRedirectUrl($returnValue, $expectedUrl);
191+
}
192+
193+
private function createRequestObject($scheme, $host, $port, $baseUrl)
194+
{
195+
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
196+
$request
197+
->expects($this->any())
198+
->method('getScheme')
199+
->will($this->returnValue($scheme));
200+
$request
201+
->expects($this->any())
202+
->method('getHost')
203+
->will($this->returnValue($host));
204+
$request
205+
->expects($this->any())
206+
->method('getPort')
207+
->will($this->returnValue($port));
208+
$request
209+
->expects($this->any())
210+
->method('getBaseUrl')
211+
->will($this->returnValue($baseUrl));
212+
213+
return $request;
214+
}
215+
216+
private function createRedirectController(Request $request, $httpPort = null, $httpsPort = null)
217+
{
218+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
219+
$container
220+
->expects($this->at(0))
221+
->method('get')
222+
->with($this->equalTo('request'))
223+
->will($this->returnValue($request));
224+
if (null !== $httpPort) {
225+
$container
226+
->expects($this->once())
227+
->method('hasParameter')
228+
->with($this->equalTo('request_listener.http_port'))
229+
->will($this->returnValue(true));
230+
$container
231+
->expects($this->once())
232+
->method('getParameter')
233+
->with($this->equalTo('request_listener.http_port'))
234+
->will($this->returnValue($httpPort));
235+
}
236+
if (null !== $httpsPort) {
237+
$container
238+
->expects($this->once())
239+
->method('hasParameter')
240+
->with($this->equalTo('request_listener.https_port'))
241+
->will($this->returnValue(true));
242+
$container
243+
->expects($this->once())
244+
->method('getParameter')
245+
->with($this->equalTo('request_listener.https_port'))
246+
->will($this->returnValue($httpsPort));
247+
}
248+
249+
$controller = new RedirectController();
250+
$controller->setContainer($container);
251+
252+
return $controller;
253+
}
254+
255+
public function assertRedirectUrl(Response $returnResponse, $expectedUrl)
256+
{
257+
$this->assertTrue($returnResponse->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnResponse->headers->get('Location'));
258+
}
127259
}

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private function createAuthorization($config, ContainerBuilder $container)
182182
$container,
183183
$access['path'],
184184
$access['host'],
185-
count($access['methods']) === 0 ? null : $access['methods'],
185+
$access['methods'],
186186
$access['ip']
187187
);
188188

@@ -574,7 +574,7 @@ private function createSwitchUserListener($container, $id, $config, $defaultProv
574574
return $switchUserListenerId;
575575
}
576576

577-
private function createRequestMatcher($container, $path = null, $host = null, $methods = null, $ip = null, array $attributes = array())
577+
private function createRequestMatcher($container, $path = null, $host = null, $methods = array(), $ip = null, array $attributes = array())
578578
{
579579
$serialized = serialize(array($path, $host, $methods, $ip, $attributes));
580580
$id = 'security.request_matcher.'.md5($serialized).sha1($serialized);
@@ -583,6 +583,10 @@ private function createRequestMatcher($container, $path = null, $host = null, $m
583583
return $this->requestMatchers[$id];
584584
}
585585

586+
if ($methods) {
587+
$methods = array_map('strtoupper', (array) $methods);
588+
}
589+
586590
// only add arguments that are necessary
587591
$arguments = array($path, $host, $methods, $ip, $attributes);
588592
while (count($arguments) > 0 && !end($arguments)) {

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
),
6464

6565
'access_control' => array(
66-
array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https'),
66+
array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https', 'methods' => array('get', 'POST')),
6767
array('path' => '/blog/.*', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'),
6868
),
6969

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<role id="ROLE_SUPER_ADMIN">ROLE_USER,ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH</role>
5858
<role id="ROLE_REMOTE">ROLE_USER,ROLE_ADMIN</role>
5959

60-
<rule path="/blog/524" role="ROLE_USER" requires-channel="https" />
60+
<rule path="/blog/524" role="ROLE_USER" requires-channel="https" methods="get,POST" />
6161
<rule role='IS_AUTHENTICATED_ANONYMOUSLY' path="/blog/.*" />
6262
</config>
6363
</srv:container>

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ security:
5151
ROLE_REMOTE: ROLE_USER,ROLE_ADMIN
5252

5353
access_control:
54-
- { path: /blog/524, role: ROLE_USER, requires_channel: https }
54+
- { path: /blog/524, role: ROLE_USER, requires_channel: https, methods: [get, POST]}
5555
-
5656
path: /blog/.*
5757
role: IS_AUTHENTICATED_ANONYMOUSLY

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function testAccess()
102102
$matcherIds = array();
103103
foreach ($rules as $rule) {
104104
list($matcherId, $roles, $channel) = $rule;
105+
$requestMatcher = $container->getDefinition($matcherId);
105106

106107
$this->assertFalse(isset($matcherIds[$matcherId]));
107108
$matcherIds[$matcherId] = true;
@@ -110,9 +111,17 @@ public function testAccess()
110111
if (1 === $i) {
111112
$this->assertEquals(array('ROLE_USER'), $roles);
112113
$this->assertEquals('https', $channel);
114+
$this->assertEquals(
115+
array('/blog/524', null, array('GET', 'POST')),
116+
$requestMatcher->getArguments()
117+
);
113118
} elseif (2 === $i) {
114119
$this->assertEquals(array('IS_AUTHENTICATED_ANONYMOUSLY'), $roles);
115120
$this->assertNull($channel);
121+
$this->assertEquals(
122+
array('/blog/.*'),
123+
$requestMatcher->getArguments()
124+
);
116125
}
117126
}
118127
}

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ private function initialize()
359359
$xpath = new \DOMXPath($document);
360360

361361
foreach ($xpath->query('descendant::input | descendant::button | descendant::textarea | descendant::select', $root) as $node) {
362-
if (!$node->hasAttribute('name')) {
362+
if (!$node->hasAttribute('name') || !$node->getAttribute('name')) {
363363
continue;
364364
}
365365

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ public function provideInitializeValues()
126126
<input type="submit" />',
127127
array(),
128128
),
129+
array(
130+
'does not take into account input fields with an empty name attribute value',
131+
'<input type="text" name="" value="foo" />
132+
<input type="submit" />',
133+
array(),
134+
),
129135
array(
130136
'takes into account disabled input fields',
131137
'<input type="text" name="foo" value="foo" disabled="disabled" />

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public function testReverseTransformWithGrouping()
9696

9797
public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsNotDot()
9898
{
99-
if ($this->isLowerThanIcuVersion('4.5')) {
100-
$this->markTestSkipped('Please upgrade ICU version to 4.5+');
99+
if ($this->isLowerThanIcuVersion('4.7')) {
100+
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
101101
}
102102

103103
\Locale::setDefault('fr');
@@ -117,8 +117,8 @@ public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsNotDot()
117117
*/
118118
public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDot()
119119
{
120-
if ($this->isLowerThanIcuVersion('4.5')) {
121-
$this->markTestSkipped('Please upgrade ICU version to 4.5+');
120+
if ($this->isLowerThanIcuVersion('4.7')) {
121+
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
122122
}
123123

124124
$transformer = new NumberToLocalizedStringTransformer(null, true);
@@ -131,8 +131,8 @@ public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDot()
131131
*/
132132
public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDot_noGroupSep()
133133
{
134-
if ($this->isLowerThanIcuVersion('4.5')) {
135-
$this->markTestSkipped('Please upgrade ICU version to 4.5+');
134+
if ($this->isLowerThanIcuVersion('4.7')) {
135+
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
136136
}
137137

138138
$transformer = new NumberToLocalizedStringTransformer(null, true);
@@ -151,8 +151,8 @@ public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsDotButNoGroupin
151151

152152
public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsNotComma()
153153
{
154-
if ($this->isLowerThanIcuVersion('4.5')) {
155-
$this->markTestSkipped('Please upgrade ICU version to 4.5+');
154+
if ($this->isLowerThanIcuVersion('4.7')) {< CAEC /div>
155+
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
156156
}
157157

158158
\Locale::setDefault('ak');
@@ -172,8 +172,8 @@ public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsNotComma()
172172
*/
173173
public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsComma()
174174
{
175-
if ($this->isLowerThanIcuVersion('4.5')) {
176-
$this->markTestSkipped('Please upgrade ICU version to 4.5+');
175+
if ($this->isLowerThanIcuVersion('4.7')) {
176+
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
177177
}
178178

179179
\Locale::setDefault('en');
@@ -187,8 +187,8 @@ public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsComma()
187187
*/
188188
public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsComma_noGroupSep()
189189
{
190-
if ($this->isLowerThanIcuVersion('4.5')) {
191-
$this->markTestSkipped('Please upgrade ICU version to 4.5+');
190+
if ($this->isLowerThanIcuVersion('4.7')) {
191+
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
192192
}
193193

194194
\Locale::setDefault('en');

0 commit comments

Comments
 (0)
0