diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /testing/web-platform/tests/credential-management/digital-identity.https.html | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-upstream/125.0.1.tar.xz firefox-upstream/125.0.1.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/credential-management/digital-identity.https.html')
-rw-r--r-- | testing/web-platform/tests/credential-management/digital-identity.https.html | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/testing/web-platform/tests/credential-management/digital-identity.https.html b/testing/web-platform/tests/credential-management/digital-identity.https.html new file mode 100644 index 0000000000..82630e2a5b --- /dev/null +++ b/testing/web-platform/tests/credential-management/digital-identity.https.html @@ -0,0 +1,125 @@ +<!DOCTYPE html> +<title>Digital Identity Credential tests.</title> +<link rel="help" href="https://wicg.github.io/digital-identities/"> +<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> + +<body> + +<script> +// Builds valid digital identity request for navigator.credentials.get() API. +function buildValidNavigatorCredentialsRequest() { + return { + identity: { + providers: [{ + holder: { + selector: { + format: ['mdoc'], + doctype: 'org.iso.18013.5.1.mDL', + fields: [ + 'org.iso.18013.5.1.family_name', + 'org.iso.18013.5.1.portrait', + ] + }, + params: { + nonce: '1234', + readerPublicKey: 'test_reader_public_key', + extraParamAsNeededByDigitalCredentials: true, + }, + }, + }], + }, + }; +} + +// Builds valid digital identity request for navigator.identity.get() API. +function buildValidNavigatorIdentityRequest() { + return { + digital: { + providers: [{ + protocol: "protocol", + selector: { + format: ['mdoc'], + doctype: 'org.iso.18013.5.1.mDL', + fields: [ + 'org.iso.18013.5.1.family_name', + 'org.iso.18013.5.1.portrait', + ] + }, + params: { + nonce: '1234', + readerPublicKey: 'test_reader_public_key', + extraParamAsNeededByDigitalCredentials: true, + }, + }], + }, + }; +} + +// Requires browser to have mode where OS-presented digital-identity-prompt is +// bypassed in favour of returning "fake_test_token" directly. +promise_test(async t => { + const {token} = await navigator.credentials.get(buildValidNavigatorCredentialsRequest()); + assert_equals("fake_test_token", token); +}, "navigator.credentials.get() API works in toplevel frame."); + +promise_test(async t => { + let request = buildValidNavigatorCredentialsRequest(); + request.identity.providers = undefined; + + await promise_rejects_js(t, TypeError, navigator.credentials.get(request)); +}, "navigator.credentials.get() API fails if IdentityCredentialRequestOptions::providers is not specified."); + +promise_test(async t => { + let request = buildValidNavigatorCredentialsRequest(); + request.identity.providers = []; + + await promise_rejects_js(t, TypeError, navigator.credentials.get(request)); +}, "navigator.credentials.get() API fails if there are no providers."); + +promise_test(async t => { + let request = buildValidNavigatorCredentialsRequest(); + let providerCopy = structuredClone(request.identity.providers[0]); + request.identity.providers.push(providerCopy); + await promise_rejects_js(t, TypeError, navigator.credentials.get(request)); +}, "navigator.credentials.get() API fails if there is more than one provider."); + +promise_test(async t => { + let request = buildValidNavigatorCredentialsRequest(); + request.identity.providers[0].holder = undefined; + + await promise_rejects_js(t, TypeError, navigator.credentials.get(request)); +}, "navigator.credentials.get() API fails if IdentityProviderConfig::holder is not specified."); + +promise_test(async t => { + let request = buildValidNavigatorIdentityRequest(); + let credential = await navigator.identity.get(request); + assert_equals("protocol", credential.protocol); + assert_equals("fake_test_token", credential.data); +}, "navigator.identity.get() API works in toplevel frame."); + +promise_test(async t => { + let request = buildValidNavigatorIdentityRequest(); + request.digital.providers = undefined; + + await promise_rejects_js(t, TypeError, navigator.identity.get(request)); +}, "navigator.identity.get() API fails if DigitalCredentialRequestOptions::providers is not specified."); + +promise_test(async t => { + let request = buildValidNavigatorIdentityRequest(); + let providerCopy = structuredClone(request.digital.providers[0]); + request.digital.providers.push(providerCopy); + await promise_rejects_js(t, TypeError, navigator.identity.get(request)); +}, "navigator.identity.get() API fails if there is more than one provider."); + +promise_test(async t=> { + let abortController = new AbortController(); + let request = buildValidNavigatorIdentityRequest(); + request.signal = abortController.signal; + let requestPromise = navigator.identity.get(request); + abortController.abort(); + await promise_rejects_dom(t, "AbortError", requestPromise); +}, "navigator.identity.get() promise is rejected when the page aborts the request."); +</script> |