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

Commit e8ba2ba

Browse files
Added JSON tests.
1 parent 409745a commit e8ba2ba

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

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)