Permalink
Browse files

Merge branch '2.1'

* 2.1: (29 commits)
  [DependencyInjection] fixed composer.json
  [Validator] Fix typos in validators.ru.xlf
  Edited some minor grammar and style errors in russian validation file
  Updated Bulgarian translation
  [Form] improve error message with a "hasser" hint for PropertyAccessDeniedException
  [Form] Updated checks for the ICU version from 4.5+ to 4.7+ due to test failures with ICU 4.6
  [Form] simplified a test from previous merge
  Update src/Symfony/Component/Form/Extension/Core/Type/FileType.php
  fixed CS
  Xliff with other node than source or target are ignored
  small fix of #5984 when the container param is not set
  Filesystem Component mirror symlinked directory fix
  [Process][Tests] fixed chainedCommandsOutput tests
  fixed CS
  Use better default ports in urlRedirectAction
  Add tests for urlRedirectAction
  info about session namespace
  fix upgrade info about locale
  Update src/Symfony/Component/DomCrawler/Tests/FormTest.php
  Update src/Symfony/Component/DomCrawler/Form.php
  ...
  • Loading branch information...
2 parents 7fce02c + 922c201 commit 18495e7b3cdfe5ae2a0333a375d93b2dae975eee @fabpot fabpot committed Nov 29, 2012
Showing with 602 additions and 92 deletions.
  1. +13 −11 UPGRADE-2.1.md
  2. +4 −0 src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
  3. +30 −10 src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php
  4. +138 −6 src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php
  5. +6 −2 src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php
  6. +1 −1 src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php
  7. +1 −1 src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml
  8. +1 −1 src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml
  9. +9 −0 src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php
  10. +1 −1 src/Symfony/Component/DomCrawler/Form.php
  11. +6 −0 src/Symfony/Component/DomCrawler/Tests/FormTest.php
  12. +17 −7 src/Symfony/Component/Filesystem/Filesystem.php
  13. +20 −0 src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
  14. +1 −0 src/Symfony/Component/Form/Extension/Core/Type/FileType.php
  15. +4 −1 src/Symfony/Component/Form/FormFactory.php
  16. +5 −3 src/Symfony/Component/Form/FormFactoryBuilder.php
  17. +4 −4 src/Symfony/Component/Form/FormRegistry.php
  18. +1 −1 src/Symfony/Component/Form/FormRegistryInterface.php
  19. +4 −4 src/Symfony/Component/Form/PreloadedExtension.php
  20. +19 −0 src/Symfony/Component/Form/Resources/translations/validators.bg.xlf
  21. +12 −12 ...ny/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php
  22. +8 −0 src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php
  23. +59 −0 src/Symfony/Component/Form/Tests/FormFactoryBuilderTest.php
  24. +18 −0 src/Symfony/Component/Form/Tests/FormFactoryTest.php
  25. +6 −0 src/Symfony/Component/Form/Tests/FormRegistryTest.php
  26. +1 −1 src/Symfony/Component/Form/Util/PropertyPath.php
  27. +3 −3 src/Symfony/Component/Process/Tests/AbstractProcessTest.php
  28. +7 −6 src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php
  29. +1 −1 src/Symfony/Component/Translation/Loader/XliffFileLoader.php
  30. +1 −1 src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php
  31. +5 −0 src/Symfony/Component/Translation/Tests/fixtures/resources.xlf
  32. +8 −8 src/Symfony/Component/Validator/Resources/translations/validators.bg.xlf
  33. +7 −7 src/Symfony/Component/Validator/Resources/translations/validators.ru.xlf
  34. +181 −0 tests/Symfony/Tests/Component/Security/Http/Firewall/DigestDataTest.php
View
@@ -29,6 +29,7 @@
Therefore you should change the namespace of this bundle in your AppKernel.php:
Before: `new Symfony\Bundle\DoctrineBundle\DoctrineBundle()`
+
After: `new Doctrine\Bundle\DoctrineBundle\DoctrineBundle()`
### HttpFoundation
@@ -52,11 +53,6 @@
default_locale: fr
```
- * The methods `getPathInfo()`, `getBaseUrl()` and `getBasePath()` of
- a `Request` now all return a raw value (vs a urldecoded value before). Any call
- to one of these methods must be checked and wrapped in a `rawurldecode()` if
- needed.
-
##### Retrieving the locale from a Twig template
Before: `{{ app.request.session.locale }}` or `{{ app.session.locale }}`
@@ -75,13 +71,11 @@
After: `$request->getLocale()`
-### HttpFoundation
-
- * The current locale for the user is not stored anymore in the session
+ ##### Simulate old behavior
- You can simulate the old behavior by registering a listener that looks like
- the following if the parameter which handles the locale value in the
- request is `_locale`:
+ You can simulate that the locale for the user is still stored in the session by
+ registering a listener that looks like the following if the parameter which
+ handles the locale value in the request is `_locale`:
```
namespace XXX;
@@ -123,6 +117,11 @@
}
```
+ * The methods `getPathInfo()`, `getBaseUrl()` and `getBasePath()` of
+ a `Request` now all return a raw value (vs a urldecoded value before). Any call
+ to one of these methods must be checked and wrapped in a `rawurldecode()` if
+ needed.
+
### Security
* `Symfony\Component\Security\Core\User\UserInterface::equals()` has moved to
@@ -1341,6 +1340,9 @@
### Session
+ * The namespace of the Session class changed from `Symfony\Component\HttpFoundation\Session`
+ to `Symfony\Component\HttpFoundation\Session\Session`.
+
* Using `get` to retrieve flash messages now returns an array.
##### Retrieving the flash messages from a Twig template
@@ -148,6 +148,10 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
$resolver->setNormalizers(array(
'em' => $emNormalizer,
));
+
+ $resolver->setAllowedTypes(array(
+ 'loader' => array('null', 'Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface'),
+ ));
}
/**
@@ -57,15 +57,15 @@ public function redirectAction($route, $permanent = false)
* In case the path is empty, the status code will be 404 when permanent is false
* and 410 otherwise.
*
- * @param string $path The absolute path or URL to redirect to
- * @param Boolean $permanent Whether the redirection is permanent
- * @param Boolean $scheme The URL scheme (null to keep the current one)
- * @param integer $httpPort The HTTP port
- * @param integer $httpsPort The HTTPS port
+ * @param string $path The absolute path or URL to redirect to
+ * @param Boolean $permanent Whether the redirect is permanent or not
+ * @param string|null $scheme The URL scheme (null to keep the current one)
+ * @param integer|null $httpPort The HTTP port (null to keep the current one for the same scheme or the configured port in the container)
+ * @param integer|null $httpsPort The HTTPS port (null to keep the current one for the same scheme or the configured port in the container)
*
* @return Response A Response instance
*/
- public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443)
+ public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = null, $httpsPort = null)
{
if ('' == $path) {
return new Response(null, $permanent ? 410 : 404);
@@ -89,10 +89,30 @@ public function urlRedirectAction($path, $permanent = false, $scheme = null, $ht
}
$port = '';
- if ('http' === $scheme && 80 != $httpPort) {
- $port = ':'.$httpPort;
- } elseif ('https' === $scheme && 443 != $httpsPort) {
- $port = ':'.$httpsPort;
+ if ('http' === $scheme) {
+ if (null === $httpPort) {
+ if ('http' === $request->getScheme()) {
+ $httpPort = $request->getPort();
+ } elseif ($this->container->hasParameter('request_listener.http_port')) {
+ $httpPort = $this->container->getParameter('request_listener.http_port');
+ }
+ }
+
+ if (null !== $httpPort && 80 != $httpPort) {
+ $port = ":$httpPort";
+ }
+ } elseif ('https' === $scheme) {
+ if (null === $httpsPort) {
+ if ('https' === $request->getScheme()) {
+ $httpsPort = $request->getPort();
+ } elseif ($this->container->hasParameter('request_listener.https_port')) {
+ $httpsPort = $this->container->getParameter('request_listener.https_port');
+ }
+ }
+
+ if (null !== $httpsPort && 443 != $httpsPort) {
+ $port = ":$httpsPort";
+ }
}
$url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$path.$qs;
@@ -87,9 +87,7 @@ public function testRoute($permanent, $expectedCode)
$returnResponse = $controller->redirectAction($route, $permanent);
- $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
-
- $this->assertTrue($returnResponse->isRedirect($url));
+ $this->assertRedirectUrl($returnResponse, $url);
$this->assertEquals($expectedCode, $returnResponse->getStatusCode());
}
@@ -119,9 +117,143 @@ public function testFullURL()
$controller = new RedirectController();
$returnResponse = $controller->urlRedirectAction('http://foo.bar/');
- $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
-
- $this->assertEquals('http://foo.bar/', $returnResponse->headers->get('Location'));
+ $this->assertRedirectUrl($returnResponse, 'http://foo.bar/');
$this->assertEquals(302, $returnResponse->getStatusCode());
}
+
+ public function testUrlRedirectDefaultPortParameters()
+ {
+ $host = 'www.example.com';
+ $baseUrl = '/base';
+ $path = '/redirect-path';
+ $httpPort = 1080;
+ $httpsPort = 1443;
+
+ $expectedUrl = "https://$host:$httpsPort$baseUrl$path";
+ $request = $this->createRequestObject('http', $host, $httpPort, $baseUrl);
+ $controller = $this->createRedirectController($request, null, $httpsPort);
+ $returnValue = $controller->urlRedirectAction($path, false, 'https');
+ $this->assertRedirectUrl($returnValue, $expectedUrl);
+
+ $expectedUrl = "http://$host:$httpPort$baseUrl$path";
+ $request = $this->createRequestObject('https', $host, $httpPort, $baseUrl);
+ $controller = $this->createRedirectController($request, $httpPort);
+ $returnValue = $controller->urlRedirectAction($path, false, 'http');
+ $this->assertRedirectUrl($returnValue, $expectedUrl);
+ }
+
+ public function urlRedirectProvider()
+ {
+ return array(
+ // Standard ports
+ array('http', null, null, 'http', 80, ""),
+ array('http', 80, null, 'http', 80, ""),
+ array('https', null, null, 'http', 80, ""),
+ array('https', 80, null, 'http', 80, ""),
+
+ array('http', null, null, 'https', 443, ""),
+ array('http', null, 443, 'https', 443, ""),
+ array('https', null, null, 'https', 443, ""),
+ array('https', null, 443, 'https', 443, ""),
+
+ // Non-standard ports
+ array('http', null, null, 'http', 8080, ":8080"),
+ array('http', 4080, null, 'http', 8080, ":4080"),
+ array('http', 80, null, 'http', 8080, ""),
+ array('https', null, null, 'http', 8080, ""),
+ array('https', null, 8443, 'http', 8080, ":8443"),
+ array('https', null, 443, 'http', 8080, ""),
+
+ array('https', null, null, 'https', 8443, ":8443"),
+ array('https', null, 4443, 'https', 8443, ":4443"),
+ array('https', null, 443, 'https', 8443, ""),
+ array('http', null, null, 'https', 8443, ""),
+ array('http', 8080, 4443, 'https', 8443, ":8080"),
+ array('http', 80, 4443, 'https', 8443, ""),
+ );
+ }
+
+ /**
+ * @dataProvider urlRedirectProvider
+ */
+ public function testUrlRedirect($scheme, $httpPort, $httpsPort, $requestScheme, $requestPort, $expectedPort)
+ {
+ $host = 'www.example.com';
+ $baseUrl = '/base';
+ $path = '/redirect-path';
+ $expectedUrl = "$scheme://$host$expectedPort$baseUrl$path";
+
+ $request = $this->createRequestObject($requestScheme, $host, $requestPort, $baseUrl);
+ $controller = $this->createRedirectController($request);
+
+ $returnValue = $controller->urlRedirectAction($path, false, $scheme, $httpPort, $httpsPort);
+ $this->assertRedirectUrl($returnValue, $expectedUrl);
+ }
+
+ private function createRequestObject($scheme, $host, $port, $baseUrl)
+ {
+ $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $request
+ ->expects($this->any())
+ ->method('getScheme')
+ ->will($this->returnValue($scheme));
+ $request
+ ->expects($this->any())
+ ->method('getHost')
+ ->will($this->returnValue($host));
+ $request
+ ->expects($this->any())
+ ->method('getPort')
+ ->will($this->returnValue($port));
+ $request
+ ->expects($this->any())
+ ->method('getBaseUrl')
+ ->will($this->returnValue($baseUrl));
+
+ return $request;
+ }
+
+ private function createRedirectController(Request $request, $httpPort = null, $httpsPort = null)
+ {
+ $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $container
+ ->expects($this->at(0))
+ ->method('get')
+ ->with($this->equalTo('request'))
+ ->will($this->returnValue($request));
+ if (null !== $httpPort) {
+ $container
+ ->expects($this->once())
+ ->method('hasParameter')
+ ->with($this->equalTo('request_listener.http_port'))
+ ->will($this->returnValue(true));
+ $container
+ ->expects($this->once())
+ ->method('getParameter')
+ ->with($this->equalTo('request_listener.http_port'))
+ ->will($this->returnValue($httpPort));
+ }
+ if (null !== $httpsPort) {
+ $container
+ ->expects($this->once())
+ ->method('hasParameter')
+ ->with($this->equalTo('request_listener.https_port'))
+ ->will($this->returnValue(true));
+ $container
+ ->expects($this->once())
+ ->method('getParameter')
+ ->with($this->equalTo('request_listener.https_port'))
+ ->will($this->returnValue($httpsPort));
+ }
+
+ $controller = new RedirectController();
+ $controller->setContainer($container);
+
+ return $controller;
+ }
+
+ public function assertRedirectUrl(Response $returnResponse, $expectedUrl)
+ {
+ $this->assertTrue($returnResponse->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnResponse->headers->get('Location'));
+ }
}
@@ -182,7 +182,7 @@ private function createAuthorization($config, ContainerBuilder $container)
$container,
$access['path'],
$access['host'],
- count($access['methods']) === 0 ? null : $access['methods'],
+ $access['methods'],
$access['ip']
);
@@ -589,7 +589,7 @@ private function createSwitchUserListener($container, $id, $config, $defaultProv
return $switchUserListenerId;
}
- private function createRequestMatcher($container, $path = null, $host = null, $methods = null, $ip = null, array $attributes = array())
+ private function createRequestMatcher($container, $path = null, $host = null, $methods = array(), $ip = null, array $attributes = array())
{
$serialized = serialize(array($path, $host, $methods, $ip, $attributes));
$id = 'security.request_matcher.'.md5($serialized).sha1($serialized);
@@ -598,6 +598,10 @@ private function createRequestMatcher($container, $path = null, $host = null, $m
return $this->requestMatchers[$id];
}
+ if ($methods) {
+ $methods = array_map('strtoupper', (array) $methods);
+ }
+
// only add arguments that are necessary
$arguments = array($path, $host, $methods, $ip, $attributes);
while (count($arguments) > 0 && !end($arguments)) {
@@ -70,7 +70,7 @@
),
'access_control' => array(
- array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https'),
+ array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https', 'methods' => array('get', 'POST')),
array('path' => '/blog/.*', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'),
),
@@ -59,7 +59,7 @@
<role id="ROLE_SUPER_ADMIN">ROLE_USER,ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH</role>
<role id="ROLE_REMOTE">ROLE_USER,ROLE_ADMIN</role>
- <rule path="/blog/524" role="ROLE_USER" requires-channel="https" />
+ <rule path="/blog/524" role="ROLE_USER" requires-channel="https" methods="get,POST" />
<rule role='IS_AUTHENTICATED_ANONYMOUSLY' path="/blog/.*" />
</config>
</srv:container>
@@ -57,7 +57,7 @@ security:
ROLE_REMOTE: ROLE_USER,ROLE_ADMIN
access_control:
- - { path: /blog/524, role: ROLE_USER, requires_channel: https }
+ - { path: /blog/524, role: ROLE_USER, requires_channel: https, methods: [get, POST]}
-
path: /blog/.*
role: IS_AUTHENTICATED_ANONYMOUSLY
@@ -102,6 +102,7 @@ public function testAccess()
$matcherIds = array();
foreach ($rules as $rule) {
list($matcherId, $roles, $channel) = $rule;
+ $requestMatcher = $container->getDefinition($matcherId);
$this->assertFalse(isset($matcherIds[$matcherId]));
$matcherIds[$matcherId] = true;
@@ -110,9 +111,17 @@ public function testAccess()
if (1 === $i) {
$this->assertEquals(array('ROLE_USER'), $roles);
$this->assertEquals('https', $channel);
+ $this->assertEquals(
+ array('/blog/524', null, array('GET', 'POST')),
+ $requestMatcher->getArguments()
+ );
} elseif (2 === $i) {
$this->assertEquals(array('IS_AUTHENTICATED_ANONYMOUSLY'), $roles);
$this->assertNull($channel);
+ $this->assertEquals(
+ array('/blog/.*'),
+ $requestMatcher->getArguments()
+ );
}
}
}
@@ -367,7 +367,7 @@ private function initialize()
$xpath = new \DOMXPath($document);
foreach ($xpath->query('descendant::input | descendant::button | descendant::textarea | descendant::select', $root) as $node) {
- if (!$node->hasAttribute('name')) {
+ if (!$node->hasAttribute('name') || !$node->getAttribute('name')) {
continue;
}
@@ -127,6 +127,12 @@ public function provideInitializeValues()
array(),
),
array(
+ 'does not take into account input fields with an empty name attribute value',
+ '<input type="text" name="" value="foo" />
+ <input type="submit" />',
+ array(),
+ ),
+ array(
'takes into account disabled input fields',
'<input type="text" name="foo" value="foo" disabled="disabled" />
<input type="submit" />',
Oops, something went wrong.

0 comments on commit 18495e7

Please sign in to comment.