Skip to content

Commit

Permalink
Fix login validation issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Dec 8, 2023
1 parent 8c441c2 commit 50ac0dc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/UseCase/Login/LoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function validatePassword(): bool
$this->account = $this->finderAccountRepository->findByUsernameOrEmail($this->login);

if ($this->account === null || $this->account->password_hash === null) {
return false;
return true;
}

return $this->passwordHasher->validate($this->password, $this->account->password_hash) === false;
Expand Down
44 changes: 44 additions & 0 deletions tests/Acceptance/LoginCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ public function failedWithEmail(AcceptanceTester $I): void
$I->dontSeeLink(Yii::t('yii.user', 'Logout'));
}

public function failedWithEmailNotExist(AcceptanceTester $I): void
{
$I->amGoingTo('navigate to the login page.');
$I->amOnRoute('login/index');

$I->wantTo('ensure that login page works.');
$I->expectTo('see page index.');
$I->see(Yii::t('yii.user', 'Sign in'), 'h1');
$I->see(Yii::t('yii.user', 'Please fill out the following fields to Sign in.'));

$I->expectTo('fill in the form.');
$I->fillField('#loginform-login', 'user@yii.com');
$I->fillField('#loginform-password', '12345678');
$I->click(Yii::t('yii.user', 'Sign in'));

$I->expectTo('see message validation.');
$I->see(Yii::t('yii.user', 'Invalid login or password.'));

$I->expectTo('see that the user is logged in.');
$I->dontSeeLink(Yii::t('yii.user', 'Logout'));
}

public function failedWithUsername(AcceptanceTester $I): void
{
$I->wantTo('security login username submit form success data.');
Expand All @@ -109,6 +131,28 @@ public function failedWithUsername(AcceptanceTester $I): void
$I->dontSeeLink(Yii::t('yii.user', 'Logout'));
}

public function failedWithUserNameNotExist(AcceptanceTester $I): void
{
$I->amGoingTo('navigate to the login page.');
$I->amOnRoute('login/index');

$I->wantTo('ensure that login page works.');
$I->expectTo('see page index.');
$I->see(Yii::t('yii.user', 'Sign in'), 'h1');
$I->see(Yii::t('yii.user', 'Please fill out the following fields to Sign in.'));

$I->expectTo('fill in the form.');
$I->fillField('#loginform-login', 'not-exist');
$I->fillField('#loginform-password', '12345678');
$I->click(Yii::t('yii.user', 'Sign in'));

$I->expectTo('see message validation.');
$I->see(Yii::t('yii.user', 'Invalid login or password.'));

$I->expectTo('see that the user is logged in.');
$I->dontSeeLink(Yii::t('yii.user', 'Logout'));
}

public function indexPage(AcceptanceTester $I): void
{
$I->amGoingTo('navigate to the login page.');
Expand Down

0 comments on commit 50ac0dc

Please sign in to comment.