Skip to content

Commit e5cb483

Browse files
jrushlowweaverryan
authored andcommitted
fix security logout fixture
1 parent ccb68bf commit e5cb483

File tree

7 files changed

+16
-12
lines changed

7 files changed

+16
-12
lines changed

src/Maker/MakeForgottenPassword.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1616
use Symfony\Bundle\MakerBundle\Doctrine\ORMDependencyBuilder;
1717
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
18+
use Symfony\Bundle\MakerBundle\FileManager;
1819
use Symfony\Bundle\MakerBundle\Generator;
1920
use Symfony\Bundle\MakerBundle\InputConfiguration;
21+
use Symfony\Bundle\MakerBundle\Renderer\FormTypeRenderer;
2022
use Symfony\Bundle\MakerBundle\Security\InteractiveSecurityHelper;
2123
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
2224
use Symfony\Bundle\SecurityBundle\SecurityBundle;
25+
use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;
2326
use Symfony\Bundle\TwigBundle\TwigBundle;
2427
use Symfony\Component\Console\Command\Command;
2528
use Symfony\Component\Console\Input\InputInterface;
2629
use Symfony\Component\Form\AbstractType;
27-
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
2830
use Symfony\Component\Form\Extension\Core\Type\EmailType;
31+
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
2932
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
3033
use Symfony\Component\Routing\RouterInterface;
31-
use Symfony\Bundle\MakerBundle\FileManager;
32-
use Symfony\Bundle\MakerBundle\Renderer\FormTypeRenderer;
3334
use Symfony\Component\Validator\Validation;
34-
use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;
3535

3636
/**
3737
* @author Romaric Drigon <[email protected]>

src/Renderer/FormTypeRenderer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ public function render(ClassNameDetails $formClassDetails, array $formFields, Cl
4242
$fields[$name] = $fieldTypeOptions;
4343
}
4444

45+
$mergedTypeUseStatements = array_merge($fieldTypeUseStatements, $extraUseClasses);
46+
sort($mergedTypeUseStatements);
47+
4548
$this->generator->generateClass(
4649
$formClassDetails->getFullName(),
4750
'form/Type.tpl.php',
4851
[
4952
'bounded_full_class_name' => $boundClassDetails ? $boundClassDetails->getFullName() : null,
5053
'bounded_class_name' => $boundClassDetails ? $boundClassDetails->getShortName() : null,
5154
'form_fields' => $fields,
52-
'field_type_use_statements' => array_merge($fieldTypeUseStatements, $extraUseClasses),
55+
'field_type_use_statements' => $mergedTypeUseStatements,
5356
'constraint_use_statements' => $constraintClasses,
5457
]
5558
);

src/Resources/skeleton/forgottenPassword/ForgottenPasswordController.tpl.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ public function reset(Request $request, UserPasswordEncoderInterface $passwordEn
106106
throw $this->createNotFoundException();
107107
}
108108

109-
$passwordResetToken = $this->getDoctrine()->getRepository(PasswordResetToken::class)->findOneBy([
110-
'selector' => substr($tokenAndSelector, 0, PasswordResetToken::SELECTOR_LENGTH),
109+
$passwordResetToken = $this->getDoctrine()->getRepository(<?= $token_class_name ?>::class)->findOneBy([
110+
'selector' => substr($tokenAndSelector, 0, <?= $token_class_name ?>::SELECTOR_LENGTH),
111111
]);
112112

113113
if (!$passwordResetToken) {
114114
throw $this->createNotFoundException();
115115
}
116116

117-
if ($passwordResetToken->isExpired() || !$passwordResetToken->isTokenEquals(substr($tokenAndSelector, PasswordResetToken::SELECTOR_LENGTH))) {
117+
if ($passwordResetToken->isExpired() || !$passwordResetToken->isTokenEquals(substr($tokenAndSelector, <?= $token_class_name ?>::SELECTOR_LENGTH))) {
118118
$this->getDoctrine()->getManager()->remove($passwordResetToken);
119119
$this->getDoctrine()->getManager()->flush();
120120

@@ -125,7 +125,7 @@ public function reset(Request $request, UserPasswordEncoderInterface $passwordEn
125125
$form->handleRequest($request);
126126

127127
if ($form->isSubmitted() && $form->isValid()) {
128-
// A PasswordResetToken should be used only once, remove it.
128+
// A <?= $token_class_name ?> should be used only once, remove it.
129129
$this->getDoctrine()->getManager()->remove($passwordResetToken);
130130

131131
// Encode the plain password, and set it.

src/Security/SecurityControllerBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function addLogoutMethod(ClassSourceManipulator $manipulator)
7171
$manipulator->addUseStatementIfNecessary(Route::class);
7272
$manipulator->addMethodBody($logoutMethodBuilder, <<<'CODE'
7373
<?php
74-
throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
74+
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
7575
CODE
7676
);
7777
$manipulator->addMethodBuilder($logoutMethodBuilder);

tests/Maker/MakeForgottenPasswordTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function getTestDetails()
2121
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeForgottenPassword')
2222
->configureDatabase()
2323
->updateSchemaAfterCommand()
24+
->addExtraDependencies('symfony/swiftmailer-bundle')
2425
];
2526
}
2627
}

tests/Security/fixtures/expected/SecurityController_login_logout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public function login(AuthenticationUtils $authenticationUtils): Response
3131
*/
3232
public function logout()
3333
{
34-
throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
34+
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
3535
}
3636
}

tests/Security/fixtures/expected/SecurityController_logout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class SecurityController extends AbstractController
1212
*/
1313
public function logout()
1414
{
15-
throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
15+
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
1616
}
1717
}

0 commit comments

Comments
 (0)