Skip to content

Commit 6c632d2

Browse files
test: update specs
1 parent 681c715 commit 6c632d2

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

spec/webauthn/authenticator_assertion_response_spec.rb

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@
502502
end
503503

504504
describe "migrated U2F credential" do
505-
let(:origin) { "https://f69df4d9.ngrok.io" }
505+
let(:origin) { seeds[:u2f_migration][:assertion][:origin] }
506506
let(:app_id) { "#{origin}/appid" }
507507
let(:migrated_credential) do
508508
WebAuthn::U2fMigrator.new(
@@ -525,17 +525,35 @@
525525
end
526526
let(:original_challenge) { WebAuthn::Encoders::Base64Encoder.decode(assertion_data[:challenge]) }
527527

528-
context "when correct FIDO AppID is given as rp_id" do
529-
it "verifies" do
530-
expect(
531-
assertion_response.verify(original_challenge, public_key: credential_public_key, sign_count: 0, rp_id: app_id)
532-
).to be_truthy
528+
it "verifies" do
529+
expect(
530+
assertion_response.verify(original_challenge, public_key: credential_public_key, sign_count: 0)
531+
).to be_truthy
532+
end
533+
534+
it "is valid" do
535+
expect(
536+
assertion_response.valid?(original_challenge, public_key: credential_public_key, sign_count: 0)
537+
).to be_truthy
538+
end
539+
540+
context "when authenticator_data contains FIDO AppID hash instead of rp_id hash" do
541+
before do
542+
allow(assertion_response.authenticator_data).to receive(:rp_id_hash).and_return(OpenSSL::Digest::SHA256.digest(app_id))
533543
end
534544

535-
it "is valid" do
536-
expect(
537-
assertion_response.valid?(original_challenge, public_key: credential_public_key, sign_count: 0, rp_id: app_id)
538-
).to be_truthy
545+
context "and FIDO AppID is given as rp_id" do
546+
it "verifies" do
547+
expect(
548+
assertion_response.verify(original_challenge, public_key: credential_public_key, sign_count: 0, rp_id: app_id)
549+
).to be_truthy
550+
end
551+
552+
it "is valid" do
553+
expect(
554+
assertion_response.valid?(original_challenge, public_key: credential_public_key, sign_count: 0, rp_id: app_id)
555+
).to be_truthy
556+
end
539557
end
540558
end
541559
end

spec/webauthn/public_key_credential_with_assertion_spec.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@
286286

287287
before do
288288
WebAuthn.configuration.legacy_u2f_appid = legacy_u2f_appid
289+
290+
allow(assertion_response.authenticator_data).to receive(:rp_id_hash).and_return(OpenSSL::Digest::SHA256.digest(legacy_u2f_appid))
289291
end
290292

291293
it "works" do
@@ -298,7 +300,7 @@
298300
).to be_truthy
299301
end
300302

301-
context "if appid extension is not requested" do
303+
context "if appid extension output is not present" do
302304
let(:public_key_credential) do
303305
WebAuthn::PublicKeyCredentialWithAssertion.new(
304306
type: credential_type,
@@ -331,7 +333,7 @@
331333
end.to raise_error("Unspecified legacy U2F AppID")
332334
end
333335

334-
context "if appid extension is not requested" do
336+
context "if appid extension output is not present" do
335337
let(:public_key_credential) do
336338
WebAuthn::PublicKeyCredentialWithAssertion.new(
337339
type: credential_type,
@@ -341,14 +343,14 @@
341343
)
342344
end
343345

344-
it "fails" do
345-
expect do
346+
it "works" do
347+
expect(
346348
public_key_credential.verify(
347349
challenge,
348350
public_key: credential_public_key,
349351
sign_count: credential_sign_count
350352
)
351-
end.to raise_error(WebAuthn::RpIdVerificationError)
353+
).to be_truthy
352354
end
353355
end
354356
end

0 commit comments

Comments
 (0)