Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1bb2bc3

Browse files
Merge branch '3.4'
* 3.4: [SecurityBundle] Fix valid provider considered undefined Revert "bug #24105 [Filesystem] check permissions if dump target dir is missing (xabbuh)" [Filesystem] skip tests if not applicable [Fabbot] Do not run php-cs-fixer if there are no change in src/ [ExpressionLanguage] make a proposal in SyntaxError message [Security] Fix exception when use_referer option is true and referer is not set or empty [HttpKernel] "controller.service_arguments" services should be public Get KERNEL_DIR through $_ENV too for KernelTestCase Get KERNEL_CLASS through $_ENV too check permissions if dump target dir is missing
2 parents 41de91c + b1b6860 commit 1bb2bc3

File tree

17 files changed

+187
-13
lines changed

17 files changed

+187
-13
lines changed

.php_cs.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
if (!file_exists(__DIR__.'/src')) {
4+
exit(0);
5+
}
6+
37
return PhpCsFixer\Config::create()
48
->setRules(array(
59
'@Symfony' => true,

src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ abstract class KernelTestCase extends TestCase
3737
*/
3838
protected static function getKernelClass()
3939
{
40-
if (!isset($_SERVER['KERNEL_CLASS'])) {
40+
if (!isset($_SERVER['KERNEL_CLASS']) && !isset($_ENV['KERNEL_CLASS'])) {
4141
throw new \LogicException(sprintf('You must set the KERNEL_CLASS environment variable to the fully-qualified class name of your Kernel in phpunit.xml / phpunit.xml.dist or override the %1$::createKernel() or %1$::getKernelClass() method.', static::class));
4242
}
4343

44-
if (!class_exists($class = $_SERVER['KERNEL_CLASS'])) {
44+
if (!class_exists($class = $_SERVER['KERNEL_CLASS'] ?? $_ENV['KERNEL_CLASS'])) {
4545
throw new \RuntimeException(sprintf('Class "%s" doesn\'t exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the %s::createKernel() method.', $class, static::class));
4646
}
4747

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
309309

310310
// Provider id (take the first registered provider if none defined)
311311
if (isset($firewall['provider'])) {
312-
$defaultProvider = $this->getUserProviderId($firewall['provider']);
313-
if (!in_array($defaultProvider, $providerIds, true)) {
312+
if (!isset($providerIds[$normalizedName = str_replace('-', '_', $firewall['provider'])])) {
314313
throw new InvalidConfigurationException(sprintf('Invalid firewall "%s": user provider "%s" not found.', $id, $firewall['provider']));
315314
}
315+
$defaultProvider = $providerIds[$normalizedName];
316316
} else {
317317
$defaultProvider = reset($providerIds);
318318
}
@@ -469,10 +469,10 @@ private function createAuthenticationListeners($container, $id, $firewall, &$aut
469469

470470
if (isset($firewall[$key])) {
471471
if (isset($firewall[$key]['provider'])) {
472-
if (!in_array($firewall[$key]['provider'], $providerIds, true)) {
472+
if (!isset($providerIds[$normalizedName = str_replace('-', '_', $firewall[$key]['provider'])])) {
473473
throw new InvalidConfigurationException(sprintf('Invalid firewall "%s": user provider "%s" not found.', $id, $firewall[$key]['provider']));
474474
}
475-
$userProvider = $this->getUserProviderId($firewall[$key]['provider']);
475+
$userProvider = $providerIds[$normalizedName];
476476
} else {
477477
$userProvider = $defaultProvider;
478478
}
@@ -574,7 +574,7 @@ private function createUserProviders($config, ContainerBuilder $container)
574574
$providerIds = array();
575575
foreach ($config['providers'] as $name => $provider) {
576576
$id = $this->createUserDaoProvider($name, $provider, $container);
577-
$providerIds[] = $id;
577+
$providerIds[str_replace('-', '_', $name)] = $id;
578578
}
579579

580580
return $providerIds;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,18 @@ public function testFirewallListenerUndefinedProvider()
405405
$this->getContainer('listener_undefined_provider');
406406
}
407407

408+
public function testFirewallWithUserProvider()
409+
{
410+
$this->getContainer('firewall_provider');
411+
$this->addToAssertionCount(1);
412+
}
413+
414+
public function testFirewallListenerWithProvider()
415+
{
416+
$this->getContainer('listener_provider');
417+
$this->addToAssertionCount(1);
418+
}
419+
408420
protected function getContainer($file)
409421
{
410422
$file = $file.'.'.$this->getFileExtension();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
$container->loadFromExtension('security', array(
4+
'providers' => array(
5+
'default' => array(
6+
'memory' => $memory = array(
7+
'users' => array('foo' => array('password' => 'foo', 'roles' => 'ROLE_USER')),
8+
),
9+
),
10+
'with-dash' => array(
11+
'memory' => $memory,
12+
),
13+
),
14+
'firewalls' => array(
15+
'main' => array(
16+
'provider' => 'default',
17+
'form_login' => true,
18+
),
19+
'other' => array(
20+
'provider' => 'with-dash',
21+
'form_login' => true,
22+
),
23+
),
24+
));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
$container->loadFromExtension('security', array(
4+
'providers' => array(
5+
'default' => array(
6+
'memory' => array(
7+
'users' => array('foo' => array('password' => 'foo', 'roles' => 'ROLE_USER')),
8+
),
9+
),
10+
),
11+
'firewalls' => array(
12+
'main' => array(
13+
'form_login' => array('provider' => 'default'),
14+
),
15+
),
16+
));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sec="http://symfony.com/schema/dic/security"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
7+
8+
<sec:config>
9+
<sec:providers>
10+
<sec:provider name="with-dash" id="foo" />
11+
</sec:providers>
12+
13+
<sec:firewalls>
14+
<sec:firewall name="main" provider="with-dash">
15+
<sec:form_login />
16+
</sec:firewall>
17+
</sec:firewalls>
18+
</sec:config>
19+
20+
</container>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sec="http://symfony.com/schema/dic/security"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
7+
8+
<sec:config>
9+
<sec:providers>
10+
<sec:provider name="default" id="foo" />
11+
</sec:providers>
12+
13+
<sec:firewalls>
14+
<sec:firewall name="main">
15+
<sec:form_login provider="default" />
16+
</sec:firewall>
17+
</sec:firewalls>
18+
</sec:config>
19+
20+
</container>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
security:
2+
providers:
3+
default:
4+
memory:
5+
users: { foo: { password: foo, roles: ROLE_USER } }
6+
with-dash:
7+
memory:
8+
users: { foo: { password: foo, roles: ROLE_USER } }
9+
10+
firewalls:
11+
main:
12+
provider: default
13+
form_login: true
14+
other:
15+
provider: with-dash
16+
form_login: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
security:
2+
providers:
3+
default:
4+
memory:
5+
users: { foo: { password: foo, roles: ROLE_USER } }
6+
7+
firewalls:
8+
main:
9+
form_login:
10+
provider: default

src/Symfony/Component/ExpressionLanguage/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ public function parsePrimaryExpression()
195195
default:
196196
if ('(' === $this->stream->current->value) {
197197
if (false === isset($this->functions[$token->value])) {
198-
throw new SyntaxError(sprintf('The function "%s" does not exist', $token->value), $token->cursor, $this->stream->getExpression());
198+
throw new SyntaxError(sprintf('The function "%s" does not exist', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, array_keys($this->functions));
199199
}
200200

201201
$node = new Node\FunctionNode($token->value, $this->parseArguments());
202202
} else {
203203
if (!in_array($token->value, $this->names, true)) {
204-
throw new SyntaxError(sprintf('Variable "%s" is not valid', $token->value), $token->cursor, $this->stream->getExpression());
204+
throw new SyntaxError(sprintf('Variable "%s" is not valid', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, $this->names);
205205
}
206206

207207
// is the name used in the compiled code different

src/Symfony/Component/ExpressionLanguage/SyntaxError.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,29 @@
1313

1414
class SyntaxError extends \LogicException
1515
{
16-
public function __construct($message, $cursor = 0, $expression = '')
16+
public function __construct($message, $cursor = 0, $expression = '', $subject = null, array $proposals = null)
1717
{
1818
$message = sprintf('%s around position %d', $message, $cursor);
1919
if ($expression) {
2020
$message = sprintf('%s for expression `%s`', $message, $expression);
2121
}
2222
$message .= '.';
2323

24+
if (null !== $subject && null !== $proposals) {
25+
$minScore = INF;
26+
foreach ($proposals as $proposal) {
27+
$distance = levenshtein($subject, $proposal);
28+
if ($distance < $minScore) {
29+
$guess = $proposal;
30+
$minScore = $distance;
31+
}
32+
}
33+
34+
if (isset($guess) && $minScore < 3) {
35+
$message .= sprintf(' Did you mean "%s"?', $guess);
36+
}
37+
}
38+
2439
parent::__construct($message);
2540
}
2641
}

src/Symfony/Component/ExpressionLanguage/Tests/ParserTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,16 @@ public function getInvalidPostfixData()
195195
),
196196
);
197197
}
198+
199+
/**
200+
* @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError
201+
* @expectedExceptionMessage Did you mean "baz"?
202+
*/
203+
public function testNameProposal()
204+
{
205+
$lexer = new Lexer();
206+
$parser = new Parser(array());
207+
208+
$parser->parse($lexer->tokenize('foo > bar'), array('foo', 'baz'));
209+
}
198210
}

src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function process(ContainerBuilder $container)
5151

5252
foreach ($container->findTaggedServiceIds($this->controllerTag, true) as $id => $tags) {
5353
$def = $container->getDefinition($id);
54+
$def->setPublic(true);
5455
$class = $def->getClass();
5556
$autowire = $def->isAutowired();
5657

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,21 @@ public function testArgumentWithNoTypeHintIsOk()
268268
$this->assertEmpty(array_keys($locator));
269269
}
270270

271+
public function testControllersAreMadePublic()
272+
{
273+
$container = new ContainerBuilder();
274+
$resolver = $container->register('argument_resolver.service')->addArgument(array());
275+
276+
$container->register('foo', ArgumentWithoutTypeController::class)
277+
->setPublic(false)
278+
->addTag('controller.service_arguments');
279+
280+
$pass = new RegisterControllerArgumentLocatorsPass();
281+
$pass->process($container);
282+
283+
$this->assertTrue($container->getDefinition('foo')->isPublic());
284+
}
285+
271286
/**
272287
* @dataProvider provideBindings
273288
*/

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,11 @@ protected function determineTargetUrl(Request $request)
122122
return $targetUrl;
123123
}
124124

125-
if ($this->options['use_referer']) {
126-
$targetUrl = $request->headers->get('Referer');
125+
if ($this->options['use_referer'] && $targetUrl = $request->headers->get('Referer')) {
127126
if (false !== $pos = strpos($targetUrl, '?')) {
128127
$targetUrl = substr($targetUrl, 0, $pos);
129128
}
130-
if ($targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
129+
if ($targetUrl && $targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
131130
return $targetUrl;
132131
}
133132
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ public function getRequestRedirections()
8383
array(),
8484
'/',
8585
),
86+
'target path as referer when referer not set' => array(
87+
Request::create('/'),
88+
array('use_referer' => true),
89+
'/',
90+
),
91+
'target path as referer when referer is ?' => array(
92+
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => '?')),
93+
array('use_referer' => true),
94+
'/',
95+
),
8696
'target path should be different than login URL' => array(
8797
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login')),
8898
array('use_referer' => true, 'login_path' => '/login'),

0 commit comments

Comments
 (0)