| <!DOCTYPE html> |
| <title>Credential Manager: create() basics.</title> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> |
| <script src="/gen/third_party/WebKit/public/platform/modules/credentialmanager/credential_manager.mojom.js"></script> |
| <script src="/gen/third_party/WebKit/public/platform/modules/webauth/authenticator.mojom.js"></script> |
| <script src="resources/credential-helpers.js"></script> |
| <script> |
| |
| if (document.location.hostname == "127.0.0.1") |
| document.location = "https://subdomain.example.test:8443/credentialmanager/credentialscontainer-create-basics.html"; |
| |
| promise_test(t => { |
| return promise_rejects(t, "NotSupportedError", |
| navigator.credentials.create()); |
| }, "navigator.credentials.create() with no argument."); |
| |
| promise_test(t => { |
| mockAuthenticator.setAuthenticatorStatus( |
| webauth.mojom.AuthenticatorStatus.INVALID_DOMAIN); |
| return promise_rejects(t, "SecurityError", |
| navigator.credentials.create({publicKey : MAKE_CREDENTIAL_OPTIONS})); |
| }, "Verify that invalid domain error returned by mock is properly handled."); |
| |
| promise_test(t => { |
| var customMakeCredOptions = { |
| // No challenge. |
| rp: PUBLIC_KEY_RP, |
| user: PUBLIC_KEY_USER, |
| pubKeyCredParams: PUBLIC_KEY_PARAMETERS, |
| }; |
| |
| return promise_rejects(t, new TypeError(), |
| navigator.credentials.create({publicKey : customMakeCredOptions})); |
| }, "navigator.credentials.create() with missing challenge"); |
| |
| promise_test(t => { |
| var customMakeCredOptions = { |
| challenge: CHALLENGE, |
| rp: PUBLIC_KEY_RP, |
| user: PUBLIC_KEY_USER, |
| // No parameters. |
| }; |
| |
| return promise_rejects(t, new TypeError(), |
| navigator.credentials.create({publicKey : customMakeCredOptions})); |
| }, "navigator.credentials.create() with missing parameters"); |
| |
| promise_test(t => { |
| var customMakeCredOptions = { |
| challenge: CHALLENGE, |
| // No rp. |
| user: PUBLIC_KEY_USER, |
| pubKeyCredParams: PUBLIC_KEY_PARAMETERS, |
| }; |
| |
| return promise_rejects(t, new TypeError(), |
| navigator.credentials.create({publicKey: customMakeCredOptions})); |
| }, "navigator.credentials.create() with missing rp"); |
| |
| promise_test(t => { |
| var customMakeCredOptions = { |
| challenge: CHALLENGE, |
| rp: PUBLIC_KEY_RP, |
| // No user. |
| pubKeyCredParams: PUBLIC_KEY_PARAMETERS, |
| }; |
| |
| return promise_rejects(t, new TypeError(), |
| navigator.credentials.create({publicKey: customMakeCredOptions})); |
| }, "navigator.credentials.create() with missing user"); |
| |
| promise_test(t => { |
| var customMakeCredOptions = { |
| challenge: CHALLENGE, |
| rp: { id: "google.com" }, |
| user: PUBLIC_KEY_USER, |
| pubKeyCredParams: PUBLIC_KEY_PARAMETERS, |
| }; |
| |
| return promise_rejects(t, new TypeError(), |
| navigator.credentials.create({publicKey: customMakeCredOptions})); |
| }, "navigator.credentials.create() with missing rp.name"); |
| |
| promise_test(t => { |
| var customMakeCredOptions = { |
| challenge: CHALLENGE, |
| rp: PUBLIC_KEY_RP, |
| user: { |
| name: "avery.a.jones@example.com", |
| displayName: "Avery A. Jones", |
| icon: "https://pics.acme.com/00/p/aBjjjpqPb.png" |
| }, |
| pubKeyCredParams: PUBLIC_KEY_PARAMETERS, |
| }; |
| |
| return promise_rejects(t, new TypeError(), |
| navigator.credentials.create({publicKey: customMakeCredOptions})); |
| }, "navigator.credentials.create() with missing user.id"); |
| |
| promise_test(t => { |
| var customMakeCredOptions = { |
| challenge: CHALLENGE, |
| rp: PUBLIC_KEY_RP, |
| user: { |
| id: new TextEncoder().encode("1098237235409872"), |
| displayName: "Avery A. Jones", |
| icon: "https://pics.acme.com/00/p/aBjjjpqPb.png" |
| }, |
| pubKeyCredParams: PUBLIC_KEY_PARAMETERS, |
| timeout: 60000, // 1 minute |
| excludeCredentials: [], // No already-registered credentials. |
| }; |
| |
| return promise_rejects(t, new TypeError(), |
| navigator.credentials.create({publicKey: customMakeCredOptions})); |
| }, "navigator.credentials.create() with missing user.name"); |
| |
| promise_test(t => { |
| var customMakeCredOptions = { |
| challenge: CHALLENGE, |
| rp: PUBLIC_KEY_RP, |
| user: { |
| id: new TextEncoder().encode("1098237235409872"), |
| name: "avery.a.jones@example.com", |
| icon: "https://pics.acme.com/00/p/aBjjjpqPb.png" |
| }, |
| pubKeyCredParams: PUBLIC_KEY_PARAMETERS, |
| }; |
| |
| return promise_rejects(t, new TypeError(), |
| navigator.credentials.create({publicKey: customMakeCredOptions})); |
| }, "navigator.credentials.create() with missing user.displayName"); |
| |
| promise_test(_ => { |
| mockAuthenticator.setRawId(RAW_ID); |
| mockAuthenticator.setId(ID); |
| mockAuthenticator.setClientDataJson(CLIENT_DATA_JSON); |
| mockAuthenticator.setAttestationObject(ATTESTATION_OBJECT); |
| mockAuthenticator.setAuthenticatorStatus( |
| webauth.mojom.AuthenticatorStatus.SUCCESS); |
| |
| return navigator.credentials.create({publicKey : MAKE_CREDENTIAL_OPTIONS}).then(r => { |
| assertValidMakeCredentialResponse(r); |
| }); |
| }, "Verify that the mock returns the values we give it."); |
| |
| promise_test(t => { |
| mockAuthenticator.setAuthenticatorStatus( |
| webauth.mojom.AuthenticatorStatus.PENDING_REQUEST); |
| return promise_rejects(t, "InvalidStateError", |
| navigator.credentials.create({ publicKey : MAKE_CREDENTIAL_OPTIONS})); |
| }, "Verify that pending request error returned by mock is properly handled."); |
| |
| promise_test(function (t) { |
| mockAuthenticator.setAuthenticatorStatus( |
| webauth.mojom.AuthenticatorStatus.UNKNOWN_ERROR); |
| return promise_rejects(t, "NotReadableError", |
| navigator.credentials.create({ publicKey : MAKE_CREDENTIAL_OPTIONS})); |
| }, "Verify that unknown error returned by mock is properly handled."); |
| |
| promise_test(t => { |
| mockAuthenticator.setAuthenticatorStatus( |
| webauth.mojom.AuthenticatorStatus.NOT_ALLOWED_ERROR); |
| return promise_rejects(t, "NotAllowedError", |
| navigator.credentials.create({ publicKey : MAKE_CREDENTIAL_OPTIONS})); |
| }, "Verify that not allowed error returned by mock is properly handled."); |
| |
| promise_test(t => { |
| mockAuthenticator.setAuthenticatorStatus( |
| webauth.mojom.AuthenticatorStatus.NOT_SUPPORTED_ERROR); |
| return promise_rejects(t, "NotSupportedError", |
| navigator.credentials.create({ publicKey : MAKE_CREDENTIAL_OPTIONS})); |
| }, "Verify that not supported error returned by mock is properly handled."); |
| |
| promise_test(t => { |
| mockAuthenticator.setAuthenticatorStatus( |
| webauth.mojom.AuthenticatorStatus.TIMED_OUT); |
| return promise_rejects(t, "NotAllowedError", |
| navigator.credentials.create({ publicKey : MAKE_CREDENTIAL_OPTIONS})); |
| }, "Verify that timed out error returned by mock is properly handled."); |
| |
| promise_test(_ => { |
| mockAuthenticator.reset(); |
| mockAuthenticator.setRawId(RAW_ID); |
| mockAuthenticator.setId(ID); |
| mockAuthenticator.setClientDataJson(CLIENT_DATA_JSON); |
| mockAuthenticator.setAttestationObject(ATTESTATION_OBJECT); |
| mockAuthenticator.setAuthenticatorStatus( |
| webauth.mojom.AuthenticatorStatus.SUCCESS); |
| |
| var customPublicKey = { |
| challenge: CHALLENGE, |
| rp: { name: "Acme" }, |
| user: PUBLIC_KEY_USER, |
| pubKeyCredParams: PUBLIC_KEY_PARAMETERS, |
| }; |
| |
| return navigator.credentials.create({publicKey: customPublicKey}).then(r => { |
| assertValidMakeCredentialResponse(r); |
| }); |
| }, "navigator.credentials.create() with missing rp.id"); |
| |
| </script> |