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.
fix(refresh_token): given
refresh_token
not provided, now throws pr…
…oper validation errors instead of 500
- Loading branch information
1 parent
361309a
commit 059ec24
Showing
5 changed files
with
49 additions
and
25 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 |
---|---|---|
|
@@ -2,8 +2,9 @@ | |
|
||
namespace App\Containers\AppSection\Authentication\UI\API\Tests\Functional; | ||
|
||
use App\Containers\AppSection\Authentication\Exceptions\RefreshTokenMissedException; | ||
use App\Containers\AppSection\Authentication\Exceptions\RefreshTokenMissingException; | ||
use App\Containers\AppSection\Authentication\UI\API\Tests\ApiTestCase; | ||
use Illuminate\Testing\Fluent\AssertableJson; | ||
|
||
/** | ||
* Class ApiRefreshProxyForWebClientTest | ||
|
@@ -17,30 +18,37 @@ class ApiRefreshProxyForWebClientTest extends ApiTestCase | |
|
||
private array $data; | ||
|
||
protected function setUp(): void | ||
public function testRequestingRefreshTokenWithoutPassingARefreshTokenShouldThrowAnException(): void | ||
{ | ||
parent::setUp(); | ||
$data = []; | ||
|
||
$this->data = [ | ||
'email' => '[email protected]', | ||
'password' => 'testing_pass', | ||
]; | ||
$response = $this->makeCall($data); | ||
|
||
$this->getTestingUser($this->data); | ||
$this->actingAs($this->testingUser, 'web'); | ||
$response->assertStatus(400); | ||
$message = (new RefreshTokenMissingException())->getMessage(); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->has('message') | ||
->where('message', $message) | ||
->etc() | ||
); | ||
} | ||
|
||
public function testRequestingRefreshTokenWithoutPassingARefreshTokenShouldThrowAnException(): void | ||
public function testGivenRefreshTokenPassedAsParameter_ItShouldBeString(): void | ||
{ | ||
$data = [ | ||
'refresh_token' => null, | ||
'refresh_token' => '', // empty equals `not string` | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(400); | ||
$message = (new RefreshTokenMissedException())->getMessage(); | ||
$this->assertResponseContainKeyValue(['message' => $message]); | ||
$response->assertStatus(422); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->hasAll(['message', 'errors' => 1]) | ||
->has( | ||
'errors', | ||
fn (AssertableJson $json) => $json->where('refresh_token.0', 'The refresh token must be a string.') | ||
) | ||
); | ||
} | ||
|
||
public function testOnSuccessfulRefreshTokenRequestEnsureValuesAreSetProperly(): void | ||
|
@@ -57,6 +65,22 @@ public function testOnSuccessfulRefreshTokenRequestEnsureValuesAreSetProperly(): | |
$this->assertResponseContainKeyValue([ | ||
'token_type' => 'Bearer', | ||
]); | ||
$this->assertResponseContainKeys(['expires_in', 'access_token']); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => $json->hasAll(['expires_in', 'access_token']) | ||
->etc() | ||
); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->data = [ | ||
'email' => '[email protected]', | ||
'password' => 'testing_pass', | ||
]; | ||
|
||
$this->getTestingUser($this->data); | ||
$this->actingAs($this->testingUser, 'web'); | ||
} | ||
} |