blob: 29a85d3c64e7db219507361fbc044313cf9943ea [file] [log] [blame]
<!doctype html>
<title>Credential Manager: get() basics.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../js-test-resources/document-interface-broker-helpers.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings_lite.js"></script>
<script src="/gen/mojo/public/mojom/base/unguessable_token.mojom-lite.js"></script>
<script src="/gen/mojo/public/mojom/base/big_buffer.mojom-lite.js"></script>
<script src="/gen/mojo/public/mojom/base/string16.mojom-lite.js"></script>
<script src="/gen/mojo/public/mojom/base/time.mojom-lite.js"></script>
<script src="/gen/url/mojom/origin.mojom-lite.js"></script>
<script src="/gen/url/mojom/url.mojom-lite.js"></script>
<script src="/gen/third_party/blink/public/mojom/credentialmanager/credential_manager.mojom-lite.js"></script>
<script src="/gen/third_party/blink/public/mojom/webauthn/authenticator.mojom-lite.js"></script>
<script src="/gen/third_party/blink/public/mojom/webauthn/virtual_authenticator.mojom-lite.js"></script>
<script src="/gen/third_party/blink/public/mojom/frame/document_interface_broker.mojom-lite.js"></script>
<script src="resources/test-inputs.js"></script>
<script src="resources/mock-navigator-credentials.js"></script>
<script>
if (document.location.host != "subdomain.example.test:8443") {
document.location = "https://subdomain.example.test:8443/credentialmanager/credentialscontainer-get-basics.html";
promise_test(_ => new Promise(_ => {}), "Stall tests on the wrong host.");
}
add_completion_callback(() => {
mockCredentialManager.reset();
});
promise_test(_ => {
return navigator.credentials.get().then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with no argument.");
promise_test(_ => {
return navigator.credentials.get({}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get({}).");
promise_test(_ => {
return navigator.credentials.get({
federated: {
providers: [ 'https://example.com/' ]
}
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including FederatedCredentialRequestOptions.");
promise_test(_ => {
return navigator.credentials.get({
password: true,
unmediated: true
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including password and unmediated.");
promise_test(_ => {
return navigator.credentials.get({
federated: {
providers: [ 'https://example.com/' ]
},
unmediated: true
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including federated and unmediated.");
promise_test(_ => {
return navigator.credentials.get({
password: true,
federated: {
providers: [ 'https://example.com/' ]
},
unmediated: true
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including federated, password and unmediated.");
promise_test(_ => {
return navigator.credentials.get({
unmediated: true
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including unmediated.");
promise_test(_ => {
return navigator.credentials.get({
mediation: "silent"
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including mediation.");
promise_test(_ => {
return navigator.credentials.get({
notValid: 'yay!'
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with an options including an unknown attribute.");
promise_test(_ => {
var id = "id";
var password = "pencil";
var name = "name";
var icon = "http://example.com/";
mockCredentialManager.setResponse(id, password, name, icon);
return navigator.credentials.get({
password: true
}).then(r => {
assert_equals(r.id, id, "id");
assert_equals(r.password, password, "password");
assert_equals(r.name, name, "name");
assert_equals(r.iconURL, icon, "icon");
});
}, "Verify that the mock returns the values we give it.");
promise_test(_ => {
mockAuthenticator.setRawId(RAW_ID);
mockAuthenticator.setDefaultsForSuccessfulGetAssertion();
return navigator.credentials.get({publicKey : GET_CREDENTIAL_OPTIONS}).then(r => {
assertValidGetCredentialResponse(r);
});
}, "Verify that mockAuthenticator returns the values we give it.");
promise_test(t => {
mockAuthenticator.setAuthenticatorStatus(
blink.mojom.AuthenticatorStatus.PENDING_REQUEST);
return promise_rejects(t, "InvalidStateError",
navigator.credentials.get({ publicKey : GET_CREDENTIAL_OPTIONS}));
}, "Verify that pending request error returned by mock is properly handled.");
promise_test(function (t) {
mockAuthenticator.setAuthenticatorStatus(
blink.mojom.AuthenticatorStatus.UNKNOWN_ERROR);
return promise_rejects(t, "NotReadableError",
navigator.credentials.get({ publicKey : GET_CREDENTIAL_OPTIONS}));
}, "Verify that unknown error returned by mock is properly handled.");
promise_test(t => {
mockAuthenticator.setAuthenticatorStatus(
blink.mojom.AuthenticatorStatus.NOT_ALLOWED_ERROR);
return promise_rejects(t, "NotAllowedError",
navigator.credentials.get({ publicKey : GET_CREDENTIAL_OPTIONS}));
}, "Verify that not allowed error returned by mock is properly handled.");
promise_test(t => {
mockAuthenticator.setAuthenticatorStatus(
blink.mojom.AuthenticatorStatus.USER_VERIFICATION_UNSUPPORTED);
return promise_rejects(t, "NotSupportedError",
navigator.credentials.get({ publicKey : GET_CREDENTIAL_OPTIONS}));
}, "Verify that user verification unsupported error returned by mock is properly handled.");
promise_test(t => {
mockAuthenticator.setAuthenticatorStatus(
blink.mojom.AuthenticatorStatus.EMPTY_ALLOW_CREDENTIALS);
var customGetCredentialOptions = deepCopy(GET_CREDENTIAL_OPTIONS);
delete customGetCredentialOptions.allowCredentials;
return promise_rejects(t, "NotSupportedError",
navigator.credentials.get({ publicKey : customGetCredentialOptions}));
}, "Verify that empty allow credentials error returned by mock is properly handled.");
promise_test(t => {
mockAuthenticator.setAuthenticatorStatus(
blink.mojom.AuthenticatorStatus.ABORT_ERROR);
return promise_rejects(t, "AbortError",
navigator.credentials.get({ publicKey : GET_CREDENTIAL_OPTIONS}));
}, "Verify that abort error returned by mock is properly handled.");
promise_test(function(t) {
var customGetCredentialOptions = deepCopy(GET_CREDENTIAL_OPTIONS);
delete customGetCredentialOptions.challenge;
return promise_rejects(t, new TypeError(),
navigator.credentials.get({publicKey: customGetCredentialOptions}));
}, "navigator.credentials.get() with missing challenge");
promise_test(_ => {
mockAuthenticator.reset();
mockAuthenticator.setDefaultsForSuccessfulGetAssertion();
var customGetCredentialOptions = deepCopy(GET_CREDENTIAL_OPTIONS);
delete customGetCredentialOptions.rpId;
console.log(customGetCredentialOptions);
return navigator.credentials.get({publicKey: customGetCredentialOptions}).then(r => {
assertValidGetCredentialResponse(r);
});
}, "navigator.credentials.get() with missing rpId");
promise_test(_ => {
mockAuthenticator.reset();
mockAuthenticator.setDefaultsForSuccessfulGetAssertion();
var customGetCredentialOptions = deepCopy(GET_CREDENTIAL_OPTIONS);
delete customGetCredentialOptions.userVerification;
return navigator.credentials.get({publicKey: customGetCredentialOptions}).then(r => {
assertValidGetCredentialResponse(r);
});
}, "navigator.credentials.get() with missing user verification requirement");
promise_test(t => {
mockAuthenticator.reset();
mockAuthenticator.setDefaultsForSuccessfulGetAssertion();
var customGetCredentialOptions = deepCopy(GET_CREDENTIAL_OPTIONS);
customGetCredentialOptions.extensions = {cableRegistration: CABLE_REGISTRATION};
return promise_rejects(t, "NotSupportedError",
navigator.credentials.get({ publicKey : customGetCredentialOptions}));
}, "navigator.credentials.get() with cableRegistration extension not supported");
promise_test(_ => {
mockAuthenticator.reset();
mockAuthenticator.setDefaultsForSuccessfulGetAssertion();
var customGetCredentialOptions = deepCopy(GET_CREDENTIAL_OPTIONS);
customGetCredentialOptions.extensions = {cableAuthentication: [CABLE_AUTHENTICATION]};
return navigator.credentials.get({publicKey: customGetCredentialOptions}).then(r => {
assertValidGetCredentialResponse(r);
});
}, "navigator.credentials.get() with cableAuthentication extension");
promise_test(t => {
var authAbortController = new AbortController();
var authAbortSignal = authAbortController.signal;
authAbortController.abort()
return promise_rejects(t, "AbortError",
navigator.credentials.get({ publicKey : GET_CREDENTIAL_OPTIONS, signal : authAbortSignal}));
}, "navigator.credentials.get() with abort signal.");
</script>