Files
accounts/api/tests/unit/models/authentication/RecoverPasswordFormTest.php
T
ErickSkrauch f7f43c1190 Revoke OAuth 2 tokens on account password change.
List all authenticated OAuth clients, revoke by deleting
2026-11-02 16:07:53 +01:00

45 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace api\tests\unit\models\authentication;
use api\components\User\Component;
use api\models\authentication\RecoverPasswordForm;
use api\tests\unit\TestCase;
use common\models\Account;
use common\models\EmailActivation;
use common\tests\fixtures\EmailActivationFixture;
use Yii;
class RecoverPasswordFormTest extends TestCase {
public function _fixtures(): array {
return [
'emailActivations' => EmailActivationFixture::class,
];
}
public function testRecoverPassword(): void {
$fixture = $this->tester->grabFixture('emailActivations', 'freshPasswordRecovery');
$component = $this->createPartialMock(Component::class, ['terminateSessions']);
$component->expects($this->once())
->method('terminateSessions')
->with($this->callback(fn(Account $account): bool => $account->id === $fixture['account_id']), 0);
Yii::$app->set('user', $component);
$model = new RecoverPasswordForm([
'key' => $fixture['key'],
'newPassword' => '12345678',
'newRePassword' => '12345678',
]);
$result = $model->recoverPassword();
$this->assertNotNull($result);
$this->assertNull($result->getRefreshToken(), 'session was not generated');
$this->assertFalse(EmailActivation::find()->andWhere(['key' => $fixture['key']])->exists());
/** @var Account $account */
$account = Account::findOne($fixture['account_id']);
$this->assertTrue($account->validatePassword('12345678'));
}
}