Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Commit

Permalink
Merge e8ba2ba into 7eef255
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGhostHunter committed Jul 11, 2020
2 parents 7eef255 + e8ba2ba commit 35b2921
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Http/AuthenticatesWebAuthn.php
Expand Up @@ -96,7 +96,8 @@ public function login(Request $request)
*/
protected function hasRemember(Request $request)
{
return $request->filled('remember') || $request->header('WebAuthn-Remember');
return filter_var($request->header('WebAuthn-Remember'), FILTER_VALIDATE_BOOLEAN)
?: $request->filled('remember');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Http/RecoversWebAuthn.php
Expand Up @@ -120,7 +120,7 @@ protected function register(Request $request, WebAuthnAuthenticatable $user)
protected function shouldDisableAllCredentials(Request $request)
{
return filter_var($request->header('WebAuthn-Unique'), FILTER_VALIDATE_BOOLEAN)
?? $request->filled('unique');
?: $request->filled('unique');
}

/**
Expand Down Expand Up @@ -176,4 +176,4 @@ public function redirectPath()

return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}
}
}
4 changes: 4 additions & 0 deletions tests/Http/WebAuthnConfirmTest.php
Expand Up @@ -105,6 +105,10 @@ public function test_asks_for_confirmation()
->get('intended')
->assertRedirect('webauthn/confirm');

$this->actingAs($this->user)
->getJson('intended')
->assertSeeText('Authenticator assertion required.');

$this->actingAs($this->user)
->followingRedirects()
->get('intended')
Expand Down
31 changes: 31 additions & 0 deletions tests/Http/WebAuthnDeviceLostTest.php
Expand Up @@ -125,6 +125,22 @@ public function test_sends_recovery_email()
]);
}

public function test_sends_recovery_email_using_json()
{
$notification = Notification::fake();

$this->postJson('webauthn/lost', [
'email' => 'john.doe@mail.com'
])
->assertSeeText(trans('larapass::recovery.sent'));

$notification->assertSentTo(TestWebAuthnUser::first(), AccountRecoveryNotification::class);

$this->assertDatabaseHas('web_authn_recoveries', [
'email' => 'john.doe@mail.com'
]);
}

public function test_error_if_email_invalid()
{
$notification = Notification::fake();
Expand All @@ -137,6 +153,11 @@ public function test_error_if_email_invalid()
->assertRedirect(route('webauthn.lost.form'))
->assertSessionHasErrors(['email']);

$this->postJson('webauthn/lost', [
'email' => 'invalid'
])
->assertSeeText('The given data was invalid');

$notification->assertNothingSent();

$this->assertDatabaseMissing('web_authn_recoveries', [
Expand All @@ -156,6 +177,11 @@ public function test_error_if_user_email_doesnt_exists()
->assertRedirect(route('webauthn.lost.form'))
->assertSessionHasErrors(['email']);

$this->postJson('webauthn/lost', [
'email' => 'foo@bar.com'
])
->assertSeeText('The given data was invalid');

$notification->assertNothingSent();

$this->assertDatabaseMissing('web_authn_recoveries', [
Expand Down Expand Up @@ -190,6 +216,11 @@ public function test_throttled_on_resend()
])
->assertRedirect(route('webauthn.lost.form'))
->assertSessionHasErrors(['email']);

$this->postJson('webauthn/lost', [
'email' => 'john.doe@mail.com'
])
->assertSeeText(trans('larapass::recovery.throttled'));
}

public function test_error_if_no_broker_is_set()
Expand Down

0 comments on commit 35b2921

Please sign in to comment.