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

Commit

Permalink
Merge pull request #7 from DarkGhostHunter/master
Browse files Browse the repository at this point in the history
Fixed trait and added more tests.
  • Loading branch information
DarkGhostHunter authored Jul 11, 2020
2 parents 7eef255 + e8ba2ba commit b997a63
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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' => '[email protected]'
])
->assertSeeText(trans('larapass::recovery.sent'));

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

$this->assertDatabaseHas('web_authn_recoveries', [
'email' => '[email protected]'
]);
}

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' => '[email protected]'
])
->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' => '[email protected]'
])
->assertSeeText(trans('larapass::recovery.throttled'));
}

public function test_error_if_no_broker_is_set()
Expand Down

0 comments on commit b997a63

Please sign in to comment.