Skip to content

Commit acbd099

Browse files
committed
test: add/update SecurityConfigUpdaterTest
1 parent 5d698fa commit acbd099

File tree

4 files changed

+74
-3
lines changed

4 files changed

+74
-3
lines changed

src/Security/SecurityConfigUpdater.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,15 @@ public function updateForAuthenticator(string $yamlSource, string $firewallName,
114114

115115
if ($supportRememberMe) {
116116
if (!isset($firewall['remember_me'])) {
117+
$firewall['remember_me_empty_line'] = $this->manipulator->createEmptyLine();
117118
$firewall['remember_me'] = [
118119
'secret' => '%kernel.secret%',
119120
'lifetime' => 604800,
120121
'path' => '/',
121122
];
122123
if (!$alwaysRememberMe) {
123124
$firewall['remember_me'][] = $this->manipulator->createCommentLine(' by default, the feature is enabled by checking a checkbox in the');
124-
$firewall['remember_me'][] = $this->manipulator->createCommentLine(' login form (see below), uncomment the following line to always enable it.');
125+
$firewall['remember_me'][] = $this->manipulator->createCommentLine(' login form, uncomment the following line to always enable it.');
125126
}
126127
} else {
127128
$firewall['remember_me']['secret'] ??= '%kernel.secret%';

tests/Security/SecurityConfigUpdaterTest.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ public function getUserClassTests(): \Generator
110110
/**
111111
* @dataProvider getAuthenticatorTests
112112
*/
113-
public function testUpdateForAuthenticator(string $firewallName, $entryPoint, string $expectedSourceFilename, string $startingSourceFilename, bool $logoutSetup): void
113+
public function testUpdateForAuthenticator(string $firewallName, $entryPoint, string $expectedSourceFilename, string $startingSourceFilename, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe): void
114114
{
115115
$this->createLogger();
116116

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

122122
$this->assertSame($expectedSource, $actualSource);
@@ -130,6 +130,8 @@ public function getAuthenticatorTests(): \Generator
130130
'empty_source.yaml',
131131
'empty_security.yaml',
132132
false,
133+
false,
134+
false,
133135
];
134136

135137
yield 'simple_security' => [
@@ -138,6 +140,8 @@ public function getAuthenticatorTests(): \Generator
138140
'simple_security_source.yaml',
139141
'simple_security.yaml',
140142
false,
143+
false,
144+
false,
141145
];
142146

143147
yield 'simple_security_with_firewalls' => [
@@ -146,6 +150,8 @@ public function getAuthenticatorTests(): \Generator
146150
'simple_security_with_firewalls.yaml',
147151
'simple_security_with_firewalls.yaml',
148152
false,
153+
false,
154+
false,
149155
];
150156

151157
yield 'simple_security_with_firewalls_and_authenticator' => [
@@ -154,6 +160,8 @@ public function getAuthenticatorTests(): \Generator
154160
'simple_security_with_firewalls_and_authenticator.yaml',
155161
'simple_security_with_firewalls_and_authenticator.yaml',
156162
false,
163+
false,
164+
false,
157165
];
158166

159167
yield 'simple_security_with_firewalls_and_logout' => [
@@ -162,6 +170,8 @@ public function getAuthenticatorTests(): \Generator
162170
'simple_security_with_firewalls_and_logout.yaml',
163171
'simple_security_with_firewalls_and_logout.yaml',
164172
true,
173+
false,
174+
false,
165175
];
166176

167177
yield 'security_52_with_multiple_authenticators' => [
@@ -170,6 +180,28 @@ public function getAuthenticatorTests(): \Generator
170180
'multiple_authenticators.yaml',
171181
'multiple_authenticators.yaml',
172182
false,
183+
false,
184+
false,
185+
];
186+
187+
yield 'simple_security_with_firewalls_and_remember_me_checkbox' => [
188+
'main',
189+
null,
190+
'simple_security_with_firewalls_and_remember_me_checkbox.yaml',
191+
'simple_security.yaml',
192+
false,
193+
true,
194+
false,
195+
];
196+
197+
yield 'simple_security_with_firewalls_and_always_remember_me' => [
198+
'main',
199+
null,
200+
'simple_security_with_firewalls_and_always_remember_me.yaml',
201+
'simple_security.yaml',
202+
false,
203+
true,
204+
true,
173205
];
174206
}
175207

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
security:
2+
enable_authenticator_manager: true
3+
4+
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
5+
providers:
6+
in_memory: { memory: ~ }
7+
8+
firewalls:
9+
dev: ~
10+
main:
11+
lazy: true
12+
custom_authenticator: App\Security\AppCustomAuthenticator
13+
14+
remember_me:
15+
secret: '%kernel.secret%'
16+
lifetime: 604800
17+
path: /
18+
always_remember_me: true
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
security:
2+
enable_authenticator_manager: true
3+
4+
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
5+
providers:
6+
in_memory: { memory: ~ }
7+
8+
firewalls:
9+
dev: ~
10+
main:
11+
lazy: true
12+
custom_authenticator: App\Security\AppCustomAuthenticator
13+
14+
remember_me:
15+
secret: '%kernel.secret%'
16+
lifetime: 604800
17+
path: /
18+
# by default, the feature is enabled by checking a checkbox in the
19+
# login form, uncomment the following line to always enable it.
20+
#always_remember_me: true

0 commit comments

Comments
 (0)