From e5cb483d22175ef1c3a5284506dbe305b9596e8a Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Fri, 31 Jan 2020 12:00:58 -0500 Subject: [PATCH] fix security logout fixture --- src/Maker/MakeForgottenPassword.php | 8 ++++---- src/Renderer/FormTypeRenderer.php | 5 ++++- .../forgottenPassword/ForgottenPasswordController.tpl.php | 8 ++++---- src/Security/SecurityControllerBuilder.php | 2 +- tests/Maker/MakeForgottenPasswordTest.php | 1 + .../fixtures/expected/SecurityController_login_logout.php | 2 +- .../fixtures/expected/SecurityController_logout.php | 2 +- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Maker/MakeForgottenPassword.php b/src/Maker/MakeForgottenPassword.php index 143014118..90a10b1be 100644 --- a/src/Maker/MakeForgottenPassword.php +++ b/src/Maker/MakeForgottenPassword.php @@ -15,23 +15,23 @@ use Symfony\Bundle\MakerBundle\DependencyBuilder; use Symfony\Bundle\MakerBundle\Doctrine\ORMDependencyBuilder; use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; +use Symfony\Bundle\MakerBundle\FileManager; use Symfony\Bundle\MakerBundle\Generator; use Symfony\Bundle\MakerBundle\InputConfiguration; +use Symfony\Bundle\MakerBundle\Renderer\FormTypeRenderer; use Symfony\Bundle\MakerBundle\Security\InteractiveSecurityHelper; use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator; use Symfony\Bundle\SecurityBundle\SecurityBundle; +use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle; use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\EmailType; +use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\RepeatedType; use Symfony\Component\Routing\RouterInterface; -use Symfony\Bundle\MakerBundle\FileManager; -use Symfony\Bundle\MakerBundle\Renderer\FormTypeRenderer; use Symfony\Component\Validator\Validation; -use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle; /** * @author Romaric Drigon diff --git a/src/Renderer/FormTypeRenderer.php b/src/Renderer/FormTypeRenderer.php index 0911201fb..6e0e10f72 100644 --- a/src/Renderer/FormTypeRenderer.php +++ b/src/Renderer/FormTypeRenderer.php @@ -42,6 +42,9 @@ public function render(ClassNameDetails $formClassDetails, array $formFields, Cl $fields[$name] = $fieldTypeOptions; } + $mergedTypeUseStatements = array_merge($fieldTypeUseStatements, $extraUseClasses); + sort($mergedTypeUseStatements); + $this->generator->generateClass( $formClassDetails->getFullName(), 'form/Type.tpl.php', @@ -49,7 +52,7 @@ public function render(ClassNameDetails $formClassDetails, array $formFields, Cl 'bounded_full_class_name' => $boundClassDetails ? $boundClassDetails->getFullName() : null, 'bounded_class_name' => $boundClassDetails ? $boundClassDetails->getShortName() : null, 'form_fields' => $fields, - 'field_type_use_statements' => array_merge($fieldTypeUseStatements, $extraUseClasses), + 'field_type_use_statements' => $mergedTypeUseStatements, 'constraint_use_statements' => $constraintClasses, ] ); diff --git a/src/Resources/skeleton/forgottenPassword/ForgottenPasswordController.tpl.php b/src/Resources/skeleton/forgottenPassword/ForgottenPasswordController.tpl.php index 3947d6dd5..d29214506 100644 --- a/src/Resources/skeleton/forgottenPassword/ForgottenPasswordController.tpl.php +++ b/src/Resources/skeleton/forgottenPassword/ForgottenPasswordController.tpl.php @@ -106,15 +106,15 @@ public function reset(Request $request, UserPasswordEncoderInterface $passwordEn throw $this->createNotFoundException(); } - $passwordResetToken = $this->getDoctrine()->getRepository(PasswordResetToken::class)->findOneBy([ - 'selector' => substr($tokenAndSelector, 0, PasswordResetToken::SELECTOR_LENGTH), + $passwordResetToken = $this->getDoctrine()->getRepository(::class)->findOneBy([ + 'selector' => substr($tokenAndSelector, 0, ::SELECTOR_LENGTH), ]); if (!$passwordResetToken) { throw $this->createNotFoundException(); } - if ($passwordResetToken->isExpired() || !$passwordResetToken->isTokenEquals(substr($tokenAndSelector, PasswordResetToken::SELECTOR_LENGTH))) { + if ($passwordResetToken->isExpired() || !$passwordResetToken->isTokenEquals(substr($tokenAndSelector, ::SELECTOR_LENGTH))) { $this->getDoctrine()->getManager()->remove($passwordResetToken); $this->getDoctrine()->getManager()->flush(); @@ -125,7 +125,7 @@ public function reset(Request $request, UserPasswordEncoderInterface $passwordEn $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - // A PasswordResetToken should be used only once, remove it. + // A should be used only once, remove it. $this->getDoctrine()->getManager()->remove($passwordResetToken); // Encode the plain password, and set it. diff --git a/src/Security/SecurityControllerBuilder.php b/src/Security/SecurityControllerBuilder.php index 3d843bd91..12923fd41 100644 --- a/src/Security/SecurityControllerBuilder.php +++ b/src/Security/SecurityControllerBuilder.php @@ -71,7 +71,7 @@ public function addLogoutMethod(ClassSourceManipulator $manipulator) $manipulator->addUseStatementIfNecessary(Route::class); $manipulator->addMethodBody($logoutMethodBuilder, <<<'CODE' addMethodBuilder($logoutMethodBuilder); diff --git a/tests/Maker/MakeForgottenPasswordTest.php b/tests/Maker/MakeForgottenPasswordTest.php index 8d51c181e..247ee68d7 100644 --- a/tests/Maker/MakeForgottenPasswordTest.php +++ b/tests/Maker/MakeForgottenPasswordTest.php @@ -21,6 +21,7 @@ public function getTestDetails() ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeForgottenPassword') ->configureDatabase() ->updateSchemaAfterCommand() + ->addExtraDependencies('symfony/swiftmailer-bundle') ]; } } diff --git a/tests/Security/fixtures/expected/SecurityController_login_logout.php b/tests/Security/fixtures/expected/SecurityController_login_logout.php index 000eedc6d..ed5a595b7 100644 --- a/tests/Security/fixtures/expected/SecurityController_login_logout.php +++ b/tests/Security/fixtures/expected/SecurityController_login_logout.php @@ -31,6 +31,6 @@ public function login(AuthenticationUtils $authenticationUtils): Response */ public function logout() { - throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall'); + throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); } } diff --git a/tests/Security/fixtures/expected/SecurityController_logout.php b/tests/Security/fixtures/expected/SecurityController_logout.php index cb1ea436a..8efa75143 100644 --- a/tests/Security/fixtures/expected/SecurityController_logout.php +++ b/tests/Security/fixtures/expected/SecurityController_logout.php @@ -12,6 +12,6 @@ class SecurityController extends AbstractController */ public function logout() { - throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall'); + throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); } }