Добавлена возможность получить права на смену ника/пароля пользователя и тесты под это дело.

This commit is contained in:
ErickSkrauch 2017-09-30 01:04:26 +03:00
parent 8e79d1dd1c
commit 35e7ae2447
3 changed files with 41 additions and 10 deletions

View File

@ -30,6 +30,8 @@ class ScopeStorage extends AbstractStorage implements ScopeInterface {
]; ];
private const CLIENT_CREDENTIALS_PERMISSIONS_INTERNAL = [ private const CLIENT_CREDENTIALS_PERMISSIONS_INTERNAL = [
P::CHANGE_ACCOUNT_USERNAME,
P::CHANGE_ACCOUNT_PASSWORD,
P::BLOCK_ACCOUNT, P::BLOCK_ACCOUNT,
P::OBTAIN_EXTENDED_ACCOUNT_INFO, P::OBTAIN_EXTENDED_ACCOUNT_INFO,
P::ESCAPE_IDENTITY_VERIFICATION, P::ESCAPE_IDENTITY_VERIFICATION,

View File

@ -4,6 +4,7 @@ namespace tests\codeception\api\functional;
use common\models\Account; use common\models\Account;
use tests\codeception\api\_pages\AccountsRoute; use tests\codeception\api\_pages\AccountsRoute;
use tests\codeception\api\_pages\AuthenticationRoute; use tests\codeception\api\_pages\AuthenticationRoute;
use tests\codeception\api\functional\_steps\OauthSteps;
use tests\codeception\api\FunctionalTester; use tests\codeception\api\FunctionalTester;
class AccountsChangePasswordCest { class AccountsChangePasswordCest {
@ -29,11 +30,7 @@ class AccountsChangePasswordCest {
$id = $I->amAuthenticated(); $id = $I->amAuthenticated();
$this->route->changePassword($id, 'password_0', 'new-password', 'new-password'); $this->route->changePassword($id, 'password_0', 'new-password', 'new-password');
$I->canSeeResponseCodeIs(200); $this->assertSuccessResponse($I);
$I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([
'success' => true,
]);
$I->notLoggedIn(); $I->notLoggedIn();
@ -45,4 +42,20 @@ class AccountsChangePasswordCest {
]); ]);
} }
public function testChangePasswordInternal(OauthSteps $I) {
$accessToken = $I->getAccessTokenByClientCredentialsGrant(['change_account_password', 'escape_identity_verification']);
$I->amBearerAuthenticated($accessToken);
$this->route->changePassword(1, null, 'new-password-1', 'new-password-1');
$this->assertSuccessResponse($I);
}
private function assertSuccessResponse(FunctionalTester $I): void {
$I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([
'success' => true,
]);
}
} }

View File

@ -3,6 +3,7 @@ namespace tests\codeception\api\functional;
use common\models\Account; use common\models\Account;
use tests\codeception\api\_pages\AccountsRoute; use tests\codeception\api\_pages\AccountsRoute;
use tests\codeception\api\functional\_steps\OauthSteps;
use tests\codeception\api\FunctionalTester; use tests\codeception\api\FunctionalTester;
class AccountsChangeUsernameCest { class AccountsChangeUsernameCest {
@ -28,11 +29,7 @@ class AccountsChangeUsernameCest {
$id = $I->amAuthenticated(); $id = $I->amAuthenticated();
$this->route->changeUsername($id, 'password_0', 'bruce_wayne'); $this->route->changeUsername($id, 'password_0', 'bruce_wayne');
$I->canSeeResponseCodeIs(200); $this->assertSuccessResponse($I);
$I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([
'success' => true,
]);
} }
public function testChangeUsernameNotAvailable(FunctionalTester $I) { public function testChangeUsernameNotAvailable(FunctionalTester $I) {
@ -50,4 +47,23 @@ class AccountsChangeUsernameCest {
]); ]);
} }
public function testChangeUsernameInternal(OauthSteps $I) {
$accessToken = $I->getAccessTokenByClientCredentialsGrant(['change_account_username', 'escape_identity_verification']);
$I->amBearerAuthenticated($accessToken);
$this->route->changeUsername(1, null, 'im_batman');
$this->assertSuccessResponse($I);
}
/**
* @param FunctionalTester $I
*/
private function assertSuccessResponse(FunctionalTester $I): void {
$I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([
'success' => true,
]);
}
} }