Skip to content

Commit

Permalink
test: add/update SecurityConfigUpdaterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
bechir committed Jun 22, 2023
1 parent c7a9417 commit aca2014
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Security/SecurityConfigUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ public function updateForAuthenticator(string $yamlSource, string $firewallName,

if ($supportRememberMe) {
if (!isset($firewall['remember_me'])) {
$firewall['remember_me_empty_line'] = $this->manipulator->createEmptyLine();
$firewall['remember_me'] = [
'secret' => '%kernel.secret%',
'lifetime' => 604800,
'path' => '/',
];
if (!$alwaysRememberMe) {
$firewall['remember_me'][] = $this->manipulator->createCommentLine(' by default, the feature is enabled by checking a checkbox in the');
$firewall['remember_me'][] = $this->manipulator->createCommentLine(' login form (see below), uncomment the following line to always enable it.');
$firewall['remember_me'][] = $this->manipulator->createCommentLine(' login form, uncomment the following line to always enable it.');
}
} else {
$firewall['remember_me']['secret'] ??= '%kernel.secret%';
Expand Down
37 changes: 36 additions & 1 deletion tests/Security/SecurityConfigUpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,17 @@ public function getUserClassTests(): \Generator
/**
* @dataProvider getAuthenticatorTests
*/
public function testUpdateForAuthenticator(string $firewallName, $entryPoint, string $expectedSourceFilename, string $startingSourceFilename, bool $logoutSetup): void
public function testUpdateForAuthenticator(string $firewallName, $entryPoint, string $expectedSourceFilename, string $startingSourceFilename, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe): void
{
$this->createLogger();

$updater = new SecurityConfigUpdater($this->ysmLogger);
$source = $this->getYamlSource($startingSourceFilename);
$actualSource = $updater->updateForAuthenticator($source, $firewallName, $entryPoint, 'App\\Security\\AppCustomAuthenticator', $logoutSetup);
$expectedSource = $this->getExpectedYaml('expected_authenticator', $expectedSourceFilename);
$source = file_get_contents(__DIR__.'/yaml_fixtures/source/'.$startingSourceFilename);
$actualSource = $updater->updateForAuthenticator($source, $firewallName, $entryPoint, 'App\\Security\\AppCustomAuthenticator', $logoutSetup, $supportRememberMe, $alwaysRememberMe);
$expectedSource = file_get_contents(__DIR__.'/yaml_fixtures/expected_authenticator/'.$expectedSourceFilename);

$this->assertSame($expectedSource, $actualSource);
}
Expand All @@ -124,6 +127,8 @@ public function getAuthenticatorTests(): \Generator
'empty_source.yaml',
'empty_security.yaml',
false,
false,
false,
];

yield 'simple_security' => [
Expand All @@ -132,6 +137,8 @@ public function getAuthenticatorTests(): \Generator
'simple_security_source.yaml',
'simple_security.yaml',
false,
false,
false,
];

yield 'simple_security_with_firewalls' => [
Expand All @@ -140,6 +147,8 @@ public function getAuthenticatorTests(): \Generator
'simple_security_with_firewalls.yaml',
'simple_security_with_firewalls.yaml',
false,
false,
false,
];

yield 'simple_security_with_firewalls_and_authenticator' => [
Expand All @@ -148,6 +157,8 @@ public function getAuthenticatorTests(): \Generator
'simple_security_with_firewalls_and_authenticator.yaml',
'simple_security_with_firewalls_and_authenticator.yaml',
false,
false,
false,
];

yield 'simple_security_with_firewalls_and_logout' => [
Expand All @@ -156,6 +167,8 @@ public function getAuthenticatorTests(): \Generator
'simple_security_with_firewalls_and_logout.yaml',
'simple_security_with_firewalls_and_logout.yaml',
true,
false,
false,
];

yield 'security_52_with_multiple_authenticators' => [
Expand All @@ -164,6 +177,28 @@ public function getAuthenticatorTests(): \Generator
'multiple_authenticators.yaml',
'multiple_authenticators.yaml',
false,
false,
false,
];

yield 'simple_security_with_firewalls_and_remember_me_checkbox' => [
'main',
null,
'simple_security_with_firewalls_and_remember_me_checkbox.yaml',
'simple_security.yaml',
false,
true,
false,
];

yield 'simple_security_with_firewalls_and_always_remember_me' => [
'main',
null,
'simple_security_with_firewalls_and_always_remember_me.yaml',
'simple_security.yaml',
false,
true,
true,
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
security:
enable_authenticator_manager: true

# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
in_memory: { memory: ~ }

firewalls:
dev: ~
main:
lazy: true
custom_authenticator: App\Security\AppCustomAuthenticator

remember_me:
secret: '%kernel.secret%'
lifetime: 604800
path: /
always_remember_me: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
security:
enable_authenticator_manager: true

# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
in_memory: { memory: ~ }

firewalls:
dev: ~
main:
lazy: true
custom_authenticator: App\Security\AppCustomAuthenticator

remember_me:
secret: '%kernel.secret%'
lifetime: 604800
path: /
# by default, the feature is enabled by checking a checkbox in the
# login form, uncomment the following line to always enable it.
#always_remember_me: true

0 comments on commit aca2014

Please sign in to comment.