Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/Changes/AuthenticatorChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Support/PasswordRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
2 changes: 1 addition & 1 deletion src/UserKeyring.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/AuthenticatorManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/CustomFactorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/EmailCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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();
});
});

Expand Down
Loading