Add regression tests for connector save-session gc and remove()

Cover the three previously-broken behaviors: gc() expiring sessions past
the TTL, gc() retaining fresh sessions, and SaveSession#remove() deleting
a session from the manager. There was no existing coverage of gc(), which
is how the leak went unnoticed.
This commit is contained in:
Michael Swift 2026-06-11 12:59:15 -04:00
parent 095338fc48
commit 7b34f22ddf

View file

@ -93,6 +93,41 @@ describe("Connector Server", function () {
});
});
describe("SaveSession.SessionManager", function () {
var SessionManager = Zotero.Server.Connector.SessionManager;
it("should expire sessions older than the TTL when gc() runs", function () {
var id = "gcOld_" + Zotero.Utilities.randomString();
var session = SessionManager.create(id, 'saveItems', {});
// Backdate creation beyond the 10-minute TTL
session.created = new Date(Date.now() - 11 * 60 * 1000);
SessionManager.gc();
assert.isUndefined(SessionManager.get(id), "stale session should be removed by gc()");
});
it("should keep sessions newer than the TTL when gc() runs", function () {
var id = "gcNew_" + Zotero.Utilities.randomString();
var session = SessionManager.create(id, 'saveItems', {});
SessionManager.gc();
assert.strictEqual(SessionManager.get(id), session, "fresh session should survive gc()");
session.remove();
});
it("should remove a session via SaveSession#remove()", function () {
var id = "remove_" + Zotero.Utilities.randomString();
var session = SessionManager.create(id, 'saveItems', {});
assert.strictEqual(SessionManager.get(id), session);
session.remove();
assert.isUndefined(SessionManager.get(id), "remove() should delete the session from the manager");
});
});
describe('/connector/getTranslatorCode', function () {
it('should respond with translator code', async function () {
var code = 'function detectWeb() {}\nfunction doImport() {}';