From f8d6e460c799fca1caee8da87fe6c8c892b5fb27 Mon Sep 17 00:00:00 2001 From: Charlie Joseph Date: Wed, 11 Nov 2026 04:08:43 +0000 Subject: [PATCH] fix(keyring): restore hasSecondFactor, which the email code rename caught by mistake --- src/Changes/AuthenticatorChanges.php | 2 +- src/Support/PasswordRules.php | 2 +- src/UserKeyring.php | 2 +- tests/Feature/AuthenticatorManagementTest.php | 4 ++-- tests/Feature/CustomFactorTest.php | 2 +- tests/Feature/EmailCodeTest.php | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Changes/AuthenticatorChanges.php b/src/Changes/AuthenticatorChanges.php index 9f51a0a4..6609f50a 100644 --- a/src/Changes/AuthenticatorChanges.php +++ b/src/Changes/AuthenticatorChanges.php @@ -137,7 +137,7 @@ public function remove(Authenticatable&Model $user, string $id, #[\SensitivePara return [$authenticator, false]; } - if ($keyring->hasExtraStep() && ! $left->hasExtraStep()) { + if ($keyring->hasSecondFactor() && ! $left->hasSecondFactor()) { $this->ensurePasswordStandsAlone($user, $password); } diff --git a/src/Support/PasswordRules.php b/src/Support/PasswordRules.php index d16ca099..6fce0d72 100644 --- a/src/Support/PasswordRules.php +++ b/src/Support/PasswordRules.php @@ -68,7 +68,7 @@ final class PasswordRules */ public static function for((Authenticatable&Model)|null $user = null, ?Closure $adjust = null, array $context = []): array { - $min = self::min($user !== null && Keyring::for($user)->hasExtraStep()); + $min = self::min($user !== null && Keyring::for($user)->hasSecondFactor()); $rule = Password::min($min)->max(config('keyring.passwords.max')); diff --git a/src/UserKeyring.php b/src/UserKeyring.php index cfdeef2a..6ac7a471 100644 --- a/src/UserKeyring.php +++ b/src/UserKeyring.php @@ -103,7 +103,7 @@ public function has(Category $category): bool * may be shorter. Recovery codes aren't one to rely on, and an emailed * code isn't a factor at all (Category::Address). */ - public function hasExtraStep(): bool + public function hasSecondFactor(): bool { return $this->withoutFallbacks()->canMeet(Requirement::aal2()); } diff --git a/tests/Feature/AuthenticatorManagementTest.php b/tests/Feature/AuthenticatorManagementTest.php index ebb34726..259ce551 100644 --- a/tests/Feature/AuthenticatorManagementTest.php +++ b/tests/Feature/AuthenticatorManagementTest.php @@ -280,12 +280,12 @@ it('only allows the shorter password with a real second factor, not recovery codes alone', function () { $codes = Authenticator::factory()->recoveryCodes()->for($this->user, 'authenticatable')->create(); - expect($this->user->keyring->hasExtraStep())->toBeFalse(); + expect($this->user->keyring->hasSecondFactor())->toBeFalse(); expect(Validator::make(['password' => 'short pass', 'password_confirmation' => 'short pass'], ['password' => PasswordRules::for($this->user)])->fails())->toBeTrue(); Authenticator::factory()->totp()->for($this->user, 'authenticatable')->create(); - expect($this->user->keyring->refresh()->hasExtraStep())->toBeTrue(); + expect($this->user->keyring->refresh()->hasSecondFactor())->toBeTrue(); expect(Validator::make(['password' => 'short pass', 'password_confirmation' => 'short pass'], ['password' => PasswordRules::for($this->user->fresh())])->fails())->toBeFalse(); }); diff --git a/tests/Feature/CustomFactorTest.php b/tests/Feature/CustomFactorTest.php index fec26e1c..26e4f8d9 100644 --- a/tests/Feature/CustomFactorTest.php +++ b/tests/Feature/CustomFactorTest.php @@ -174,7 +174,7 @@ public function verify(Attempt $attempt, Authenticator $authenticator, Request $ it('doesn\'t count as the account\'s second factor', function () { $keyring = $this->user->keyring; - expect($keyring->hasExtraStep())->toBeFalse() + expect($keyring->hasSecondFactor())->toBeFalse() ->and($keyring->canMeet(Requirement::aal2()))->toBeFalse() ->and($keyring->canMeet(Requirement::factors(2)))->toBeTrue(); }); diff --git a/tests/Feature/EmailCodeTest.php b/tests/Feature/EmailCodeTest.php index bd1c916b..29fa91af 100644 --- a/tests/Feature/EmailCodeTest.php +++ b/tests/Feature/EmailCodeTest.php @@ -664,7 +664,7 @@ function signInWithEmailedCode(array $extra = []): TestResponse emailAuthenticator($this->user); $keyring = $this->user->keyring; - expect($keyring->hasExtraStep())->toBeFalse() + expect($keyring->hasSecondFactor())->toBeFalse() ->and($keyring->has(Category::Possession))->toBeFalse() ->and($keyring->has(Category::Address))->toBeTrue() ->and($keyring->canMeet(Requirement::aal2()))->toBeFalse() @@ -759,7 +759,7 @@ function signInWithEmailedCode(array $extra = []): TestResponse $response = $this->postJson(route('keyring.authenticators.confirm', 'totp'), ['code' => totpCode($secret)])->assertOk(); expect($response->json('recoveryCodes'))->toHaveCount(8) - ->and($this->user->keyring->refresh()->hasExtraStep())->toBeTrue(); + ->and($this->user->keyring->refresh()->hasSecondFactor())->toBeTrue(); }); it('doesn\'t stand in for the possession factor a fresh verification asks of an account that has one', function () { @@ -814,7 +814,7 @@ function signInWithEmailedCode(array $extra = []): TestResponse $this->post(route('keyring.login.verify', 'magic-word'), ['code' => 'please'])->assertRedirect('/dashboard'); expect(app(SessionAssurance::class)->level())->toBe(Assurance::AAL1) - ->and($this->user->keyring->hasExtraStep())->toBeFalse(); + ->and($this->user->keyring->hasSecondFactor())->toBeFalse(); }); });