forked from apiato/apiato
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update and tighten password validation rules
- Loading branch information
1 parent
a074e65
commit ff32b1d
Showing
6 changed files
with
131 additions
and
32 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 |
---|---|---|
|
@@ -29,15 +29,15 @@ public function testGivenEmailVerificationEnabled_RegisterNewUserWithCredentials | |
|
||
$data = [ | ||
'email' => '[email protected]', | ||
'password' => 'secretpass', | ||
'password' => 's3cr3tPa$$', | ||
'verification_url' => 'http://some.test/known/url', | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(200); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->has('data') | ||
fn(AssertableJson $json) => $json->has('data') | ||
->where('data.email', $data['email']) | ||
->etc() | ||
); | ||
|
@@ -48,14 +48,14 @@ public function testGivenEmailVerificationDisabled_RegisterNewUserWithCredential | |
config(['appSection-authentication.require_email_verification' => false]); | ||
$data = [ | ||
'email' => '[email protected]', | ||
'password' => 'secretpass', | ||
'password' => 's3cr3tPa$$', | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(200); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->has('data') | ||
fn(AssertableJson $json) => $json->has('data') | ||
->where('data.email', $data['email']) | ||
->etc() | ||
); | ||
|
@@ -72,7 +72,7 @@ public function testRegisterNewUserUsingGetVerb(): void | |
|
||
$response->assertStatus(405); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->has('message') | ||
fn(AssertableJson $json) => $json->has('message') | ||
->where('message', 'The GET method is not supported for this route. Supported methods: POST.') | ||
->etc() | ||
); | ||
|
@@ -96,7 +96,7 @@ public function testRegisterExistingUser(): void | |
|
||
$response->assertStatus(422); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->has('errors') | ||
fn(AssertableJson $json) => $json->has('errors') | ||
->where('errors.email.0', 'The email has already been taken.') | ||
->etc() | ||
); | ||
|
@@ -112,23 +112,21 @@ public function testRegisterNewUserWithoutData(): void | |
|
||
if (config('appSection-authentication.require_email_verification')) { | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->hasAll(['message', 'errors' => 3]) | ||
fn(AssertableJson $json) => $json->hasAll(['message', 'errors' => 3]) | ||
->has( | ||
'errors', | ||
fn (AssertableJson $json) => | ||
$json->where('email.0', 'The email field is required.') | ||
->where('password.0', 'The password field is required.') | ||
->where('verification_url.0', 'The verification url field is required.') | ||
fn(AssertableJson $json) => $json->where('email.0', 'The email field is required.') | ||
->where('password.0', 'The password field is required.') | ||
->where('verification_url.0', 'The verification url field is required.') | ||
) | ||
); | ||
} else { | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->hasAll(['message', 'errors' => 2]) | ||
fn(AssertableJson $json) => $json->hasAll(['message', 'errors' => 2]) | ||
->has( | ||
'errors', | ||
fn (AssertableJson $json) => | ||
$json->where('email.0', 'The email field is required.') | ||
->where('password.0', 'The password field is required.') | ||
fn(AssertableJson $json) => $json->where('email.0', 'The email field is required.') | ||
->where('password.0', 'The password field is required.') | ||
) | ||
); | ||
} | ||
|
@@ -138,19 +136,40 @@ public function testRegisterNewUserWithInvalidEmail(): void | |
{ | ||
$data = [ | ||
'email' => 'missing-at.test', | ||
'password' => 'secret', | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(422); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->has('errors') | ||
fn(AssertableJson $json) => $json->has('errors') | ||
->where('errors.email.0', 'The email must be a valid email address.') | ||
->etc() | ||
); | ||
} | ||
|
||
public function testRegisterNewUserWithInvalidPassword(): void | ||
{ | ||
$data = [ | ||
'password' => '((((()))))', | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(422); | ||
$response->assertJson( | ||
fn(AssertableJson $json) => $json->has('errors') | ||
->has( | ||
'errors.password', | ||
fn(AssertableJson $json) => $json | ||
->where('0', 'The password must contain at least one uppercase and one lowercase letter.') | ||
->where('1', 'The password must contain at least one letter.') | ||
->where('2', 'The password must contain at least one number.') | ||
) | ||
->etc() | ||
); | ||
} | ||
|
||
public function testRegisterNewUserWithNotAllowedVerificationUrl(): void | ||
{ | ||
if (!config('appSection-authentication.require_email_verification')) { | ||
|
@@ -161,15 +180,15 @@ public function testRegisterNewUserWithNotAllowedVerificationUrl(): void | |
|
||
$data = [ | ||
'email' => '[email protected]', | ||
'password' => 'secret', | ||
'password' => 's3cr3tPa$$', | ||
'verification_url' => 'http://notallowed.test/wrong', | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(422); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->hasAll(['message', 'errors' => 1]) | ||
fn(AssertableJson $json) => $json->hasAll(['message', 'errors' => 1]) | ||
->where('errors.verification_url.0', 'The selected verification url is invalid.') | ||
); | ||
} | ||
|
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