Skip to content

Commit

Permalink
fix: invalid challenge causes a query exception (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijs authored Feb 26, 2024
1 parent d598f0f commit 7199d4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Auth/EloquentWebAuthnProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function retrieveByCredentials(array $credentials): ?User
return $this->retrieveById($webauthnKey->user_id);
} catch (ModelNotFoundException $e) {
// No result
return null;
}
}

Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/Auth/EloquentWebAuthnProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,29 @@ public function it_retrieve_user_new_format()
$this->assertNotNull($result);
$this->assertEquals($user->id, $result->id);
}

/**
* @test
*/
public function it_does_not_fail_when_retrieving_user()
{
Webauthn::shouldReceive('validateAssertion')->andReturn(true);
Webauthn::shouldReceive('model')->andReturn(WebauthnKey::class);

$provider = new EloquentWebAuthnProvider(
app('config'),
app(CredentialAssertionValidator::class),
app(Hasher::class),
User::class,
);

$result = $provider->retrieveByCredentials([
'id' => Base64UrlSafe::encode('id'),
'rawId' => 'rawId',
'type' => 'public-key',
'response' => 'response',
]);

$this->assertNull($result);
}
}

0 comments on commit 7199d4e

Please sign in to comment.