blob: cf5e0d43c5a7f5ce29627f6bd5c3a6cc3de4366a [file] [log] [blame]
<!DOCTYPE html><!-- webkit-test-runner [ WebAuthenticationModernEnabled=true ] -->
<title>Web Authentication API: PublicKeyCredential's [[create]] with invalid parameters.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/util.js"></script>
<script>
const rp = {
name: "example.com"
};
const user = {
name: "John Appleseed",
id: asciiToUint8Array("123456"),
displayName: "Appleseed"
};
const challenge = asciiToUint8Array("123456");
const pubKeyCredParam = { type: "public-key", alg: -7 };
const excludeCredentials = { type: "public-key", id: asciiToUint8Array("123456") };
const missingAttributeVector = [
// missing top level attribute
[undefined, user, challenge, [pubKeyCredParam]],
[rp, undefined, challenge, [pubKeyCredParam]],
[rp, user, undefined, [pubKeyCredParam]],
[rp, user, challenge, undefined],
// missing rp attribute
[{ name: undefined }, user, challenge, [pubKeyCredParam]],
// missing user attribute
[rp, { name: undefined, id: user.id, displayName: user.displayName}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: undefined, displayName: user.displayName}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: user.id, displayName: undefined}, challenge, [pubKeyCredParam]],
// missing pubKeyCredParams attribute
[rp, user, challenge, [{ type: undefined, alg: pubKeyCredParam.alg }]],
[rp, user, challenge, [{ type: pubKeyCredParam.type, alg: undefined }]],
// missing excludeCredentials attribute
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: undefined, id: excludeCredentials.id }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: excludeCredentials.type, id: undefined }]]
];
const wrongTypeAttributeVector = [
// wrong rp attribute type
[{ name: Symbol() }, user, challenge, [pubKeyCredParam]],
[{ name: rp.name, icon: Symbol() }, user, challenge, [pubKeyCredParam]],
[{ name: rp.name, id: Symbol() }, user, challenge, [pubKeyCredParam]],
// wrong user attribute type
[rp, { name: Symbol(), id: user.id, displayName: user.displayName}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: 1, displayName: user.displayName}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: true, displayName: user.displayName}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: null, displayName: user.displayName}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: Symbol(), displayName: user.displayName}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: { }, displayName: user.displayName}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: "foo", displayName: user.displayName}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: [ ], displayName: user.displayName}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: user.id, displayName: Symbol()}, challenge, [pubKeyCredParam]],
[rp, { name: user.name, id: user.id, displayName: user.displayName, icon: Symbol()}, challenge, [pubKeyCredParam]],
// wrong challenge type
[rp, user, 1, [pubKeyCredParam]],
[rp, user, true, [pubKeyCredParam]],
[rp, user, null, [pubKeyCredParam]],
[rp, user, Symbol(), [pubKeyCredParam]],
[rp, user, "foo", [pubKeyCredParam]],
[rp, user, [ ], [pubKeyCredParam]],
[rp, user, { }, [pubKeyCredParam]],
// wrong pubKeyCredParam type
[rp, user, challenge, [{ type: 1, alg: pubKeyCredParam.alg }]],
[rp, user, challenge, [{ type: true, alg: pubKeyCredParam.alg }]],
[rp, user, challenge, [{ type: null, alg: pubKeyCredParam.alg }]],
[rp, user, challenge, [{ type: Symbol(), alg: pubKeyCredParam.alg }]],
[rp, user, challenge, [{ type: "foo", alg: pubKeyCredParam.alg }]],
[rp, user, challenge, [{ type: [ ], alg: pubKeyCredParam.alg }]],
[rp, user, challenge, [{ type: { }, alg: pubKeyCredParam.alg }]],
[rp, user, challenge, [{ type: pubKeyCredParam.type, alg: Symbol() }]],
// wrong timeout type
[rp, user, challenge, [pubKeyCredParam], Symbol(), undefined],
// wrong excludeCredentials
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: 1, id: excludeCredentials.id }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: true, id: excludeCredentials.id }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: null, id: excludeCredentials.id }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: Symbol(), id: excludeCredentials.id }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: "foo", id: excludeCredentials.id }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: [ ], id: excludeCredentials.id }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: { }, id: excludeCredentials.id }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: excludeCredentials.type, id: 1 }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: excludeCredentials.type, id: true }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: excludeCredentials.type, id: null }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: excludeCredentials.type, id: Symbol() }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: excludeCredentials.type, id: "foo" }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: excludeCredentials.type, id: [ ] }]],
[rp, user, challenge, [pubKeyCredParam], undefined, [{ type: excludeCredentials.type, id: { } }]]
];
function makeOptions(attributes)
{
if (attributes.length == 4)
return { publicKey: { rp: attributes[0], user: attributes[1], challenge: attributes[2], pubKeyCredParams: attributes[3] } };
return { publicKey: { rp: attributes[0], user: attributes[1], challenge: attributes[2], pubKeyCredParams: attributes[3], timeout: attributes[4], excludeCredentials: attributes[5]} };
}
let index = 1;
function runTest(attributesVectors) {
attributesVectors.forEach(function(attributesVector) {
attributesVector.forEach(async function(attributes) {
promise_test(function(t) {
return promise_rejects_js(t, TypeError,
navigator.credentials.create(makeOptions(attributes)));
}, "PublicKeyCredential's [[create]] with with invalid parameters. " + index);
index = index + 1;
});
});
}
const vectors = [];
vectors.push(missingAttributeVector);
vectors.push(wrongTypeAttributeVector);
runTest(vectors);
</script>