blob: 8a71a981fd35cf9d429237b60c1fb874fdce7d35 [file] [log] [blame]
<!DOCTYPE html>
<title>Credential Manager: create() with custom origins.</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>
// For tests that don't require custom-set origins.
if (document.location.hostname == "127.0.0.1")
document.location = "https://subdomain.example.test:8443/credentialmanager/credentialscontainer-create-origins.html";
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(_ => {
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");
// For tests that require custom-set origins.
const VALID_ORIGIN_RPID_PAIRS = [
{ 'origin': 'https://google.test:8443',
'rpId': 'google.test' },
{ 'origin': 'https://google.test:8443',
'rpId': '' },
{'origin': 'https://subdomain.example.test:8443',
'rpId': 'example.test' },
{'origin': 'https://subdomain.example.test:8443',
'rpId': 'subdomain.example.test' },
{'origin': 'https://localhost:8443',
'rpId': 'localhost' },
];
for (let test of VALID_ORIGIN_RPID_PAIRS) {
promise_test(t => {
let eventWatcher = new EventWatcher(t, window, "message");
var w = window.open(test.origin
+ "/credentialmanager/resources/publickey-create-helper.html?rpId="
+ test.rpId);
return eventWatcher.wait_for("message").then(message => {
assert_equals(message.data, "SUCCESS");
});
}, "navigator.credentials.create({publicKey}) in '" + test.origin
+ "' with valid |rp.id| '" + test.rpId + "' should succeed.");
}
const INVALID_ORIGIN_RPID_PAIRS = [
{ 'origin': 'https://google.test:8443',
'rpId': 'localhost' },
{ 'origin': 'https://google.test:8443',
'rpId': 'foo.google.test' },
{ 'origin': 'https://google.test:8443',
'rpId': null },
{ 'origin': 'https://google.test:8443',
'rpId': String(0) },
{ 'origin': 'https://google.test:8443',
'rpId': 'test' },
];
for (let test of INVALID_ORIGIN_RPID_PAIRS) {
promise_test(t => {
let eventWatcher = new EventWatcher(t, window, "message");
var w = window.open(test.origin
+ "/credentialmanager/resources/publickey-create-helper.html?rpId="
+ test.rpId);
return eventWatcher.wait_for("message").then(message => {
assert_equals(message.data, "SecurityError");
});
}, "navigator.credentials.create({publicKey}) in '" + test.origin
+ "' with invalid |rp.id| '" + test.rpId + "' should fail.");
}
</script>