| <!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 [[get]] throws TypeError when invalid options are passed."); |
| |
| jsTestIsAsync = true; |
| |
| const challenge = asciiToUint8Array("123456"); |
| const allowCredential = { type: "public-key", id: asciiToUint8Array("123456") }; |
| |
| const missingAttributeVector = [ |
| // missing top level attribute |
| [undefined], |
| // missing allowCredentials attribute |
| [challenge, undefined, undefined, [{ type: undefined, id: allowCredential.id }]], |
| [challenge, undefined, undefined, [{ type: allowCredential.type, id: undefined }]] |
| ]; |
| |
| const wrongTypeAttributeVector = [ |
| // wrong challenge type |
| [1], |
| [true], |
| [null], |
| [Symbol()], |
| ["foo"], |
| [[ ]], |
| [{ }], |
| // wrong timeout type |
| [challenge, Symbol(), undefined, undefined], |
| // wrong rpId type |
| [challenge, undefined, Symbol(), undefined], |
| // wrong allowCredentials type |
| [challenge, undefined, undefined, [{ type: 1, id: allowCredential.id }]], |
| [challenge, undefined, undefined, [{ type: true, id: allowCredential.id }]], |
| [challenge, undefined, undefined, [{ type: null, id: allowCredential.id }]], |
| [challenge, undefined, undefined, [{ type: Symbol(), id: allowCredential.id }]], |
| [challenge, undefined, undefined, [{ type: "foo", id: allowCredential.id }]], |
| [challenge, undefined, undefined, [{ type: [ ], id: allowCredential.id }]], |
| [challenge, undefined, undefined, [{ type: { }, id: allowCredential.id }]], |
| [challenge, undefined, undefined, [{ type: allowCredential.type, id: 1 }]], |
| [challenge, undefined, undefined, [{ type: allowCredential.type, id: true }]], |
| [challenge, undefined, undefined, [{ type: allowCredential.type, id: null }]], |
| [challenge, undefined, undefined, [{ type: allowCredential.type, id: Symbol() }]], |
| [challenge, undefined, undefined, [{ type: allowCredential.type, id: "foo" }]], |
| [challenge, undefined, undefined, [{ type: allowCredential.type, id: [ ] }]], |
| [challenge, undefined, undefined, [{ type: allowCredential.type, id: { } }]] |
| ]; |
| |
| function makeOptions(attributes) |
| { |
| if (attributes.length == 1) |
| return { publicKey: { challenge: attributes[0] } }; |
| return { publicKey: { challenge: attributes[0], timeout: attributes[1], rpId: attributes[2], allowCredentials: attributes[3] } }; |
| } |
| |
| function runTest(attributesVectors) { |
| attributesVectors.forEach(function(attributesVector) { |
| attributesVector.forEach(async function(attributes) { |
| invalidOptions = makeOptions(attributes); |
| await shouldReject('navigator.credentials.get(invalidOptions)'); |
| }); |
| }); |
| |
| finishJSTest(); |
| } |
| |
| const vectors = []; |
| vectors.push(missingAttributeVector); |
| vectors.push(wrongTypeAttributeVector); |
| runTest(vectors); |
| </script> |
| </body> |
| </html> |