From fe2c4226215e68fb35ef3eb951d7dffa029d535c Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 23 May 2016 22:42:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=BE=D0=B5=20=D0=BE=D0=B1?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B0=D0=BB?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC=D0=B0=20=D1=85=D1=8D=D1=88?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=BB=D1=8F=20=D0=B2=D0=BE=20=D0=B2=D1=80=D0=B5?= =?UTF-8?q?=D0=BC=D1=8F=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/models/authentication/LoginForm.php | 12 +++++++- .../AccountsChangeEmailInitializeCest.php | 15 ---------- .../models/authentication/LoginFormTest.php | 29 +++++++++++++++++-- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/api/models/authentication/LoginForm.php b/api/models/authentication/LoginForm.php index aba11d3..5f1a77f 100644 --- a/api/models/authentication/LoginForm.php +++ b/api/models/authentication/LoginForm.php @@ -67,7 +67,17 @@ class LoginForm extends ApiForm { return false; } - return $this->getAccount()->getJWT(); + if ($this->rememberMe) { + // TODO: здесь нужно записать какую-то + } + + $account = $this->getAccount(); + if ($account->password_hash_strategy === Account::PASS_HASH_STRATEGY_OLD_ELY) { + $account->setPassword($this->password); + $account->save(); + } + + return $account->getJWT(); } } diff --git a/tests/codeception/api/functional/AccountsChangeEmailInitializeCest.php b/tests/codeception/api/functional/AccountsChangeEmailInitializeCest.php index 4feb158..b90a571 100644 --- a/tests/codeception/api/functional/AccountsChangeEmailInitializeCest.php +++ b/tests/codeception/api/functional/AccountsChangeEmailInitializeCest.php @@ -28,19 +28,4 @@ class AccountsChangeEmailInitializeCest { ]); } - public function testChangeEmailWithOldPasswordStrategy(FunctionalTester $I) { - $I->wantTo('see, that account use old account password hash strategy'); - $I->loggedInAsActiveAccount('AccWithOldPassword', '12345678'); - - $this->route->changeEmailInitialize('password_0'); - $I->canSeeResponseCodeIs(200); - $I->canSeeResponseIsJson(); - $I->canSeeResponseContainsJson([ - 'success' => false, - 'errors' => [ - 'email' => 'error.old_hash_strategy', - ], - ]); - } - } diff --git a/tests/codeception/api/unit/models/authentication/LoginFormTest.php b/tests/codeception/api/unit/models/authentication/LoginFormTest.php index f1c131e..dfc134d 100644 --- a/tests/codeception/api/unit/models/authentication/LoginFormTest.php +++ b/tests/codeception/api/unit/models/authentication/LoginFormTest.php @@ -4,12 +4,25 @@ namespace tests\codeception\api\models\authentication; use api\models\authentication\LoginForm; use Codeception\Specify; use common\models\Account; -use tests\codeception\api\unit\TestCase; +use tests\codeception\api\unit\DbTestCase; +use tests\codeception\common\fixtures\AccountFixture; use Yii; -class LoginFormTest extends TestCase { +/** + * @property AccountFixture $accounts + */ +class LoginFormTest extends DbTestCase { use Specify; + public function fixtures() { + return [ + 'accounts' => [ + 'class' => AccountFixture::class, + 'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php', + ], + ]; + } + public function testValidateLogin() { $this->specify('error.login_not_exist if login not exists', function () { $model = $this->createModel([ @@ -84,6 +97,18 @@ class LoginFormTest extends TestCase { }); } + public function testLoginWithRehashing() { + $this->specify('user, that login using account with old pass hash strategy should update it automatically', function () { + $model = new LoginForm([ + 'login' => $this->accounts['user-with-old-password-type']['username'], + 'password' => '12345678', + ]); + expect($model->login())->notEquals(false); + expect($model->errors)->isEmpty(); + expect($model->getAccount()->password_hash_strategy)->equals(Account::PASS_HASH_STRATEGY_YII2); + }); + } + /** * @param array $params * @return LoginForm