This repository has been archived by the owner on Oct 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: case insensitive login & store lowercase email (#175)
- Loading branch information
1 parent
4ad7681
commit 2e32335
Showing
6 changed files
with
118 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,36 @@ | |
$this->assertTrue(Hash::check($this->validPassword, $user->password)); | ||
}); | ||
|
||
it('should create user and force lowercase email', function () { | ||
Config::set('fortify.models.user', \ARKEcosystem\Fortify\Models\User::class); | ||
|
||
$user = (new CreateNewUser())->create([ | ||
'name' => 'John Doe', | ||
'username' => 'alfonsobries', | ||
'email' => '[email protected]', | ||
'password' => $this->validPassword, | ||
'password_confirmation' => $this->validPassword, | ||
'terms' => true, | ||
]); | ||
|
||
$this->assertSame('[email protected]', $user->email); | ||
$this->assertSame('John Doe', $user->name); | ||
$this->assertTrue(Hash::check($this->validPassword, $user->password)); | ||
}); | ||
|
||
it('should not create user with uppercase characters', function () { | ||
Config::set('fortify.models.user', \ARKEcosystem\Fortify\Models\User::class); | ||
|
||
expectValidationError(fn () => (new CreateNewUser())->create([ | ||
'name' => 'John Doe', | ||
'username' => 'JOHNDOE', | ||
'email' => '[email protected]', | ||
'password' => 'sec$r2t12345', | ||
'password_confirmation' => 'sec$r2t12345', | ||
'terms' => true, | ||
]), 'username', trans('fortify::validation.messages.username.lowercase_only')); | ||
}); | ||
|
||
it('should create a valid user with username if the username_alt setting is set', function () { | ||
Config::set('fortify.models.user', \ARKEcosystem\Fortify\Models\User::class); | ||
Config::set('fortify.username_alt', 'username'); | ||
|
@@ -107,7 +137,7 @@ | |
]), 'terms', 'The terms must be accepted.'); | ||
}); | ||
|
||
it('should match the confirmation', function () { | ||
it('password should match the confirmation', function () { | ||
Config::set('fortify.models.user', \ARKEcosystem\Fortify\Models\User::class); | ||
|
||
expectValidationError(fn () => (new CreateNewUser())->create([ | ||
|
@@ -120,7 +150,7 @@ | |
]), 'password', 'The password confirmation does not match.'); | ||
}); | ||
|
||
it('should be equal to or longer than 12 characters', function () { | ||
it('password should be equal to or longer than 12 characters', function () { | ||
Config::set('fortify.models.user', \ARKEcosystem\Fortify\Models\User::class); | ||
|
||
expectValidationError(fn () => (new CreateNewUser())->create([ | ||
|
@@ -133,7 +163,7 @@ | |
]), 'password', 'The password must be at least 12 characters.'); | ||
}); | ||
|
||
it('should require an uppercase letter', function () { | ||
it('password should require an uppercase letter', function () { | ||
Config::set('fortify.models.user', \ARKEcosystem\Fortify\Models\User::class); | ||
|
||
expectValidationError(fn () => (new CreateNewUser())->create([ | ||
|
@@ -146,7 +176,7 @@ | |
]), 'password', 'The password must contain at least one uppercase and one lowercase letter.'); | ||
}); | ||
|
||
it('should require one number', function () { | ||
it('password should require one number', function () { | ||
Config::set('fortify.models.user', \ARKEcosystem\Fortify\Models\User::class); | ||
|
||
expectValidationError(fn () => (new CreateNewUser())->create([ | ||
|
@@ -159,7 +189,7 @@ | |
]), 'password', 'The password must contain at least one number.'); | ||
}); | ||
|
||
it('should require one special character', function () { | ||
it('password should require one special character', function () { | ||
Config::set('fortify.models.user', \ARKEcosystem\Fortify\Models\User::class); | ||
|
||
expectValidationError(fn () => (new CreateNewUser())->create([ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,38 @@ | |
expect($user->email_verified_at)->toBeNull(); | ||
}); | ||
|
||
it('should update with lowercase email', function () { | ||
$user = createUserModel(UserWithoutVerification::class); | ||
|
||
expect($user->name)->toBe('John Doe'); | ||
expect($user->email)->toBe('[email protected]'); | ||
|
||
resolve(UpdateUserProfileInformation::class)->update($user, [ | ||
'name' => 'Jane Doe', | ||
'email' => '[email protected]', | ||
]); | ||
|
||
expect($user->name)->toBe('Jane Doe'); | ||
expect($user->email)->toBe('[email protected]'); | ||
}); | ||
|
||
it('should update with lowercase email for a user that requires verification', function () { | ||
$user = createUserModel(UserWithNotifications::class); | ||
|
||
expect($user->name)->toBe('John Doe'); | ||
expect($user->email)->toBe('[email protected]'); | ||
expect($user->email_verified_at)->not()->toBeNull(); | ||
|
||
resolve(UpdateUserProfileInformation::class)->update($user, [ | ||
'name' => 'Jane Doe', | ||
'email' => '[email protected]', | ||
]); | ||
|
||
expect($user->name)->toBe('Jane Doe'); | ||
expect($user->email)->toBe('[email protected]'); | ||
expect($user->email_verified_at)->toBeNull(); | ||
}); | ||
|
||
it('should throw an exception if the name is missing', function () { | ||
$user = createUserModel(); | ||
|
||
|