blob: cf18ff77ef33fa324320d3c5b3ac64da9ea42832 [file] [log] [blame]
<!DOCTYPE html>
<title>Web Authentication API: PublicKeyCredential's [[get]] failure cases.</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({ });
promise_test(t => {
const options = {
publicKey: {
challenge: asciiToUint8Array("123456"),
timeout: 10
}
};
return promiseRejects(t, "NotAllowedError",
navigator.credentials.get(options), "Operation timed out.");
}, "PublicKeyCredential's [[get]] with timeout");
promise_test(t => {
const options = {
publicKey: {
rpId: "example.com",
challenge: asciiToUint8Array("123456")
}
};
return promiseRejects(t, "SecurityError",
navigator.credentials.get(options), "The provided RP ID is not a registrable domain suffix of the effective domain of the document.");
}, "PublicKeyCredential's [[get]] with a mismatched RP ID");
promise_test(t => {
const options = {
publicKey: {
challenge: asciiToUint8Array("123456"),
extensions: { appid: "abc" }
}
};
return promiseRejects(t, "SecurityError",
navigator.credentials.get(options), "The origin of the document is not authorized for the provided App ID.");
}, "PublicKeyCredential's [[get]] with a mismatched APP ID (invalid URLs)");
promise_test(t => {
const options = {
publicKey: {
challenge: asciiToUint8Array("123456"),
extensions: { appid: "ftp://localhost" }
}
};
return promiseRejects(t, "SecurityError",
navigator.credentials.get(options), "The origin of the document is not authorized for the provided App ID.");
}, "PublicKeyCredential's [[get]] with a mismatched APP ID (different protocols)");
promise_test(t => {
const options = {
publicKey: {
challenge: asciiToUint8Array("123456"),
extensions: { appid: "https://127.0.0.1" }
}
};
return promiseRejects(t, "SecurityError",
navigator.credentials.get(options), "The origin of the document is not authorized for the provided App ID.");
}, "PublicKeyCredential's [[get]] with a mismatched APP ID (different sites 1)");
promise_test(t => {
const options = {
publicKey: {
challenge: asciiToUint8Array("123456"),
extensions: { appid: "https://haha.localhost" }
}
};
return promiseRejects(t, "SecurityError",
navigator.credentials.get(options), "The origin of the document is not authorized for the provided App ID.");
}, "PublicKeyCredential's [[get]] with a mismatched APP ID (different sites 2)");
promise_test(t => {
const options = {
publicKey: {
challenge: asciiToUint8Array("123456")
}
};
const result = promiseRejects(t, "NotAllowedError", navigator.credentials.get(options), "This request has been voided by a new request.");
promiseRejects(t, "NotAllowedError", navigator.credentials.get(options), "This request has been voided by a new request.");
return result;
}, "PublicKeyCredential's [[get]] with two consecutive requests");
promise_test(function(t) {
const requestOptions = {
publicKey: {
challenge: asciiToUint8Array("123456")
}
};
const result = promiseRejects(t, "NotAllowedError", navigator.credentials.get(requestOptions), "This request has been voided by a new request.");
const creationOptions = {
publicKey: {
rp: {
name: "example.com"
},
user: {
name: "John Appleseed",
id: asciiToUint8Array("123456"),
displayName: "John",
},
challenge: asciiToUint8Array("123456"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
}
};
promiseRejects(t, "NotAllowedError", navigator.credentials.create(creationOptions), "This request has been voided by a new request.");
return result;
}, "PublicKeyCredential's [[get]] with two consecutive requests (2)");
promise_test(t => {
const options = {
publicKey: {
challenge: asciiToUint8Array("123456")
}
};
const result = promiseRejects(t, "NotAllowedError", navigator.credentials.get(options), "This request has been cancelled by a new request.");
window.open("./resources/new-page.html?isCreation=false");
return result;
}, "PublicKeyCredential's [[get]] with new requests in a new page");
promise_test(t => {
const options = {
publicKey: {
challenge: asciiToUint8Array("123456")
}
};
const result = promiseRejects(t, "NotAllowedError", navigator.credentials.get(options), "This request has been cancelled by a new request.");
window.open("./resources/new-page.html?isCreation=true");
return result;
}, "PublicKeyCredential's [[get]] with new requests in a new page (2)");
</script>