| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="/js-test-resources/js-test.js"></script> |
| <script src="./resources/util.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| <script> |
| description("Tests that PublicKeyCredential's [[create]] throws TypeError when invalid options are passed."); |
| |
| jsTestIsAsync = true; |
| |
| 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]} }; |
| } |
| |
| function runTest(attributesVectors) { |
| attributesVectors.forEach(function(attributesVector) { |
| attributesVector.forEach(async function(attributes) { |
| invalidOptions = makeOptions(attributes); |
| await shouldReject('navigator.credentials.create(invalidOptions)'); |
| }); |
| }); |
| |
| finishJSTest(); |
| } |
| |
| const vectors = []; |
| vectors.push(missingAttributeVector); |
| vectors.push(wrongTypeAttributeVector); |
| runTest(vectors); |
| </script> |
| </body> |
| </html> |