2016-09-01 13:01:43 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\functional\authserver;
|
2016-09-01 13:01:43 +05:30
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\_pages\AuthserverRoute;
|
|
|
|
use api\tests\functional\_steps\AuthserverSteps;
|
2019-02-23 04:41:57 +05:30
|
|
|
use Ramsey\Uuid\Uuid;
|
2016-09-01 13:01:43 +05:30
|
|
|
|
|
|
|
class ValidateCest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var AuthserverRoute
|
|
|
|
*/
|
|
|
|
private $route;
|
|
|
|
|
|
|
|
public function _before(AuthserverSteps $I) {
|
|
|
|
$this->route = new AuthserverRoute($I);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validate(AuthserverSteps $I) {
|
|
|
|
$I->wantTo('validate my accessToken');
|
2017-01-24 04:30:08 +05:30
|
|
|
[$accessToken] = $I->amAuthenticated();
|
2016-09-01 13:01:43 +05:30
|
|
|
$this->route->validate([
|
|
|
|
'accessToken' => $accessToken,
|
|
|
|
]);
|
|
|
|
$I->seeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseEquals('');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function wrongArguments(AuthserverSteps $I) {
|
|
|
|
$I->wantTo('get error on wrong amount of arguments');
|
|
|
|
$this->route->validate([
|
|
|
|
'key' => 'value',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseCodeIs(400);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'IllegalArgumentException',
|
|
|
|
'errorMessage' => 'credentials can not be null.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function wrongAccessToken(AuthserverSteps $I) {
|
|
|
|
$I->wantTo('get error on wrong accessToken');
|
|
|
|
$this->route->validate([
|
|
|
|
'accessToken' => Uuid::uuid4()->toString(),
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseCodeIs(401);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'ForbiddenOperationException',
|
|
|
|
'errorMessage' => 'Invalid token.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function expiredAccessToken(AuthserverSteps $I) {
|
|
|
|
$I->wantTo('get error on expired accessToken');
|
|
|
|
$this->route->validate([
|
2019-07-15 04:29:56 +05:30
|
|
|
// Knowingly expired token from the dump
|
2016-09-01 13:01:43 +05:30
|
|
|
'accessToken' => '6042634a-a1e2-4aed-866c-c661fe4e63e2',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseCodeIs(401);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'ForbiddenOperationException',
|
|
|
|
'errorMessage' => 'Token expired.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|