decrease minimum username length to 3 character (#362)
This commit is contained in:
@@ -4,7 +4,7 @@ App\Entity\User:
|
|||||||
- App\Validator\Constraints\Role: ~
|
- App\Validator\Constraints\Role: ~
|
||||||
username:
|
username:
|
||||||
- NotBlank: ~
|
- NotBlank: ~
|
||||||
- Length: { min: 5, max: 60 }
|
- Length: { min: 3, max: 60 }
|
||||||
email:
|
email:
|
||||||
- NotBlank: ~
|
- NotBlank: ~
|
||||||
- Email: ~
|
- Email: ~
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class CreateUserCommand extends Command
|
|||||||
$pwd = $this->encoder->encodePassword($user, $user->getPlainPassword());
|
$pwd = $this->encoder->encodePassword($user, $user->getPlainPassword());
|
||||||
$user->setPassword($pwd);
|
$user->setPassword($pwd);
|
||||||
|
|
||||||
$errors = $this->validator->validate($user);
|
$errors = $this->validator->validate($user, null, ['registration']);
|
||||||
if ($errors->count() > 0) {
|
if ($errors->count() > 0) {
|
||||||
/** @var \Symfony\Component\Validator\ConstraintViolation $error */
|
/** @var \Symfony\Component\Validator\ConstraintViolation $error */
|
||||||
foreach ($errors as $error) {
|
foreach ($errors as $error) {
|
||||||
@@ -149,13 +149,13 @@ class CreateUserCommand extends Command
|
|||||||
/* @var QuestionHelper $helper */
|
/* @var QuestionHelper $helper */
|
||||||
$helper = $this->getHelper('question');
|
$helper = $this->getHelper('question');
|
||||||
|
|
||||||
$passwordQuestion = new Question('Please enter the password');
|
$passwordQuestion = new Question('Please enter the password: ');
|
||||||
$passwordQuestion->setHidden(true);
|
$passwordQuestion->setHidden(true);
|
||||||
$passwordQuestion->setHiddenFallback(false);
|
$passwordQuestion->setHiddenFallback(false);
|
||||||
$passwordQuestion->setValidator(function (?string $value) {
|
$passwordQuestion->setValidator(function (?string $value) {
|
||||||
$password = trim($value);
|
$password = trim($value);
|
||||||
if (empty($password) || strlen($password) < 6) {
|
if (empty($password)) {
|
||||||
throw new \Exception('The password is too short, must be at least 6 character');
|
throw new \Exception('The password may not be empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ use App\Entity\User;
|
|||||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @coversDefaultClass \App\Command\CreateUserCommand
|
* @coversDefaultClass \App\Command\CreateUserCommand
|
||||||
@@ -36,15 +34,10 @@ class CreateUserCommandTest extends KernelTestCase
|
|||||||
|
|
||||||
$passwordEncoder = $container->get('security.password_encoder');
|
$passwordEncoder = $container->get('security.password_encoder');
|
||||||
|
|
||||||
$validationResult = $this->getMockBuilder(ConstraintViolationListInterface::class)->getMock();
|
|
||||||
$validationResult->method('count')->willReturn(0);
|
|
||||||
$validator = $this->getMockBuilder(ValidatorInterface::class)->getMock();
|
|
||||||
$validator->method('validate')->willReturn($validationResult);
|
|
||||||
|
|
||||||
$this->application->add(new CreateUserCommand(
|
$this->application->add(new CreateUserCommand(
|
||||||
$passwordEncoder,
|
$passwordEncoder,
|
||||||
$container->get('doctrine'),
|
$container->get('doctrine'),
|
||||||
$validator
|
$container->get('validator')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +68,14 @@ class CreateUserCommandTest extends KernelTestCase
|
|||||||
return $commandTester;
|
return $commandTester;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUserWithValidationProblem()
|
||||||
|
{
|
||||||
|
$commandTester = $this->createUser('xx', '', 'ROLE_USER', '');
|
||||||
|
$output = $commandTester->getDisplay();
|
||||||
|
$this->assertContains('[ERROR] plainPassword ()', $output);
|
||||||
|
// TODO the test validator is misconfigured, doesn't find "short username" and "empty email"
|
||||||
|
}
|
||||||
|
|
||||||
public function testUserAlreadyExisting()
|
public function testUserAlreadyExisting()
|
||||||
{
|
{
|
||||||
$this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar');
|
$this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar');
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class UserControllerTest extends ControllerBaseTest
|
|||||||
[
|
[
|
||||||
[
|
[
|
||||||
'user_create' => [
|
'user_create' => [
|
||||||
'username' => 'Test',
|
'username' => 'xx',
|
||||||
'plainPassword' => ['first' => 'sdfsdf', 'second' => 'sdfxxx'],
|
'plainPassword' => ['first' => 'sdfsdf', 'second' => 'sdfxxx'],
|
||||||
'alias' => 'ycvyxcb',
|
'alias' => 'ycvyxcb',
|
||||||
'title' => '34rtwrtewrt',
|
'title' => '34rtwrtewrt',
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class UserTest extends AbstractEntityTest
|
|||||||
return [
|
return [
|
||||||
['', ''],
|
['', ''],
|
||||||
[null, null],
|
[null, null],
|
||||||
['test', 'test@'], // too short username
|
['xx', 'test@'], // too short username
|
||||||
[str_pad('#', 61, '-'), 'test@x.'], // too long username
|
[str_pad('#', 61, '-'), 'test@x.'], // too long username
|
||||||
[str_pad('#', 61, '-'), 'test@x.', ['xxxxx']], // too short password and invalid role
|
[str_pad('#', 61, '-'), 'test@x.', ['xxxxx']], // too short password and invalid role
|
||||||
];
|
];
|
||||||
@@ -51,7 +51,7 @@ class UserTest extends AbstractEntityTest
|
|||||||
public function getValidTestData()
|
public function getValidTestData()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[str_pad('#', 6, '-'), 'test@x.x'], // shortest possible username
|
[str_pad('#', 3, '-'), 'test@x.x'], // shortest possible username
|
||||||
[str_pad('#', 60, '-'), 'test@x.x', ['ROLE_CUSTOMER']], // longest possible password and valid role
|
[str_pad('#', 60, '-'), 'test@x.x', ['ROLE_CUSTOMER']], // longest possible password and valid role
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user