Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /webauthn/createcredential-passing.https.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<title>WebAuthn credential.create() Passing Tests</title>
<meta name="timeout" content="long">
<link rel="author" title="Adam Powers" href="mailto:adam@fidoalliance.org">
<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>
standardSetup(function() {
"use strict";
// CreateCredentialTest passing tests
// default arguments
new CreateCredentialsTest().runTest("passing credentials.create() with default arguments");
// rp
new CreateCredentialsTest({path: "options.publicKey.rp.id", value: window.location.hostname}).runTest("passing credentials.create() with rpId (hostname)");
// user
new CreateCredentialsTest("options.publicKey.user.id", new ArrayBuffer(1)).runTest("very short user id");
new CreateCredentialsTest("options.publicKey.user.id", new ArrayBuffer(64)).runTest("max length user id");
new CreateCredentialsTest("options.publicKey.user.id", new Uint8Array(64)).runTest("Uint8Array user id");
new CreateCredentialsTest("options.publicKey.user.id", new Int8Array(64)).runTest("Int8Array user id");
new CreateCredentialsTest("options.publicKey.user.id", new Int16Array(32)).runTest("Int16Array user id");
new CreateCredentialsTest("options.publicKey.user.id", new Int32Array(16)).runTest("Int32Array user id");
new CreateCredentialsTest("options.publicKey.user.id", new Float32Array(16)).runTest("Float32Array user id");
var dvBuf1 = new ArrayBuffer(16);
new CreateCredentialsTest("options.publicKey.user.id", new DataView(dvBuf1)).runTest("DataView user id");
// good challenge values
// all these challenges are zero-filled buffers... think anyone will complain?
new CreateCredentialsTest("options.publicKey.challenge", new Int16Array(33)).runTest("Int16Array challenge");
new CreateCredentialsTest("options.publicKey.challenge", new Int32Array(17)).runTest("Int32Array challenge");
new CreateCredentialsTest("options.publicKey.challenge", new Float32Array(17)).runTest("Float32Array challenge");
new CreateCredentialsTest("options.publicKey.challenge", new Float64Array(9)).runTest("Float64Array challenge");
var dvBuf2 = new ArrayBuffer(65);
new CreateCredentialsTest("options.publicKey.challenge", new DataView(dvBuf2)).runTest("DataView challenge");
new CreateCredentialsTest("options.publicKey.challenge", new ArrayBuffer(8192)).runTest("Absurdly large challenge");
// good pubKeyCredParams values
// empty pubKeyCredParams should default to EC256 and RS256
new CreateCredentialsTest("options.publicKey.pubKeyCredParams", []).runTest("pubKeyCredParams is empty Array");
const pkParamEC256 = {
type: "public-key",
alg: cose_alg_ECDSA_w_SHA256
};
const pkParamEC512 = {
type: "public-key",
alg: cose_alg_ECDSA_w_SHA512
};
new CreateCredentialsTest("options.publicKey.pubKeyCredParams", [pkParamEC256]).runTest("EC256 pubKeyCredParams");
new CreateCredentialsTest("options.publicKey.pubKeyCredParams", [pkParamEC512, pkParamEC256])
.runTest("SelectEC256 pubKeyCredParams from a list");
// pubKeyCredParams with unknown value
new CreateCredentialsTest("options.publicKey.pubKeyCredParams", [{ "type": "unknown", alg: -7, }, { "type": "public-key", alg: -7, }])
.runTest("pubKeyCredParams with unknown value");
// timeout
new CreateCredentialsTest({path: "options.publicKey.timeout", value: undefined}).runTest("passing credentials.create() with no timeout");
// valid authenticatorSelection values
var defaultAuthnrSel = {
authenticatorAttachment: "cross-platform",
requireResidentKey: false,
userVerification: "preferred"
};
// attachment
var authnrSelAttachUndef = cloneObject(defaultAuthnrSel);
authnrSelAttachUndef.authenticatorAttachment = undefined;
var authnrSelAttachEmptyStr = cloneObject(defaultAuthnrSel);
authnrSelAttachEmptyStr.authenticatorAttachment = "";
var authnrSelAttachEmptyObj = cloneObject(defaultAuthnrSel);
authnrSelAttachEmptyObj.authenticatorAttachment = {};
var authnrSelAttachNull = cloneObject(defaultAuthnrSel);
authnrSelAttachNull.authenticatorAttachment = null;
var authnrSelAttachUnknownValue = cloneObject(defaultAuthnrSel);
authnrSelAttachUnknownValue.authenticatorAttachment = "unknown-value";
// resident key
var authnrSelRkUndef = cloneObject(defaultAuthnrSel);
authnrSelRkUndef.requireResidentKey = undefined;
var authnrSelRkFalse = cloneObject(defaultAuthnrSel);
authnrSelRkFalse.requireResidentKey = false;
// user verification
var authnrSelUvUndef = cloneObject(defaultAuthnrSel);
authnrSelUvUndef.userVerification = undefined;
var authnrSelUvDiscouraged = cloneObject(defaultAuthnrSel);
authnrSelUvDiscouraged.userVerification = "discouraged";
var authnrSelUvEmptyStr = cloneObject(defaultAuthnrSel);
authnrSelUvEmptyStr.userVerification = "";
var authnrSelUvEmptyObj = cloneObject(defaultAuthnrSel);
authnrSelUvEmptyObj.userVerification = {};
var authnrSelUvStr = cloneObject(defaultAuthnrSel);
authnrSelUvStr.userVerification = "requiredshirtshoestshirt";
var authnrSelUvNull = cloneObject(defaultAuthnrSel);
authnrSelUvNull.userVerification = null;
new CreateCredentialsTest({path: "options.publicKey.authenticatorSelection", value: undefined}).runTest("authenticatorSelection is undefined");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", {}).runTest("authenticatorSelection is empty object");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", cloneObject(defaultAuthnrSel)).runTest("authenticatorSelection default values");
// authnr selection attachment
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelAttachUndef).runTest("authenticatorSelection attachment undefined");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelAttachEmptyStr).runTest("authenticatorSelection attachment empty string");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelAttachEmptyObj).runTest("authenticatorSelection attachment empty object");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelAttachNull).runTest("authenticatorSelection attachment null");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelAttachUnknownValue).runTest("authenticatorSelection attachment unknown value");
// authnr selection resident key
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelRkUndef).runTest("authenticatorSelection residentKey undefined");
// XXX: assumes authnr is behaving like most U2F authnrs; really depends on the authnr or mock configuration
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelRkFalse).runTest("authenticatorSelection residentKey false");
// authnr selection user verification
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelUvUndef).runTest("authenticatorSelection userVerification undefined");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelUvDiscouraged).runTest("authenticatorSelection userVerification discouraged");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelUvEmptyStr).runTest("authenticatorSelection userVerification empty string");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelUvEmptyObj).runTest("authenticatorSelection userVerification empty object");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelUvStr).runTest("authenticatorSelection userVerification unknown value");
new CreateCredentialsTest("options.publicKey.authenticatorSelection", authnrSelUvNull).runTest("authenticatorSelection userVerification null");
// good attestation values
new CreateCredentialsTest("options.publicKey.attestation", "none").runTest("attestation parameter: attestation is \"none\"");
new CreateCredentialsTest("options.publicKey.attestation", "indirect").runTest("attestation parameter: attestation is \"indirect\"");
new CreateCredentialsTest("options.publicKey.attestation", "direct").runTest("attestation parameter: attestation is \"direct\"");
new CreateCredentialsTest({path: "options.publicKey.attestation", value: undefined}).runTest("attestation parameter: attestation is undefined");
// attestation unknown values
new CreateCredentialsTest("options.publicKey.attestation", {}).runTest("attestation parameter: attestation is empty object");
new CreateCredentialsTest("options.publicKey.attestation", []).runTest("attestation parameter: attestation is empty array");
new CreateCredentialsTest("options.publicKey.attestation", null).runTest("attestation parameter: attestation is null");
new CreateCredentialsTest("options.publicKey.attestation", "noneofyourbusiness").runTest("attestation parameter: attestation is \"noneofyourbusiness\"");
new CreateCredentialsTest("options.publicKey.attestation", "").runTest("attestation parameter: attestation is empty string");
// TODO: test this with multiple mock authenticators to make sure that the right options are chosen when available?
// good extension values
new CreateCredentialsTest({path: "options.publicKey.extensions", value: undefined}).runTest("extensions undefined");
new CreateCredentialsTest("options.publicKey.extensions", {}).runTest("extensions are empty object");
new CreateCredentialsTest("options.publicKey.extensions", {foo: "", bar: "", bat: ""}).runTest("extensions are dict of empty strings");
});
/* JSHINT */
/* globals standardSetup, CreateCredentialsTest, cose_alg_ECDSA_w_SHA256, cose_alg_ECDSA_w_SHA512, cloneObject */
</script>