summaryrefslogtreecommitdiffstats
path: root/services/fxaccounts/tests/xpcshell/test_accounts.js
diff options
context:
space:
mode:
Diffstat (limited to 'services/fxaccounts/tests/xpcshell/test_accounts.js')
-rw-r--r--services/fxaccounts/tests/xpcshell/test_accounts.js60
1 files changed, 40 insertions, 20 deletions
diff --git a/services/fxaccounts/tests/xpcshell/test_accounts.js b/services/fxaccounts/tests/xpcshell/test_accounts.js
index c4aec73a03..239adb206f 100644
--- a/services/fxaccounts/tests/xpcshell/test_accounts.js
+++ b/services/fxaccounts/tests/xpcshell/test_accounts.js
@@ -6,7 +6,7 @@
const { CryptoUtils } = ChromeUtils.importESModule(
"resource://services-crypto/utils.sys.mjs"
);
-const { FxAccounts } = ChromeUtils.importESModule(
+const { FxAccounts, ERROR_INVALID_ACCOUNT_STATE } = ChromeUtils.importESModule(
"resource://gre/modules/FxAccounts.sys.mjs"
);
const { FxAccountsClient } = ChromeUtils.importESModule(
@@ -120,7 +120,7 @@ function MockFxAccountsClient() {
// mock calls up to the auth server to determine whether the
// user account has been verified
- this.recoveryEmailStatus = async function (sessionToken) {
+ this.recoveryEmailStatus = async function () {
// simulate a call to /recovery_email/status
return {
email: this._email,
@@ -139,7 +139,7 @@ function MockFxAccountsClient() {
return !this._deletedOnServer;
};
- this.accountKeys = function (keyFetchToken) {
+ this.accountKeys = function () {
return new Promise(resolve => {
do_timeout(50, () => {
resolve({
@@ -188,7 +188,7 @@ Object.setPrototypeOf(
* mock the now() method, so that we can simulate the passing of
* time and verify that signatures expire correctly.
*/
-function MockFxAccounts(credentials = null) {
+function MockFxAccounts() {
let result = new FxAccounts({
VERIFICATION_POLL_TIMEOUT_INITIAL: 100, // 100ms
@@ -453,10 +453,10 @@ add_test(function test_polling_timeout() {
fxa.setSignedInUser(test_user).then(() => {
p.then(
- success => {
+ () => {
do_throw("this should not succeed");
},
- fail => {
+ () => {
removeObserver();
fxa.signOut().then(run_next_test);
}
@@ -471,7 +471,7 @@ add_task(async function test_onverified_once() {
let numNotifications = 0;
- function observe(aSubject, aTopic, aData) {
+ function observe() {
numNotifications += 1;
}
Services.obs.addObserver(observe, ONVERIFIED_NOTIFICATION);
@@ -777,11 +777,10 @@ add_task(async function test_getKeyForScope_nonexistent_account() {
});
});
- // XXX - the exception message here isn't ideal, but doesn't really matter...
- await Assert.rejects(
- fxa.keys.getKeyForScope(SCOPE_OLD_SYNC),
- /A different user signed in/
- );
+ await Assert.rejects(fxa.keys.getKeyForScope(SCOPE_OLD_SYNC), err => {
+ Assert.equal(err.message, ERROR_INVALID_ACCOUNT_STATE);
+ return true; // expected error
+ });
await promiseLogout;
@@ -972,17 +971,17 @@ add_test(function test_fetchAndUnwrapAndDeriveKeys_no_token() {
makeObserver(ONLOGOUT_NOTIFICATION, function () {
log.debug("test_fetchAndUnwrapKeys_no_token observed logout");
- fxa._internal.getUserAccountData().then(user2 => {
+ fxa._internal.getUserAccountData().then(() => {
fxa._internal.abortExistingFlow().then(run_next_test);
});
});
fxa
.setSignedInUser(user)
- .then(user2 => {
+ .then(() => {
return fxa.keys._fetchAndUnwrapAndDeriveKeys();
})
- .catch(error => {
+ .catch(() => {
log.info("setSignedInUser correctly rejected");
});
});
@@ -1273,11 +1272,7 @@ add_task(async function test_getOAuthTokenCachedScopeNormalization() {
let numOAuthTokenCalls = 0;
let client = fxa._internal.fxAccountsClient;
- client.accessTokenWithSessionToken = async (
- _sessionTokenHex,
- _clientId,
- scopeString
- ) => {
+ client.accessTokenWithSessionToken = async (_sessionTokenHex, _clientId) => {
numOAuthTokenCalls++;
return MOCK_TOKEN_RESPONSE;
};
@@ -1405,6 +1400,31 @@ add_test(function test_getOAuthToken_error() {
});
});
+add_test(async function test_getOAuthTokenAndKey_errors_if_user_change() {
+ const fxa = new MockFxAccounts();
+ const alice = getTestUser("alice");
+ const bob = getTestUser("bob");
+ alice.verified = true;
+ bob.verified = true;
+
+ fxa.getOAuthToken = async () => {
+ // We mock what would happen if the user got changed
+ // after we got the access token
+ await fxa.setSignedInUser(bob);
+ return "access token";
+ };
+ fxa.keys.getKeyForScope = () => Promise.resolve("key!");
+ await fxa.setSignedInUser(alice);
+ await Assert.rejects(
+ fxa.getOAuthTokenAndKey({ scope: "foo", ttl: 10 }),
+ err => {
+ Assert.equal(err.message, ERROR_INVALID_ACCOUNT_STATE);
+ return true; // expected error
+ }
+ );
+ run_next_test();
+});
+
add_task(async function test_listAttachedOAuthClients() {
const ONE_HOUR = 60 * 60 * 1000;
const ONE_DAY = 24 * ONE_HOUR;