Skip to content

Commit 49639ca

Browse files
committed
[Security] Run functional tests also for the authenticator system
1 parent 080eef0 commit 49639ca

34 files changed

+337
-174
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/Functional/AbstractWebTestCase.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public static function tearDownAfterClass(): void
3333
static::deleteTmpDir();
3434
}
3535

36+
public function provideSecuritySystems()
37+
{
38+
yield [['enable_authenticator_manager' => true]];
39+
yield [['enable_authenticator_manager' => false]];
40+
}
41+
3642
protected static function deleteTmpDir()
3743
{
3844
if (!file_exists($dir = sys_get_temp_dir().'/'.static::getVarDir())) {
@@ -61,9 +67,10 @@ protected static function createKernel(array $options = []): KernelInterface
6167
return new $class(
6268
static::getVarDir(),
6369
$options['test_case'],
64-
isset($options['root_config']) ? $options['root_config'] : 'config.yml',
65-
isset($options['environment']) ? $options['environment'] : strtolower(static::getVarDir().$options['test_case']),
66-
isset($options['debug']) ? $options['debug'] : false
70+
$options['root_config'] ?? 'config.yml',
71+
$options['environment'] ?? strtolower(static::getVarDir().$options['test_case']),
72+
$options['debug'] ?? false,
73+
$options['enable_authenticator_manager'] ?? false
6774
);
6875
}
6976

src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@
1313

1414
class AuthenticationCommencingTest extends AbstractWebTestCase
1515
{
16-
public function testAuthenticationIsCommencingIfAccessDeniedExceptionIsWrapped()
16+
/**
17+
* @dataProvider provideClientOptions
18+
*/
19+
public function testAuthenticationIsCommencingIfAccessDeniedExceptionIsWrapped(array $options)
1720
{
18-
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => 'config.yml']);
21+
$client = $this->createClient($options);
1922

2023
$client->request('GET', '/secure-but-not-covered-by-access-control');
2124
$this->assertRedirect($client->getResponse(), '/login');
2225
}
26+
27+
public function provideClientOptions()
28+
{
29+
yield [['test_case' => 'StandardFormLogin', 'root_config' => 'config.yml', 'enable_authenticator_manager' => true]];
30+
yield [['test_case' => 'StandardFormLogin', 'root_config' => 'legacy_config.yml', 'enable_authenticator_manager' => false]];
31+
}
2332
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/ClearRememberMeTest.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
class ClearRememberMeTest extends AbstractWebTestCase
2121
{
22-
public function testUserChangeClearsCookie()
22+
/**
23+
* @dataProvider provideClientOptions
24+
*/
25+
public function testUserChangeClearsCookie(array $options)
2326
{
24-
$client = $this->createClient(['test_case' => 'ClearRememberMe', 'root_config' => 'config.yml']);
27+
$client = $this->createClient($options);
2528

2629
$client->request('POST', '/login', [
2730
'_username' => 'johannes',
@@ -36,6 +39,12 @@ public function testUserChangeClearsCookie()
3639
$this->assertRedirect($client->getResponse(), '/login');
3740
$this->assertNull($cookieJar->get('REMEMBERME'));
3841
}
42+
43+
public function provideClientOptions()
44+
{
45+
yield [['test_case' => 'ClearRememberMe', 'root_config' => 'config.yml', 'enable_authenticator_manager' => true]];
46+
yield [['test_case' => 'ClearRememberMe', 'root_config' => 'legacy_config.yml', 'enable_authenticator_manager' => false]];
47+
}
3948
}
4049

4150
class RememberMeFooController

src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php

+21-17
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
class CsrfFormLoginTest extends AbstractWebTestCase
1515
{
1616
/**
17-
* @dataProvider getConfigs
17+
* @dataProvider provideClientOptions
1818
*/
19-
public function testFormLoginAndLogoutWithCsrfTokens($config)
19+
public function testFormLoginAndLogoutWithCsrfTokens($options)
2020
{
21-
$client = $this->createClient(['test_case' => 'CsrfFormLogin', 'root_config' => $config]);
21+
$client = $this->createClient($options);
2222

2323
$form = $client->request('GET', '/login')->selectButton('login')->form();
2424
$form['user_login[username]'] = 'johannes';
@@ -44,13 +44,17 @@ public function testFormLoginAndLogoutWithCsrfTokens($config)
4444
}
4545

4646
/**
47-
* @dataProvider getConfigs
47+
* @dataProvider provideClientOptions
4848
*/
49-
public function testFormLoginWithInvalidCsrfToken($config)
49+
public function testFormLoginWithInvalidCsrfToken($options)
5050
{
51-
$client = $this->createClient(['test_case' => 'CsrfFormLogin', 'root_config' => $config]);
51+
$client = $this->createClient($options);
5252

5353
$form = $client->request('GET', '/login')->selectButton('login')->form();
54+
if ($options['enable_authenticator_manager'] ?? false) {
55+
$form['user_login[username]'] = 'johannes';
56+
$form['user_login[password]'] = 'test';
57+
}
5458
$form['user_login[_token]'] = '';
5559
$client->submit($form);
5660

@@ -61,11 +65,11 @@ public function testFormLoginWithInvalidCsrfToken($config)
6165
}
6266

6367
/**
64-
* @dataProvider getConfigs
68+
* @dataProvider provideClientOptions
6569
*/
66-
public function testFormLoginWithCustomTargetPath($config)
70+
public function testFormLoginWithCustomTargetPath($options)
6771
{
68-
$client = $this->createClient(['test_case' => 'CsrfFormLogin', 'root_config' => $config]);
72+
$client = $this->createClient($options);
6973

7074
$form = $client->request('GET', '/login')->selectButton('login')->form();
7175
$form['user_login[username]'] = 'johannes';
@@ -81,11 +85,11 @@ public function testFormLoginWithCustomTargetPath($config)
8185
}
8286

8387
/**
84-
* @dataProvider getConfigs
88+
* @dataProvider provideClientOptions
8589
*/
86-
public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
90+
public function testFormLoginRedirectsToProtectedResourceAfterLogin($options)
8791
{
88-
$client = $this->createClient(['test_case' => 'CsrfFormLogin', 'root_config' => $config]);
92+
$client = $this->createClient($options);
8993

9094
$client->request('GET', '/protected-resource');
9195
$this->assertRedirect($client->getResponse(), '/login');
@@ -101,11 +105,11 @@ public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
101105
$this->assertStringContainsString('You\'re browsing to path "/protected-resource".', $text);
102106
}
103107

104-
public function getConfigs()
108+
public function provideClientOptions()
105109
{
106-
return [
107-
['config.yml'],
108-
['routes_as_path.yml'],
109-
];
110+
yield [['test_case' => 'CsrfFormLogin', 'root_config' => 'config.yml', 'enable_authenticator_manager' => true]];
111+
yield [['test_case' => 'CsrfFormLogin', 'root_config' => 'legacy_config.yml', 'enable_authenticator_manager' => false]];
112+
yield [['test_case' => 'CsrfFormLogin', 'root_config' => 'routes_as_path.yml', 'enable_authenticator_manager' => true]];
113+
yield [['test_case' => 'CsrfFormLogin', 'root_config' => 'legacy_routes_as_path.yml', 'enable_authenticator_manager' => false]];
110114
}
111115
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ public function testItUsesTheConfiguredEntryPointWhenUsingUnknownCredentials()
3131
);
3232
}
3333

34-
public function testItUsesTheConfiguredEntryPointFromTheExceptionListenerWithFormLoginAndNoCredentials()
34+
/**
35+
* @dataProvider provideSecuritySystems
36+
*/
37+
public function testItUsesTheConfiguredEntryPointFromTheExceptionListenerWithFormLoginAndNoCredentials(array $options)
3538
{
36-
$client = $this->createClient(['test_case' => 'FirewallEntryPoint', 'root_config' => 'config_form_login.yml']);
39+
$client = $this->createClient($options + ['test_case' => 'FirewallEntryPoint', 'root_config' => 'config_form_login.yml']);
3740

3841
$client->request('GET', '/secure/resource');
3942

src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
class FormLoginTest extends AbstractWebTestCase
1515
{
1616
/**
17-
* @dataProvider getConfigs
17+
* @dataProvider provideClientOptions
1818
*/
19-
public function testFormLogin($config)
19+
public function testFormLogin(array $options)
2020
{
21-
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config]);
21+
$client = $this->createClient($options);
2222

2323
$form = $client->request('GET', '/login')->selectButton('login')->form();
2424
$form['_username'] = 'johannes';
@@ -33,11 +33,11 @@ public function testFormLogin($config)
3333
}
3434

3535
/**
36-
* @dataProvider getConfigs
36+
* @dataProvider provideClientOptions
3737
*/
38-
public function testFormLogout($config)
38+
public function testFormLogout(array $options)
3939
{
40-
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config]);
40+
$client = $this->createClient($options);
4141

4242
$form = $client->request('GET', '/login')->selectButton('login')->form();
4343
$form['_username'] = 'johannes';
@@ -66,11 +66,11 @@ public function testFormLogout($config)
6666
}
6767

6868
/**
69-
* @dataProvider getConfigs
69+
* @dataProvider provideClientOptions
7070
*/
71-
public function testFormLoginWithCustomTargetPath($config)
71+
public function testFormLoginWithCustomTargetPath(array $options)
7272
{
73-
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config]);
73+
$client = $this->createClient($options);
7474

7575
$form = $client->request('GET', '/login')->selectButton('login')->form();
7676
$form['_username'] = 'johannes';
@@ -86,11 +86,11 @@ public function testFormLoginWithCustomTargetPath($config)
8686
}
8787

8888
/**
89-
* @dataProvider getConfigs
89+
* @dataProvider provideClientOptions
9090
*/
91-
public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
91+
public function testFormLoginRedirectsToProtectedResourceAfterLogin(array $options)
9292
{
93-
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config]);
93+
$client = $this->createClient($options);
9494

9595
$client->request('GET', '/protected_resource');
9696
$this->assertRedirect($client->getResponse(), '/login');
@@ -106,11 +106,11 @@ public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
106106
$this->assertStringContainsString('You\'re browsing to path "/protected_resource".', $text);
107107
}
108108

109-
public function getConfigs()
109+
public function provideClientOptions()
110110
{
111-
return [
112-
['config.yml'],
113-
['routes_as_path.yml'],
114-
];
111+
yield [['test_case' => 'StandardFormLogin', 'root_config' => 'config.yml', 'enable_authenticator_manager' => true]];
112+
yield [['test_case' => 'StandardFormLogin', 'root_config' => 'legacy_config.yml', 'enable_authenticator_manager' => false]];
113+
yield [['test_case' => 'StandardFormLogin', 'root_config' => 'routes_as_path.yml', 'enable_authenticator_manager' => true]];
114+
yield [['test_case' => 'StandardFormLogin', 'root_config' => 'legacy_routes_as_path.yml', 'enable_authenticator_manager' => false]];
115115
}
116116
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/JsonLoginTest.php

+25-10
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
*/
1919
class JsonLoginTest extends AbstractWebTestCase
2020
{
21-
public function testDefaultJsonLoginSuccess()
21+
/**
22+
* @dataProvider provideSecuritySystems
23+
*/
24+
public function testDefaultJsonLoginSuccess(array $options)
2225
{
23-
$client = $this->createClient(['test_case' => 'JsonLogin', 'root_config' => 'config.yml']);
26+
$client = $this->createClient($options + ['test_case' => 'JsonLogin', 'root_config' => 'config.yml']);
2427
$client->request('POST', '/chk', [], [], ['CONTENT_TYPE' => 'application/json'], '{"user": {"login": "dunglas", "password": "foo"}}');
2528
$response = $client->getResponse();
2629

@@ -29,9 +32,12 @@ public function testDefaultJsonLoginSuccess()
2932
$this->assertSame(['message' => 'Welcome @dunglas!'], json_decode($response->getContent(), true));
3033
}
3134

32-
public function testDefaultJsonLoginFailure()
35+
/**
36+
* @dataProvider provideSecuritySystems
37+
*/
38+
public function testDefaultJsonLoginFailure(array $options)
3339
{
34-
$client = $this->createClient(['test_case' => 'JsonLogin', 'root_config' => 'config.yml']);
40+
$client = $this->createClient($options + ['test_case' => 'JsonLogin', 'root_config' => 'config.yml']);
3541
$client->request('POST', '/chk', [], [], ['CONTENT_TYPE' => 'application/json'], '{"user": {"login": "dunglas", "password": "bad"}}');
3642
$response = $client->getResponse();
3743

@@ -40,9 +46,12 @@ public function testDefaultJsonLoginFailure()
4046
$this->assertSame(['error' => 'Invalid credentials.'], json_decode($response->getContent(), true));
4147
}
4248

43-
public function testCustomJsonLoginSuccess()
49+
/**
50+
* @dataProvider provideSecuritySystems
51+
*/
52+
public function testCustomJsonLoginSuccess(array $options)
4453
{
45-
$client = $this->createClient(['test_case' => 'JsonLogin', 'root_config' => 'custom_handlers.yml']);
54+
$client = $this->createClient($options + ['test_case' => 'JsonLogin', 'root_config' => 'custom_handlers.yml']);
4655
$client->request('POST', '/chk', [], [], ['CONTENT_TYPE' => 'application/json'], '{"user": {"login": "dunglas", "password": "foo"}}');
4756
$response = $client->getResponse();
4857

@@ -51,9 +60,12 @@ public function testCustomJsonLoginSuccess()
5160
$this->assertSame(['message' => 'Good game @dunglas!'], json_decode($response->getContent(), true));
5261
}
5362

54-
public function testCustomJsonLoginFailure()
63+
/**
64+
* @dataProvider provideSecuritySystems
65+
*/
66+
public function testCustomJsonLoginFailure(array $options)
5567
{
56-
$client = $this->createClient(['test_case' => 'JsonLogin', 'root_config' => 'custom_handlers.yml']);
68+
$client = $this->createClient($options + ['test_case' => 'JsonLogin', 'root_config' => 'custom_handlers.yml']);
5769
$client->request('POST', '/chk', [], [], ['CONTENT_TYPE' => 'application/json'], '{"user": {"login": "dunglas", "password": "bad"}}');
5870
$response = $client->getResponse();
5971

@@ -62,9 +74,12 @@ public function testCustomJsonLoginFailure()
6274
$this->assertSame(['message' => 'Something went wrong'], json_decode($response->getContent(), true));
6375
}
6476

65-
public function testDefaultJsonLoginBadRequest()
77+
/**
78+
* @dataProvider provideSecuritySystems
79+
*/
80+
public function testDefaultJsonLoginBadRequest(array $options)
6681
{
67-
$client = $this->createClient(['test_case' => 'JsonLogin', 'root_config' => 'config.yml']);
82+
$client = $this->createClient($options + ['test_case' => 'JsonLogin', 'root_config' => 'config.yml']);
6883
$client->request('POST', '/chk', [], [], ['CONTENT_TYPE' => 'application/json'], 'Not a json content');
6984
$response = $client->getResponse();
7085

src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php

+17-14
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
class LocalizedRoutesAsPathTest extends AbstractWebTestCase
1515
{
1616
/**
17-
* @dataProvider getLocales
17+
* @dataProvider getLocalesAndClientConfig
1818
*/
19-
public function testLoginLogoutProcedure($locale)
19+
public function testLoginLogoutProcedure($locale, array $options)
2020
{
21-
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes.yml']);
21+
$client = $this->createClient(['test_case' => 'StandardFormLogin'] + $options);
2222

2323
$crawler = $client->request('GET', '/'.$locale.'/login');
2424
$form = $crawler->selectButton('login')->form();
@@ -36,11 +36,11 @@ public function testLoginLogoutProcedure($locale)
3636

3737
/**
3838
* @group issue-32995
39-
* @dataProvider getLocales
39+
* @dataProvider getLocalesAndClientConfig
4040
*/
41-
public function testLoginFailureWithLocalizedFailurePath($locale)
41+
public function testLoginFailureWithLocalizedFailurePath($locale, array $options)
4242
{
43-
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => 'localized_form_failure_handler.yml']);
43+
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => ($options['enable_authenticator_manager'] ? '' : 'legacy_').'localized_form_failure_handler.yml'] + $options);
4444

4545
$crawler = $client->request('GET', '/'.$locale.'/login');
4646
$form = $crawler->selectButton('login')->form();
@@ -52,29 +52,32 @@ public function testLoginFailureWithLocalizedFailurePath($locale)
5252
}
5353

5454
/**
55-
* @dataProvider getLocales
55+
* @dataProvider getLocalesAndClientConfig
5656
*/
57-
public function testAccessRestrictedResource($locale)
57+
public function testAccessRestrictedResource($locale, array $options)
5858
{
59-
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes.yml']);
59+
$client = $this->createClient(['test_case' => 'StandardFormLogin'] + $options);
6060

6161
$client->request('GET', '/'.$locale.'/secure/');
6262
$this->assertRedirect($client->getResponse(), '/'.$locale.'/login');
6363
}
6464

6565
/**
66-
* @dataProvider getLocales
66+
* @dataProvider getLocalesAndClientConfig
6767
*/
68-
public function testAccessRestrictedResourceWithForward($locale)
68+
public function testAccessRestrictedResourceWithForward($locale, array $options)
6969
{
70-
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes_with_forward.yml']);
70+
$client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes_with_forward.yml'] + $options);
7171

7272
$crawler = $client->request('GET', '/'.$locale.'/secure/');
7373
$this->assertCount(1, $crawler->selectButton('login'), (string) $client->getResponse());
7474
}
7575

76-
public function getLocales()
76+
public function getLocalesAndClientConfig()
7777
{
78-
return [['en'], ['de']];
78+
yield ['en', ['enable_authenticator_manager' => true, 'root_config' => 'localized_routes.yml']];
79+
yield ['en', ['enable_authenticator_manager' => false, 'root_config' => 'legacy_localized_routes.yml']];
80+
yield ['de', ['enable_authenticator_manager' => true, 'root_config' => 'localized_routes.yml']];
81+
yield ['de', ['enable_authenticator_manager' => false, 'root_config' => 'legacy_localized_routes.yml']];
7982
}
8083
}

0 commit comments

Comments
 (0)