fx128: Fix login manager

Use async methods (since the sync ones seem to already be broken from JS
despite https://bugzilla.mozilla.org/show_bug.cgi?id=1832756 still being
open) and avoid loading Firefox Accounts module
This commit is contained in:
Dan Stillman 2024-12-06 02:49:43 -05:00
parent 26bcc49174
commit a0bdeab401
4 changed files with 13 additions and 13 deletions

View file

@ -291,6 +291,9 @@ function modify_omni {
replace_line 'let uninstall = \(\) => \{' 'let uninstall = async () => {' modules/addons/XPIInstall.sys.mjs
replace_line 'cancelUninstallAddon\(aAddon\)' 'async cancelUninstallAddon(aAddon)' modules/addons/XPIInstall.sys.mjs
# Prevent login manager from trying to load FxAccountsCommon.sys.mjs
replace_line 'return login.hostname == lazy.FXA_PWDMGR_HOST;' 'return false;' modules/storage-json.sys.mjs
# No idea why this is necessary, but without it initialization fails with "TypeError: "constructor" is read-only"
replace_line 'LoginStore.prototype.constructor = LoginStore;' '\/\/LoginStore.prototype.constructor = LoginStore;' modules/LoginStore.sys.mjs
#

View file

@ -68,17 +68,14 @@ Zotero.Sync.Data.Local = {
},
setAPIKey: function (apiKey) {
var loginManager = Components.classes["@mozilla.org/login-manager;1"]
.getService(Components.interfaces.nsILoginManager);
setAPIKey: async function (apiKey) {
var oldLoginInfo = this._getAPIKeyLoginInfo();
// Clear old login
if ((!apiKey || apiKey === "")) {
if (oldLoginInfo) {
Zotero.debug("Clearing old API key");
loginManager.removeLogin(oldLoginInfo);
Services.logins.removeLogin(oldLoginInfo);
}
Zotero.Notifier.trigger('delete', 'api-key', []);
return;
@ -97,11 +94,11 @@ Zotero.Sync.Data.Local = {
);
if (!oldLoginInfo) {
Zotero.debug("Setting API key");
loginManager.addLogin(loginInfo);
await Services.logins.addLoginAsync(loginInfo);
}
else {
Zotero.debug("Replacing API key");
loginManager.modifyLogin(oldLoginInfo, loginInfo);
await Services.logins.modifyLoginAsync(oldLoginInfo, loginInfo);
}
Zotero.Notifier.trigger('modify', 'api-key', []);
},

View file

@ -1664,7 +1664,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
if (!json.username) throw new Error("username not found in key response");
if (!json.access) throw new Error("'access' not found in key response");
Zotero.Sync.Data.Local.setAPIKey(json.key);
yield Zotero.Sync.Data.Local.setAPIKey(json.key);
return json;
})
@ -1674,7 +1674,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
this.resetStorageController('zfs');
var apiKey = yield Zotero.Sync.Data.Local.getAPIKey();
var client = this.getAPIClient({apiKey});
Zotero.Sync.Data.Local.setAPIKey();
yield Zotero.Sync.Data.Local.setAPIKey();
yield client.deleteAPIKey();
})

View file

@ -5,17 +5,17 @@ describe("Zotero.Sync.Data.Local", function() {
it("should get and set an API key", function* () {
var apiKey1 = Zotero.Utilities.randomString(24);
var apiKey2 = Zotero.Utilities.randomString(24);
Zotero.Sync.Data.Local.setAPIKey(apiKey1);
yield Zotero.Sync.Data.Local.setAPIKey(apiKey1);
yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(apiKey1), apiKey1);
Zotero.Sync.Data.Local.setAPIKey(apiKey2);
yield Zotero.Sync.Data.Local.setAPIKey(apiKey2);
yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(apiKey2), apiKey2);
})
it("should clear an API key by setting an empty string", function* () {
var apiKey = Zotero.Utilities.randomString(24);
Zotero.Sync.Data.Local.setAPIKey(apiKey);
Zotero.Sync.Data.Local.setAPIKey("");
yield Zotero.Sync.Data.Local.setAPIKey(apiKey);
yield Zotero.Sync.Data.Local.setAPIKey("");
yield assert.eventually.strictEqual(Zotero.Sync.Data.Local.getAPIKey(apiKey), "");
})
})