Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix getVerifiedMfaOptionsCount - get count of all WebAuthns #332

Merged
merged 7 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion application/common/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,13 @@ public function getVerifiedMfaOptionsCount(): int
{
$count = 0;
foreach ($this->mfas as $mfaOption) {
if ($mfaOption->verified === 1) {
if ($mfaOption->verified !== 1) {
continue;
}

if ($mfaOption->type === Mfa::TYPE_WEBAUTHN) {
$count += $mfaOption->getMfaWebauthns()->count();
} else {
$count += 1;
}
}
Expand Down
29 changes: 22 additions & 7 deletions application/features/bootstrap/EmailContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use common\models\Method;
use common\models\Mfa;
use common\models\MfaBackupcode;
use common\models\MfaWebauthn;
use common\models\User;
use Sil\SilIdBroker\Behat\Context\YiiContext;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -93,7 +94,7 @@ public function aEmailToThatUserShouldNotHaveBeenLogged($messageType)
]);
Assert::isEmpty($emailLogs, sprintf(
'Expected NOT to find any email logs for a(n) %s email to User %s, '
. 'but instead found %s of them.',
. 'but instead found %s of them.',
var_export($messageType, true),
var_export($this->tempUser->id, true),
count($emailLogs)
Expand Down Expand Up @@ -168,6 +169,11 @@ protected function createMfa(
$mfa->last_used_utc = MySqlDateTime::relative($diffConfig);
}
Assert::true($mfa->save(), "Could not create new mfa.");

if ($type == Mfa::TYPE_WEBAUTHN) {
MfaWebauthn::createWebauthn($mfa, '');
}

$user->refresh();
}

Expand Down Expand Up @@ -215,7 +221,7 @@ public function aEmailToThatUserShouldHaveBeenLogged($messageType)
]);
Assert::count($emailLogs, 1, sprintf(
'Expected to find an email log for a(n) %s email to User %s, but '
. 'instead found %s of them.',
. 'instead found %s of them.',
var_export($messageType, true),
var_export($this->tempUser->id, true),
count($emailLogs)
Expand Down Expand Up @@ -291,14 +297,14 @@ public function thatUserDoesNotHaveAPassword()
Assert::null(
$this->tempUser->current_password_id,
'The user already has a password, but this test needs a user '
. 'without a password.'
. 'without a password.'
);
}
}

/**
* @Given a second user exists with a totp mfa option
*/
*/
public function aSecondUserExistsWithATotpMfaOption()
{
$this->tempUser2 = $this->createNewUser();
Expand Down Expand Up @@ -557,15 +563,24 @@ public function weAreConfiguredNotToSendRefreshBackupCodesEmails()
public function noMfasExist()
{
MfaBackupcode::deleteAll();
MfaWebauthn::deleteAll();
Mfa::deleteAll();
}

/**
* @Given a verified webauthn mfa option does exist
* @Given :arg1 verified webauthn mfa option does exist
briskt marked this conversation as resolved.
Show resolved Hide resolved
*/
public function aVerifiedWebAuthnMfaOptionDoesExist()
public function aVerifiedWebAuthnMfaOptionDoesExist($count)
{
$this->createMfa(Mfa::TYPE_WEBAUTHN);

if (intval($count) > 1) {
$mfa = $this->testMfaOption;

for ($i=1; $i < $count; $i++) {
MfaWebauthn::createWebauthn($mfa, '');
}
}
}


Expand Down Expand Up @@ -1139,7 +1154,7 @@ public function thatUserHasAPasswordThatExpiresInDays($n)
Assert::true(
$currentPassword->save(),
'Failed to save updated password expiration date. '
. join(', ', $currentPassword->getFirstErrors())
. join(', ', $currentPassword->getFirstErrors())
);
}

Expand Down
25 changes: 13 additions & 12 deletions application/features/email.feature
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,26 @@ Feature: Email
And I remove records of any emails that have been sent
And no mfas exist
And a user already exists
And a verified webauthn mfa option <webauthnExistsOrNot>
And <webauthnCount> verified webauthn mfa option <webauthnExistsOrNot>
And a totp mfa option <totpExistsOrNot>
And a backup code mfa option <backupExistsOrNot>
And a "get-backup-codes" email <hasOrHasNot> been sent to that user
When I check if a get backup codes email should be sent
Then I see that a get backup codes email <shouldOrNot> be sent

Examples:
| sendGetBackupCodesEml | webauthnExistsOrNot | totpExistsOrNot | backupExistsOrNot | hasOrHasNot | shouldOrNot |
| to send | does NOT exist | does NOT exist | does NOT exist | has NOT | should NOT |
| to send | does exist | does NOT exist | does NOT exist | has NOT | should |
| to send | does NOT exist | does exist | does NOT exist | has NOT | should |
| to send | does exist | does exist | does NOT exist | has NOT | should NOT |
| to send | does exist | does exist | does exist | has NOT | should NOT |
| to send | does NOT exist | does exist | does exist | has NOT | should NOT |
| to send | does exist | does NOT exist | does exist | has NOT | should NOT |
| to send | does NOT exist | does NOT exist | does exist | has NOT | should NOT |
| to send | does exist | does NOT exist | does NOT exist | has | should NOT |
| NOT to send | does NOT exist | does exist | does NOT exist | has NOT | should NOT |
| sendGetBackupCodesEml | webauthnCount | webauthnExistsOrNot | totpExistsOrNot | backupExistsOrNot | hasOrHasNot | shouldOrNot |
| to send | a | does NOT exist | does NOT exist | does NOT exist | has NOT | should NOT |
briskt marked this conversation as resolved.
Show resolved Hide resolved
| to send | a | does exist | does NOT exist | does NOT exist | has NOT | should |
| to send | 2 | does exist | does NOT exist | does NOT exist | has NOT | should NOT |
| to send | a | does NOT exist | does exist | does NOT exist | has NOT | should |
| to send | a | does exist | does exist | does NOT exist | has NOT | should NOT |
| to send | a | does exist | does exist | does exist | has NOT | should NOT |
| to send | a | does NOT exist | does exist | does exist | has NOT | should NOT |
| to send | a | does exist | does NOT exist | does exist | has NOT | should NOT |
| to send | a | does NOT exist | does NOT exist | does exist | has NOT | should NOT |
| to send | a | does exist | does NOT exist | does NOT exist | has | should NOT |
| NOT to send | a | does NOT exist | does exist | does NOT exist | has NOT | should NOT |

Scenario Outline: When to send mfa option added emails (after one has been added or deleted)
Given we are configured <sendMfaOptionAddedEml> mfa option added emails
Expand Down
Loading