blob: 3421c77899018daee0fc114a8cf1b9b9ee1142a6 [file] [log] [blame]
<!DOCTYPE html>
<title>Web Authentication API: PublicKeyCredential's [[get]] 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>
// Default mock configuration. Tests need to override if they need different configuration.
if (window.testRunner)
testRunner.setWebAuthenticationMockConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", payloadBase64: [testAssertionMessageBase64] } });
function checkResult(credential)
{
// Check respond
assert_array_equals(Base64URL.parse(credential.id), Base64URL.parse(testHidCredentialIdBase64));
assert_equals(credential.type, 'public-key');
assert_array_equals(new Uint8Array(credential.rawId), Base64URL.parse(testHidCredentialIdBase64));
assert_equals(bytesToASCIIString(credential.response.clientDataJSON), '{"type":"webauthn.get","challenge":"MTIzNDU2","origin":"https://localhost:9443"}');
assert_equals(credential.response.userHandle, null);
assert_not_exists(credential.getClientExtensionResults(), "appid");
// Check authData
const authData = decodeAuthData(new Uint8Array(credential.response.authenticatorData));
assert_equals(bytesToHexString(authData.rpIdHash), "46cc7fb9679d55b2db9092e1c8d9e5e1d02b7580f0b4812c770962e1e48f5ad8");
assert_equals(authData.flags, 1);
assert_equals(authData.counter, 80);
}
promise_test(t => {
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
timeout: 100
}
};
return navigator.credentials.get(options).then(credential => {
return checkResult(credential);
});
}, "PublicKeyCredential's [[get]] with minimum options in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
allowCredentials: [
{ type: "public-key", id: Base64URL.parse(testHidCredentialIdBase64), transports: ["usb"] }
],
timeout: 100
}
};
return navigator.credentials.get(options).then(credential => {
return checkResult(credential);
});
}, "PublicKeyCredential's [[get]] with matched allow credentials in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
userVerification: "preferred",
timeout: 100
}
};
return navigator.credentials.get(options).then(credential => {
return checkResult(credential);
});
}, "PublicKeyCredential's [[get]] with userVerification { preferred } in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
userVerification: "discouraged",
timeout: 100
}
};
return navigator.credentials.get(options).then(credential => {
return checkResult(credential);
});
}, "PublicKeyCredential's [[get]] with userVerification { discouraged } in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
allowCredentials: [
{ type: "public-key", id: Base64URL.parse(testHidCredentialIdBase64), transports: ["usb"] }
],
userVerification: "preferred",
timeout: 100
}
};
return navigator.credentials.get(options).then(credential => {
return checkResult(credential);
});
}, "PublicKeyCredential's [[get]] with mixed options in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
timeout: 100
}
};
promiseRejects(t, "NotAllowedError", navigator.credentials.get(options), "This request has been voided by a new request.");
return navigator.credentials.get(options).then(credential => {
return checkResult(credential);
});
}, "PublicKeyCredential's [[get]] with two consecutive requests.");
</script>