mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Rework tests structure. Upgrade codeception to 2.5.3. Merge params configuration into app configuration.
This commit is contained in:
158
api/tests/functional/authserver/AuthorizationCest.php
Normal file
158
api/tests/functional/authserver/AuthorizationCest.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
namespace api\tests\functional\authserver;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use api\tests\_pages\AuthserverRoute;
|
||||
use api\tests\FunctionalTester;
|
||||
|
||||
class AuthorizationCest {
|
||||
|
||||
/**
|
||||
* @var AuthserverRoute
|
||||
*/
|
||||
private $route;
|
||||
|
||||
public function _before(FunctionalTester $I) {
|
||||
$this->route = new AuthserverRoute($I);
|
||||
}
|
||||
|
||||
public function byName(FunctionalTester $I) {
|
||||
$I->wantTo('authenticate by username and password');
|
||||
$this->route->authenticate([
|
||||
'username' => 'admin',
|
||||
'password' => 'password_0',
|
||||
'clientToken' => Uuid::uuid4()->toString(),
|
||||
]);
|
||||
|
||||
$this->testSuccessResponse($I);
|
||||
}
|
||||
|
||||
public function byEmail(FunctionalTester $I) {
|
||||
$I->wantTo('authenticate by email and password');
|
||||
$this->route->authenticate([
|
||||
'username' => 'admin@ely.by',
|
||||
'password' => 'password_0',
|
||||
'clientToken' => Uuid::uuid4()->toString(),
|
||||
]);
|
||||
|
||||
$this->testSuccessResponse($I);
|
||||
}
|
||||
|
||||
public function byNamePassedViaPOSTBody(FunctionalTester $I) {
|
||||
$I->wantTo('authenticate by username and password sent via post body');
|
||||
$this->route->authenticate(json_encode([
|
||||
'username' => 'admin',
|
||||
'password' => 'password_0',
|
||||
'clientToken' => Uuid::uuid4()->toString(),
|
||||
]));
|
||||
|
||||
$this->testSuccessResponse($I);
|
||||
}
|
||||
|
||||
public function byEmailWithEnabledTwoFactorAuth(FunctionalTester $I) {
|
||||
$I->wantTo('get valid error by authenticate account with enabled two factor auth');
|
||||
$this->route->authenticate([
|
||||
'username' => 'otp@gmail.com',
|
||||
'password' => 'password_0',
|
||||
'clientToken' => Uuid::uuid4()->toString(),
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(401);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'ForbiddenOperationException',
|
||||
'errorMessage' => 'Account protected with two factor auth.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function byEmailWithParamsAsJsonInPostBody(FunctionalTester $I) {
|
||||
$I->wantTo('authenticate by email and password, passing values as serialized string in post body');
|
||||
$this->route->authenticate(json_encode([
|
||||
'username' => 'admin@ely.by',
|
||||
'password' => 'password_0',
|
||||
'clientToken' => Uuid::uuid4()->toString(),
|
||||
]));
|
||||
|
||||
$this->testSuccessResponse($I);
|
||||
}
|
||||
|
||||
public function longClientToken(FunctionalTester $I) {
|
||||
$I->wantTo('send non uuid clientToken, but less then 255 characters');
|
||||
$this->route->authenticate([
|
||||
'username' => 'admin@ely.by',
|
||||
'password' => 'password_0',
|
||||
'clientToken' => str_pad('', 255, 'x'),
|
||||
]);
|
||||
$this->testSuccessResponse($I);
|
||||
}
|
||||
|
||||
public function tooLongClientToken(FunctionalTester $I) {
|
||||
$I->wantTo('send non uuid clientToken with more then 255 characters length');
|
||||
$this->route->authenticate([
|
||||
'username' => 'admin@ely.by',
|
||||
'password' => 'password_0',
|
||||
'clientToken' => str_pad('', 256, 'x'),
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(400);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'IllegalArgumentException',
|
||||
'errorMessage' => 'clientToken is too long.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function wrongArguments(FunctionalTester $I) {
|
||||
$I->wantTo('get error on wrong amount of arguments');
|
||||
$this->route->authenticate([
|
||||
'key' => 'value',
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(400);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'IllegalArgumentException',
|
||||
'errorMessage' => 'credentials can not be null.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function wrongNicknameAndPassword(FunctionalTester $I) {
|
||||
$I->wantTo('authenticate by username and password with wrong data');
|
||||
$this->route->authenticate([
|
||||
'username' => 'nonexistent_user',
|
||||
'password' => 'nonexistent_password',
|
||||
'clientToken' => Uuid::uuid4()->toString(),
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(401);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'ForbiddenOperationException',
|
||||
'errorMessage' => 'Invalid credentials. Invalid nickname or password.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function bannedAccount(FunctionalTester $I) {
|
||||
$I->wantTo('authenticate in suspended account');
|
||||
$this->route->authenticate([
|
||||
'username' => 'Banned',
|
||||
'password' => 'password_0',
|
||||
'clientToken' => Uuid::uuid4()->toString(),
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(401);
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'ForbiddenOperationException',
|
||||
'errorMessage' => 'This account has been suspended.',
|
||||
]);
|
||||
}
|
||||
|
||||
private function testSuccessResponse(FunctionalTester $I) {
|
||||
$I->seeResponseCodeIs(200);
|
||||
$I->seeResponseIsJson();
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.accessToken');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.clientToken');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.availableProfiles[0].id');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.availableProfiles[0].name');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.availableProfiles[0].legacy');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.selectedProfile.id');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.selectedProfile.name');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.selectedProfile.legacy');
|
||||
}
|
||||
|
||||
}
|
||||
53
api/tests/functional/authserver/InvalidateCest.php
Normal file
53
api/tests/functional/authserver/InvalidateCest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace api\tests\functional\authserver;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use api\tests\_pages\AuthserverRoute;
|
||||
use api\tests\functional\_steps\AuthserverSteps;
|
||||
|
||||
class InvalidateCest {
|
||||
|
||||
/**
|
||||
* @var AuthserverRoute
|
||||
*/
|
||||
private $route;
|
||||
|
||||
public function _before(AuthserverSteps $I) {
|
||||
$this->route = new AuthserverRoute($I);
|
||||
}
|
||||
|
||||
public function invalidate(AuthserverSteps $I) {
|
||||
$I->wantTo('invalidate my token');
|
||||
[$accessToken, $clientToken] = $I->amAuthenticated();
|
||||
$this->route->invalidate([
|
||||
'accessToken' => $accessToken,
|
||||
'clientToken' => $clientToken,
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseEquals('');
|
||||
}
|
||||
|
||||
public function wrongArguments(AuthserverSteps $I) {
|
||||
$I->wantTo('get error on wrong amount of arguments');
|
||||
$this->route->invalidate([
|
||||
'key' => 'value',
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(400);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'IllegalArgumentException',
|
||||
'errorMessage' => 'credentials can not be null.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function wrongAccessTokenOrClientToken(AuthserverSteps $I) {
|
||||
$I->wantTo('invalidate by wrong client and access token');
|
||||
$this->route->invalidate([
|
||||
'accessToken' => Uuid::uuid4()->toString(),
|
||||
'clientToken' => Uuid::uuid4()->toString(),
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseEquals('');
|
||||
}
|
||||
|
||||
}
|
||||
77
api/tests/functional/authserver/RefreshCest.php
Normal file
77
api/tests/functional/authserver/RefreshCest.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace api\tests\functional\authserver;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use api\tests\_pages\AuthserverRoute;
|
||||
use api\tests\functional\_steps\AuthserverSteps;
|
||||
|
||||
class RefreshCest {
|
||||
|
||||
/**
|
||||
* @var AuthserverRoute
|
||||
*/
|
||||
private $route;
|
||||
|
||||
public function _before(AuthserverSteps $I) {
|
||||
$this->route = new AuthserverRoute($I);
|
||||
}
|
||||
|
||||
public function refresh(AuthserverSteps $I) {
|
||||
$I->wantTo('refresh my accessToken');
|
||||
[$accessToken, $clientToken] = $I->amAuthenticated();
|
||||
$this->route->refresh([
|
||||
'accessToken' => $accessToken,
|
||||
'clientToken' => $clientToken,
|
||||
]);
|
||||
|
||||
$I->seeResponseCodeIs(200);
|
||||
$I->seeResponseIsJson();
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.accessToken');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.clientToken');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.selectedProfile.id');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.selectedProfile.name');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.selectedProfile.legacy');
|
||||
$I->cantSeeResponseJsonMatchesJsonPath('$.availableProfiles');
|
||||
}
|
||||
|
||||
public function wrongArguments(AuthserverSteps $I) {
|
||||
$I->wantTo('get error on wrong amount of arguments');
|
||||
$this->route->refresh([
|
||||
'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 access or client tokens');
|
||||
$this->route->refresh([
|
||||
'accessToken' => Uuid::uuid4()->toString(),
|
||||
'clientToken' => Uuid::uuid4()->toString(),
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(401);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'ForbiddenOperationException',
|
||||
'errorMessage' => 'Invalid token.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function refreshTokenFromBannedUser(AuthserverSteps $I) {
|
||||
$I->wantTo('refresh token from suspended account');
|
||||
$this->route->refresh([
|
||||
'accessToken' => '918ecb41-616c-40ee-a7d2-0b0ef0d0d732',
|
||||
'clientToken' => '6042634a-a1e2-4aed-866c-c661fe4e63e2',
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(401);
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'ForbiddenOperationException',
|
||||
'errorMessage' => 'This account has been suspended.',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
75
api/tests/functional/authserver/SignoutCest.php
Normal file
75
api/tests/functional/authserver/SignoutCest.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace api\tests\functional\authserver;
|
||||
|
||||
use api\tests\_pages\AuthserverRoute;
|
||||
use api\tests\functional\_steps\AuthserverSteps;
|
||||
|
||||
class SignoutCest {
|
||||
|
||||
/**
|
||||
* @var AuthserverRoute
|
||||
*/
|
||||
private $route;
|
||||
|
||||
public function _before(AuthserverSteps $I) {
|
||||
$this->route = new AuthserverRoute($I);
|
||||
}
|
||||
|
||||
public function byName(AuthserverSteps $I) {
|
||||
$I->wantTo('signout by nickname and password');
|
||||
$this->route->signout([
|
||||
'username' => 'admin',
|
||||
'password' => 'password_0',
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseEquals('');
|
||||
}
|
||||
|
||||
public function byEmail(AuthserverSteps $I) {
|
||||
$I->wantTo('signout by email and password');
|
||||
$this->route->signout([
|
||||
'username' => 'admin@ely.by',
|
||||
'password' => 'password_0',
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseEquals('');
|
||||
}
|
||||
|
||||
public function wrongArguments(AuthserverSteps $I) {
|
||||
$I->wantTo('get error on wrong amount of arguments');
|
||||
$this->route->signout([
|
||||
'key' => 'value',
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(400);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'IllegalArgumentException',
|
||||
'errorMessage' => 'credentials can not be null.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function wrongNicknameAndPassword(AuthserverSteps $I) {
|
||||
$I->wantTo('signout by nickname and password with wrong data');
|
||||
$this->route->signout([
|
||||
'username' => 'nonexistent_user',
|
||||
'password' => 'nonexistent_password',
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(401);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'ForbiddenOperationException',
|
||||
'errorMessage' => 'Invalid credentials. Invalid nickname or password.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function bannedAccount(AuthserverSteps $I) {
|
||||
$I->wantTo('signout from banned account');
|
||||
$this->route->signout([
|
||||
'username' => 'Banned',
|
||||
'password' => 'password_0',
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseEquals('');
|
||||
}
|
||||
|
||||
}
|
||||
69
api/tests/functional/authserver/ValidateCest.php
Normal file
69
api/tests/functional/authserver/ValidateCest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace api\tests\functional\authserver;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use api\tests\_pages\AuthserverRoute;
|
||||
use api\tests\functional\_steps\AuthserverSteps;
|
||||
|
||||
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');
|
||||
[$accessToken] = $I->amAuthenticated();
|
||||
$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([
|
||||
// Заведомо истёкший токен из дампа
|
||||
'accessToken' => '6042634a-a1e2-4aed-866c-c661fe4e63e2',
|
||||
]);
|
||||
$I->canSeeResponseCodeIs(401);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'ForbiddenOperationException',
|
||||
'errorMessage' => 'Token expired.',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user