Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Authentication/Passwords/NothingPersonalValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ protected function isNotPersonal(string $password, ?User $user): bool
$needles = $this->strip_explode($userName);

// extract local-part and domain parts from email as separate needles
[
$localPart,
$domain,
] = explode('@', $email);
if (str_contains($email, '@')) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str_contains() requires PHP8. So using it here is a bug.
But we use polyfill-php80, so the test does not fail on PHP 7.4.

$ composer why symfony/polyfill-php80
friendsofphp/php-cs-fixer v3.16.0 requires symfony/polyfill-php80 (^1.27)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is a transitive dependency of a dev dependency, so using it here is still a bug.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is a bug, but we cannot detect it by testing.
Why don't we require symfony/polyfill-php80?

[
$localPart,
$domain,
] = explode('@', $email);
} else {
$localPart = $email;
$domain = null;
}
// might be john.doe@example.com and we want all the needles we can get
$emailParts = $this->strip_explode($localPart);
if (! empty($domain)) {
Expand Down
18 changes: 18 additions & 0 deletions tests/Controllers/RegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,24 @@ public function testRegisterActionRedirectsIfLoggedIn(): void
$result->assertRedirectTo(config('Auth')->registerRedirect());
}

public function testRegisterActionWithBadEmailValue(): void
{
$result = $this->withSession()->post('/register', [
'username' => 'JohnDoe',
'email' => 'john.doe',
'password' => '123456789aa',
'password_confirm' => '123456789aa',
]);

$result->assertStatus(302);
$result->assertRedirect();
$result->assertSessionMissing('error');
$result->assertSessionHas(
'errors',
['email' => 'The Email Address field must contain a valid email address.']
);
}

protected function setupConfig(): void
{
$config = config('Validation');
Expand Down
37 changes: 37 additions & 0 deletions tests/Unit/NothingPersonalValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,41 @@ public static function maxSimilarityProvider()
],
];
}

/**
* @dataProvider badEmailsProvider
*/
public function testCheckPasswordWithBadEmail(string $email, bool $expected): void
{
$config = new Auth();
$this->validator = new NothingPersonalValidator($config);

$user = new User([
'username' => 'CaptainJoe',
'email' => $email,
]);

$password = '123456789a';

$result = $this->validator->check($password, $user);

$this->assertSame($expected, $result->isOK());
}

public static function badEmailsProvider()
{
return [
[
'test',
true,
], [
'test@example',
true,
],
[
'test@example.com',
true,
],
];
}
}