Skip to content

Commit

Permalink
Merge pull request #723 from GeorgKott/fix_nothing_personal_validator…
Browse files Browse the repository at this point in the history
…_error

fix: nothing personal validator error with bad email value
  • Loading branch information
kenjis committed May 2, 2023
2 parents 0ceb817 + 57f35b9 commit 1225c80
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
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, '@')) {
[
$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

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 - MySQLi - highest

Took 0.92s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 - Postgre - highest

Took 0.92s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 - SQLite3 - highest

Took 0.82s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 - SQLite3 - highest

Took 0.90s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 - MySQLi - highest

Took 0.93s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - MySQLi - highest

Took 0.85s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - SQLite3 - highest

Took 0.89s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - MySQLi - highest

Took 1.10s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - SQLite3 - highest

Took 1.02s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 - MySQLi - highest

Took 1.21s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 - SQLSRV - highest

Took 1.77s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 297 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 - OCI8 - highest

Took 1.89s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue
{
$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,
],
];
}
}

0 comments on commit 1225c80

Please sign in to comment.