blob: 0757e188635f0887c77dd7645b5a5fe07bcbb40b [file] [edit]
<!DOCTYPE html><!-- webkit-test-runner [ WebAuthenticationModernEnabled=false ] -->
<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.internals)
internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", payloadBase64: [testAssertionMessageBase64] } });
promise_test(t => {
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
timeout: 100
}
};
return navigator.credentials.get(options).then(credential => {
return checkCtapGetAssertionResult(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 checkCtapGetAssertionResult(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 checkCtapGetAssertionResult(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 checkCtapGetAssertionResult(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 checkCtapGetAssertionResult(credential);
});
}, "PublicKeyCredential's [[get]] with mixed options in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
timeout: 100
}
};
// Stall the first request to wait for cancellation.
if (window.internals)
internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", payloadBase64: [testAssertionMessageBase64], expectCancel: true } });
promiseRejects(t, "NotAllowedError", navigator.credentials.get(options), "This request has been cancelled by a new request.");
if (window.internals)
internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", payloadBase64: [testAssertionMessageBase64] } });
return navigator.credentials.get(options).then(credential => {
return checkCtapGetAssertionResult(credential);
});
}, "PublicKeyCredential's [[get]] with two consecutive requests.");
promise_test(t => {
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
timeout: 100
}
};
if (window.internals)
internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", payloadBase64: [testAssertionMessageLongBase64, testAssertionMessageLongBase64] } });
return navigator.credentials.get(options).then(credential => {
return checkCtapGetAssertionResult(credential, "MIIBkzCCATigAwIBAjCCAZMwggE4oAMCAQIwggGTMII=");
});
}, "PublicKeyCredential's [[get]] with multiple accounts in a mock hid authenticator.");
promise_test(t => {
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
userVerification: "discouraged",
timeout: 100
}
};
if (window.internals)
internals.setMockWebAuthenticationConfiguration({ hid: { supportClientPin: true, payloadBase64: [testAssertionMessageBase64] } });
return navigator.credentials.get(options).then(credential => {
return checkCtapGetAssertionResult(credential);
});
}, "PublicKeyCredential's [[get]] with PIN supported in the authenticator but userVerification = 'discouraged' in a mock hid authenticator.");
promise_test(t => {
let config = { hid: { stage: "request", subStage: "msg", error: "success", payloadBase64: [testAssertionMessageBase64] } };
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
timeout: 100,
allowCredentials: [],
}
};
const numCredentials = 20;
for (let i = 0; i < numCredentials; i++) {
options.publicKey.allowCredentials.push({ type: "public-key", id: generateID(i) });
config.hid.payloadBase64.unshift("Lg==");
}
if (window.internals)
internals.setMockWebAuthenticationConfiguration(config);
return navigator.credentials.get(options).then(credential => {
return checkCtapGetAssertionResult(credential);
});
}, "PublicKeyCredential's [[get]] with many allowCredentials necessitating batching in a mock hid authenticator.");
promise_test(t => {
let config = { hid: { maxCredentialCountInList: 5, stage: "request", subStage: "msg", error: "success", payloadBase64: [testAssertionMessageBase64] } };
const options = {
publicKey: {
challenge: Base64URL.parse("MTIzNDU2"),
timeout: 100,
allowCredentials: [],
}
};
const numCredentials = 20;
for (let i = 0; i < numCredentials; i++)
options.publicKey.allowCredentials.push({ type: "public-key", id: generateID(i) });
for (let i = 0; i < Math.ceil(numCredentials/config.hid.maxCredentialCountInList); i++)
config.hid.payloadBase64.unshift("Lg==");
if (window.internals)
internals.setMockWebAuthenticationConfiguration(config);
return navigator.credentials.get(options).then(credential => {
checkCtapGetAssertionResult(credential);
});
}, "PublicKeyCredential's [[get]] with many allowCredentials necessitating batching in a mock hid authenticator. 2");
</script>