diff --git a/composer.json b/composer.json index c2bda57..f469327 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,6 @@ "webmozart/assert": "^1.2.0" }, "require-dev": { - "yiisoft/yii2-codeception": "*", "yiisoft/yii2-debug": "*", "yiisoft/yii2-faker": "*", "flow/jsonpath": "^0.3.1", diff --git a/tests/codeception/api/_pages/AccountsRoute.php b/tests/codeception/api/_pages/AccountsRoute.php index 8c4f1cb..a1154e1 100644 --- a/tests/codeception/api/_pages/AccountsRoute.php +++ b/tests/codeception/api/_pages/AccountsRoute.php @@ -1,21 +1,14 @@ route = "/v1/accounts/{$accountId}"; - $this->actor->sendGET($this->getUrl()); + $this->getActor()->sendGET("/v1/accounts/{$accountId}"); } public function changePassword(int $accountId, $currentPassword = null, $newPassword = null, $newRePassword = null) { - $this->route = "/v1/accounts/{$accountId}/password"; - $this->actor->sendPOST($this->getUrl(), [ + $this->getActor()->sendPOST("/v1/accounts/{$accountId}/password", [ 'password' => $currentPassword, 'newPassword' => $newPassword, 'newRePassword' => $newRePassword, @@ -23,55 +16,65 @@ class AccountsRoute extends BasePage { } public function changeUsername(int $accountId, $currentPassword = null, $newUsername = null) { - $this->route = "/v1/accounts/{$accountId}/username"; - $this->actor->sendPOST($this->getUrl(), [ + $this->getActor()->sendPOST("/v1/accounts/{$accountId}/username", [ 'password' => $currentPassword, 'username' => $newUsername, ]); } public function changeEmailInitialize(int $accountId, $password = '') { - $this->route = "/v1/accounts/{$accountId}/email-verification"; - $this->actor->sendPOST($this->getUrl(), [ + $this->getActor()->sendPOST("/v1/accounts/{$accountId}/email-verification", [ 'password' => $password, ]); } public function changeEmailSubmitNewEmail(int $accountId, $key = null, $email = null) { - $this->route = "/v1/accounts/{$accountId}/new-email-verification"; - $this->actor->sendPOST($this->getUrl(), [ + $this->getActor()->sendPOST("/v1/accounts/{$accountId}/new-email-verification", [ 'key' => $key, 'email' => $email, ]); } public function changeEmail(int $accountId, $key = null) { - $this->route = "/v1/accounts/{$accountId}/email"; - $this->actor->sendPOST($this->getUrl(), [ + $this->getActor()->sendPOST("/v1/accounts/{$accountId}/email", [ 'key' => $key, ]); } public function changeLanguage(int $accountId, $lang = null) { - $this->route = "/v1/accounts/{$accountId}/language"; - $this->actor->sendPOST($this->getUrl(), [ + $this->getActor()->sendPOST("/v1/accounts/{$accountId}/language", [ 'lang' => $lang, ]); } public function acceptRules(int $accountId) { - $this->route = "/v1/accounts/{$accountId}/rules"; - $this->actor->sendPOST($this->getUrl()); + $this->getActor()->sendPOST("/v1/accounts/{$accountId}/rules"); + } + + public function getTwoFactorAuthCredentials(int $accountId) { + $this->getActor()->sendGET("/v1/accounts/{$accountId}/two-factor-auth"); + } + + public function enableTwoFactorAuth(int $accountId, $totp = null, $password = null) { + $this->getActor()->sendPOST("/v1/accounts/{$accountId}/two-factor-auth", [ + 'totp' => $totp, + 'password' => $password, + ]); + } + + public function disableTwoFactorAuth(int $accountId, $totp = null, $password = null) { + $this->getActor()->sendDELETE("/v1/accounts/{$accountId}/two-factor-auth", [ + 'totp' => $totp, + 'password' => $password, + ]); } public function ban(int $accountId) { - $this->route = "/v1/accounts/{$accountId}/ban"; - $this->actor->sendPOST($this->getUrl()); + $this->getActor()->sendPOST("/v1/accounts/{$accountId}/ban"); } - public function pardon($accountId) { - $this->route = "/v1/accounts/{$accountId}/ban"; - $this->actor->sendDELETE($this->getUrl()); + public function pardon(int $accountId) { + $this->getActor()->sendDELETE("/v1/accounts/{$accountId}/ban"); } } diff --git a/tests/codeception/api/_pages/AuthenticationRoute.php b/tests/codeception/api/_pages/AuthenticationRoute.php index c0d178b..6ce52f1 100644 --- a/tests/codeception/api/_pages/AuthenticationRoute.php +++ b/tests/codeception/api/_pages/AuthenticationRoute.php @@ -1,11 +1,6 @@ route = ['authentication/login']; $params = [ 'login' => $login, 'password' => $password, @@ -27,25 +21,22 @@ class AuthenticationRoute extends BasePage { $params['totp'] = $rememberMeOrToken; } - $this->actor->sendPOST($this->getUrl(), $params); + $this->getActor()->sendPOST('/authentication/login', $params); } public function logout() { - $this->route = ['authentication/logout']; - $this->actor->sendPOST($this->getUrl()); + $this->getActor()->sendPOST('/authentication/logout'); } public function forgotPassword($login = null, $token = null) { - $this->route = ['authentication/forgot-password']; - $this->actor->sendPOST($this->getUrl(), [ + $this->getActor()->sendPOST('/authentication/forgot-password', [ 'login' => $login, 'totp' => $token, ]); } public function recoverPassword($key = null, $newPassword = null, $newRePassword = null) { - $this->route = ['authentication/recover-password']; - $this->actor->sendPOST($this->getUrl(), [ + $this->getActor()->sendPOST('/authentication/recover-password', [ 'key' => $key, 'newPassword' => $newPassword, 'newRePassword' => $newRePassword, @@ -53,8 +44,7 @@ class AuthenticationRoute extends BasePage { } public function refreshToken($refreshToken = null) { - $this->route = ['authentication/refresh-token']; - $this->actor->sendPOST($this->getUrl(), [ + $this->getActor()->sendPOST('/authentication/refresh-token', [ 'refresh_token' => $refreshToken, ]); } diff --git a/tests/codeception/api/_pages/AuthserverRoute.php b/tests/codeception/api/_pages/AuthserverRoute.php index 0f5fc67..435f302 100644 --- a/tests/codeception/api/_pages/AuthserverRoute.php +++ b/tests/codeception/api/_pages/AuthserverRoute.php @@ -1,36 +1,26 @@ route = ['authserver/authentication/authenticate']; - $this->actor->sendPOST($this->getUrl(), $params); + $this->getActor()->sendPOST('/authserver/authentication/authenticate', $params); } public function refresh($params) { - $this->route = ['authserver/authentication/refresh']; - $this->actor->sendPOST($this->getUrl(), $params); + $this->getActor()->sendPOST('/authserver/authentication/refresh', $params); } public function validate($params) { - $this->route = ['authserver/authentication/validate']; - $this->actor->sendPOST($this->getUrl(), $params); + $this->getActor()->sendPOST('/authserver/authentication/validate', $params); } public function invalidate($params) { - $this->route = ['authserver/authentication/invalidate']; - $this->actor->sendPOST($this->getUrl(), $params); + $this->getActor()->sendPOST('/authserver/authentication/invalidate', $params); } public function signout($params) { - $this->route = ['authserver/authentication/signout']; - $this->actor->sendPOST($this->getUrl(), $params); + $this->getActor()->sendPOST('/authserver/authentication/signout', $params); } } diff --git a/tests/codeception/api/_pages/BasePage.php b/tests/codeception/api/_pages/BasePage.php new file mode 100644 index 0000000..8bf9dad --- /dev/null +++ b/tests/codeception/api/_pages/BasePage.php @@ -0,0 +1,21 @@ +actor = $I; + } + + public function getActor(): FunctionalTester { + return $this->actor; + } + +} diff --git a/tests/codeception/api/_pages/IdentityInfoRoute.php b/tests/codeception/api/_pages/IdentityInfoRoute.php index 75cd984..c3a8ed4 100644 --- a/tests/codeception/api/_pages/IdentityInfoRoute.php +++ b/tests/codeception/api/_pages/IdentityInfoRoute.php @@ -1,16 +1,10 @@ route = ['identity-info/index']; - $this->actor->sendGET($this->getUrl()); + $this->getActor()->sendGET('/account/v1/info'); } } diff --git a/tests/codeception/api/_pages/InternalRoute.php b/tests/codeception/api/_pages/InternalRoute.php index d508f96..ceacfb8 100644 --- a/tests/codeception/api/_pages/InternalRoute.php +++ b/tests/codeception/api/_pages/InternalRoute.php @@ -1,16 +1,10 @@ route = '/internal/accounts/info'; - $this->actor->sendGET($this->getUrl(), [$param => $value]); + $this->getActor()->sendGET('/internal/accounts/info', [$param => $value]); } } diff --git a/tests/codeception/api/_pages/LoginRoute.php b/tests/codeception/api/_pages/LoginRoute.php deleted file mode 100644 index 6cfc5e5..0000000 --- a/tests/codeception/api/_pages/LoginRoute.php +++ /dev/null @@ -1,20 +0,0 @@ -actor->sendPOST($this->getUrl(), [ - 'login' => $login, - 'password' => $password, - ]); - } - -} diff --git a/tests/codeception/api/_pages/MojangApiRoute.php b/tests/codeception/api/_pages/MojangApiRoute.php index edf95ac..7a2a25c 100644 --- a/tests/codeception/api/_pages/MojangApiRoute.php +++ b/tests/codeception/api/_pages/MojangApiRoute.php @@ -1,27 +1,19 @@ route = '/mojang/profiles/' . $username; $params = $at === null ? [] : ['at' => $at]; - $this->actor->sendGET($this->getUrl(), $params); + $this->getActor()->sendGET("/mojang/profiles/{$username}", $params); } public function usernamesByUuid($uuid) { - $this->route = "/mojang/profiles/{$uuid}/names"; - $this->actor->sendGET($this->getUrl()); + $this->getActor()->sendGET("/mojang/profiles/{$uuid}/names"); } public function uuidsByUsernames($uuids) { - $this->route = '/mojang/profiles'; - $this->actor->sendPOST($this->getUrl(), $uuids); + $this->getActor()->sendPOST('/mojang/profiles', $uuids); } } diff --git a/tests/codeception/api/_pages/OauthRoute.php b/tests/codeception/api/_pages/OauthRoute.php index ae9d2aa..c700211 100644 --- a/tests/codeception/api/_pages/OauthRoute.php +++ b/tests/codeception/api/_pages/OauthRoute.php @@ -1,26 +1,18 @@ route = '/oauth2/v1/validate'; - $this->actor->sendGET($this->getUrl($queryParams)); + $this->getActor()->sendGET('/oauth2/v1/validate', $queryParams); } public function complete($queryParams = [], $postParams = []) { - $this->route = '/oauth2/v1/complete'; - $this->actor->sendPOST($this->getUrl($queryParams), $postParams); + $this->getActor()->sendPOST('/oauth2/v1/complete?' . http_build_query($queryParams), $postParams); } public function issueToken($postParams = []) { - $this->route = '/oauth2/v1/token'; - $this->actor->sendPOST($this->getUrl(), $postParams); + $this->getActor()->sendPOST('/oauth2/v1/token', $postParams); } } diff --git a/tests/codeception/api/_pages/OptionsRoute.php b/tests/codeception/api/_pages/OptionsRoute.php index e248ca0..9413aeb 100644 --- a/tests/codeception/api/_pages/OptionsRoute.php +++ b/tests/codeception/api/_pages/OptionsRoute.php @@ -1,16 +1,10 @@ route = ['options/index']; - $this->actor->sendGET($this->getUrl()); + $this->getActor()->sendGET('/options'); } } diff --git a/tests/codeception/api/_pages/SessionServerRoute.php b/tests/codeception/api/_pages/SessionServerRoute.php index b3ac951..5d34346 100644 --- a/tests/codeception/api/_pages/SessionServerRoute.php +++ b/tests/codeception/api/_pages/SessionServerRoute.php @@ -1,36 +1,26 @@ route = '/minecraft/session/join'; - $this->actor->sendPOST($this->getUrl(), $params); + $this->getActor()->sendPOST('/minecraft/session/join', $params); } public function joinLegacy(array $params) { - $this->route = '/minecraft/session/legacy/join'; - $this->actor->sendGET($this->getUrl(), $params); + $this->getActor()->sendGET('/minecraft/session/legacy/join', $params); } public function hasJoined(array $params) { - $this->route = '/minecraft/session/hasJoined'; - $this->actor->sendGET($this->getUrl(), $params); + $this->getActor()->sendGET('/minecraft/session/hasJoined', $params); } public function hasJoinedLegacy(array $params) { - $this->route = '/minecraft/session/legacy/hasJoined'; - $this->actor->sendGET($this->getUrl(), $params); + $this->getActor()->sendGET('/minecraft/session/legacy/hasJoined', $params); } public function profile($profileUuid) { - $this->route = '/minecraft/session/profile/' . $profileUuid; - $this->actor->sendGET($this->getUrl()); + $this->getActor()->sendGET("/minecraft/session/profile/{$profileUuid}"); } } diff --git a/tests/codeception/api/_pages/SignupRoute.php b/tests/codeception/api/_pages/SignupRoute.php index a74c460..4aba204 100644 --- a/tests/codeception/api/_pages/SignupRoute.php +++ b/tests/codeception/api/_pages/SignupRoute.php @@ -1,26 +1,18 @@ route = ['signup/index']; - $this->actor->sendPOST($this->getUrl(), $registrationData); + $this->getActor()->sendPOST('/signup', $registrationData); } public function sendRepeatMessage($email = '') { - $this->route = ['signup/repeat-message']; - $this->actor->sendPOST($this->getUrl(), ['email' => $email]); + $this->getActor()->sendPOST('/signup/repeat-message', ['email' => $email]); } public function confirm($key = '') { - $this->route = ['signup/confirm']; - $this->actor->sendPOST($this->getUrl(), [ + $this->getActor()->sendPOST('/signup/confirm', [ 'key' => $key, ]); } diff --git a/tests/codeception/api/_pages/TwoFactorAuthRoute.php b/tests/codeception/api/_pages/TwoFactorAuthRoute.php deleted file mode 100644 index 3db04f3..0000000 --- a/tests/codeception/api/_pages/TwoFactorAuthRoute.php +++ /dev/null @@ -1,36 +0,0 @@ -setRoute($accountId); - $this->actor->sendGET($this->getUrl()); - } - - public function enable(int $accountId, $totp = null, $password = null) { - $this->setRoute($accountId); - $this->actor->sendPOST($this->getUrl(), [ - 'totp' => $totp, - 'password' => $password, - ]); - } - - public function disable(int $accountId, $totp = null, $password = null) { - $this->setRoute($accountId); - $this->actor->sendDELETE($this->getUrl(), [ - 'totp' => $totp, - 'password' => $password, - ]); - } - - private function setRoute(int $accountId) { - $this->route = "/v1/accounts/{$accountId}/two-factor-auth"; - } - -} diff --git a/tests/codeception/api/functional.suite.yml b/tests/codeception/api/functional.suite.yml index 3fbb784..9a6ac97 100644 --- a/tests/codeception/api/functional.suite.yml +++ b/tests/codeception/api/functional.suite.yml @@ -10,6 +10,7 @@ modules: - Asserts - REST: depends: Yii2 + url: /api config: Yii2: configFile: '../config/api/functional.php' diff --git a/tests/codeception/api/functional/AccountBanCest.php b/tests/codeception/api/functional/AccountsBanCest.php similarity index 98% rename from tests/codeception/api/functional/AccountBanCest.php rename to tests/codeception/api/functional/AccountsBanCest.php index 6100bdd..7c3064c 100644 --- a/tests/codeception/api/functional/AccountBanCest.php +++ b/tests/codeception/api/functional/AccountsBanCest.php @@ -6,7 +6,7 @@ use tests\codeception\api\_pages\AccountsRoute; use tests\codeception\api\functional\_steps\OauthSteps; use tests\codeception\api\FunctionalTester; -class AccountBanCest { +class AccountsBanCest { /** * @var AccountsRoute diff --git a/tests/codeception/api/functional/TwoFactorAuthDisableCest.php b/tests/codeception/api/functional/AccountsDisableTwoFactorAuthCest.php similarity index 74% rename from tests/codeception/api/functional/TwoFactorAuthDisableCest.php rename to tests/codeception/api/functional/AccountsDisableTwoFactorAuthCest.php index 8b05de3..15c8318 100644 --- a/tests/codeception/api/functional/TwoFactorAuthDisableCest.php +++ b/tests/codeception/api/functional/AccountsDisableTwoFactorAuthCest.php @@ -2,24 +2,24 @@ namespace tests\codeception\api\functional; use OTPHP\TOTP; -use tests\codeception\api\_pages\TwoFactorAuthRoute; +use tests\codeception\api\_pages\AccountsRoute; use tests\codeception\api\FunctionalTester; -class TwoFactorAuthDisableCest { +class AccountsDisableTwoFactorAuthCest { /** - * @var TwoFactorAuthRoute + * @var AccountsRoute */ private $route; public function _before(FunctionalTester $I) { - $this->route = new TwoFactorAuthRoute($I); + $this->route = new AccountsRoute($I); } public function testFails(FunctionalTester $I) { $accountId = $I->amAuthenticated('AccountWithEnabledOtp'); - $this->route->disable($accountId); + $this->route->disableTwoFactorAuth($accountId); $I->canSeeResponseContainsJson([ 'success' => false, 'errors' => [ @@ -28,7 +28,7 @@ class TwoFactorAuthDisableCest { ], ]); - $this->route->disable($accountId, '123456', 'invalid_password'); + $this->route->disableTwoFactorAuth($accountId, '123456', 'invalid_password'); $I->canSeeResponseContainsJson([ 'success' => false, 'errors' => [ @@ -38,7 +38,7 @@ class TwoFactorAuthDisableCest { ]); $accountId = $I->amAuthenticated('AccountWithOtpSecret'); - $this->route->disable($accountId, '123456', 'invalid_password'); + $this->route->disableTwoFactorAuth($accountId, '123456', 'invalid_password'); $I->canSeeResponseContainsJson([ 'success' => false, 'errors' => [ @@ -50,7 +50,7 @@ class TwoFactorAuthDisableCest { public function testSuccessEnable(FunctionalTester $I) { $accountId = $I->amAuthenticated('AccountWithEnabledOtp'); $totp = TOTP::create('BBBB'); - $this->route->disable($accountId, $totp->now(), 'password_0'); + $this->route->disableTwoFactorAuth($accountId, $totp->now(), 'password_0'); $I->canSeeResponseCodeIs(200); $I->canSeeResponseIsJson(); $I->canSeeResponseContainsJson([ diff --git a/tests/codeception/api/functional/TwoFactorAuthEnableCest.php b/tests/codeception/api/functional/AccountsEnableTwoFactorAuthCest.php similarity index 74% rename from tests/codeception/api/functional/TwoFactorAuthEnableCest.php rename to tests/codeception/api/functional/AccountsEnableTwoFactorAuthCest.php index 8a00b7b..74057b6 100644 --- a/tests/codeception/api/functional/TwoFactorAuthEnableCest.php +++ b/tests/codeception/api/functional/AccountsEnableTwoFactorAuthCest.php @@ -2,24 +2,24 @@ namespace tests\codeception\api\functional; use OTPHP\TOTP; -use tests\codeception\api\_pages\TwoFactorAuthRoute; +use tests\codeception\api\_pages\AccountsRoute; use tests\codeception\api\FunctionalTester; -class TwoFactorAuthEnableCest { +class AccountsEnableTwoFactorAuthCest { /** - * @var TwoFactorAuthRoute + * @var AccountsRoute */ private $route; public function _before(FunctionalTester $I) { - $this->route = new TwoFactorAuthRoute($I); + $this->route = new AccountsRoute($I); } public function testFails(FunctionalTester $I) { $accountId = $I->amAuthenticated('AccountWithOtpSecret'); - $this->route->enable($accountId); + $this->route->enableTwoFactorAuth($accountId); $I->canSeeResponseContainsJson([ 'success' => false, 'errors' => [ @@ -28,7 +28,7 @@ class TwoFactorAuthEnableCest { ], ]); - $this->route->enable($accountId, '123456', 'invalid_password'); + $this->route->enableTwoFactorAuth($accountId, '123456', 'invalid_password'); $I->canSeeResponseContainsJson([ 'success' => false, 'errors' => [ @@ -38,7 +38,7 @@ class TwoFactorAuthEnableCest { ]); $accountId = $I->amAuthenticated('AccountWithEnabledOtp'); - $this->route->enable($accountId, '123456', 'invalid_password'); + $this->route->enableTwoFactorAuth($accountId, '123456', 'invalid_password'); $I->canSeeResponseContainsJson([ 'success' => false, 'errors' => [ @@ -50,7 +50,7 @@ class TwoFactorAuthEnableCest { public function testSuccessEnable(FunctionalTester $I) { $accountId = $I->amAuthenticated('AccountWithOtpSecret'); $totp = TOTP::create('AAAA'); - $this->route->enable($accountId, $totp->now(), 'password_0'); + $this->route->enableTwoFactorAuth($accountId, $totp->now(), 'password_0'); $I->canSeeResponseCodeIs(200); $I->canSeeResponseIsJson(); $I->canSeeResponseContainsJson([ diff --git a/tests/codeception/api/functional/AccountPardonCest.php b/tests/codeception/api/functional/AccountsPardonCest.php similarity index 97% rename from tests/codeception/api/functional/AccountPardonCest.php rename to tests/codeception/api/functional/AccountsPardonCest.php index 5c2781e..a3e11df 100644 --- a/tests/codeception/api/functional/AccountPardonCest.php +++ b/tests/codeception/api/functional/AccountsPardonCest.php @@ -6,7 +6,7 @@ use tests\codeception\api\_pages\AccountsRoute; use tests\codeception\api\functional\_steps\OauthSteps; use tests\codeception\api\FunctionalTester; -class AccountPardonCest { +class AccountsPardonCest { /** * @var AccountsRoute diff --git a/tests/codeception/api/functional/TwoFactorAuthCredentialsCest.php b/tests/codeception/api/functional/AccountsTwoFactorAuthCredentialsCest.php similarity index 70% rename from tests/codeception/api/functional/TwoFactorAuthCredentialsCest.php rename to tests/codeception/api/functional/AccountsTwoFactorAuthCredentialsCest.php index edbaf99..365cbdb 100644 --- a/tests/codeception/api/functional/TwoFactorAuthCredentialsCest.php +++ b/tests/codeception/api/functional/AccountsTwoFactorAuthCredentialsCest.php @@ -1,23 +1,23 @@ route = new TwoFactorAuthRoute($I); + $this->route = new AccountsRoute($I); } public function testGetCredentials(FunctionalTester $I) { $accountId = $I->amAuthenticated(); - $this->route->credentials($accountId); + $this->route->getTwoFactorAuthCredentials($accountId); $I->canSeeResponseCodeIs(200); $I->canSeeResponseIsJson(); $I->canSeeResponseJsonMatchesJsonPath('$.secret');