Skip to content

Commit

Permalink
Remove compatibility with 6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
maelanleborgne committed Mar 7, 2024
1 parent ce2bfd3 commit 72784c0
Show file tree
Hide file tree
Showing 16 changed files with 11 additions and 303 deletions.
14 changes: 5 additions & 9 deletions src/Maker/MakeAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Symfony\Bundle\MakerBundle\Security\SecurityControllerBuilder;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
use Symfony\Bundle\MakerBundle\Util\FeatureSupportTrait;
use Symfony\Bundle\MakerBundle\Util\UseStatementGenerator;
use Symfony\Bundle\MakerBundle\Util\YamlManipulationFailedException;
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
Expand Down Expand Up @@ -63,7 +62,6 @@
*/
final class MakeAuthenticator extends AbstractMaker
{
use FeatureSupportTrait;
private const AUTH_TYPE_EMPTY_AUTHENTICATOR = 'empty-authenticator';
private const AUTH_TYPE_FORM_LOGIN = 'form-login';

Expand Down Expand Up @@ -278,7 +276,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$input->hasArgument('logout-setup') ? $input->getArgument('logout-setup') : false,
$supportRememberMe,
$alwaysRememberMe,
$this->supportsLogoutRouteLoader() && !file_exists('config/routes/security.yaml'),
!file_exists('config/routes/security.yaml'),
)
);
}
Expand Down Expand Up @@ -383,10 +381,6 @@ private function generateFormLoginFiles(string $controllerClass, string $userNam

$this->securityControllerBuilder->addLoginMethod($manipulator);

if ($logoutSetup && !$this->supportsLogoutRouteLoader()) {
$this->securityControllerBuilder->addLogoutMethod($manipulator);
}

$this->generator->dumpFile($controllerPath, $manipulator->getSourceCode());

// create login form template
Expand All @@ -404,7 +398,7 @@ private function generateFormLoginFiles(string $controllerClass, string $userNam
);
}

private function generateNextMessage(bool $securityYamlUpdated, string $authenticatorType, string $authenticatorClass, $userClass, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe, bool $defaultSecurityRoute): array
private function generateNextMessage(bool $securityYamlUpdated, string $authenticatorType, string $authenticatorClass, $userClass, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe, bool $hasSecurityRouteFile): array
{
$nextTexts = ['Next:'];
$nextTexts[] = '- Customize your new authenticator.';
Expand Down Expand Up @@ -433,7 +427,9 @@ private function generateNextMessage(bool $securityYamlUpdated, string $authenti
}

// If the security.logout_route_loader is not loaded from the default flex recipe
$nextTexts[] = '- Be sure to add the "logout" route to <info>config/routes/security.yaml</info> or upgrade the <info>symfony/security-bundle</info> recipe.';
if (!$hasSecurityRouteFile) {
$nextTexts[] = '- Be sure to add the "logout" route to <info>config/routes/security.yaml</info> or upgrade the <info>symfony/security-bundle</info> recipe.';
}

return $nextTexts;
}
Expand Down
13 changes: 1 addition & 12 deletions src/Maker/Security/MakeFormLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Symfony\Bundle\MakerBundle\Security\SecurityControllerBuilder;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
use Symfony\Bundle\MakerBundle\Util\FeatureSupportTrait;
use Symfony\Bundle\MakerBundle\Util\UseStatementGenerator;
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
use Symfony\Bundle\MakerBundle\Validator;
Expand All @@ -49,8 +48,6 @@
*/
final class MakeFormLogin extends AbstractMaker
{
use FeatureSupportTrait;

private const SECURITY_CONFIG_PATH = 'config/packages/security.yaml';
private YamlSourceManipulator $ysm;
private string $controllerName;
Expand Down Expand Up @@ -136,7 +133,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$controllerNameDetails = $generator->createClassNameDetails($this->controllerName, 'Controller\\', 'Controller');
$templatePath = strtolower($controllerNameDetails->getRelativeNameWithoutSuffix());

$controllerPath = $generator->generateController(
$generator->generateController(
$controllerNameDetails->getFullName(),
'security/formLogin/LoginController.tpl.php',
[
Expand All @@ -146,14 +143,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
]
);

if ($this->willLogout && !$this->supportsLogoutRouteLoader()) {
$manipulator = new ClassSourceManipulator($generator->getFileContentsForPendingOperation($controllerPath));

$this->securityControllerBuilder->addLogoutMethod($manipulator);

$generator->dumpFile($controllerPath, $manipulator->getSourceCode());
}

$generator->generateTemplate(
sprintf('%s/login.html.twig', $templatePath),
'security/formLogin/login_form.tpl.php',
Expand Down
35 changes: 0 additions & 35 deletions src/Util/FeatureSupportTrait.php

This file was deleted.

44 changes: 0 additions & 44 deletions tests/Maker/MakeAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,50 +269,6 @@ public function getTestDetails(): \Generator
$this->assertFileExists($runner->getPath('templates/security/login.html.twig'));
$this->assertFileExists($runner->getPath('src/Security/AppCustomAuthenticator.php'));

$securityConfig = $runner->readYaml('config/packages/security.yaml');
$this->assertEquals(
'app_logout',
$securityConfig['security']['firewalls']['main']['logout']['path']
);
}),
];

yield 'auth_login_form_user_entity_with_logout_route_loader' => [$this->createMakerTest()
->addExtraDependencies('doctrine', 'twig', 'symfony/form')
->run(function (MakerTestRunner $runner) {
$this->makeUser($runner, 'userEmail');
// We pretend that the LogoutRouteLoader is registered
$runner->addToAutoloader('Symfony\\Bundle\\SecurityBundle\\Routing\\', \dirname(__DIR__).'/fixtures/security-bundle/routing/');
$runner->modifyYamlFile('config/services.yaml', function (array $config) {
$config['services']['security.route_loader.logout'] = [
'class' => 'Symfony\Bundle\SecurityBundle\\Routing\\LogoutRouteLoader',
'tags' => ['routing.route_loader'],
];

return $config;
});
$output = $runner->runMaker([
// authenticator type => login-form
1,
// class name
'AppCustomAuthenticator',
// controller name
'SecurityController',
// logout support
'yes',
// remember me support => no
'no',
]);

$this->runLoginTest($runner, 'userEmail', true, 'App\\Entity\\User', true);

$this->assertStringContainsString('Success', $output);

$this->assertFileExists($runner->getPath('src/Controller/SecurityController.php'));
$this->assertFileEquals(\dirname(__DIR__).'/fixtures/make-auth/SecurityController-no-logout.php', $runner->getPath('src/Controller/SecurityController.php'));
$this->assertFileExists($runner->getPath('templates/security/login.html.twig'));
$this->assertFileExists($runner->getPath('src/Security/AppCustomAuthenticator.php'));

$securityConfig = $runner->readYaml('config/packages/security.yaml');
$this->assertEquals(
'/logout',
Expand Down
28 changes: 2 additions & 26 deletions tests/Maker/Security/MakeFormLoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getTestDetails(): \Generator
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['login_path']);
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['check_path']);
$this->assertTrue($securityConfig['security']['firewalls']['main']['form_login']['enable_csrf']);
$this->assertSame('app_logout', $securityConfig['security']['firewalls']['main']['logout']['path']);
$this->assertSame('/logout', $securityConfig['security']['firewalls']['main']['logout']['path']);

$this->runLoginTest($runner);
}),
Expand All @@ -66,7 +66,7 @@ public function getTestDetails(): \Generator
$this->assertStringContainsString('Success', $output);
$fixturePath = \dirname(__DIR__, 2).'/fixtures/security/make-form-login/expected';

$this->assertFileEquals($fixturePath.'/SecurityControllerWithoutLogout.php', $runner->getPath('src/Controller/SecurityController.php'));
$this->assertFileEquals($fixturePath.'/SecurityController.php', $runner->getPath('src/Controller/SecurityController.php'));
$this->assertFileEquals($fixturePath.'/login_no_logout.html.twig', $runner->getPath('templates/security/login.html.twig'));

$securityConfig = $runner->readYaml('config/packages/security.yaml');
Expand Down Expand Up @@ -94,30 +94,6 @@ public function getTestDetails(): \Generator

$securityConfig = $runner->readYaml('config/packages/security.yaml');

$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['login_path']);
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['check_path']);
$this->assertSame('app_logout', $securityConfig['security']['firewalls']['main']['logout']['path']);
}),
];

yield 'generates_form_login_with_logout_with_route_loader' => [$this->createMakerTest()
->run(function (MakerTestRunner $runner) {
// We pretend that the LogoutRouteLoader is registered
$runner->addToAutoloader('Symfony\\Bundle\\SecurityBundle\\Routing\\', \dirname(__DIR__, 2).'/fixtures/security-bundle/routing');
$this->makeUser($runner);
$output = $runner->runMaker([
'SecurityController', // Controller Name
'y', // Generate Logout
]);

$this->assertStringContainsString('Success', $output);
$fixturePath = \dirname(__DIR__, 2).'/fixtures/security/make-form-login/expected';

$this->assertFileEquals($fixturePath.'/SecurityControllerLogoutRouteLoader.php', $runner->getPath('src/Controller/SecurityController.php'));
$this->assertFileEquals($fixturePath.'/login_routeloader_logout.html.twig', $runner->getPath('templates/security/login.html.twig'));

$securityConfig = $runner->readYaml('config/packages/security.yaml');

$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['login_path']);
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['check_path']);
$this->assertSame('/logout', $securityConfig['security']['firewalls']['main']['logout']['path']);
Expand Down
16 changes: 1 addition & 15 deletions tests/Security/SecurityConfigUpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,11 @@ public function getUserClassTests(): \Generator
/**
* @dataProvider getAuthenticatorTests
*/
public function testUpdateForAuthenticator(string $firewallName, $entryPoint, string $expectedSourceFilename, string $startingSourceFilename, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe, bool $useLogoutRouteLoader = false): 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);
if ($useLogoutRouteLoader) {
$updater->forceSupportLogoutRouteLoader();
}
$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);
Expand Down Expand Up @@ -200,17 +197,6 @@ public function getAuthenticatorTests(): \Generator
true,
true,
];

yield 'simple_security_with_firewalls_and_logout_via_loader' => [
'main',
'App\\Security\\AppCustomAuthenticator',
'simple_security_with_firewalls_and_logout_via_loader.yaml',
'simple_security_with_firewalls_and_logout.yaml',
true,
false,
false,
true,
];
}

public function testUpdateForFormLogin(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ security:
# the entry_point start() method determines what happens when an anonymous user accesses a protected page
entry_point: App\Security\AppCustomAuthenticator
logout:
path: app_logout
path: /logout
# where to redirect after logout
# target: app_any_route

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Security/yaml_fixtures/expected_logout/logout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ security:
main:
lazy: true
logout:
path: app_logout
path: /logout
# where to redirect after logout
# target: app_any_route
26 changes: 0 additions & 26 deletions tests/fixtures/make-auth/SecurityController-no-logout.php

This file was deleted.

7 changes: 0 additions & 7 deletions tests/fixtures/security-bundle/routing/LogoutRouteLoader.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,4 @@ public function login(AuthenticationUtils $authenticationUtils): Response
'error' => $error,
]);
}

#[Route(path: '/logout', name: 'app_logout')]
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,4 @@ public function login(AuthenticationUtils $authenticationUtils): Response
'error' => $error,
]);
}

#[Route(path: '/logout', name: 'app_logout')]
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}

This file was deleted.

0 comments on commit 72784c0

Please sign in to comment.