Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
@@ -63,17 +63,14 @@ class SecurityDataCollectorTest extends TestCase
$collector = new SecurityDataCollector($tokenStorage, $this->getRoleHierarchy());
$collector->collect($this->getRequest(), $this->getResponse());
$collector->lateCollect();
$this->assertTrue($collector->isEnabled());
$this->assertTrue($collector->isAuthenticated());
$this->assertSame('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $collector->getTokenClass());
$this->assertSame('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $collector->getTokenClass()->getValue());
$this->assertTrue($collector->supportsRoleHierarchy());
$this->assertSame($normalizedRoles, $collector->getRoles()->getRawData()[1]);
if ($inheritedRoles) {
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getRawData()[1]);
} else {
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getRawData()[0][0]);
}
$this->assertSame($normalizedRoles, $collector->getRoles()->getValue(true));
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getValue(true));
$this->assertSame('hhamon', $collector->getUser());
}
@@ -94,6 +91,7 @@ class SecurityDataCollectorTest extends TestCase
$collector = new SecurityDataCollector(null, null, null, null, $firewallMap);
$collector->collect($request, $this->getResponse());
$collector->lateCollect();
$collected = $collector->getFirewall();
$this->assertSame($firewallConfig->getName(), $collected['name']);
@@ -107,7 +105,7 @@ class SecurityDataCollectorTest extends TestCase
$this->assertSame($firewallConfig->getAccessDeniedHandler(), $collected['access_denied_handler']);
$this->assertSame($firewallConfig->getAccessDeniedUrl(), $collected['access_denied_url']);
$this->assertSame($firewallConfig->getUserChecker(), $collected['user_checker']);
$this->assertSame($firewallConfig->getListeners(), $collected['listeners']->getRawData()[0][0]);
$this->assertSame($firewallConfig->getListeners(), $collected['listeners']->getValue());
}
public function testGetFirewallReturnsNull()
@@ -59,8 +59,8 @@ class AddSecurityVotersPassTest extends TestCase
$compilerPass = new AddSecurityVotersPass();
$compilerPass->process($container);
$calls = $container->getDefinition('security.access.decision_manager')->getMethodCalls();
$refs = $calls[0][1][0];
$argument = $container->getDefinition('security.access.decision_manager')->getArgument(0);
$refs = $argument->getValues();
$this->assertEquals(new Reference('highest_prio_service'), $refs[0]);
$this->assertEquals(new Reference('lowest_prio_service'), $refs[1]);
$this->assertCount(4, $refs);
@@ -96,13 +96,28 @@ class AddSessionDomainConstraintPassTest extends TestCase
$this->assertTrue($utils->createRedirectResponse($request, 'http://pirate.com/foo')->isRedirect('http://pirate.com/foo'));
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
* @expectedExceptionMessage You have requested a non-existent service "security.http_utils".
*/
public function testNoHttpUtils()
{
$container = new ContainerBuilder();
$container->setParameter('session.storage.options', array());
$pass = new AddSessionDomainConstraintPass();
$pass->process($container);
}
private function createContainer($sessionStorageOptions)
{
$container = new ContainerBuilder();
$container->setParameter('kernel.bundles_metadata', array());
$container->setParameter('kernel.cache_dir', __DIR__);
$container->setParameter('kernel.charset', 'UTF-8');
$container->setParameter('kernel.container_class', 'cc');
$container->setParameter('kernel.debug', true);
$container->setParameter('kernel.project_dir', __DIR__);
$container->setParameter('kernel.root_dir', __DIR__);
$container->setParameter('kernel.secret', __DIR__);
if (null !== $sessionStorageOptions) {
@@ -119,12 +134,13 @@ class AddSessionDomainConstraintPassTest extends TestCase
);
$ext = new FrameworkExtension();
$ext->load(array(), $container);
$ext->load(array('framework' => array('csrf_protection' => false)), $container);
$ext = new SecurityExtension();
$ext->load($config, $container);
(new AddSessionDomainConstraintPass())->process($container);
$pass = new AddSessionDomainConstraintPass();
$pass->process($container);
return $container;
}
@@ -43,12 +43,8 @@ abstract class CompleteConfigurationTest extends TestCase
$expectedProviders = array(
'security.user.provider.concrete.default',
'security.user.provider.concrete.default_foo',
'security.user.provider.concrete.digest',
'security.user.provider.concrete.digest_foo',
'security.user.provider.concrete.basic',
'security.user.provider.concrete.basic_foo',
'security.user.provider.concrete.basic_bar',
'security.user.provider.concrete.service',
'security.user.provider.concrete.chain',
);
@@ -69,7 +65,7 @@ abstract class CompleteConfigurationTest extends TestCase
$arguments = $container->getDefinition('security.firewall.map')->getArguments();
$listeners = array();
$configs = array();
foreach (array_keys($arguments[1]) as $contextId) {
foreach (array_keys($arguments[1]->getValues()) as $contextId) {
$contextDef = $container->getDefinition($contextId);
$arguments = $contextDef->getArguments();
$listeners[] = array_map('strval', $arguments['index_0']);
@@ -172,6 +168,8 @@ abstract class CompleteConfigurationTest extends TestCase
'security.access_listener',
),
), $listeners);
$this->assertFalse($container->hasAlias('Symfony\Component\Security\Core\User\UserCheckerInterface', 'No user checker alias is registered when custom user checker services are registered'));
}
public function testFirewallRequestMatchers()
@@ -181,7 +179,7 @@ abstract class CompleteConfigurationTest extends TestCase
$arguments = $container->getDefinition('security.firewall.map')->getArguments();
$matchers = array();
foreach ($arguments[1] as $reference) {
foreach ($arguments[1]->getValues() as $reference) {
if ($reference instanceof Reference) {
$definition = $container->getDefinition((string) $reference);
$matchers[] = $definition->getArguments();
@@ -200,13 +198,21 @@ abstract class CompleteConfigurationTest extends TestCase
), $matchers);
}
public function testUserCheckerAliasIsRegistered()
{
$container = $this->getContainer('no_custom_user_checker');
$this->assertTrue($container->hasAlias('Symfony\Component\Security\Core\User\UserCheckerInterface', 'Alias for user checker is registered when no custom user checker service is registered'));
$this->assertFalse($container->getAlias('Symfony\Component\Security\Core\User\UserCheckerInterface')->isPublic());
}
public function testAccess()
{
$container = $this->getContainer('container1');
$rules = array();
foreach ($container->getDefinition('security.access_map')->getMethodCalls() as $call) {
if ($call[0] == 'add') {
if ('add' == $call[0]) {
$rules[] = array((string) $call[1][0], $call[1][1], $call[1][2]);
}
}
@@ -215,7 +221,7 @@ abstract class CompleteConfigurationTest extends TestCase
foreach ($rules as list($matcherId, $attributes, $channel)) {
$requestMatcher = $container->getDefinition($matcherId);
$this->assertFalse(isset($matcherIds[$matcherId]));
$this->assertArrayNotHasKey($matcherId, $matcherIds);
$matcherIds[$matcherId] = true;
$i = count($matcherIds);
@@ -335,6 +341,11 @@ abstract class CompleteConfigurationTest extends TestCase
$this->assertEquals('security.user_checker', $this->getContainer('container1')->getAlias('security.user_checker.secure'));
}
public function testUserPasswordEncoderCommandIsRegistered()
{
$this->assertTrue($this->getContainer('remember_me_options')->has('security.console.user_password_encoder_command'));
}
protected function getContainer($file)
{
$file = $file.'.'.$this->getFileExtension();
@@ -20,8 +20,6 @@ class MainConfigurationTest extends TestCase
/**
* The minimal, required config needed to not have any required validation
* issues.
*
* @var array
*/
protected static $minimalConfig = array(
'providers' => array(
@@ -86,9 +84,9 @@ class MainConfigurationTest extends TestCase
$processor = new Processor();
$configuration = new MainConfiguration(array(), array());
$processedConfig = $processor->processConfiguration($configuration, array($config));
$this->assertTrue(isset($processedConfig['firewalls']['stub']['logout']['csrf_token_generator']));
$this->assertArrayHasKey('csrf_token_generator', $processedConfig['firewalls']['stub']['logout']);
$this->assertEquals('a_token_generator', $processedConfig['firewalls']['stub']['logout']['csrf_token_generator']);
$this->assertTrue(isset($processedConfig['firewalls']['stub']['logout']['csrf_token_id']));
$this->assertArrayHasKey('csrf_token_id', $processedConfig['firewalls']['stub']['logout']);
$this->assertEquals('a_token_id', $processedConfig['firewalls']['stub']['logout']['csrf_token_id']);
}
@@ -14,6 +14,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Security\Facto
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\GuardAuthenticationFactory;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -107,7 +108,7 @@ class GuardAuthenticationFactoryTest extends TestCase
$providerDefinition = $container->getDefinition('security.authentication.provider.guard.my_firewall');
$this->assertEquals(array(
'index_0' => array(new Reference('authenticator123')),
'index_0' => new IteratorArgument(array(new Reference('authenticator123'))),
'index_1' => new Reference('my_user_provider'),
'index_2' => 'my_firewall',
'index_3' => new Reference('security.user_checker.my_firewall'),
@@ -115,7 +116,7 @@ class GuardAuthenticationFactoryTest extends TestCase
$listenerDefinition = $container->getDefinition('security.authentication.listener.guard.my_firewall');
$this->assertEquals('my_firewall', $listenerDefinition->getArgument(2));
$this->assertEquals(array(new Reference('authenticator123')), $listenerDefinition->getArgument(3));
$this->assertEquals(array(new Reference('authenticator123')), $listenerDefinition->getArgument(3)->getValues());
}
public function testExistingDefaultEntryPointUsed()
@@ -24,14 +24,14 @@ class LoginController implements ContainerAwareInterface
{
$form = $this->container->get('form.factory')->create('Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Form\UserLoginType');
return $this->container->get('templating')->renderResponse('CsrfFormLoginBundle:Login:login.html.twig', array(
return new Response($this->container->get('twig')->render('@CsrfFormLogin/Login/login.html.twig', array(
'form' => $form->createView(),
));
)));
}
public function afterLoginAction()
{
return $this->container->get('templating')->renderResponse('CsrfFormLoginBundle:Login:after_login.html.twig');
return new Response($this->container->get('twig')->render('@CsrfFormLogin/Login/after_login.html.twig'));
}
public function loginCheckAction()
@@ -1,4 +1,4 @@
{% extends "::base.html.twig" %}
{% extends "base.html.twig" %}
{% block body %}
Hello {{ app.user.username }}!<br /><br />
@@ -1,4 +1,4 @@
{% extends "::base.html.twig" %}
{% extends "base.html.twig" %}
{% block body %}
@@ -30,11 +30,11 @@ class LocalizedController implements ContainerAwareInterface
$error = $request->getSession()->get(Security::AUTHENTICATION_ERROR);
}
return $this->container->get('templating')->renderResponse('FormLoginBundle:Localized:login.html.twig', array(
return new Response($this->container->get('twig')->render('@FormLogin/Localized/login.html.twig', array(
// last username entered by the user
'last_username' => $request->getSession()->get(Security::LAST_USERNAME),
'error' => $error,
));
)));
}
public function loginCheckAction()
@@ -32,16 +32,16 @@ class LoginController implements ContainerAwareInterface
$error = $request->getSession()->get(Security::AUTHENTICATION_ERROR);
}
return $this->container->get('templating')->renderResponse('FormLoginBundle:Login:login.html.twig', array(
return new Response($this->container->get('twig')->render('@FormLogin/Login/login.html.twig', array(
// last username entered by the user
'last_username' => $request->getSession()->get(Security::LAST_USERNAME),
'error' => $error,
));
)));
}
public function afterLoginAction(UserInterface $user)
{
return $this->container->get('templating')->renderResponse('FormLoginBundle:Login:after_login.html.twig', array('user' => $user));
return new Response($this->container->get('twig')->render('@FormLogin/Login/after_login.html.twig', array('user' => $user)));
}
public function loginCheckAction()
@@ -1,4 +1,4 @@
{% extends "::base.html.twig" %}
{% extends "base.html.twig" %}
{% block body %}
@@ -1,4 +1,4 @@
{% extends "::base.html.twig" %}
{% extends "base.html.twig" %}
{% block body %}
Hello {{ user.username }}!<br /><br />
@@ -1,4 +1,4 @@
{% extends "::base.html.twig" %}
{% extends "base.html.twig" %}
{% block body %}
@@ -40,6 +40,9 @@ class SetAclCommandTest extends WebTestCase
const OBJECT_CLASS = 'Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AclBundle\Entity\Car';
const SECURITY_CLASS = 'Symfony\Component\Security\Core\User\User';
/**
* @group legacy
*/
public function testSetAclUser()
{
$objectId = 1;
@@ -13,8 +13,10 @@ namespace Symfony\Bundle\SecurityBundle\Tests\Functional;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\SecurityBundle\Command\UserPasswordEncoderCommand;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Security\Core\Encoder\Pbkdf2PasswordEncoder;
/**
@@ -24,6 +26,7 @@ use Symfony\Component\Security\Core\Encoder\Pbkdf2PasswordEncoder;
*/
class UserPasswordEncoderCommandTest extends WebTestCase
{
/** @var CommandTester */
private $passwordEncoderCommandTester;
public function testEncodePasswordEmptySalt()
@@ -105,6 +108,7 @@ class UserPasswordEncoderCommandTest extends WebTestCase
array(
'command' => 'security:encode-password',
'password' => 'p@ssw0rd',
'user-class' => 'Symfony\Component\Security\Core\User\User',
'--empty-salt' => true,
)
);
@@ -143,6 +147,74 @@ class UserPasswordEncoderCommandTest extends WebTestCase
), array('interactive' => false));
}
public function testEncodePasswordAsksNonProvidedUserClass()
{
$this->passwordEncoderCommandTester->setInputs(array('Custom\Class\Pbkdf2\User', "\n"));
$this->passwordEncoderCommandTester->execute(array(
'command' => 'security:encode-password',
'password' => 'password',
), array('decorated' => false));
$this->assertContains(<<<EOTXT
For which user class would you like to encode a password? [Custom\Class\Bcrypt\User]:
[0] Custom\Class\Bcrypt\User
[1] Custom\Class\Pbkdf2\User
[2] Custom\Class\Test\User
[3] Symfony\Component\Security\Core\User\User
EOTXT
, $this->passwordEncoderCommandTester->getDisplay(true));
}
public function testNonInteractiveEncodePasswordUsesFirstUserClass()
{
$this->passwordEncoderCommandTester->execute(array(
'command' => 'security:encode-password',
'password' => 'password',
), array('interactive' => false));
$this->assertContains('Encoder used Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder', $this->passwordEncoderCommandTester->getDisplay());
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage There are no configured encoders for the "security" extension.
*/
public function testThrowsExceptionOnNoConfiguredEncoders()
{
$application = new ConsoleApplication();
$application->add(new UserPasswordEncoderCommand($this->getMockBuilder(EncoderFactoryInterface::class)->getMock(), array()));
$passwordEncoderCommand = $application->find('security:encode-password');
$tester = new CommandTester($passwordEncoderCommand);
$tester->execute(array(
'command' => 'security:encode-password',
'password' => 'password',
), array('interactive' => false));
}
/**
* @group legacy
* @expectedDeprecation Passing null as the first argument of "Symfony\Bundle\SecurityBundle\Command\UserPasswordEncoderCommand::__construct" is deprecated since Symfony 3.3 and will be removed in 4.0. If the command was registered by convention, make it a service instead.
*/
public function testLegacy()
{
$application = new ConsoleApplication();
$application->add(new UserPasswordEncoderCommand());
$passwordEncoderCommand = $application->find('security:encode-password');
self::bootKernel(array('test_case' => 'PasswordEncode'));
$passwordEncoderCommand->setContainer(self::$kernel->getContainer());
$tester = new CommandTester($passwordEncoderCommand);
$tester->execute(array(
'command' => 'security:encode-password',
'password' => 'password',
), array('interactive' => false));
$this->assertContains('Encoder used Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder', $tester->getDisplay());
}
protected function setUp()
{
putenv('COLUMNS='.(119 + strlen(PHP_EOL)));
@@ -151,8 +223,7 @@ class UserPasswordEncoderCommandTest extends WebTestCase
$application = new Application($kernel);
$application->add(new UserPasswordEncoderCommand());
$passwordEncoderCommand = $application->find('security:encode-password');
$passwordEncoderCommand = $application->get('security:encode-password');
$this->passwordEncoderCommandTester = new CommandTester($passwordEncoderCommand);
}
@@ -68,6 +68,6 @@ class WebTestCase extends BaseWebTestCase
protected static function getVarDir()
{
return substr(strrchr(get_called_class(), '\\'), 1);
return 'SB'.substr(strrchr(get_called_class(), '\\'), 1);
}
}
@@ -11,30 +11,6 @@
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\app;
// get the autoload file
$dir = __DIR__;
$lastDir = null;
while ($dir !== $lastDir) {
$lastDir = $dir;
if (is_file($dir.'/autoload.php')) {
require_once $dir.'/autoload.php';
break;
}
if (is_file($dir.'/autoload.php.dist')) {
require_once $dir.'/autoload.php.dist';
break;
}
if (file_exists($dir.'/vendor/autoload.php')) {
require_once $dir.'/vendor/autoload.php';
break;
}
$dir = dirname($dir);
}
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Kernel;
@@ -1,6 +1,3 @@
framework:
templating: { engines: ['twig'] }
# Twig Configuration
twig:
debug: '%kernel.debug%'
@@ -22,12 +22,7 @@ class FirewallContextTest extends TestCase
public function testGetters()
{
$config = new FirewallConfig('main', 'user_checker', 'request_matcher');
$exceptionListener = $this
->getMockBuilder(ExceptionListener::class)
->disableOriginalConstructor()
->getMock();
$exceptionListener = $this->getExceptionListenerMock();
$listeners = array(
$this
->getMockBuilder(ListenerInterface::class)
@@ -37,7 +32,28 @@ class FirewallContextTest extends TestCase
$context = new FirewallContext($listeners, $exceptionListener, $config);
$this->assertEquals(array($listeners, $exceptionListener), $context->getContext());
$this->assertEquals($listeners, $context->getListeners());
$this->assertEquals($exceptionListener, $context->getExceptionListener());
$this->assertEquals($config, $context->getConfig());
}
/**
* @expectedDeprecation Method Symfony\Bundle\SecurityBundle\Security\FirewallContext::getContext() is deprecated since Symfony 3.3 and will be removed in 4.0. Use Symfony\Bundle\SecurityBundle\Security\FirewallContext::getListeners/getExceptionListener() instead.
* @group legacy
*/
public function testGetContext()
{
$context = (new FirewallContext($listeners = array(), $exceptionListener = $this->getExceptionListenerMock(), new FirewallConfig('main', 'request_matcher', 'user_checker')))
->getContext();
$this->assertEquals(array($listeners, $exceptionListener), $context);
}
private function getExceptionListenerMock()
{
return $this
->getMockBuilder(ExceptionListener::class)
->disableOriginalConstructor()
->getMock();
}
}
@@ -12,11 +12,15 @@
namespace Symfony\Bundle\SecurityBundle\Tests\Security;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security\FirewallConfig;
use Symfony\Bundle\SecurityBundle\Security\FirewallContext;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
class FirewallMapTest extends TestCase
{
@@ -58,8 +62,15 @@ class FirewallMapTest extends TestCase
$request = new Request();
$firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock();
$firewallContext->expects($this->once())->method('getConfig')->willReturn('CONFIG');
$firewallContext->expects($this->once())->method('getContext')->willReturn(array('LISTENERS', 'EXCEPTION LISTENER'));
$firewallConfig = new FirewallConfig('main', $this->getMockBuilder(UserCheckerInterface::class)->getMock());
$firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig);
$listener = $this->getMockBuilder(ListenerInterface::class)->getMock();
$firewallContext->expects($this->once())->method('getListeners')->willReturn(array($listener));
$exceptionListener = $this->getMockBuilder(ExceptionListener::class)->disableOriginalConstructor()->getMock();
$firewallContext->expects($this->once())->method('getExceptionListener')->willReturn($exceptionListener);
$matcher = $this->getMockBuilder(RequestMatcherInterface::class)->getMock();
$matcher->expects($this->once())
@@ -72,8 +83,8 @@ class FirewallMapTest extends TestCase
$firewallMap = new FirewallMap($container, array('security.firewall.map.context.foo' => $matcher));
$this->assertEquals(array('LISTENERS', 'EXCEPTION LISTENER'), $firewallMap->getListeners($request));
$this->assertEquals('CONFIG', $firewallMap->getFirewallConfig($request));
$this->assertEquals(array(array($listener), $exceptionListener), $firewallMap->getListeners($request));
$this->assertEquals($firewallConfig, $firewallMap->getFirewallConfig($request));
$this->assertEquals('security.firewall.map.context.foo', $request->attributes->get(self::ATTRIBUTE_FIREWALL_CONTEXT));
}
}