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

Commit b997a63

Browse files
Merge pull request #7 from DarkGhostHunter/master
Fixed trait and added more tests.
2 parents 7eef255 + e8ba2ba commit b997a63

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

src/Http/AuthenticatesWebAuthn.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public function login(Request $request)
9696
*/
9797
protected function hasRemember(Request $request)
9898
{
99-
return $request->filled('remember') || $request->header('WebAuthn-Remember');
99+
return filter_var($request->header('WebAuthn-Remember'), FILTER_VALIDATE_BOOLEAN)
100+
?: $request->filled('remember');
100101
}
101102

102103
/**

src/Http/RecoversWebAuthn.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function register(Request $request, WebAuthnAuthenticatable $user)
120120
protected function shouldDisableAllCredentials(Request $request)
121121
{
122122
return filter_var($request->header('WebAuthn-Unique'), FILTER_VALIDATE_BOOLEAN)
123-
?? $request->filled('unique');
123+
?: $request->filled('unique');
124124
}
125125

126126
/**
@@ -176,4 +176,4 @@ public function redirectPath()
176176

177177
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
178178
}
179-
}
179+
}

tests/Http/WebAuthnConfirmTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public function test_asks_for_confirmation()
105105
->get('intended')
106106
->assertRedirect('webauthn/confirm');
107107

108+
$this->actingAs($this->user)
109+
->getJson('intended')
110+
->assertSeeText('Authenticator assertion required.');
111+
108112
$this->actingAs($this->user)
109113
->followingRedirects()
110114
->get('intended')

tests/Http/WebAuthnDeviceLostTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ public function test_sends_recovery_email()
125125
]);
126126
}
127127

128+
public function test_sends_recovery_email_using_json()
129+
{
130+
$notification = Notification::fake();
131+
132+
$this->postJson('webauthn/lost', [
133+
'email' => 'john.doe@mail.com'
134+
])
135+
->assertSeeText(trans('larapass::recovery.sent'));
136+
137+
$notification->assertSentTo(TestWebAuthnUser::first(), AccountRecoveryNotification::class);
138+
139+
$this->assertDatabaseHas('web_authn_recoveries', [
140+
'email' => 'john.doe@mail.com'
141+
]);
142+
}
143+
128144
public function test_error_if_email_invalid()
129145
{
130146
$notification = Notification::fake();
@@ -137,6 +153,11 @@ public function test_error_if_email_invalid()
137153
->assertRedirect(route('webauthn.lost.form'))
138154
->assertSessionHasErrors(['email']);
139155

156+
$this->postJson('webauthn/lost', [
157+
'email' => 'invalid'
158+
])
159+
->assertSeeText('The given data was invalid');
160+
140161
$notification->assertNothingSent();
141162

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

180+
$this->postJson('webauthn/lost', [
181+
'email' => 'foo@bar.com'
182+
])
183+
->assertSeeText('The given data was invalid');
184+
159185
$notification->assertNothingSent();
160186

161187
$this->assertDatabaseMissing('web_authn_recoveries', [
@@ -190,6 +216,11 @@ public function test_throttled_on_resend()
190216
])
191217
->assertRedirect(route('webauthn.lost.form'))
192218
->assertSessionHasErrors(['email']);
219+
220+
$this->postJson('webauthn/lost', [
221+
'email' => 'john.doe@mail.com'
222+
])
223+
->assertSeeText(trans('larapass::recovery.throttled'));
193224
}
194225

195226
public function test_error_if_no_broker_is_set()

0 commit comments

Comments
 (0)