Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android' OR appname == 'thunderbird' && !nightly_build
- Manifest: services/fxaccounts/tests/xpcshell/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
"use strict";
const { FxAccounts } = ChromeUtils.importESModule(
"resource://gre/modules/FxAccounts.sys.mjs"
);
const { CLIENT_IS_THUNDERBIRD } = ChromeUtils.importESModule(
"resource://gre/modules/FxAccountsCommon.sys.mjs"
);
add_task(
async function test_non_https_remote_server_uri_with_requireHttps_false() {
ensureOauthNotConfigured();
Services.prefs.setStringPref("identity.fxaccounts.autoconfig.uri", "");
Services.prefs.setBoolPref("identity.fxaccounts.allowHttp", true);
Services.prefs.setStringPref(
"identity.fxaccounts.remote.root",
);
Assert.equal(
await FxAccounts.config.promiseConnectAccountURI("test"),
);
ensureOauthConfigured();
let url = new URL(await FxAccounts.config.promiseConnectAccountURI("test"));
Assert.equal(url.host, "example.com");
Assert.equal(url.searchParams.get("context"), "oauth_webchannel_v1");
Assert.equal(url.searchParams.get("service"), "sync");
Assert.equal(url.searchParams.get("entrypoint"), "test");
Assert.equal(url.searchParams.get("action"), "email");
Assert.equal(
url.searchParams.get("client_id"),
CLIENT_IS_THUNDERBIRD ? "8269bacd7bbc7f80" : "5882386c6d801776"
);
Assert.equal(url.searchParams.get("response_type"), "code");
Services.prefs.clearUserPref("identity.fxaccounts.remote.root");
Services.prefs.clearUserPref("identity.fxaccounts.allowHttp");
resetOauthConfig();
}
);
add_task(async function test_non_https_remote_server_uri() {
Services.prefs.setStringPref(
"identity.fxaccounts.remote.root",
);
await Assert.rejects(
FxAccounts.config.promiseConnectAccountURI(),
/Firefox Accounts server must use HTTPS/
);
Services.prefs.clearUserPref("identity.fxaccounts.remote.root");
});
add_task(async function test_is_production_config() {
// should start with no auto-config URL.
Assert.ok(!FxAccounts.config.getAutoConfigURL());
// which means we are using prod.
Assert.ok(FxAccounts.config.isProductionConfig());
// Set an auto-config URL.
Services.prefs.setStringPref(
"identity.fxaccounts.autoconfig.uri",
);
Assert.ok(!FxAccounts.config.isProductionConfig());
// Clear the auto-config URL, but set one of the other config params.
Services.prefs.clearUserPref("identity.fxaccounts.autoconfig.uri");
Assert.ok(!FxAccounts.config.isProductionConfig());
Services.prefs.clearUserPref("identity.sync.tokenserver.uri");
});
add_task(async function test_promise_account_service_param() {
ensureOauthNotConfigured();
Services.prefs.setStringPref("identity.fxaccounts.autoconfig.uri", "");
Services.prefs.setStringPref(
"identity.fxaccounts.remote.root",
);
Assert.equal(
await FxAccounts.config.promiseConnectAccountURI("test", {
service: "custom-service",
}),
);
ensureOauthConfigured();
let url = new URL(
await FxAccounts.config.promiseConnectAccountURI("test", {
service: "custom-service",
})
);
Assert.equal(url.searchParams.get("context"), "oauth_webchannel_v1");
Assert.equal(
url.searchParams.get("client_id"),
CLIENT_IS_THUNDERBIRD ? "8269bacd7bbc7f80" : "5882386c6d801776"
);
Assert.equal(url.searchParams.get("service"), "custom-service");
resetOauthConfig();
});