Skip to content

Commit

Permalink
Suppressing unexpected errors with `WebAuthn::PublicKeyCredentialWith…
Browse files Browse the repository at this point in the history
…Attestation#verify`
  • Loading branch information
soartec-lab committed Oct 21, 2023
1 parent d897c1a commit bcfc5c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/webauthn/public_key_credential_with_attestation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

module WebAuthn
class PublicKeyCredentialWithAttestation < PublicKeyCredential
class InvalidChallengeError < Error; end

def self.response_class
WebAuthn::AuthenticatorAttestationResponse
end

def verify(challenge, user_verification: nil)
challenge.is_a?(String) || raise(InvalidChallengeError, "challenge must be a String. input challenge class: #{challenge.class}")

super

response.verify(encoder.decode(challenge), user_verification: user_verification)
Expand Down
10 changes: 9 additions & 1 deletion spec/webauthn/public_key_credential_with_attestation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@
end
end

context "when challenge is invalid" do
context "when challenge class is invalid" do
it "raise error" do
expect {
public_key_credential.verify(nil)
}.to raise_error(WebAuthn::PublicKeyCredentialWithAttestation::InvalidChallengeError)
end
end

context "when challenge value is invalid" do
it "fails" do
expect {
public_key_credential.verify(Base64.urlsafe_encode64("another challenge"))
Expand Down

0 comments on commit bcfc5c0

Please sign in to comment.