| <!DOCTYPE html> |
| <meta charset="utf-8"> |
| <title>WebAuthn uiMode: 'immediate' Tests</title> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script src="/resources/testdriver.js"></script> |
| <script src="/resources/testdriver-vendor.js"></script> |
| <script src=helpers.js></script> |
| <body></body> |
| <script> |
| "use strict"; |
| |
| // Test uiMode: 'immediate' with mediation: 'optional' (Success case with Resident Key). |
| virtualAuthenticatorPromiseTest(async t => { |
| const credential = await createCredential({ |
| options: { |
| publicKey: { |
| authenticatorSelection: { |
| residentKey: "required", |
| requireResidentKey: true, |
| } |
| } |
| } |
| }); |
| await test_driver.bless("activate immediate mode"); |
| const assertion = await navigator.credentials.get({ |
| publicKey: { |
| challenge: new Uint8Array(16), |
| rpId: window.location.hostname, |
| }, |
| uiMode: "immediate", |
| }); |
| assert_class_string(assertion, "PublicKeyCredential"); |
| }, { |
| protocol: "ctap2", |
| hasResidentKey: true, |
| hasUserVerification: true, |
| isUserVerified: true, |
| transport: "internal", |
| }, "Immediate mediation (optional) with a resident credential"); |
| |
| // Test uiMode: 'immediate' with mediation: 'required' (Success case). |
| virtualAuthenticatorPromiseTest(async t => { |
| const credential = await createCredential({ |
| options: { |
| publicKey: { |
| authenticatorSelection: { |
| residentKey: "required", |
| requireResidentKey: true, |
| } |
| } |
| } |
| }); |
| await test_driver.bless("activate immediate mode"); |
| const assertion = await navigator.credentials.get({ |
| publicKey: { |
| challenge: new Uint8Array(16), |
| rpId: window.location.hostname, |
| }, |
| uiMode: "immediate", |
| mediation: "required" |
| }); |
| assert_class_string(assertion, "PublicKeyCredential"); |
| }, { |
| protocol: "ctap2", |
| hasResidentKey: true, |
| hasUserVerification: true, |
| isUserVerified: true, |
| transport: "internal", |
| }, "Immediate mediation (required) with a resident credential"); |
| |
| // Test uiMode: 'immediate' failure when allowCredentials is provided. |
| virtualAuthenticatorPromiseTest(async t => { |
| const credential = await createCredential(); |
| await test_driver.bless("activate immediate mode"); |
| const promise = navigator.credentials.get({ |
| publicKey: { |
| challenge: new Uint8Array(16), |
| rpId: window.location.hostname, |
| allowCredentials: [{ |
| type: "public-key", |
| id: credential.rawId, |
| }], |
| }, |
| uiMode: "immediate", |
| }); |
| return promise_rejects_dom(t, "NotAllowedError", promise); |
| }, { |
| protocol: "ctap2", |
| hasResidentKey: true, |
| hasUserVerification: true, |
| isUserVerified: true, |
| transport: "internal", |
| }, "Immediate mediation fails if allowCredentials is not empty"); |
| |
| // Test uiMode: 'immediate' failure without user activation. |
| virtualAuthenticatorPromiseTest(async t => { |
| const credential = await createCredential(); |
| |
| const promise = navigator.credentials.get({ |
| publicKey: { |
| challenge: new Uint8Array(16), |
| rpId: window.location.hostname, |
| }, |
| uiMode: "immediate", |
| }); |
| return promise_rejects_dom(t, "NotAllowedError", promise); |
| }, { |
| protocol: "ctap2", |
| hasResidentKey: true, |
| hasUserVerification: true, |
| isUserVerified: true, |
| transport: "internal", |
| }, "Immediate mediation fails without user activation"); |
| |
| // Test uiMode: 'immediate' when no credentials are available. |
| virtualAuthenticatorPromiseTest(async t => { |
| await test_driver.bless("activate immediate mode"); |
| const promise = navigator.credentials.get({ |
| publicKey: { |
| challenge: new Uint8Array(16), |
| rpId: window.location.hostname, |
| }, |
| uiMode: "immediate", |
| mediation: "optional" |
| }); |
| return promise_rejects_dom(t, "NotAllowedError", promise); |
| }, { |
| protocol: "ctap2", |
| hasResidentKey: true, |
| hasUserVerification: true, |
| transport: "internal", |
| }, "Immediate mediation (optional) with no credentials"); |
| |
| // Test uiMode: 'immediate' incompatibility with mediation: 'conditional'. |
| virtualAuthenticatorPromiseTest(async t => { |
| const promise = navigator.credentials.get({ |
| publicKey: { |
| challenge: new Uint8Array(16), |
| rpId: window.location.hostname, |
| }, |
| uiMode: "immediate", |
| mediation: "conditional" |
| }); |
| return promise_rejects_dom(t, "NotSupportedError", promise); |
| }, { |
| protocol: "ctap2", |
| hasResidentKey: true, |
| hasUserVerification: true, |
| transport: "internal", |
| }, "Immediate mediation is incompatible with conditional mediation"); |
| |
| </script> |