Commit 26acd83e authored by Emma's avatar Emma 🦉

fix redirect to login when password is too long

parent 854f9f75
Pipeline #22693508 passed with stage
in 4 minutes and 46 seconds
......@@ -22,13 +22,19 @@ final class PasswordEncodingSubscriber implements EventSubscriberInterface {
}
public function onPostSubmit(FormEvent $event) {
if ($event->getForm()->getErrors()->count() > 0) {
if (!$event->getForm()->isValid()) {
return;
}
/** @var UserData $user */
/* @var UserData $user */
$user = $event->getForm()->getData();
if (!$user instanceof UserData) {
throw new \UnexpectedValueException(
'Form data must be instance of '.UserData::class
);
}
if ($user->getPlainPassword() !== null) {
$encoded = $this->encoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($encoded);
......
......@@ -8,6 +8,27 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
* @covers \App\Controller\UserController
*/
class UserControllerTest extends WebTestCase {
public function testCannotSignUpWithPasswordLongerThan72Characters() {
$client = $this->createClient();
$crawler = $client->request('GET', '/registration');
$password = str_repeat('a', 73);
$form = $crawler->selectButton('user[submit]')->form([
'user[username]' => 'random4',
'user[password][first]' => $password,
'user[password][second]' => $password,
'user[verification]' => 'bypass',
]);
$crawler = $client->submit($form);
$this->assertContains(
'This value is too long. It should have 72 characters or less.',
$crawler->filter('.form__error')->text()
);
}
public function testCanReceiveSubmissionNotifications() {
$client = $this->createEmmaClient();
$crawler = $client->request('GET', '/f/cats/3');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment