Skip to content

Commit 562aa63

Browse files
test: update specs
1 parent 681c715 commit 562aa63

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

spec/webauthn/authenticator_assertion_response_spec.rb

Lines changed: 40 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,47 @@
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)
543+
.to receive(:rp_id_hash)
544+
.and_return(OpenSSL::Digest::SHA256.digest(app_id))
533545
end
534546

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
547+
context "and FIDO AppID is given as rp_id" do
548+
it "verifies" do
549+
expect(
550+
assertion_response.verify(
551+
original_challenge,
552+
public_key: credential_public_key,
553+
sign_count: 0,
554+
rp_id: app_id
555+
)
556+
).to be_truthy
557+
end
558+
559+
it "is valid" do
560+
expect(
561+
assertion_response.valid?(
562+
original_challenge,
563+
public_key: credential_public_key,
564+
sign_count: 0,
565+
rp_id: app_id
566+
)
567+
).to be_truthy
568+
end
539569
end
540570
end
541571
end

spec/webauthn/public_key_credential_with_assertion_spec.rb

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

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

291295
it "works" do
@@ -298,7 +302,7 @@
298302
).to be_truthy
299303
end
300304

301-
context "if appid extension is not requested" do
305+
context "if appid extension output is not present" do
302306
let(:public_key_credential) do
303307
WebAuthn::PublicKeyCredentialWithAssertion.new(
304308
type: credential_type,
@@ -331,7 +335,7 @@
331335
end.to raise_error("Unspecified legacy U2F AppID")
332336
end
333337

334-
context "if appid extension is not requested" do
338+
context "if appid extension output is not present" do
335339
let(:public_key_credential) do
336340
WebAuthn::PublicKeyCredentialWithAssertion.new(
337341
type: credential_type,
@@ -341,14 +345,14 @@
341345
)
342346
end
343347

344-
it "fails" do
345-
expect do
348+
it "works" do
349+
expect(
346350
public_key_credential.verify(
347351
challenge,
348352
public_key: credential_public_key,
349353
sign_count: credential_sign_count
350354
)
351-
end.to raise_error(WebAuthn::RpIdVerificationError)
355+
).to be_truthy
352356
end
353357
end
354358
end

0 commit comments

Comments
 (0)