Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,18 @@ public function load(array $configs, ContainerBuilder $container)

$loader->load('security.xml');

$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);

if ($this->isConfigEnabled($container, $config['form'])) {
$this->formConfigEnabled = true;
$this->registerFormConfiguration($config, $container, $loader);
$config['validation']['enabled'] = true;

if ($this->isConfigEnabled($container, $config['form']['csrf_protection'])) {
$config['csrf_protection']['enabled'] = true;
}
}

$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);

if (isset($config['templating'])) {
$this->registerTemplatingConfiguration($config['templating'], $config['ide'], $container, $loader);
}
Expand Down Expand Up @@ -159,10 +163,6 @@ private function registerFormConfiguration($config, ContainerBuilder $container,
{
$loader->load('form.xml');
if ($this->isConfigEnabled($container, $config['form']['csrf_protection'])) {
if (!$this->isConfigEnabled($container, $config['csrf_protection'])) {
throw new \LogicException('CSRF protection needs to be enabled in order to use CSRF protection for forms.');
}

$loader->load('form_csrf.xml');

$container->setParameter('form.type_extension.csrf.enabled', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ public function testCsrfProtectionNeedsSessionToBeEnabled()
$this->createContainerFromFile('csrf_needs_session');
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage CSRF protection needs to be enabled in order to use CSRF protection for forms.
*/
public function testCsrfProtectionForFormsNeedCsrfProtectionToBeEnabled()
public function testCsrfProtectionForFormsEnablesCsrfProtectionAutomatically()
{
$this->createContainerFromFile('csrf');
$container = $this->createContainerFromFile('csrf');

$this->assertTrue($container->hasDefinition('security.csrf.token_manager'));
}

public function testSecureRandomIsAvailableIfCsrfIsDisabled()
Expand Down