From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- .../extensions/test/xpcshell/test_cookies.js | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 toolkit/mozapps/extensions/test/xpcshell/test_cookies.js (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_cookies.js') diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_cookies.js b/toolkit/mozapps/extensions/test/xpcshell/test_cookies.js new file mode 100644 index 0000000000..56f745929b --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_cookies.js @@ -0,0 +1,102 @@ +"use strict"; + +let server = createHttpServer({ hosts: ["example.com"] }); + +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "45", "45"); + +Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", true); +Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); + +// Tests that cookies are not sent with background requests. +add_task(async function test_cookies() { + const ID = "bg-cookies@tests.mozilla.org"; + + // Add a new handler to the test web server for the given file path. + // The handler appends the incoming requests to `results` and replies + // with the provided body. + function makeHandler(path, results, body) { + server.registerPathHandler(path, (request, response) => { + results.push(request); + response.write(body); + }); + } + + let gets = []; + makeHandler("/get", gets, JSON.stringify({ results: [] })); + Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, "http://example.com/get"); + + let updates = []; + makeHandler( + "/update", + updates, + JSON.stringify({ + addons: { + [ID]: { + updates: [ + { + version: "2.0", + update_link: "http://example.com/update.xpi", + applications: { + gecko: {}, + }, + }, + ], + }, + }, + }) + ); + + let xpiFetches = []; + makeHandler("/update.xpi", xpiFetches, ""); + + const COOKIE = "test"; + // cookies.add() takes a time in seconds + let expiration = Date.now() / 1000 + 60 * 60; + Services.cookies.add( + "example.com", + "/", + COOKIE, + "testing", + false, + false, + false, + expiration, + {}, + Ci.nsICookie.SAMESITE_NONE, + Ci.nsICookie.SCHEME_HTTP + ); + + await promiseStartupManager(); + + let addon = await promiseInstallWebExtension({ + manifest: { + version: "1.0", + browser_specific_settings: { + gecko: { + id: ID, + update_url: "http://example.com/update", + }, + }, + }, + }); + + equal(gets.length, 1, "Saw one addon metadata request"); + equal(gets[0].hasHeader("Cookie"), false, "Metadata request has no cookies"); + + await Promise.all([ + AddonTestUtils.promiseInstallEvent("onDownloadFailed"), + AddonManagerPrivate.backgroundUpdateCheck(), + ]); + + equal(updates.length, 1, "Saw one update check request"); + equal(updates[0].hasHeader("Cookie"), false, "Update request has no cookies"); + + equal(xpiFetches.length, 1, "Saw one request for updated xpi"); + equal( + xpiFetches[0].hasHeader("Cookie"), + false, + "Request for updated XPI has no cookies" + ); + + await addon.uninstall(); +}); -- cgit v1.2.3