blob: 5446f5570f29d5346af787cf564c93e5670af70c [file] [log] [blame]
<!DOCTYPE html>
<title>Web Authentication API: PublicKeyCredential's [[create]] success cases with a mock hid authenticator.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/util.js"></script>
<script src="./resources/cbor.js"></script>
<script>
// Default mock configuration. Tests need to override if they need different configuration.
if (window.internals)
internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", payloadBase64: [testCreationMessageBase64] } });
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential);
});
}, "PublicKeyCredential's [[create]] with minimum options in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
authenticatorSelection: { authenticatorAttachment: "cross-platform" },
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential);
});
}, "PublicKeyCredential's [[create]] with authenticatorSelection { 'cross-platform' } in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
authenticatorSelection: { requireResidentKey: false },
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential);
});
}, "PublicKeyCredential's [[create]] with requireResidentKey { false } in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
authenticatorSelection: { userVerification: "preferred" },
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential);
});
}, "PublicKeyCredential's [[create]] with userVerification { 'preferred' } in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
authenticatorSelection: { userVerification: "discouraged" },
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential);
});
}, "PublicKeyCredential's [[create]] with userVerification { 'discouraged' } in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
authenticatorSelection: { authenticatorAttachment: "cross-platform", requireResidentKey: false, userVerification: "preferred" },
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential);
});
}, "PublicKeyCredential's [[create]] with mixed options in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
timeout: 100
}
};
promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "This request has been voided by a new request.");
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential);
});
}, "PublicKeyCredential's [[create]] with two consecutive requests.");
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
attestation: "none",
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential);
});
}, "PublicKeyCredential's [[create]] with none attestation in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
attestation: "direct",
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential, false);
});
}, "PublicKeyCredential's [[create]] with direct attestation in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
attestation: "indirect",
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential, false);
});
}, "PublicKeyCredential's [[create]] with indirect attestation in a mock hid authenticator.");
// When RP ID is not google.com, googleLegacyAppidSupport should not have any effects.
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
extensions: { googleLegacyAppidSupport: true },
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential);
});
}, "PublicKeyCredential's [[create]] with googleLegacyAppidSupport extension in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: Base64URL.parse(testUserhandleBase64),
displayName: "Appleseed",
},
challenge: Base64URL.parse("MTIzNDU2"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
extensions: { googleLegacyAppidSupport: true, appid: "" },
timeout: 100
}
};
return navigator.credentials.create(options).then(credential => {
checkCtapMakeCredentialResult(credential);
});
}, "PublicKeyCredential's [[create]] with googleLegacyAppidSupport and appid extensions in a mock hid authenticator.");
</script>