From 6f50c6fc12670804dff1de820fa6334669286663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Thu, 16 Jan 2025 15:25:28 +0100 Subject: [PATCH] Fix + formatting (#391) --- .../content-script-tests/sources/content.es | 2 +- .../tests/integration/content-script-test.es | 2 +- .../tests/integration/messaging-test.es | 8 +- modules/core/sources/app.es | 14 +- modules/core/sources/app/module.es | 4 +- modules/core/sources/app/service.es | 2 +- modules/core/sources/background.es | 2 +- modules/core/sources/content.es | 16 +- .../core/sources/content/actions-manager.es | 4 +- modules/core/sources/content/console.es | 2 +- .../core/sources/content/match-patterns.es | 2 +- modules/core/sources/content/register.es | 2 +- modules/core/sources/content/run.es | 4 +- .../core/sources/crypto/pkcs-conversion.es | 4 +- modules/core/sources/crypto/utils.es | 26 +- modules/core/sources/decorators.es | 2 +- modules/core/sources/http.es | 6 +- modules/core/sources/kord/inject.es | 6 +- modules/core/sources/message-queue.es | 4 +- modules/core/sources/request-sanitizer.es | 4 +- modules/core/sources/services/pacemaker.es | 2 +- modules/core/sources/webrequest.es | 2 +- modules/core/tests/http-server.es | 8 +- modules/core/tests/integration/http-test.es | 4 +- modules/core/tests/unit/app-test.es | 2 +- modules/core/tests/unit/app/module-test.es | 2 +- modules/core/tests/unit/bloom-filter-test.es | 2 +- .../tests/unit/content/match-patterns-test.es | 16 +- modules/core/tests/unit/decorators-test.es | 4 +- modules/core/tests/unit/encoding-test.es | 2 +- modules/core/tests/unit/events-test.es | 2 +- .../core/tests/unit/fixed-size-cache-test.es | 2 +- modules/core/tests/unit/helpers-md5-test.es | 2 +- .../unit/helpers/strip-api-headers-test.es | 2 +- modules/core/tests/unit/http-test.es | 2 +- modules/core/tests/unit/message-queue-test.es | 18 +- .../core/tests/unit/pkcs-conversion-test.es | 2 +- modules/core/tests/unit/prefs-test.es | 2 +- .../tests/unit/services/pacemaker-test.es | 2 +- modules/core/tests/unit/url-test.es | 14 +- modules/core/tests/unit/utils/dexie.es | 3 +- modules/core/tests/unit/wait-test.es | 2 +- modules/fetcher/sources/manager.es | 6 +- modules/hpnv2/sources/background.es | 4 +- modules/hpnv2/sources/config-loader.es | 10 +- modules/hpnv2/sources/database.es | 4 +- modules/hpnv2/sources/digest.es | 2 +- modules/hpnv2/sources/endpoints.es | 129 ++++---- modules/hpnv2/sources/group-signer.es | 2 +- modules/hpnv2/sources/manager.es | 99 +++--- modules/hpnv2/sources/message-throttler.es | 10 +- modules/hpnv2/sources/star.es | 6 +- modules/hpnv2/sources/trusted-clock.es | 10 +- .../hpnv2/tests/unit/config-loader-test.es | 10 +- modules/hpnv2/tests/unit/digest-test.es | 4 +- modules/hpnv2/tests/unit/manager-test.es | 4 +- .../tests/unit/message-throttler-test.es | 8 +- .../hpnv2/tests/unit/trusted-clock-test.es | 2 +- modules/hpnv2/tests/unit/utils-test.es | 2 +- .../sources/background.es | 8 +- .../sources/content-extractor.es | 27 +- .../web-discovery-project/sources/content.es | 4 +- .../sources/doublefetch-handler.es | 60 ++-- .../web-discovery-project/sources/network.es | 10 +- .../sources/safebrowsing-endpoint.es | 6 +- .../sources/web-discovery-project.es | 296 ++++++++++-------- .../tests/integration/doublefetch-test.es | 10 +- .../integration/utility-regression-test.es | 160 +++++----- .../integration/web-discovery-project-test.es | 2 +- .../tests/unit/ad-detection-test.es | 4 +- .../tests/unit/content-extractor-test.es | 55 ++-- .../tests/unit/content-test.es | 18 +- .../tests/unit/doublefetch-handler-test.es | 30 +- .../tests/unit/fallback-dns-test.es | 6 +- .../tests/unit/network-test.es | 14 +- .../unit/remote-resource-watcher-test.es | 20 +- .../tests/unit/signature-verifier-test.es | 22 +- .../tests/unit/web-discovery-project-test.es | 40 +-- .../sources/background.es | 2 +- .../webrequest-pipeline/sources/background.es | 10 +- .../webrequest-pipeline/sources/pipeline.es | 14 +- .../sources/webrequest-context.es | 2 +- .../integration/webrequest-pipeline-test.es | 60 ++-- .../tests/unit/pipeline-test.es | 8 +- .../web-discovery-project/doublefetch.es | 10 +- update-brave.sh | 2 + 86 files changed, 736 insertions(+), 689 deletions(-) diff --git a/modules/content-script-tests/sources/content.es b/modules/content-script-tests/sources/content.es index 2aeff9c2..3f57405b 100644 --- a/modules/content-script-tests/sources/content.es +++ b/modules/content-script-tests/sources/content.es @@ -19,7 +19,7 @@ registerContentScript({ action1: (...args) => WDP.app.modules["content-script-tests"].action( "getSomeValue", - ...args + ...args, ), }; }, diff --git a/modules/content-script-tests/tests/integration/content-script-test.es b/modules/content-script-tests/tests/integration/content-script-test.es index 765e4743..0ace95e5 100644 --- a/modules/content-script-tests/tests/integration/content-script-test.es +++ b/modules/content-script-tests/tests/integration/content-script-test.es @@ -64,7 +64,7 @@ export default function () { "content-script-tests", "action1", { windowId: tabId }, - ...args + ...args, ); // Wait for window to exist diff --git a/modules/content-script-tests/tests/integration/messaging-test.es b/modules/content-script-tests/tests/integration/messaging-test.es index ccfba8ec..de3aaa4d 100644 --- a/modules/content-script-tests/tests/integration/messaging-test.es +++ b/modules/content-script-tests/tests/integration/messaging-test.es @@ -2,11 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import { - expect, - sleep, - Events, -} from "../../../tests/core/integration/helpers"; +import { expect, sleep, Events } from "../../../tests/core/integration/helpers"; export default function () { describe.skip("content-script", () => { @@ -26,7 +22,7 @@ export default function () { document.body.dispatchEvent( new MouseEvent("mousedown", { bubbles: true, - }) + }), ); } diff --git a/modules/core/sources/app.es b/modules/core/sources/app.es index c8b7ab08..a764fe7d 100644 --- a/modules/core/sources/app.es +++ b/modules/core/sources/app.es @@ -169,7 +169,7 @@ export default class App { this.prefchangeEventListener = subscribe( "prefchange", this.onPrefChange, - this + this, ); } @@ -184,8 +184,8 @@ export default class App { console.error("App", "cannot load service", serviceName, e); throw e; } - } - ) + }, + ), ); } @@ -213,8 +213,8 @@ export default class App { const services = {}; const scopedServices = await Promise.all( module.requiredServices.map((serviceName) => - this.services[serviceName].moduleFactory(module.name) - ) + this.services[serviceName].moduleFactory(module.name), + ), ); module.requiredServices.forEach((serviceName, i) => { services[serviceName] = scopedServices[i]; @@ -236,10 +236,10 @@ export default class App { const allModules = this.moduleList; const core = allModules.find((x) => x.name === "core"); const modules = allModules.filter( - (x) => x.name !== "core" && shouldEnableModule(x.name) + (x) => x.name !== "core" && shouldEnableModule(x.name), ); const disabledModules = allModules.filter( - (x) => !shouldEnableModule(x.name) + (x) => !shouldEnableModule(x.name), ); // all modules start in undefined state diff --git a/modules/core/sources/app/module.es b/modules/core/sources/app/module.es index fb8b36b7..e82e025c 100644 --- a/modules/core/sources/app/module.es +++ b/modules/core/sources/app/module.es @@ -18,7 +18,7 @@ export default class Module extends LifeCycle { Logger.get("life-cycle", { level: "log", prefix: `[lifecycle:${name}]`, - }) + }), ); this._init = (...args) => this.background.init(...args); @@ -36,7 +36,7 @@ export default class Module extends LifeCycle { (serviceName) => { const initializer = this.background.providesServices[serviceName]; this._services[serviceName] = new Service(initializer); - } + }, ); return this._services; diff --git a/modules/core/sources/app/service.es b/modules/core/sources/app/service.es index c14be765..d8bb3bf3 100644 --- a/modules/core/sources/app/service.es +++ b/modules/core/sources/app/service.es @@ -34,7 +34,7 @@ export default class Service { }, (e) => { this._readyDefer.reject(e); - } + }, ); return this._readyDefer.promise; diff --git a/modules/core/sources/background.es b/modules/core/sources/background.es index 92f6a24e..90036a31 100644 --- a/modules/core/sources/background.es +++ b/modules/core/sources/background.es @@ -114,7 +114,7 @@ export default background({ { url }, selector, attribute, - options + options, ); }, diff --git a/modules/core/sources/content.es b/modules/core/sources/content.es index 14de9b6f..98fc6688 100644 --- a/modules/core/sources/content.es +++ b/modules/core/sources/content.es @@ -69,7 +69,7 @@ function recordMouseDown(ev, WDP) { "recordMouseDown", event, getContextHTML(ev), - href + href, ); } @@ -90,7 +90,7 @@ function click(selector) { function queryHTML( selector, attribute, - { shadowRootSelector = null, attributeType = "property" } = {} + { shadowRootSelector = null, attributeType = "property" } = {}, ) { const root = shadowRootSelector ? window.document.querySelector(shadowRootSelector).shadowRoot @@ -112,7 +112,7 @@ function queryHTML( ...hash, [attr]: getAttr(el, attr), }), - {} + {}, ); } return getAttr(el, attribute); @@ -130,9 +130,13 @@ registerContentScript({ recordMouseDown(ev, WDP); }; window.addEventListener("mousedown", throttle(window, onMouseDown, 250)); - window.addEventListener("pagehide", () => { - window.removeEventListener("mousedown", onMouseDown); - }, { once: true }); + window.addEventListener( + "pagehide", + () => { + window.removeEventListener("mousedown", onMouseDown); + }, + { once: true }, + ); // Expose content actions return { diff --git a/modules/core/sources/content/actions-manager.es b/modules/core/sources/content/actions-manager.es index 74d59bb2..d8f8cb36 100644 --- a/modules/core/sources/content/actions-manager.es +++ b/modules/core/sources/content/actions-manager.es @@ -89,8 +89,8 @@ class RemoteMessagesBuffer { return Promise.reject( new Error( - `content-script actions buffer limit exceeded: ${this.buffer.length} ${this.MAX_BUFFER_LEN}` - ) + `content-script actions buffer limit exceeded: ${this.buffer.length} ${this.MAX_BUFFER_LEN}`, + ), ); }; } diff --git a/modules/core/sources/content/console.es b/modules/core/sources/content/console.es index fa7ac10e..a88c4549 100644 --- a/modules/core/sources/content/console.es +++ b/modules/core/sources/content/console.es @@ -19,5 +19,5 @@ export default config.environment === "development" get() { return noop; }, - } + }, ); diff --git a/modules/core/sources/content/match-patterns.es b/modules/core/sources/content/match-patterns.es index a8ccffaf..5e64aee1 100644 --- a/modules/core/sources/content/match-patterns.es +++ b/modules/core/sources/content/match-patterns.es @@ -88,7 +88,7 @@ function createHostMatcher(scheme, host) { if (host[1] !== ".") { throw new Error( - ' only "*" and "*." followed by hostname parts are valid' + ' only "*" and "*." followed by hostname parts are valid', ); } diff --git a/modules/core/sources/content/register.es b/modules/core/sources/content/register.es index b7ac6895..5b7033da 100644 --- a/modules/core/sources/content/register.es +++ b/modules/core/sources/content/register.es @@ -105,7 +105,7 @@ export function registerContentScript(spec) { ) { console.error( '"excludeMatches" should either be undefined or an array of match patterns', - spec + spec, ); return; } diff --git a/modules/core/sources/content/run.es b/modules/core/sources/content/run.es index cde65396..8861bb4f 100644 --- a/modules/core/sources/content/run.es +++ b/modules/core/sources/content/run.es @@ -99,7 +99,7 @@ export default function () { // Inject enabled content-scripts and register content-script actions so that // background can request actions from them. contentScriptActions.setActionCallbacks( - runContentScripts(window, chrome, WDP) + runContentScripts(window, chrome, WDP), ); // Stop listening for messages on window unload @@ -108,7 +108,7 @@ export default function () { () => { contentScriptActions.unload(); }, - { once: true } + { once: true }, ); }); } diff --git a/modules/core/sources/crypto/pkcs-conversion.es b/modules/core/sources/crypto/pkcs-conversion.es index 4b39b693..936b4165 100644 --- a/modules/core/sources/crypto/pkcs-conversion.es +++ b/modules/core/sources/crypto/pkcs-conversion.es @@ -94,7 +94,7 @@ function padIfSigned(array) { export function exportPublicKey(key) { const origValues = [key.n, key.e]; const values = origValues.map((x) => - padIfSigned(fromBase64(fromBase64url(x))) + padIfSigned(fromBase64(fromBase64url(x))), ); const numBytes = values.reduce((a, x) => a + bytesToEncode(x.length), 0); @@ -107,7 +107,7 @@ export function exportPublicKey(key) { new Uint8Array([ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, - ]) + ]), ); buffer.pushByte(0x03); // BIT STRING pushLength(buffer, bytesToEncode(numBytes) + 1); diff --git a/modules/core/sources/crypto/utils.es b/modules/core/sources/crypto/utils.es index b270fe0c..78e089f3 100644 --- a/modules/core/sources/crypto/utils.es +++ b/modules/core/sources/crypto/utils.es @@ -3,13 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import crypto from "../../platform/crypto"; -import { - toBase64, - fromBase64, - toHex, - fromHex, - toUTF8, -} from "../encoding"; +import { toBase64, fromBase64, toHex, fromHex, toUTF8 } from "../encoding"; import { exportPublicKey } from "./pkcs-conversion"; @@ -57,7 +51,7 @@ async function importAESKey(key) { toArrayBuffer(key, "hex"), { name: "AES-GCM", length: 256 }, true, - ["encrypt", "decrypt"] + ["encrypt", "decrypt"], ); } @@ -71,7 +65,7 @@ async function encryptAES(data, key, iv) { .then((encrypted) => [ fromArrayBuffer(_iv, "b64"), fromArrayBuffer(encrypted, "b64"), - ]) + ]), ); } @@ -83,7 +77,7 @@ async function decryptAES(encrypted, key) { return Promise.resolve() .then(() => (typeof key === "string" ? importAESKey(key) : key)) .then((importedKey) => - crypto.subtle.decrypt({ name: "AES-GCM", iv }, importedKey, encryptedMsg) + crypto.subtle.decrypt({ name: "AES-GCM", iv }, importedKey, encryptedMsg), ); } @@ -91,7 +85,7 @@ async function importRSAKey( pk, pub = true, h = "SHA-256", - algorithm = "RSA-OAEP" + algorithm = "RSA-OAEP", ) { let uses; if (pub) { @@ -113,7 +107,7 @@ async function importRSAKey( hash: { name: h }, }, true, - uses + uses, ); } @@ -131,13 +125,13 @@ async function generateRSAKeypair(bits = 2048, hashName = "SHA-256") { hash: { name: hashName }, }, true, - ["sign", "verify"] + ["sign", "verify"], ) .then((key) => Promise.all([ crypto.subtle.exportKey("spki", key.publicKey).then(toBase64), crypto.subtle.exportKey("pkcs8", key.privateKey).then(toBase64), - ]) + ]), ); } @@ -147,8 +141,8 @@ async function signRSA(privateKey, data) { await crypto.subtle.sign( { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-256" } }, privateKey, - _data - ) + _data, + ), ); } diff --git a/modules/core/sources/decorators.es b/modules/core/sources/decorators.es index e05832df..db3dba66 100644 --- a/modules/core/sources/decorators.es +++ b/modules/core/sources/decorators.es @@ -75,7 +75,7 @@ export async function withTimeout(promise, timeoutInMs) { setTimeout( () => reject(new Error(`Timed out after ${timeoutInMs / 1000} seconds`)), - timeoutInMs + timeoutInMs, ); }); return await Promise.race([promise, timer]); diff --git a/modules/core/sources/http.es b/modules/core/sources/http.es index 8fe5da8a..7440e22a 100644 --- a/modules/core/sources/http.es +++ b/modules/core/sources/http.es @@ -73,7 +73,7 @@ export function defaultHttpHandler( data, sync, encoding, - background + background, ) { const XMLHttpRequest = XMLHttpRequestFactory(); const req = new XMLHttpRequest(); @@ -204,7 +204,7 @@ export function promiseHttpHandler(method, url, data, timeout, compressedPost) { `Compressed request to ${url}, bytes saved = ${ dataLength - data.length } (${((100 * (dataLength - data.length)) / dataLength).toFixed(1)}%)`, - "WDP.httpHandler" + "WDP.httpHandler", ); httpHandler( method, @@ -214,7 +214,7 @@ export function promiseHttpHandler(method, url, data, timeout, compressedPost) { timeout, data, undefined, - "gzip" + "gzip", ); } else { httpHandler(method, url, resolve, reject, timeout, data); diff --git a/modules/core/sources/kord/inject.es b/modules/core/sources/kord/inject.es index b2ac3d01..e41c7f2c 100644 --- a/modules/core/sources/kord/inject.es +++ b/modules/core/sources/kord/inject.es @@ -23,7 +23,7 @@ export function ifModuleEnabled(promise) { "Ignoring disabled module exception while calling action," + " the following exception can be safely ignored. This log" + ' is only printed in "debug" mode.', - err + err, ); return Promise.resolve(); } @@ -100,13 +100,13 @@ export default { } if (!api[prop]) { throw new Error( - `Could not access '${prop}' from service: ${serviceName}.` + `Could not access '${prop}' from service: ${serviceName}.`, ); } return api[prop](...args); }, }), - {} + {}, ), }; diff --git a/modules/core/sources/message-queue.es b/modules/core/sources/message-queue.es index b98c8f05..5d17fdac 100644 --- a/modules/core/sources/message-queue.es +++ b/modules/core/sources/message-queue.es @@ -53,7 +53,7 @@ export default function (name, callback) { const registerCallbackOnData = () => { getNextData() .then(([data, resolvePush, rejectPush]) => - Promise.resolve(callback(data)).then(resolvePush).catch(rejectPush) + Promise.resolve(callback(data)).then(resolvePush).catch(rejectPush), ) .catch((ex) => console.error(`MessageQueue ${name} :: error: ${ex}`)) .then(registerCallbackOnData); @@ -73,7 +73,7 @@ export default function (name, callback) { const resolve = globalResolve; globalResolve = null; return new Promise((resolvePush, rejectPush) => - resolve([data, resolvePush, rejectPush]) + resolve([data, resolvePush, rejectPush]), ); } diff --git a/modules/core/sources/request-sanitizer.es b/modules/core/sources/request-sanitizer.es index 3a1d55ad..94717c4d 100644 --- a/modules/core/sources/request-sanitizer.es +++ b/modules/core/sources/request-sanitizer.es @@ -35,7 +35,7 @@ function safeFilter(req) { } } else if ( isTrackableOriginHeaderFromOurExtension( - findHeader(requestHeaders, "origin") + findHeader(requestHeaders, "origin"), ) ) { headersToRemove.push("origin"); // Prevent extension origin leaks @@ -44,7 +44,7 @@ function safeFilter(req) { if (headersToRemove.length > 0) { return { requestHeaders: requestHeaders.filter( - (h) => !headersToRemove.includes(h.name.toLowerCase()) + (h) => !headersToRemove.includes(h.name.toLowerCase()), ), }; } diff --git a/modules/core/sources/services/pacemaker.es b/modules/core/sources/services/pacemaker.es index fa8f2f05..ce0aa168 100644 --- a/modules/core/sources/services/pacemaker.es +++ b/modules/core/sources/services/pacemaker.es @@ -146,7 +146,7 @@ class Pacemaker { // instant timeouts or intervals are executed straight away. Otherwise, we // just set a timeout to trigger a _tick in `this.freq` milliseconds. const hasInstantTask = added.some( - ({ startImmediately }) => startImmediately + ({ startImmediately }) => startImmediately, ); this._scheduleNextTick(hasInstantTask ? 0 : this.freq); } diff --git a/modules/core/sources/webrequest.es b/modules/core/sources/webrequest.es index 04cb82b9..539bc11c 100644 --- a/modules/core/sources/webrequest.es +++ b/modules/core/sources/webrequest.es @@ -32,7 +32,7 @@ export const EXTRA_INFO_SPEC = !isEdge ? { onBeforeRequest: getOptionArray(webrequest.OnBeforeRequestOptions), onBeforeSendHeaders: getOptionArray( - webrequest.OnBeforeSendHeadersOptions + webrequest.OnBeforeSendHeadersOptions, ), onSendHeaders: getOptionArray(webrequest.OnSendHeadersOptions), onHeadersReceived: getOptionArray(webrequest.OnHeadersReceivedOptions), diff --git a/modules/core/tests/http-server.es b/modules/core/tests/http-server.es index b52d5e5a..da5976be 100644 --- a/modules/core/tests/http-server.es +++ b/modules/core/tests/http-server.es @@ -60,8 +60,8 @@ async function mockPath(mockInfo) { } catch (error) { throw new Error( `Could not register mock in test server: ${JSON.stringify( - mockInfo - )} ${error}` + mockInfo, + )} ${error}`, ); } } @@ -71,7 +71,7 @@ async function mockDirectories(path, directories) { await mock({ path, directories }); } catch (error) { throw new Error( - `Could not register directories mock in test server: ${path} ${directories} ${error}` + `Could not register directories mock in test server: ${path} ${directories} ${error}`, ); } } @@ -86,7 +86,7 @@ class TestServer { registerPathHandler( path, - { result = "{}", headers = [], status = "200", timeout = 0 } = {} + { result = "{}", headers = [], status = "200", timeout = 0 } = {}, ) { this.needsReset = true; return mockPath({ path, result, headers, status, timeout }); diff --git a/modules/core/tests/integration/http-test.es b/modules/core/tests/integration/http-test.es index 61cde656..2506603c 100644 --- a/modules/core/tests/integration/http-test.es +++ b/modules/core/tests/integration/http-test.es @@ -10,7 +10,7 @@ export default function () { const responseTest = "hello world"; beforeEach(() => - testServer.registerPathHandler("/", { result: responseTest }) + testServer.registerPathHandler("/", { result: responseTest }), ); describe("fetch", () => { it("doesn't send origin header", async () => { @@ -36,7 +36,7 @@ export default function () { () => { throw new Error("promise unexpectedly fulfilled"); }, - () => {} + () => {}, )); }); diff --git a/modules/core/tests/unit/app-test.es b/modules/core/tests/unit/app-test.es index c7176c9c..e59ed836 100644 --- a/modules/core/tests/unit/app-test.es +++ b/modules/core/tests/unit/app-test.es @@ -95,5 +95,5 @@ export default describeModule( }, }; }, - tests + tests, ); diff --git a/modules/core/tests/unit/app/module-test.es b/modules/core/tests/unit/app/module-test.es index edfe665f..3c562153 100644 --- a/modules/core/tests/unit/app/module-test.es +++ b/modules/core/tests/unit/app/module-test.es @@ -226,5 +226,5 @@ export default describeModule( await chai.expect(m.isReady()).to.be.fulfilled; }); }); - } + }, ); diff --git a/modules/core/tests/unit/bloom-filter-test.es b/modules/core/tests/unit/bloom-filter-test.es index bcdeeb00..99cb958b 100644 --- a/modules/core/tests/unit/bloom-filter-test.es +++ b/modules/core/tests/unit/bloom-filter-test.es @@ -32,5 +32,5 @@ export default describeModule( expect(uut.testSingle("y")).to.be.true; }); }); - } + }, ); diff --git a/modules/core/tests/unit/content/match-patterns-test.es b/modules/core/tests/unit/content/match-patterns-test.es index 86592902..b340c370 100644 --- a/modules/core/tests/unit/content/match-patterns-test.es +++ b/modules/core/tests/unit/content/match-patterns-test.es @@ -34,9 +34,7 @@ export default describeModule( "ws://sockets.somewhere.org/", "wss://ws.example.com/stuff/", ], - nonMatches: [ - "file:///a/", - ], + nonMatches: ["file:///a/"], }, { pattern: "*://*.mozilla.org/*", @@ -49,10 +47,7 @@ export default describeModule( "ws://ws.mozilla.org/", "wss://secure.mozilla.org/something", ], - nonMatches: [ - "http://mozilla.com/", - "http://firefox.org/", - ], + nonMatches: ["http://mozilla.com/", "http://firefox.org/"], }, { pattern: "*://mozilla.org/", @@ -62,10 +57,7 @@ export default describeModule( "ws://mozilla.org/", "wss://mozilla.org/", ], - nonMatches: [ - "http://a.mozilla.org/", - "http://mozilla.org/a", - ], + nonMatches: ["http://a.mozilla.org/", "http://mozilla.org/a"], }, { pattern: "https://*/path", @@ -171,5 +163,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/core/tests/unit/decorators-test.es b/modules/core/tests/unit/decorators-test.es index 77309b6f..d066b1f9 100644 --- a/modules/core/tests/unit/decorators-test.es +++ b/modules/core/tests/unit/decorators-test.es @@ -21,7 +21,7 @@ export default describeModule( it("should succeed with a resolved Promise", async () => { expect(await withTimeout(Promise.resolve("PASSED"), 1)).to.equal( - "PASSED" + "PASSED", ); }); @@ -112,5 +112,5 @@ export default describeModule( chai.expect(target.calledOnce).to.be.true; }); }); - } + }, ); diff --git a/modules/core/tests/unit/encoding-test.es b/modules/core/tests/unit/encoding-test.es index 8fe70cf8..d2c248e0 100644 --- a/modules/core/tests/unit/encoding-test.es +++ b/modules/core/tests/unit/encoding-test.es @@ -85,5 +85,5 @@ export default describeModule( chai.expect(arrayEquals(this.module().toUTF8(s), utf8)).to.equal(true); }); }); - } + }, ); diff --git a/modules/core/tests/unit/events-test.es b/modules/core/tests/unit/events-test.es index 0987dbe0..75fd4b88 100644 --- a/modules/core/tests/unit/events-test.es +++ b/modules/core/tests/unit/events-test.es @@ -115,5 +115,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/core/tests/unit/fixed-size-cache-test.es b/modules/core/tests/unit/fixed-size-cache-test.es index c60f128d..18b0c9a2 100644 --- a/modules/core/tests/unit/fixed-size-cache-test.es +++ b/modules/core/tests/unit/fixed-size-cache-test.es @@ -210,5 +210,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/core/tests/unit/helpers-md5-test.es b/modules/core/tests/unit/helpers-md5-test.es index 3fec0c13..e3ce920f 100644 --- a/modules/core/tests/unit/helpers-md5-test.es +++ b/modules/core/tests/unit/helpers-md5-test.es @@ -35,5 +35,5 @@ export default describeModule( expect(md5("日本")).to.equal("4dbed2e657457884e67137d3514119b3"); }); }); - } + }, ); diff --git a/modules/core/tests/unit/helpers/strip-api-headers-test.es b/modules/core/tests/unit/helpers/strip-api-headers-test.es index 8797593d..70fae4c2 100644 --- a/modules/core/tests/unit/helpers/strip-api-headers-test.es +++ b/modules/core/tests/unit/helpers/strip-api-headers-test.es @@ -44,5 +44,5 @@ export default describeModule( }); } }); - } + }, ); diff --git a/modules/core/tests/unit/http-test.es b/modules/core/tests/unit/http-test.es index 324d4a41..f06c7385 100644 --- a/modules/core/tests/unit/http-test.es +++ b/modules/core/tests/unit/http-test.es @@ -29,5 +29,5 @@ export default describeModule( }, function () { context("promiseHttpHandler", function () {}); - } + }, ); diff --git a/modules/core/tests/unit/message-queue-test.es b/modules/core/tests/unit/message-queue-test.es index 680dbff9..aeaf0319 100644 --- a/modules/core/tests/unit/message-queue-test.es +++ b/modules/core/tests/unit/message-queue-test.es @@ -79,7 +79,7 @@ export default describeModule( }).then((result) => { messages.push(result); return result; - }) + }), ); // Push 100 messages in the queue and maintain an array with the @@ -100,14 +100,14 @@ export default describeModule( if (expected !== JSON.stringify(messages)) { reject( new Error( - `Wrong order in 'messages' ${JSON.stringify(messages)}` - ) + `Wrong order in 'messages' ${JSON.stringify(messages)}`, + ), ); } else if (expected !== JSON.stringify(promiseResults)) { reject( new Error( - `Wrong order in 'promises' ${JSON.stringify(promiseResults)}` - ) + `Wrong order in 'promises' ${JSON.stringify(promiseResults)}`, + ), ); } else { resolve(); @@ -125,7 +125,7 @@ export default describeModule( () => { expect(queue.getSize()).to.equal(0); expect(processedMessages).to.equal(2); - } + }, ); }); @@ -247,7 +247,7 @@ export default describeModule( }) .then(() => { events.push(4); - }) + }), ); queue.push(() => { events.push(5); @@ -255,7 +255,7 @@ export default describeModule( queue.push(() => Promise.resolve().then(() => { events.push(6); - }) + }), ); queue.push(() => { events.push(7); @@ -270,5 +270,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/core/tests/unit/pkcs-conversion-test.es b/modules/core/tests/unit/pkcs-conversion-test.es index 1b9673f2..5377e492 100644 --- a/modules/core/tests/unit/pkcs-conversion-test.es +++ b/modules/core/tests/unit/pkcs-conversion-test.es @@ -60,5 +60,5 @@ export default describeModule( expect(PKCS.exportPublicKey(privateKeyJWK)).to.equal(publicKey); }); }); - } + }, ); diff --git a/modules/core/tests/unit/prefs-test.es b/modules/core/tests/unit/prefs-test.es index abdc0cf7..3d168b79 100644 --- a/modules/core/tests/unit/prefs-test.es +++ b/modules/core/tests/unit/prefs-test.es @@ -51,5 +51,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/core/tests/unit/services/pacemaker-test.es b/modules/core/tests/unit/services/pacemaker-test.es index cc41cdd1..f029f79e 100644 --- a/modules/core/tests/unit/services/pacemaker-test.es +++ b/modules/core/tests/unit/services/pacemaker-test.es @@ -231,5 +231,5 @@ export default describeModule( task.stop(); }); }); - } + }, ); diff --git a/modules/core/tests/unit/url-test.es b/modules/core/tests/unit/url-test.es index f833bb05..62b99493 100644 --- a/modules/core/tests/unit/url-test.es +++ b/modules/core/tests/unit/url-test.es @@ -536,14 +536,14 @@ export default describeModule( chai.expect( equals( "https://en.wikipedia.org/wiki/Murphy's_law", - "https://en.wikipedia.org/wiki/Murphy%27s_law" - ) + "https://en.wikipedia.org/wiki/Murphy%27s_law", + ), ).to.be.true; chai.expect( equals( "https://de.wikipedia.org/wiki/Stojanka_Novaković", - "https://de.wikipedia.org/wiki/Stojanka_Novakovi%C4%87" - ) + "https://de.wikipedia.org/wiki/Stojanka_Novakovi%C4%87", + ), ).to.be.true; }); }); @@ -615,7 +615,7 @@ export default describeModule( chai .expect( actual.searchParams.params.length, - "detected QS values" + "detected QS values", ) .to.equal(expected.searchParams.length); let i = 0; @@ -629,7 +629,7 @@ export default describeModule( chai .expect( actual.searchParams.params.length, - "detected QS values" + "detected QS values", ) .to.equal(Object.keys(expected.query_keys).length); chai @@ -722,5 +722,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/core/tests/unit/utils/dexie.es b/modules/core/tests/unit/utils/dexie.es index bce3ed24..3a0049b6 100644 --- a/modules/core/tests/unit/utils/dexie.es +++ b/modules/core/tests/unit/utils/dexie.es @@ -21,8 +21,7 @@ async function getInitDexie() { initDexie.__proto__.delete = Dexie.delete; initDexie.__proto__.exists = Dexie.exists; - - return + return; } module.exports = { "platform/lib/dexie": { diff --git a/modules/core/tests/unit/wait-test.es b/modules/core/tests/unit/wait-test.es index c2989e67..e5114ac3 100644 --- a/modules/core/tests/unit/wait-test.es +++ b/modules/core/tests/unit/wait-test.es @@ -57,5 +57,5 @@ export default describeModule( return waitFor(fn); }); }); - } + }, ); diff --git a/modules/fetcher/sources/manager.es b/modules/fetcher/sources/manager.es index 3bc66894..f5549161 100644 --- a/modules/fetcher/sources/manager.es +++ b/modules/fetcher/sources/manager.es @@ -11,7 +11,7 @@ export default class Manager { async _doFetch() { const getJobResponse = await fetch( - `${config.settings.FETCHER_GATEWAY}/v1/get_job` + `${config.settings.FETCHER_GATEWAY}/v1/get_job`, ); if (getJobResponse.status !== 200) { @@ -50,7 +50,7 @@ export default class Manager { const fetchResponse = await this.webDiscoveryProject.action( "anonymousHttpGet", url, - headers + headers, ); const t1 = Date.now(); console.error("RESPONSE", fetchResponse); @@ -74,7 +74,7 @@ export default class Manager { fetch_timestamp: Date.now(), fetch_duration_ms: t1 - t0, }), - } + }, ); console.error("Response from gateway", await pushJobResponse.json()); diff --git a/modules/hpnv2/sources/background.es b/modules/hpnv2/sources/background.es index 9a0a0c72..9fca5e7c 100644 --- a/modules/hpnv2/sources/background.es +++ b/modules/hpnv2/sources/background.es @@ -41,7 +41,7 @@ export default background({ if (rp.startsWith(config.settings.ENDPOINT_SAFE_QUORUM_ENDPOINT)) { const path = rp.replace( config.settings.ENDPOINT_SAFE_QUORUM_ENDPOINT, - "" + "", ); const res = await this.manager.send({ action: "safe-browsing-quorum", @@ -52,7 +52,7 @@ export default background({ const { result } = await res.json(); if (result === undefined) { throw new Error( - 'Could not parse result from quorum server (expected "result" field)' + 'Could not parse result from quorum server (expected "result" field)', ); } return result; diff --git a/modules/hpnv2/sources/config-loader.es b/modules/hpnv2/sources/config-loader.es index a5dfcc95..2abf7d45 100644 --- a/modules/hpnv2/sources/config-loader.es +++ b/modules/hpnv2/sources/config-loader.es @@ -117,13 +117,13 @@ export default class ConfigLoader { this.failedTimeSyncAttemptsInARow += 1; const cooldown = Math.min( 5 * 1000 * this.failedTimeSyncAttemptsInARow, - 60 * 60 * 1000 + 60 * 60 * 1000, ); logger.warn( `Failed to synchronize clock (reason: ${e}). ` + `${this.failedTimeSyncAttemptsInARow} failed attempts in a row. ` + - `Try again in ${cooldown / 1000} seconds...` + `Try again in ${cooldown / 1000} seconds...`, ); pacemaker.clearTimeout(this.nextClockSyncUpdate); this.nextClockSyncUpdate = pacemaker.setTimeout(() => { @@ -150,7 +150,7 @@ export default class ConfigLoader { // time-based attacks to target individual users by serving // them different group keys. const timeoutInMs = Math.floor( - minCooldown + random() * randomExtraCooldown + minCooldown + random() * randomExtraCooldown, ); pacemaker.clearTimeout(this.nextConfigUpdate); @@ -167,13 +167,13 @@ export default class ConfigLoader { } if (this.failedAttemptsInARow > 0) { logger.warn( - `${this.failedAttemptsInARow} failed config load attempts in a row` + `${this.failedAttemptsInARow} failed config load attempts in a row`, ); healthy = false; } if (this.failedAttemptsInARow > 0) { logger.warn( - `${this.failedTimeSyncAttemptsInARow} failed time sync attempts in a row` + `${this.failedTimeSyncAttemptsInARow} failed time sync attempts in a row`, ); healthy = false; } diff --git a/modules/hpnv2/sources/database.es b/modules/hpnv2/sources/database.es index c14c2ce1..ddfcaf81 100644 --- a/modules/hpnv2/sources/database.es +++ b/modules/hpnv2/sources/database.es @@ -40,7 +40,7 @@ export default class Database { async setGroupPubKey( date, - { groupPubKey, pubKey, credentials, gsk, joinmsg, banned } + { groupPubKey, pubKey, credentials, gsk, joinmsg, banned }, ) { logger.info("DB: setGroupPubKey:", date); this.groupPubKeys[date] = { @@ -206,7 +206,7 @@ export default class Database { const expireDate = formatHoursAsYYYYMMDD(currentHours - ttlInHours); logger.debug( "DB: purgeOldPubKeys: looking for keys older than", - expireDate + expireDate, ); function isSafeToDelete(dateAsYYYYMMDD) { diff --git a/modules/hpnv2/sources/digest.es b/modules/hpnv2/sources/digest.es index 49f360de..804ffaa7 100644 --- a/modules/hpnv2/sources/digest.es +++ b/modules/hpnv2/sources/digest.es @@ -100,7 +100,7 @@ function digest(keys, payload) { const field = NORM_FUNCTIONS.get(norm)(getField(payload, key)); if (field === undefined) { throw new InvalidMsgError( - "Found undefined field when calculating digest" + "Found undefined field when calculating digest", ); } return field; diff --git a/modules/hpnv2/sources/endpoints.es b/modules/hpnv2/sources/endpoints.es index aae6e663..14618d01 100644 --- a/modules/hpnv2/sources/endpoints.es +++ b/modules/hpnv2/sources/endpoints.es @@ -40,7 +40,7 @@ async function deriveKey(serverEcdhPubKey, clientPrivateKey) { clientPrivateKey, { name: "AES-GCM", length: 256 }, true, - ["encrypt", "decrypt"] + ["encrypt", "decrypt"], ); } @@ -58,19 +58,19 @@ async function importAesKey(data) { data, { name: "AES-GCM", length: 128 }, false, - ["encrypt", "decrypt"] + ["encrypt", "decrypt"], ); } async function encryptAES(iv, key, data) { return new Uint8Array( - await subtle.encrypt({ name: "AES-GCM", iv, tagLength: 128 }, key, data) + await subtle.encrypt({ name: "AES-GCM", iv, tagLength: 128 }, key, data), ); } async function decryptAES(iv, key, data) { return new Uint8Array( - await subtle.decrypt({ name: "AES-GCM", iv, tagLength: 128 }, key, data) + await subtle.decrypt({ name: "AES-GCM", iv, tagLength: 128 }, key, data), ); } @@ -128,7 +128,7 @@ async function myfetch( timeoutInMs, cache = "no-store", star, - } = {} + } = {}, ) { // eslint-disable-next-line no-param-reassign timeoutInMs = timeoutInMs || 60 * SECOND; @@ -152,7 +152,7 @@ async function myfetch( options.body = toUTF8(JSON.stringify(body)); } - logger.debug('myFetch', { url, method, star, options }); + logger.debug("myFetch", { url, method, star, options }); // When messages are sent through proxies, we cannot rely on TLS alone. // Proxies terminate TLS connections, so we have to apply end-to-end encryption @@ -201,7 +201,7 @@ async function myfetch( star.originalMsg.payload.url, options.body, oc, - fetchOptions + fetchOptions, ); // Override headers and let STAR aggregator forward with original fetch @@ -210,14 +210,14 @@ async function myfetch( options.headers.append("Content-Type", "application/json"); options.body = toUTF8(JSON.stringify(starMsg)); url = star.url; - logger.debug('Got STAR share', url, starMsg); + logger.debug("Got STAR share", url, starMsg); } // eslint-disable-next-line no-async-promise-executor return new Promise(async (resolve, reject) => { const timer = pacemaker.setTimeout(() => { reject( - new MsgTimeoutError(`Exceeded timeout of ${timeoutInMs / 1000} sec`) + new MsgTimeoutError(`Exceeded timeout of ${timeoutInMs / 1000} sec`), ); abortController.abort(); }, timeoutInMs); @@ -265,7 +265,7 @@ export default class Endpoints { this.unloaded = false; oldMessages.forEach((x) => - x.reject(new NotReadyError("Request cancelled because of unload")) + x.reject(new NotReadyError("Request cancelled because of unload")), ); } @@ -305,64 +305,67 @@ export default class Endpoints { if (this.unloaded || this.sendTimer !== null) { return; } - this.sendTimer = pacemaker.setTimeout(() => { - const n = Math.floor(random() * this.messages.length); - const { - url, - msg, - originalMsg, - cnt, - payloadEncryption, - resolve, - reject, - absoluteTimeout, - } = this.messages.splice(n, 1)[0]; - - myfetch(url, { - method: "POST", - body: msg, - payloadEncryption, - star: { - url: this.ENDPOINT_STAR, + this.sendTimer = pacemaker.setTimeout( + () => { + const n = Math.floor(random() * this.messages.length); + const { + url, + msg, originalMsg, - prepareStarMessage: (url, page, oc, fetchOptions) => - this.star.prepareMessage(url, page, oc, fetchOptions), - }, - }) - .then(resolve, (e) => { - if (cnt < this.maxRetries) { - logger.log("Will retry sending msg after error", e); - this.messages.push({ - url, - msg, - cnt: cnt + 1, - payloadEncryption, - resolve, - reject, - absoluteTimeout, - }); - } else { - logger.warn( - "_scheduleSend failed (gave up after", - this.maxRetries, - "retry attempts)", - e - ); - reject(e); - } + cnt, + payloadEncryption, + resolve, + reject, + absoluteTimeout, + } = this.messages.splice(n, 1)[0]; + + myfetch(url, { + method: "POST", + body: msg, + payloadEncryption, + star: { + url: this.ENDPOINT_STAR, + originalMsg, + prepareStarMessage: (url, page, oc, fetchOptions) => + this.star.prepareMessage(url, page, oc, fetchOptions), + }, }) - .then(() => { - this.sendTimer = null; - if (this.messages.length > 0) { - this._scheduleSend(); - } - }); - }, 500 + Math.floor(random() * 1500)); // TODO: improve? + .then(resolve, (e) => { + if (cnt < this.maxRetries) { + logger.log("Will retry sending msg after error", e); + this.messages.push({ + url, + msg, + cnt: cnt + 1, + payloadEncryption, + resolve, + reject, + absoluteTimeout, + }); + } else { + logger.warn( + "_scheduleSend failed (gave up after", + this.maxRetries, + "retry attempts)", + e, + ); + reject(e); + } + }) + .then(() => { + this.sendTimer = null; + if (this.messages.length > 0) { + this._scheduleSend(); + } + }); + }, + 500 + Math.floor(random() * 1500), + ); // TODO: improve? } async send( msg, - { instant, serverEcdhPubKey, absoluteTimeout, originalMsg } = {} + { instant, serverEcdhPubKey, absoluteTimeout, originalMsg } = {}, ) { function prepareEndToEndEncryptionIfNeeded() { if (!serverEcdhPubKey || serverEcdhPubKey.unsupportedByBrowser) { @@ -381,7 +384,7 @@ export default class Endpoints { const { timeoutInMs, isExpired } = toRelativeTimeout(absoluteTimeout); if (isExpired) { throw new MsgTimeoutError( - "dropping request because the absolute timeout expired" + "dropping request because the absolute timeout expired", ); } diff --git a/modules/hpnv2/sources/group-signer.es b/modules/hpnv2/sources/group-signer.es index 03f8cef7..4948298e 100644 --- a/modules/hpnv2/sources/group-signer.es +++ b/modules/hpnv2/sources/group-signer.es @@ -50,7 +50,7 @@ export default class GroupSigner { constructor() { const build = typeof WebAssembly !== "undefined" ? "wasm" : "asmjs"; this.worker = new Worker( - `${config.baseURL}hpnv2/worker.${build}.bundle.js` + `${config.baseURL}hpnv2/worker.${build}.bundle.js`, ); this.promises = {}; this.worker.onmessage = (args) => { diff --git a/modules/hpnv2/sources/manager.es b/modules/hpnv2/sources/manager.es index 712cccda..4b6d3885 100644 --- a/modules/hpnv2/sources/manager.es +++ b/modules/hpnv2/sources/manager.es @@ -133,7 +133,7 @@ export class InitState { } if (this.state_ === InitState.DESTROYED) { throw new Error( - `Internal error: already dead (cannot change to ${ppState(state_)})` + `Internal error: already dead (cannot change to ${ppState(state_)})`, ); } @@ -141,16 +141,16 @@ export class InitState { case InitState.UNINITIALIZED: throw new Error( `Internal error: Cannot go back to uninitialized state (${ppState( - this.state - )})` + this.state, + )})`, ); case InitState.INIT_PENDING: if (this.state !== InitState.UNINITIALIZED) { throw new Error( `Internal error: expected INIT_PENDING, but came from state=${ppState( - this.state - )}` + this.state, + )}`, ); } this.state = state_; @@ -160,8 +160,8 @@ export class InitState { if (this.state !== InitState.INIT_PENDING) { throw new Error( `Internal error: expected INIT_PENDING (current=${ppState( - this.state - )})` + this.state, + )})`, ); } this.state = state_; @@ -175,7 +175,7 @@ export class InitState { default: throw new Error( - `Unexpected state: new=${state_} (current=${ppState(this.state)})` + `Unexpected state: new=${state_} (current=${ppState(this.state)})`, ); } @@ -192,7 +192,7 @@ export class InitState { if (this.state === InitState.DESTROYED) { logger.warn( - "Trying to wait to initialization, but the object is already dead." + "Trying to wait to initialization, but the object is already dead.", ); throw new NotReadyError(); } @@ -221,7 +221,7 @@ export class InitState { if (this.state !== InitState.READY) { logger.error( "Still not ready after waking up. Unexpected state:", - ppState(this.state) + ppState(this.state), ); throw new NotReadyError(); } @@ -423,7 +423,7 @@ export default class Manager { await this.db.init(); } catch (e) { this.logError( - "Could not init (indexed)DB, will switch to memory-only DB" + "Could not init (indexed)DB, will switch to memory-only DB", ); } await this.initUserPK(); @@ -448,7 +448,7 @@ export default class Manager { } catch (e) { logger.warn( "Failed to synchronize clocks with the server. Continue with the initialization. " + - "Errors are expected now, but the system should eventually arrive at a consistent state." + "Errors are expected now, but the system should eventually arrive at a consistent state.", ); errors = true; } @@ -458,14 +458,14 @@ export default class Manager { } catch (e) { logger.warn( "Failed to fetch the config from the server. " + - "Errors are expected now, but the system should eventually arrive at a consistent state." + "Errors are expected now, but the system should eventually arrive at a consistent state.", ); errors = true; } if (errors) { logger.warn( "Background initialization finished with errors, " + - "but the failed operations will be retried automatically." + "but the failed operations will be retried automatically.", ); } else { logger.info("Background initialization finished without errors."); @@ -493,7 +493,7 @@ export default class Manager { Object.keys(this.groupPubKeys).map((shortDate) => { this.groupPubKeys[shortDate].banned = true; return this.db.setGroupPubKey(shortDate, this.groupPubKeys[shortDate]); - }) + }), ); } @@ -512,7 +512,7 @@ export default class Manager { }) { if (VERSION < minVersion) { this.logError( - `We are running an old version of the protocol, which is no longer supported by the server. All communication will be stopped. Our version: ${VERSION} does not meet the minimum version required by the server: ${minVersion}` + `We are running an old version of the protocol, which is no longer supported by the server. All communication will be stopped. Our version: ${VERSION} does not meet the minimum version required by the server: ${minVersion}`, ); this.isOldVersion = true; return; @@ -521,7 +521,7 @@ export default class Manager { const ok = Manager.checkGroupPublicKeys( groupPubKeys, pubKeys, - this.groupPubKeys + this.groupPubKeys, ); if (!ok) { await this.punish(); @@ -549,11 +549,11 @@ export default class Manager { latestKey, "by", randomDelayInMs / MINUTE, - "minutes" + "minutes", ); this._joinScheduler.cooldowns.set( latestKey, - Date.now() + randomDelayInMs + Date.now() + randomDelayInMs, ); } } @@ -565,7 +565,7 @@ export default class Manager { key.groupPubKey = fromBase64(groupPubKeys[shortDate]); key.pubKey = pubKeys[shortDate] && fromBase64(pubKeys[shortDate]); return this.db.setGroupPubKey(shortDate, key); - }) + }), ); } @@ -632,7 +632,7 @@ export default class Manager { logger.warn( "Failed to join group. Retrying again in", timeoutInMs / MINUTE, - "min" + "min", ); this._joinScheduler.nextJoinTimer = pacemaker.setTimeout(() => { @@ -669,7 +669,7 @@ export default class Manager { this.log( "Group", date, - "exceeded the join cooldown. Ready to join now." + "exceeded the join cooldown. Ready to join now.", ); this._joinScheduler.cooldowns.delete(date); return true; @@ -686,7 +686,7 @@ export default class Manager { // Make sure join promises are resolved via reflectPromise const results = await Promise.all( - joinDates.map((x) => reflectPromise(this.joinGroup(x))) + joinDates.map((x) => reflectPromise(this.joinGroup(x))), ); const error = results.find(({ isError }) => isError); if (error) { @@ -715,7 +715,7 @@ export default class Manager { if (!inSync) { logger.info( "Clock time is out of sync. Loading of today's key might fail:", - today + today, ); } const pk = this.getPublicKey(today); @@ -732,13 +732,13 @@ export default class Manager { pubKey, { name: "ECDH", namedCurve: "P-256" }, false, - [] + [], ); this.ecdhPubKey = { key, date }; } catch (e) { logger.error( "ECDH is not supported by the browser. Cannot send unencrypted data through a 3rd proxy proxy.", - e + e, ); throw e; } @@ -797,10 +797,10 @@ export default class Manager { this.userPK64, false, "SHA-256", - "RSASSA-PKCS1-v1_5" + "RSASSA-PKCS1-v1_5", ); this.publicKeyB64 = exportPublicKey( - await crypto.subtle.exportKey("jwk", this.userPK) + await crypto.subtle.exportKey("jwk", this.userPK), ); } @@ -855,7 +855,7 @@ export default class Manager { const credentials = await this.signer.finishJoin( groupPubKey, gsk, - fromBase64(joinResponse) + fromBase64(joinResponse), ); await this.db.setGroupPubKey(date, { groupPubKey, credentials, pubKey }); return this.groupPubKeys[date]; @@ -881,10 +881,7 @@ export default class Manager { // give up. By default, the timeout is very conservative, but the sender can // overwrite the default if needed. If do not want any timeout at all, you can pass 0 // to wait forever. When sending times out, it will fail with an "NotReadyError". - async send( - msg, - { waitForInitTimeoutInMs = 3 * MINUTE, ttl } = {} - ) { + async send(msg, { waitForInitTimeoutInMs = 3 * MINUTE, ttl } = {}) { if (this.isOldVersion) { // Refusing to send messages, as the client runs an old version of the protocol // that is not longer supported. Note that even if the changes are backward @@ -915,17 +912,17 @@ export default class Manager { // Although we could wait and speculate that loading will soon be initialized, // it is more likely that it will not happen, and it will just block. logger.info( - "Module is not initialized. Instead of waiting until we hit the timeout, give up immediately." + "Module is not initialized. Instead of waiting until we hit the timeout, give up immediately.", ); throw new NotReadyError(); } logger.debug( - "Initialization is still pending. Waiting for it to complete..." + "Initialization is still pending. Waiting for it to complete...", ); await initState.waitUntilReady(waitForInitTimeoutInMs); logger.debug( - "Initialization is still pending. Waiting for it to complete...DONE" + "Initialization is still pending. Waiting for it to complete...DONE", ); } @@ -981,7 +978,7 @@ export default class Manager { hours, period, limit, - skipQuotaCheck + skipQuotaCheck, ) { const tag = md5(JSON.stringify(pretag)); let cnt; @@ -992,7 +989,7 @@ export default class Manager { cnt = 0; } else { throw new MsgQuotaError( - `${e.message} (action: ${action}, tag: ${tag}, limit: ${limit} per ${period} hours)` + `${e.message} (action: ${action}, tag: ${tag}, limit: ${limit} per ${period} hours)`, ); } } @@ -1036,26 +1033,18 @@ export default class Manager { return Manager.compressAndPad(Manager.encodeMessage(MSG_SIGNED, data)); } - async _sendNoVerify({ - msg, - config, - serverEcdhPubKey, - absoluteTimeout, - }) { + async _sendNoVerify({ msg, config, serverEcdhPubKey, absoluteTimeout }) { const { instant = false } = config; // Hack: this uses the first '{' as the message code. this.log("Sending noverify msg", msg); return this.endpoints.send( Manager.compressAndPad(toUTF8(JSON.stringify(msg))), - { instant, serverEcdhPubKey, absoluteTimeout } + { instant, serverEcdhPubKey, absoluteTimeout }, ); } - async _send( - { msg: _msg, config, serverEcdhPubKey }, - skipQuotaCheck = false - ) { + async _send({ msg: _msg, config, serverEcdhPubKey }, skipQuotaCheck = false) { const msg = _msg; const { action } = msg; @@ -1072,7 +1061,7 @@ export default class Manager { const { inSync, hoursSinceEpoch } = this.trustedClock.checkTime(); if (!inSync) { logger.info( - "Sending could fail, as the clock is out of sync with the server." + "Sending could fail, as the clock is out of sync with the server.", ); } const hours = period * Math.floor(hoursSinceEpoch / period); @@ -1093,7 +1082,7 @@ export default class Manager { hours, period, limit, - skipQuotaCheck + skipQuotaCheck, ); this.unsentSignedMessages.set(msg, signedMsg); } @@ -1101,7 +1090,7 @@ export default class Manager { this.log("Sending signed msg", msg); const result = await this.endpoints.send( Manager.encodeSignedMessage(utf8Msg, signedMsg.sig, signedMsg.cnt), - { instant, serverEcdhPubKey, originalMsg: msg } + { instant, serverEcdhPubKey, originalMsg: msg }, ); this.unsentSignedMessages.delete(msg); @@ -1198,14 +1187,14 @@ export default class Manager { isHealthy() { if (this.isOldVersion) { logger.warn( - "Client is too old. The protocol is no longer accepted by the server" + "Client is too old. The protocol is no longer accepted by the server", ); return false; } if (!this.initState.isReady()) { logger.warn( - `hpnv2 is not loaded (current state: ${ppState(this.initState.state)})` + `hpnv2 is not loaded (current state: ${ppState(this.initState.state)})`, ); return false; } @@ -1221,7 +1210,7 @@ export default class Manager { } const today = formatHoursAsYYYYMMDD( - this.trustedClock.checkTime().hoursSinceEpoch + this.trustedClock.checkTime().hoursSinceEpoch, ); const pk = this.getPublicKey(today); if (!pk) { diff --git a/modules/hpnv2/sources/message-throttler.es b/modules/hpnv2/sources/message-throttler.es index b042a652..4ec00a22 100644 --- a/modules/hpnv2/sources/message-throttler.es +++ b/modules/hpnv2/sources/message-throttler.es @@ -94,12 +94,12 @@ export default class MessageThrottler { `To mitigate the situation, the server recommends to wait up to ${ delay / 1000 } seconds if possible. ` + - `Choosing a random delay of ${randomDelay / 1000} seconds...` + `Choosing a random delay of ${randomDelay / 1000} seconds...`, ); await this.delay(randomDelay); logger.log( "Waking up from random delay. Ready to send message of type:", - msg.action + msg.action, ); } } @@ -159,7 +159,7 @@ export default class MessageThrottler { const _settings = { minUptimeForThrottle: withDefault( settings.minUptimeForThrottle, - 20 * MINUTE + 20 * MINUTE, ), safeDelayAbsolute: withDefault(settings.safeDelayAbsolute, 30 * SECOND), safeDelayFraction: withDefault(settings.safeDelayFraction, 0.01), @@ -182,7 +182,7 @@ export default class MessageThrottler { } catch (e) { logger.warn( "Failed to update throttling config. Keep using the old recommendations.", - e + e, ); } } @@ -284,7 +284,7 @@ export default class MessageThrottler { const maxSafeDelay = Math.min( maxDelayBasedOnUptime, - maxDelayBasedOnTimestamps + maxDelayBasedOnTimestamps, ); return Math.min(delay, maxSafeDelay); } diff --git a/modules/hpnv2/sources/star.es b/modules/hpnv2/sources/star.es index 7ac10923..7140fc82 100644 --- a/modules/hpnv2/sources/star.es +++ b/modules/hpnv2/sources/star.es @@ -40,7 +40,7 @@ export default class Star { // same `tag` all the time). const t0 = Date.now(); const { tag, key, share } = JSON.parse( - this.create_share(measurement, THRESHOLD, EPOCH) + this.create_share(measurement, THRESHOLD, EPOCH), ); const t1 = Date.now(); logger.debug("create_share:", t1 - t0); @@ -53,7 +53,7 @@ export default class Star { name: "AES-GCM", }, false, - ["encrypt"] + ["encrypt"], ); // Generate random `iv` @@ -66,7 +66,7 @@ export default class Star { iv, }, aesKey, - hpnMsg + hpnMsg, ); return { diff --git a/modules/hpnv2/sources/trusted-clock.es b/modules/hpnv2/sources/trusted-clock.es index 3d11a95f..c37abf82 100644 --- a/modules/hpnv2/sources/trusted-clock.es +++ b/modules/hpnv2/sources/trusted-clock.es @@ -75,12 +75,12 @@ export default class TrustedClock { if (inSync) { logger.debug( "Local system clock in sync with the server. Last synched at:", - serverTime + serverTime, ); } else { logger.warn( "Local system clock out of sync with the server. Last synched at:", - serverTime + serverTime, ); } }, 60 * 1000); @@ -103,7 +103,7 @@ export default class TrustedClock { checkTime() { const minutesLocal = this.minutesLocal; const minutesSystem = Math.round( - (this.timeDrift + Date.now()) / (1000 * 60) + (this.timeDrift + Date.now()) / (1000 * 60), ); const hoursSystem = Math.floor(minutesSystem / 60); @@ -131,14 +131,14 @@ export default class TrustedClock { expectedConfigTs, ", actual:", actualConfigTs, - ")" + ")", ); prefs.set("config_ts", expectedConfigTs); } } else { // try to update the clock from the server logger.log( - "Clock is out of sync. It needs a current timestamp from the server to get in sync again." + "Clock is out of sync. It needs a current timestamp from the server to get in sync again.", ); this.onClockOutOfSync(); } diff --git a/modules/hpnv2/tests/unit/config-loader-test.es b/modules/hpnv2/tests/unit/config-loader-test.es index 63b204ee..46de1851 100644 --- a/modules/hpnv2/tests/unit/config-loader-test.es +++ b/modules/hpnv2/tests/unit/config-loader-test.es @@ -78,7 +78,7 @@ function createEndpointStub() { // only select the requested fields config = Object.assign( {}, - ...fields.split(",").map((field) => ({ [field]: config[field] })) + ...fields.split(",").map((field) => ({ [field]: config[field] })), ); } return JSON.stringify(config); @@ -252,7 +252,7 @@ export default describeModule( new Date() .toISOString() .replace(/[^0-9]/g, "") - .slice(0, 8) + .slice(0, 8), ); if ( @@ -285,7 +285,7 @@ export default describeModule( expect(configs.length).to.be.within( minExpectedChanges, maxExpectedChanges, - "Got an unusual number of different configurations during the simulation" + "Got an unusual number of different configurations during the simulation", ); // verify whether the number of requests made is realistic: @@ -299,7 +299,7 @@ export default describeModule( expect(endpoints._stats.calls.getConfig).to.be.within( minExpectedRequests, maxExpectedRequests, - "Made an unusual number of requests the simulation" + "Made an unusual number of requests the simulation", ); } }; @@ -346,5 +346,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/hpnv2/tests/unit/digest-test.es b/modules/hpnv2/tests/unit/digest-test.es index 476f07e1..74d08b29 100644 --- a/modules/hpnv2/tests/unit/digest-test.es +++ b/modules/hpnv2/tests/unit/digest-test.es @@ -24,7 +24,7 @@ export default describeModule( it("simple digest", () => { expect(() => digest(["foo"], {})).to.throw( - "Found undefined field when calculating digest" + "Found undefined field when calculating digest", ); expect(digest(["foo"], { foo: 5, bar: 6 })).to.deep.equal([5]); }); @@ -55,5 +55,5 @@ export default describeModule( expect(JSON.stringify(flatten(msg))).to.equal(JSON.stringify(flatMsg)); }); }); - } + }, ); diff --git a/modules/hpnv2/tests/unit/manager-test.es b/modules/hpnv2/tests/unit/manager-test.es index a232e018..7b53efae 100644 --- a/modules/hpnv2/tests/unit/manager-test.es +++ b/modules/hpnv2/tests/unit/manager-test.es @@ -82,7 +82,7 @@ export default describeModule( groupPubKey: Buffer.from(makeFakeGroupPublicKey(date), "base64"), pubKey: Buffer.from( makeFakeGroupPublicKey(`${date}${seed}`), - "base64" + "base64", ), date, }; @@ -320,5 +320,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/hpnv2/tests/unit/message-throttler-test.es b/modules/hpnv2/tests/unit/message-throttler-test.es index 2140144a..bdb90ff1 100644 --- a/modules/hpnv2/tests/unit/message-throttler-test.es +++ b/modules/hpnv2/tests/unit/message-throttler-test.es @@ -102,7 +102,7 @@ export default describeModule( normal: defaultRules, midnight: defaultRules, }, - fakeSourceMap() + fakeSourceMap(), ); }); @@ -122,7 +122,7 @@ export default describeModule( uut.startRequest(fakeMessage(), trustedClock).then(() => { const elapsedSec = Date.now() - start; expect(elapsedSec).to.be.at.most(maxDelay); - }) + }), ); } clock.runAll(); @@ -144,7 +144,7 @@ export default describeModule( try { await uut.startRequest( msg, - fakeTrustedClock({ uptimeInMin: 30 * DAY }) + fakeTrustedClock({ uptimeInMin: 30 * DAY }), ); } finally { uut.endRequest(msg); @@ -175,5 +175,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/hpnv2/tests/unit/trusted-clock-test.es b/modules/hpnv2/tests/unit/trusted-clock-test.es index 524d57f8..2d1e01f6 100644 --- a/modules/hpnv2/tests/unit/trusted-clock-test.es +++ b/modules/hpnv2/tests/unit/trusted-clock-test.es @@ -193,5 +193,5 @@ export default describeModule( expect(MOCKED_PREFS.get("config_ts")).equals("20020102"); }); }); - } + }, ); diff --git a/modules/hpnv2/tests/unit/utils-test.es b/modules/hpnv2/tests/unit/utils-test.es index 2608318c..f42d5405 100644 --- a/modules/hpnv2/tests/unit/utils-test.es +++ b/modules/hpnv2/tests/unit/utils-test.es @@ -114,5 +114,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/web-discovery-project/sources/background.es b/modules/web-discovery-project/sources/background.es index 2731c685..b356aae9 100644 --- a/modules/web-discovery-project/sources/background.es +++ b/modules/web-discovery-project/sources/background.es @@ -63,7 +63,7 @@ export default background({ { urls: ["*://*/*"], }, - ["responseHeaders"] + ["responseHeaders"], ); if (history && history.onVisitRemoved) { @@ -93,7 +93,7 @@ export default background({ if (this.onHeadersReceivedListener) { WebRequest.onHeadersReceived.removeListener( - this.onHeadersReceivedListener + this.onHeadersReceivedListener, ); this.onHeadersReceivedListener = undefined; } @@ -140,7 +140,7 @@ export default background({ anonymousHttpGet(url, overrideHeaders) { return WebDiscoveryProject.doublefetchHandler.anonymousHttpGet( url, - overrideHeaders + overrideHeaders, ); }, @@ -170,7 +170,7 @@ export default background({ acc[val] = data[val]; return acc; }, - WebDiscoveryProject.state.v[url][key] || {} + WebDiscoveryProject.state.v[url][key] || {}, ); return Promise.resolve(); } diff --git a/modules/web-discovery-project/sources/content-extractor.es b/modules/web-discovery-project/sources/content-extractor.es index 2f7140f0..18f15af6 100644 --- a/modules/web-discovery-project/sources/content-extractor.es +++ b/modules/web-discovery-project/sources/content-extractor.es @@ -142,7 +142,7 @@ export function _allMandatoryFieldsSet(payload, expectedFields) { // { "0": { "t": "foo", "u": "" } } // true (partial matches are OK) // return Object.values(arrayValue).some((innerValue) => - Object.values(innerValue).some(isDefined) + Object.values(innerValue).some(isDefined), ); } @@ -258,7 +258,7 @@ export class ContentExtractor { }; this._patternsLastUpdated = new Date(); logger.debug( - `Successfully updated "${ruleset}" patterns at ${this._patternsLastUpdated}` + `Successfully updated "${ruleset}" patterns at ${this._patternsLastUpdated}`, ); } @@ -342,7 +342,7 @@ export class ContentExtractor { if (this._WebDiscoveryProject.debug) { logger.debug( - `Not search engine >>> url=${url}, i=${i}, searchEngines=${searchEngines}, ruleset=${ruleset}` + `Not search engine >>> url=${url}, i=${i}, searchEngines=${searchEngines}, ruleset=${ruleset}`, ); } return -1; @@ -376,7 +376,7 @@ export class ContentExtractor { if ( Object.prototype.hasOwnProperty.call( this.refineFuncMappings, - e[0] + e[0], ) ) { return this.refineFuncMappings[e[0]](attribVal, e[1], e[2]); @@ -390,7 +390,10 @@ export class ContentExtractor { if (rules[key][eachKey].etype === "ctry") { innerDict[eachKey] = [this._WebDiscoveryProject.getCountryCode()]; } - } else if (rules[key][eachKey].type === "searchQuery" || rules[key][eachKey].type === "widgetTitle") { + } else if ( + rules[key][eachKey].type === "searchQuery" || + rules[key][eachKey].type === "widgetTitle" + ) { urlArray = this._getAttribute( cd, key, @@ -398,7 +401,7 @@ export class ContentExtractor { rules[key][eachKey].etype, rules[key][eachKey].keyName, rules[key][eachKey].functionsApplied || null, - baseURI + baseURI, ); innerDict[eachKey] = urlArray; if (ruleset === "normal") { @@ -408,7 +411,7 @@ export class ContentExtractor { "Populating query Cache <<<< ", url, " >>>> ", - query + query, ); this._WebDiscoveryProject.addStrictQueries(url, query); this._WebDiscoveryProject.queryCache[url] = { @@ -426,7 +429,7 @@ export class ContentExtractor { rules[key][eachKey].etype, rules[key][eachKey].keyName, rules[key][eachKey].functionsApplied || null, - baseURI + baseURI, ); innerDict[eachKey] = urlArray; } @@ -458,11 +461,11 @@ export class ContentExtractor { attrib, keyName, functionsApplied, - baseURI + baseURI, ) { const arr = []; const rootElement = Array.prototype.slice.call( - cd.querySelectorAll(parentItem) + cd.querySelectorAll(parentItem), ); for (let i = 0; i < rootElement.length; i += 1) { const val = item ? rootElement[i].querySelector(item) : rootElement[i]; @@ -486,7 +489,7 @@ export class ContentExtractor { if ( Object.prototype.hasOwnProperty.call( this.refineFuncMappings, - e[0] + e[0], ) ) { return this.refineFuncMappings[e[0]](accum, e[1], e[2]); @@ -640,7 +643,7 @@ export class ContentExtractor { payloadRules, ", error:", ee, - ")" + ")", ); } else { logger.warn(`_processExtractedData failed: ${ee}`); diff --git a/modules/web-discovery-project/sources/content.es b/modules/web-discovery-project/sources/content.es index 8b2942a6..52e45fae 100644 --- a/modules/web-discovery-project/sources/content.es +++ b/modules/web-discovery-project/sources/content.es @@ -109,7 +109,7 @@ export function parseDom(url, window, wdp) { // Let's iterate over each possible section of the ads. detectAdRules.adSections.forEach((eachAdSection, idx) => { const adNodes = Array.prototype.slice.call( - doc.querySelectorAll(eachAdSection) + doc.querySelectorAll(eachAdSection), ); adNodes.forEach((eachAd) => { @@ -175,7 +175,7 @@ function contentScript(window, chrome, WDP) { window.addEventListener("copy", onCopy); function stop(ev) { - if (ev && (ev.target !== window.document)) { + if (ev && ev.target !== window.document) { return; } diff --git a/modules/web-discovery-project/sources/doublefetch-handler.es b/modules/web-discovery-project/sources/doublefetch-handler.es index 77041a02..3690ccbb 100644 --- a/modules/web-discovery-project/sources/doublefetch-handler.es +++ b/modules/web-discovery-project/sources/doublefetch-handler.es @@ -104,7 +104,7 @@ export default class DoublefetchHandler { logger.debug( "Previous request failed (error: ", e || "", - "). Ignore and continue..." + "). Ignore and continue...", ); }; @@ -133,7 +133,7 @@ export default class DoublefetchHandler { url, entry, 3000, - overrideHeaders + overrideHeaders, ); entry.requestPromise = requestPromise; @@ -147,7 +147,7 @@ export default class DoublefetchHandler { logger.debug( `doublefetch for ${entry.url} completed after ${ elapsedMs / 1000 - } seconds.` + } seconds.`, ); this._stats.httpRequests.finished += 1; @@ -156,7 +156,7 @@ export default class DoublefetchHandler { this._pendingRequests.splice(index, 1); } else if (elapsedMs < this.zombieRequestTimelimitMs) { logger.error( - `_pendingRequests is in an inconsistent state (url=${entry.url}).` + `_pendingRequests is in an inconsistent state (url=${entry.url}).`, ); this._stats.errors.inconsistentStateDetected += 1; } @@ -198,7 +198,7 @@ export default class DoublefetchHandler { } const completeMatch = pendingWithUnknownRequestId.filter((x) => - urlEquals(request.url, x.url) + urlEquals(request.url, x.url), ); if (completeMatch.length > 0) { // should not be ambiguous, but when in doubt, let the oldest one win @@ -210,7 +210,7 @@ export default class DoublefetchHandler { // Requests like "http://goo.gl/..." may have been modified to "https://goo.gl/...". const normalizeSchema = (x) => x.replace(/^https:\/\//, "http://"); const ignoringSchema = pendingWithUnknownRequestId.filter((x) => - urlEquals(normalizeSchema(request.url), normalizeSchema(x.url)) + urlEquals(normalizeSchema(request.url), normalizeSchema(x.url)), ); if (ignoringSchema.length > 0) { // should not be ambiguous, but when in doubt, let the oldest one win @@ -235,7 +235,7 @@ export default class DoublefetchHandler { this.zombieRequestTimelimitMs ) { logger.error( - `doublefetch for url ${this._pendingRequests[0].url} was not cleaned up after ${this.zombieRequestTimelimitMs} ms.` + `doublefetch for url ${this._pendingRequests[0].url} was not cleaned up after ${this.zombieRequestTimelimitMs} ms.`, ); this._stats.errors.danglingEntryFound += 1; this._pendingRequests.shift(); @@ -284,13 +284,17 @@ export default class DoublefetchHandler { if (matchingPendingEvent) { /* eslint-disable no-param-reassign */ response.requestHeaders = request.requestHeaders.filter( - (header) => !isSensitiveHeader(header) + (header) => !isSensitiveHeader(header), ); if ( response.requestHeaders.length !== request.requestHeaders.length ) { this._stats.strippedHeaders += 1; } + + if (request.url.startsWith("https://www.google.com/search?")) { + response.requestHeaders.push({ name: "Cookie", value: "SG_SS=1;" }); + } } }, }; @@ -322,7 +326,7 @@ export default class DoublefetchHandler { if (contentLength && contentLength > this.maxDoubleFetchSize) { this._stats.rejected.exceededSizeLimit += 1; logger.debug( - `Response of ${request.url} exceeds limit of ${this.maxDoubleFetchSize} bytes. Aborting double fetch request.` + `Response of ${request.url} exceeds limit of ${this.maxDoubleFetchSize} bytes. Aborting double fetch request.`, ); response.block(); @@ -372,7 +376,7 @@ export default class DoublefetchHandler { "Learned new DNS resolution from doublefetch:", parsedURL.hostname, " -> ", - request.ip + request.ip, ); matchingPendingEvent.onCompletedHandlerFinished(); @@ -385,7 +389,7 @@ export default class DoublefetchHandler { if (this._state === State.INITIALIZING) { throw new Error( "Assertion failed: After all pending operation have finished, " + - "we must never end up in the INITIALIZING state" + "we must never end up in the INITIALIZING state", ); } @@ -434,8 +438,8 @@ export default class DoublefetchHandler { Promise.all( this._pendingRequests .filter((x) => x.requestPromise) - .map((x) => x.requestPromise.catch(() => {})) - ) + .map((x) => x.requestPromise.catch(() => {})), + ), ) .then(() => this._unloadPipeline()) .then(() => this._setState(State.DISABLED)); @@ -455,7 +459,7 @@ export default class DoublefetchHandler { url, entry, onCompletedHandlerTimeoutInMs = 3000, - overrideHeaders = {} + overrideHeaders = {}, ) { let handlerTimedOut; let timeoutTimer; @@ -480,7 +484,13 @@ export default class DoublefetchHandler { }; }); - return getRequest(url, overrideHeaders).then((response) => { + return getRequest( + url, + overrideHeaders, + url.startsWith("https://www.google.com/search?") + ? { redirect: "follow" } + : undefined, + ).then((response) => { // Normally, the onCompleted handler should trigger immediately // (either before or after the request is resolved). // To avoid that we hang forever if we fail to correlated requests, @@ -489,7 +499,7 @@ export default class DoublefetchHandler { timeoutTimer = pacemaker.setTimeout(() => { logger.warn( 'Waiting for the "onCompleted" handler timed out for url', - url + url, ); handlerTimedOut(); }, onCompletedHandlerTimeoutInMs); @@ -519,8 +529,8 @@ export default class DoublefetchHandler { this._webRequestPipeline.action( "addPipelineStep", "onBeforeSendHeaders", - beforeSendHeadersHandler - ) + beforeSendHeadersHandler, + ), ) .then(() => { this._onBeforeSendHeadersHandler = beforeSendHeadersHandler; @@ -529,8 +539,8 @@ export default class DoublefetchHandler { this._webRequestPipeline.action( "addPipelineStep", "onHeadersReceived", - headersReceivedHandler - ) + headersReceivedHandler, + ), ) .then(() => { this._onHeadersReceivedHandler = headersReceivedHandler; @@ -539,8 +549,8 @@ export default class DoublefetchHandler { this._webRequestPipeline.action( "addPipelineStep", "onCompleted", - completedHandler - ) + completedHandler, + ), ) .then(() => { this._onCompletedHandler = completedHandler; @@ -553,7 +563,11 @@ export default class DoublefetchHandler { } return ifModuleEnabled( - this._webRequestPipeline.action("removePipelineStep", stage, handler.name) + this._webRequestPipeline.action( + "removePipelineStep", + stage, + handler.name, + ), ); } diff --git a/modules/web-discovery-project/sources/network.es b/modules/web-discovery-project/sources/network.es index 2a999177..234f6c8e 100644 --- a/modules/web-discovery-project/sources/network.es +++ b/modules/web-discovery-project/sources/network.es @@ -113,7 +113,7 @@ export class Network { if (msg.payload.url && (await this.isHostNamePrivate(msg.payload.url))) { logger.debug( "sanitizeUrlsWithPrivateDomains: dropped because of private URL:", - msg.payload.url + msg.payload.url, ); return null; } @@ -126,14 +126,14 @@ export class Network { ) { logger.debug( 'sanitizeUrlsWithPrivateDomains: private "canonical_url" URL nulled out:', - msg.payload.url + msg.payload.url, ); msg.payload.x.canonical_url = null; } if (msg.payload.ref && (await this.isHostNamePrivate(msg.payload.ref))) { logger.debug( 'sanitizeUrlsWithPrivateDomains: private "ref" URL nulled out:', - msg.payload.ref + msg.payload.ref, ); msg.payload.ref = null; } @@ -146,7 +146,7 @@ export class Network { ) { logger.debug( 'sanitizeUrlsWithPrivateDomains: private "red" URL nulled out:', - msg.payload.red[i] + msg.payload.red[i], ); msg.payload.red[i] = null; } @@ -180,7 +180,7 @@ export class Network { "Could not resolve domain", host, ". Be conservative and assume that the domain is private.", - e + e, ); return true; } diff --git a/modules/web-discovery-project/sources/safebrowsing-endpoint.es b/modules/web-discovery-project/sources/safebrowsing-endpoint.es index 59c0ffc7..9ab73220 100644 --- a/modules/web-discovery-project/sources/safebrowsing-endpoint.es +++ b/modules/web-discovery-project/sources/safebrowsing-endpoint.es @@ -45,13 +45,13 @@ class Hpnv2Sender { if (shouldRetry) { logger.debug( "message failed, retry possible --> pushing to DLQ", - msg + msg, ); this.pushToDlq([{ msg, resolve, reject, attempts, e }]); } else { logger.debug( "message failed, retry will likely fail --> dropping message", - msg + msg, ); reject(e); } @@ -200,7 +200,7 @@ export default class SafebrowsingEndpoint { if (this.dlq.length > this.dlqMaxSize) { for (const { msg, reject, e } of this.dlq.splice( 0, - this.dlq.length - this.dlqMaxSize + this.dlq.length - this.dlqMaxSize, )) { logger.warn("DLQ overrun. Dropping message:", msg); reject(e); diff --git a/modules/web-discovery-project/sources/web-discovery-project.es b/modules/web-discovery-project/sources/web-discovery-project.es index 37d96e47..38c61ec6 100644 --- a/modules/web-discovery-project/sources/web-discovery-project.es +++ b/modules/web-discovery-project/sources/web-discovery-project.es @@ -1694,7 +1694,7 @@ const WebDiscoveryProject = { if (query_stringsParts["url"]) { masked_url = query_stringsParts["url"][0]; masked_url = WebDiscoveryProject.maskURL( - decodeURIComponent("" + masked_url) + decodeURIComponent("" + masked_url), ); return masked_url; } @@ -1798,7 +1798,7 @@ const WebDiscoveryProject = { } if ( - (!WebDiscoveryProject.utility_regression_tests) & + !WebDiscoveryProject.utility_regression_tests & (url_parts.port != "") & (url_parts.port != "80" && url_parts.port != "443") ) { @@ -1826,8 +1826,8 @@ const WebDiscoveryProject = { } if ( - (!WebDiscoveryProject.utility_regression_tests) & - url_parts.hostname.indexOf("localhost") > -1 || + !WebDiscoveryProject.utility_regression_tests & + (url_parts.hostname.indexOf("localhost") > -1) || url_parts.hostname.endsWith(".local") ) { return true; @@ -1884,10 +1884,11 @@ const WebDiscoveryProject = { dropLongURL: function (url, options) { _log("DLU called with arguments:", url, options); try { - if (options == null) options = { - strict: false, - allowlisted: false, - }; + if (options == null) + options = { + strict: false, + allowlisted: false, + }; if (WebDiscoveryProject.checkForEmail(url)) return true; @@ -1929,7 +1930,7 @@ const WebDiscoveryProject = { url_parts.query_string && url_parts.query_string.length > WebDiscoveryProject.qs_len ) { - _log('DLU failed: length of query string is longer than qs_len'); + _log("DLU failed: length of query string is longer than qs_len"); return true; } @@ -1937,23 +1938,29 @@ const WebDiscoveryProject = { var v = url_parts.query_string.split(/[&;]/); if (v.length > 4) { // that means that there is a least one &; hence 5 params - _log('DLU failed: there are more than 4 parameters'); + _log("DLU failed: there are more than 4 parameters"); return true; } if ( !options.allowlisted && WebDiscoveryProject.checkForLongNumber( url_parts.query_string, - 12 + 12, ) != null ) { - _log('DLU failed: long number in the query string: ', url_parts.query_string); + _log( + "DLU failed: long number in the query string: ", + url_parts.query_string, + ); return true; } } - if (!options.allowlisted && WebDiscoveryProject.checkForLongNumber(url_parts.path, 12) != null) { - _log('DLU failed: long number in path: ', url_parts.path); + if ( + !options.allowlisted && + WebDiscoveryProject.checkForLongNumber(url_parts.path, 12) != null + ) { + _log("DLU failed: long number in path: ", url_parts.path); return true; } } @@ -1970,7 +1977,7 @@ const WebDiscoveryProject = { return true; } else { if (vpath[i].length > 12 && WebDiscoveryProject.isHash(vpath[i])) { - _log('DLU failed: hash in the URL ', vpath[i]); + _log("DLU failed: hash in the URL ", vpath[i]); return true; } } @@ -1983,7 +1990,7 @@ const WebDiscoveryProject = { if (options.strict == true) mult = 0.5; if (cstr.length > WebDiscoveryProject.rel_segment_len * mult) { if (WebDiscoveryProject.isHash(cstr)) { - _log('DLU failed: hash in the path ', cstr); + _log("DLU failed: hash in the path ", cstr); return true; } } @@ -2017,7 +2024,7 @@ const WebDiscoveryProject = { if (ind_pos != -1) path_query_string = url_parts.path.slice( ind_pos, - url_parts.path.length + url_parts.path.length, ); if ( @@ -2240,7 +2247,7 @@ const WebDiscoveryProject = { // try { for (const [key, { status, location }] of Object.entries( - WebDiscoveryProject.httpCache + WebDiscoveryProject.httpCache, )) { if ( key !== url && @@ -2287,7 +2294,10 @@ const WebDiscoveryProject = { auxGetPageData: function (url, page_data, original_url, onsuccess, onerror) { WebDiscoveryProject.doublefetchHandler .anonymousHttpGet(url) - .then(({ body }) => parseHtml(body)) + .then(({ body }) => { + console.error("GOT BODY:", body); + return parseHtml(body); + }) .then((doc) => { const x = WebDiscoveryProject.getPageData(url, doc); @@ -2482,11 +2492,11 @@ const WebDiscoveryProject = { var tt1 = t1.replace( /[^A-Za-z 0-9 \.,\?""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, - "" + "", ); var tt2 = t2.replace( /[^A-Za-z 0-9 \.,\?""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, - "" + "", ); if (tt1.length > t1.length * 0.5 && tt2.length > t2.length * 0.5) { @@ -2601,16 +2611,16 @@ const WebDiscoveryProject = { null, function (referral_url) { _log( - "PPP in fetchReferral success auxGetPageData: " + referral_url + "PPP in fetchReferral success auxGetPageData: " + referral_url, ); callback(); }, function (referral_url) { _log( - "PPP in fetchReferral failure auxGetPageData: " + referral_url + "PPP in fetchReferral failure auxGetPageData: " + referral_url, ); callback(); - } + }, ); } else { _log("PPP in fetchReferral already in docCache: " + referral_url); @@ -2649,7 +2659,7 @@ const WebDiscoveryProject = { return discard("URL failed the isSuspiciousURL check"); } - let allowlisted = page_doc["alw"] + let allowlisted = page_doc["alw"]; if (WebDiscoveryProject.dropLongURL(url)) { // The URL itself is considered unsafe, but it has a canonical URL, so it should be public @@ -2697,7 +2707,7 @@ const WebDiscoveryProject = { "The URL", url, "failed one of the doublefetch heuristics. Details:", - explanation + explanation, ); resolve({ url, @@ -2727,7 +2737,7 @@ const WebDiscoveryProject = { if (!allowDoublefetch) { privateUrlFound( url, - `URL rejected by heuristics before doublefetch: ${rejectDetails}` + `URL rejected by heuristics before doublefetch: ${rejectDetails}`, ); return; } @@ -2758,11 +2768,11 @@ const WebDiscoveryProject = { let nifshmatch = WebDiscoveryProject.validFrameCount( page_doc["x"], - data + data, ); let nfshmatch = WebDiscoveryProject.validFrameSetCount( page_doc["x"], - data + data, ); data.nifshmatch = nifshmatch; @@ -2775,23 +2785,20 @@ const WebDiscoveryProject = { // WebDiscoveryProject.fetchReferral(page_doc["ref"], function () { var url_strict_value = WebDiscoveryProject.calculateStrictness( - url, - page_doc - ); - - var structure_strict_value = WebDiscoveryProject.calculateStrictness( url, page_doc, - true ); + var structure_strict_value = + WebDiscoveryProject.calculateStrictness(url, page_doc, true); + var allowlisted = page_doc["alw"]; url_strict_value = url_strict_value && !allowlisted; if (page_doc["ref"] && page_doc["ref"] != "") { // the page has a referral _log( - "PPP: page has a referral, " + url + " < " + page_doc["ref"] + "PPP: page has a referral, " + url + " < " + page_doc["ref"], ); var hasurl = WebDiscoveryProject.hasURL(page_doc["ref"], url); _log( @@ -2800,11 +2807,15 @@ const WebDiscoveryProject = { " < " + page_doc["ref"] + ">>>> " + - hasurl + hasurl, ); // overwrite strict value because the link exists on a public fetchable page - _log("Strictness values:", url_strict_value, structure_strict_value); + _log( + "Strictness values:", + url_strict_value, + structure_strict_value, + ); if (hasurl) { url_strict_value = false; structure_strict_value = false; @@ -2817,7 +2828,14 @@ const WebDiscoveryProject = { // there is no canonical or if there is canonical and is the same as the url, } - _log("strict URL:", url, "> struct:", structure_strict_value, " url:", url_strict_value); + _log( + "strict URL:", + url, + "> struct:", + structure_strict_value, + " url:", + url_strict_value, + ); if ( WebDiscoveryProject.validDoubleFetch(page_doc["x"], data, { @@ -2842,19 +2860,19 @@ const WebDiscoveryProject = { page_doc["x"]["canonical_url"], { strict: url_strict_value, - } + }, ) ) { privateUrlFound( url, - "rejected by dropLongURL (strict=true) heuristic" + "rejected by dropLongURL (strict=true) heuristic", ); return; } } else { privateUrlFound( url, - "rejected by dropLongURL (strict=true) heuristic" + "rejected by dropLongURL (strict=true) heuristic", ); return; } @@ -2864,7 +2882,7 @@ const WebDiscoveryProject = { // since we do not know the origin mark as private privateUrlFound( url, - `rejected by validDoubleFetch(structure_strict=${structure_strict_value})` + `rejected by validDoubleFetch(structure_strict=${structure_strict_value})`, ); return; } @@ -2898,7 +2916,10 @@ const WebDiscoveryProject = { if ( page_doc["x"]["canonical_url"] != null && page_doc["x"]["canonical_url"] != "" && - (allowlisted || WebDiscoveryProject.dropLongURL(page_doc["x"]["canonical_url"]) == false) + (allowlisted || + WebDiscoveryProject.dropLongURL( + page_doc["x"]["canonical_url"], + ) == false) ) { page_doc["url"] = page_doc["x"]["canonical_url"]; page_doc["x"] = data; @@ -2906,7 +2927,10 @@ const WebDiscoveryProject = { } else { // there was no canonical either on page_doc['x'] or in data or it was droppable - if (allowlisted || WebDiscoveryProject.dropLongURL(url) == false) { + if ( + allowlisted || + WebDiscoveryProject.dropLongURL(url) == false + ) { page_doc["url"] = url; page_doc["x"] = data; @@ -2920,7 +2944,7 @@ const WebDiscoveryProject = { // this should not happen since it would be covered by the isok checks, but better safe, privateUrlFound( url, - `rejected by fail-safe branch (dropLongURL(${url} should have been passed)` + `rejected by fail-safe branch (dropLongURL(${url} should have been passed)`, ); return; } @@ -2928,7 +2952,7 @@ const WebDiscoveryProject = { } var clean_url = WebDiscoveryProject.getCleanerURL( - page_doc["url"] + page_doc["url"], ); if (clean_url != page_doc["url"]) { @@ -2945,7 +2969,7 @@ const WebDiscoveryProject = { first_url_double_fetched, function (url, page_doc, original_url, data) { _log( - "success on clean_url doubleFetch, need further validation" + "success on clean_url doubleFetch, need further validation", ); if ( @@ -2954,7 +2978,7 @@ const WebDiscoveryProject = { data, { structure_strict: false, - } + }, ) ) { // if it the second double fetch is valid, that means that the clean_url is (url parameter) is @@ -2978,7 +3002,7 @@ const WebDiscoveryProject = { // the page with url_clean have more input password fields or more forms, this is dangerous, privateUrlFound( original_url, - "rejected by extra password / form fields (after doublefetch)" + "rejected by extra password / form fields (after doublefetch)", ); } else { // safe, here we will send the url before clean_url @@ -2990,10 +3014,10 @@ const WebDiscoveryProject = { // there was a failure, the clean_url does not go to the same place, therefore it's better // not to replace _log( - "failure on clean_url doubleFetch! structure did not match" + "failure on clean_url doubleFetch! structure did not match", ); publicUrlFound(original_url, page_doc); - } + }, ); } else { publicUrlFound(original_url, page_doc); @@ -3002,7 +3026,7 @@ const WebDiscoveryProject = { } else { privateUrlFound( url, - "rejected as the structure of the document changed significantly (after doublefetch)" + "rejected as the structure of the document changed significantly (after doublefetch)", ); } }, @@ -3010,9 +3034,9 @@ const WebDiscoveryProject = { _log("failure on doubleFetch!", error_message); privateUrlFound( url, - `rejected as doublefetch failed with an error ${error_message}` + `rejected as doublefetch failed with an error ${error_message}`, ); - } + }, ); }); }, @@ -3338,7 +3362,7 @@ const WebDiscoveryProject = { if (WebDiscoveryProject.state["v"][activeURL] == null) { const braveQuery = WebDiscoveryProject.contentExtractor.tryExtractBraveSerpQuery( - activeURL + activeURL, ); logger.debug("[onLocationChange] isBraveQuery", braveQuery); if (braveQuery) { @@ -3362,13 +3386,13 @@ const WebDiscoveryProject = { }) .catch((e) => { logger.info( - `Failed to get content for originalURL=${originalURL} (internalURL=${url}, details=${e})` + `Failed to get content for originalURL=${originalURL} (internalURL=${url}, details=${e})`, ); }); }, WebDiscoveryProject.WAIT_TIME, activeURL, - originalURL + originalURL, ); } @@ -3408,7 +3432,9 @@ const WebDiscoveryProject = { } } - const allowlisted = WebDiscoveryProject.allowlist.some(allowlist_regex => allowlist_regex.test(activeURL)); + const allowlisted = WebDiscoveryProject.allowlist.some( + (allowlist_regex) => allowlist_regex.test(activeURL), + ); // Page details to be saved. WebDiscoveryProject.state["v"][activeURL] = { @@ -3488,7 +3514,7 @@ const WebDiscoveryProject = { function (cd) { if ( !WebDiscoveryProject.contentExtractor.isSearchEngineUrl( - currURL + currURL, ) ) { try { @@ -3522,7 +3548,7 @@ const WebDiscoveryProject = { WebDiscoveryProject.addURLtoDB( currURL, WebDiscoveryProject.state["v"][currURL]["ref"], - WebDiscoveryProject.state["v"][currURL] + WebDiscoveryProject.state["v"][currURL], ); } }, @@ -3530,20 +3556,20 @@ const WebDiscoveryProject = { if (WebDiscoveryProject.debug) { _log("CANNOT GET THE CONTENT OF : " + currURL); } - } + }, ) .catch((ee) => { _log( "Error fetching title and length of page: " + ee + " : " + - currURL + currURL, ); }); }, WebDiscoveryProject.PAGE_WAIT_TIME, activeURL, - originalURL + originalURL, ); } else { // oops, it exists on the active page, probably it comes from a back button or back @@ -3562,7 +3588,7 @@ const WebDiscoveryProject = { WebDiscoveryProject.addURLtoDB( url, WebDiscoveryProject.state["v"][url]["ref"], - WebDiscoveryProject.state["v"][url] + WebDiscoveryProject.state["v"][url], ); delete WebDiscoveryProject.state["v"][url]; delete WebDiscoveryProject.queryCache[url]; @@ -3598,8 +3624,8 @@ const WebDiscoveryProject = { WebDiscoveryProject.counter += 4; }, - { timeout: 1000 } - ) + { timeout: 1000 }, + ), ); // 1 second // TODO - could be replaced by tab events (closed, updated, new) @@ -3626,12 +3652,12 @@ const WebDiscoveryProject = { ) { // move to "dead pages" after 5 minutes WebDiscoveryProject.state["m"].push( - WebDiscoveryProject.state["v"][url] + WebDiscoveryProject.state["v"][url], ); WebDiscoveryProject.addURLtoDB( url, WebDiscoveryProject.state["v"][url]["ref"], - WebDiscoveryProject.state["v"][url] + WebDiscoveryProject.state["v"][url], ); delete WebDiscoveryProject.state["v"][url]; delete WebDiscoveryProject.queryCache[url]; @@ -3647,12 +3673,12 @@ const WebDiscoveryProject = { WebDiscoveryProject.state["v"][url]["tend"] = null; WebDiscoveryProject.state["v"][url]["too_long"] = true; WebDiscoveryProject.state["m"].push( - WebDiscoveryProject.state["v"][url] + WebDiscoveryProject.state["v"][url], ); WebDiscoveryProject.addURLtoDB( url, WebDiscoveryProject.state["v"][url]["ref"], - WebDiscoveryProject.state["v"][url] + WebDiscoveryProject.state["v"][url], ); delete WebDiscoveryProject.state["v"][url]; delete WebDiscoveryProject.queryCache[url]; @@ -3667,8 +3693,8 @@ const WebDiscoveryProject = { _log(ee); }); }, - { timeout: 5000 } - ) + { timeout: 5000 }, + ), ); // Every 10 seconds @@ -3686,8 +3712,8 @@ const WebDiscoveryProject = { WebDiscoveryProject.loadBloomFilter(); } }, - { timeout: 10 * 1000 } - ) + { timeout: 10 * 1000 }, + ), ); // 10 seconds // Clean http cache (when >1 hour) @@ -3696,8 +3722,8 @@ const WebDiscoveryProject = { function cleanHttpCache() { WebDiscoveryProject.cleanHttpCache(); }, - { timeout: 15 * 1000 } - ) + { timeout: 15 * 1000 }, + ), ); // 15 seconds // Purge clean link cache (when >1 minute) @@ -3706,8 +3732,8 @@ const WebDiscoveryProject = { function cleanLinkCache() { WebDiscoveryProject.cleanLinkCache(); }, - { timeout: 15 * 1000 } - ) + { timeout: 15 * 1000 }, + ), ); // 15 seconds // Purge ad lookup (when >15 minutes) @@ -3716,8 +3742,8 @@ const WebDiscoveryProject = { function purgeAdLookUp() { WebDiscoveryProject.purgeAdLookUp(); }, - { timeout: 15 * 1000 } - ) + { timeout: 15 * 1000 }, + ), ); // 15 seconds // Clean doc cache (>1 hour) @@ -3726,8 +3752,8 @@ const WebDiscoveryProject = { function cleanDocCache() { WebDiscoveryProject.cleanDocCache(); }, - { timeout: 60 * 1000 } - ) + { timeout: 60 * 1000 }, + ), ); // 1 minute // Every minute @@ -3738,12 +3764,12 @@ const WebDiscoveryProject = { 1, WebDiscoveryProject.doubleFetchTimeInSec, null, - WebDiscoveryProject.processUnchecks + WebDiscoveryProject.processUnchecks, ); WebDiscoveryProject.auxGetQuery(); }, - { timeout: 60 * 1000 } - ) + { timeout: 60 * 1000 }, + ), ); // 1 minute // Every 5 minutes @@ -3753,8 +3779,8 @@ const WebDiscoveryProject = { logger.debug("web-discovery-project: flush network cache"); WebDiscoveryProject.network.flushExpiredCacheEntries(); }, - { timeout: 5 * 60 * 1000 } - ) + { timeout: 5 * 60 * 1000 }, + ), ); // 5 minutes // Every 20 minutes @@ -3766,8 +3792,8 @@ const WebDiscoveryProject = { } WebDiscoveryProject.checkActiveUsage(); }, - { timeout: 20 * 60 * 1000 } - ) + { timeout: 20 * 60 * 1000 }, + ), ); // 20 minutes // Every 4 hours @@ -3776,8 +3802,8 @@ const WebDiscoveryProject = { function checkAllOpenPages() { WebDiscoveryProject.fetchSafeQuorumConfig(); }, - { timeout: 4 * 60 * 60 * 1000 } - ) + { timeout: 4 * 60 * 60 * 1000 }, + ), ); // 4 hours return tasks; @@ -3805,7 +3831,7 @@ const WebDiscoveryProject = { }, currentURL: function () { return getActiveTab().then(({ url }) => - WebDiscoveryProject.cleanCurrentUrl(url) + WebDiscoveryProject.cleanCurrentUrl(url), ); }, cleanCurrentUrl: function (url) { @@ -3920,7 +3946,7 @@ const WebDiscoveryProject = { " :: " + ev.target.value + " >>" + - JSON.stringify(WebDiscoveryProject.lastEv) + JSON.stringify(WebDiscoveryProject.lastEv), ); } @@ -4099,7 +4125,7 @@ const WebDiscoveryProject = { } else { WebDiscoveryProject.activeUsage = JSON.parse(data); } - } + }, ); } @@ -4114,7 +4140,7 @@ const WebDiscoveryProject = { _log(`Active usage last sent from db as ${data}`); WebDiscoveryProject.activeUsageLastSent = parseInt(data); } - } + }, ); return Promise.all(promises).then(() => { @@ -4157,7 +4183,7 @@ const WebDiscoveryProject = { " : " + msg.payload.tin + " : " + - duration + duration, ); } else { var duration = null; @@ -4167,7 +4193,7 @@ const WebDiscoveryProject = { " : " + msg.payload.tin + " : " + - duration + duration, ); } @@ -4195,7 +4221,7 @@ const WebDiscoveryProject = { msg.payload["ref"] = null; } } - } + }, ); } @@ -4251,7 +4277,7 @@ const WebDiscoveryProject = { msg.payload.x.canonical_url != "" ) { short_canonical_url = WebDiscoveryProject.isShortenerURL( - msg.payload.x.canonical_url + msg.payload.x.canonical_url, ); } @@ -4336,7 +4362,11 @@ const WebDiscoveryProject = { //Remove the msg if the query is too long, - if (msg.action == "query" || msg.action == "anon-query" || msg.action == "widgetTitle") { + if ( + msg.action == "query" || + msg.action == "anon-query" || + msg.action == "widgetTitle" + ) { //Remove the msg if the query is too long, if (msg.payload.q == null || msg.payload.q == "") { return null; @@ -4369,7 +4399,7 @@ const WebDiscoveryProject = { // That it where we currently set the threshold. if (cleanR.length < 4) { _log( - `Dropping message for query ${msg.payload.q}, as there are too few search results.` + `Dropping message for query ${msg.payload.q}, as there are too few search results.`, ); return null; } @@ -4413,7 +4443,7 @@ const WebDiscoveryProject = { if (accepted) { _log( "all checks passed: telemetry message added to the send queue:", - msg + msg, ); // do not wait for the promise to complete (keeping the old fire-and-forget API) @@ -4425,7 +4455,7 @@ const WebDiscoveryProject = { "Successfully sent message after", (Date.now() - start) / 1000.0, "sec", - msg + msg, ); }) .catch((e) => { @@ -4433,7 +4463,7 @@ const WebDiscoveryProject = { `Finally giving up on sending message (reason: ${e}, elapsed: ${ (Date.now() - start) / 1000.0 } sec)`, - msg + msg, ); }); } else { @@ -4510,7 +4540,7 @@ const WebDiscoveryProject = { 1000000000000, 0, url, - WebDiscoveryProject.processUnchecks + WebDiscoveryProject.processUnchecks, ); }, @@ -4582,12 +4612,12 @@ const WebDiscoveryProject = { resolve( res .map((x) => ({ url: x[0], page_doc: x[1] })) - .filter((x) => isRelevantUrl(x.url)) + .filter((x) => isRelevantUrl(x.url)), ); } catch (e) { reject(e); } - } + }, ); }); } else { @@ -4624,7 +4654,7 @@ const WebDiscoveryProject = { logger.error(e); return { url, state: "error", explanation: `error: ${e}` }; } - }) + }), ); return results.sort((x, y) => x.url < y.url); }, @@ -4671,7 +4701,7 @@ const WebDiscoveryProject = { return WebDiscoveryProject.contentExtractor.checkURL( pageContent, url, - ruleset + ruleset, ); }, @@ -4692,7 +4722,7 @@ const WebDiscoveryProject = { _log( "aggregates: " + JSON.stringify(metricsBefore) + - JSON.stringify(metricsAfter) + JSON.stringify(metricsAfter), ); } @@ -4865,7 +4895,7 @@ const WebDiscoveryProject = { JSON.stringify(WebDiscoveryProject.activeUsage), (result) => { _log("Active usage stats saved:", result); - } + }, ); }, checkActiveUsage: function () { @@ -4892,7 +4922,7 @@ const WebDiscoveryProject = { */ const tDiff = parseInt( - (new Date().getTime() - WebDiscoveryProject.activeUsageLastSent) / 1000 + (new Date().getTime() - WebDiscoveryProject.activeUsageLastSent) / 1000, ); if (tDiff > 3600) { const activeHours = Object.keys(WebDiscoveryProject.activeUsage); @@ -4909,7 +4939,7 @@ const WebDiscoveryProject = { JSON.stringify(WebDiscoveryProject.activeUsage), (result) => { _log("Active usage stats saved:", result); - } + }, ); WebDiscoveryProject.saveActiveUsageTime(); } @@ -4924,7 +4954,7 @@ const WebDiscoveryProject = { }; _log( - `Sending alive message for the hour: ${h} , ${JSON.stringify(payload)}` + `Sending alive message for the hour: ${h} , ${JSON.stringify(payload)}`, ); WebDiscoveryProject.telemetry({ @@ -4941,7 +4971,7 @@ const WebDiscoveryProject = { (result) => { WebDiscoveryProject.activeUsageLastSent = t; _log(`Active usage last sent as ${t}`); - } + }, ); }, saveStrictQueries: function () { @@ -4951,7 +4981,7 @@ const WebDiscoveryProject = { JSON.stringify(WebDiscoveryProject.strictQueries), (result) => { _log("localStrictQueries saved:", result); - } + }, ); }, dumpBloomFilter: function () { @@ -4962,7 +4992,7 @@ const WebDiscoveryProject = { bf.join("|"), (result) => { _log("bloom filter saved:", result); - } + }, ); } }, @@ -4972,13 +5002,13 @@ const WebDiscoveryProject = { _log("There was no data on WebDiscoveryProject.bf"); WebDiscoveryProject.bloomFilter = new BloomFilter( Array(bloomFilterSize).join("0"), - bloomFilterNHashes + bloomFilterNHashes, ); } else { var _data = data.split("|").map(Number); WebDiscoveryProject.bloomFilter = new BloomFilter( _data, - bloomFilterNHashes + bloomFilterNHashes, ); } }); @@ -4993,7 +5023,7 @@ const WebDiscoveryProject = { } else { WebDiscoveryProject.strictQueries = JSON.parse(data); } - } + }, ); }, auxGetQuery: function () { @@ -5010,7 +5040,7 @@ const WebDiscoveryProject = { }, function (a, b, c, d) { _log("Error aux>>>> " + d); - } + }, ); WebDiscoveryProject.strictQueries.splice(idx, 1); WebDiscoveryProject.saveStrictQueries(); @@ -5372,10 +5402,10 @@ const WebDiscoveryProject = { for (const original of urls) { if (original.t === "canonical") { msg.payload.x.canonical_url = WebDiscoveryProject.maskURLStrict( - original.url + original.url, ); _log( - `Sanitized 'canonical': ${original.url} -> ${msg.payload.x.canonical_url}` + `Sanitized 'canonical': ${original.url} -> ${msg.payload.x.canonical_url}`, ); } @@ -5387,10 +5417,10 @@ const WebDiscoveryProject = { if (original.t.startsWith("red")) { let redPos = original.t.split(":")[1]; msg.payload.red[redPos] = WebDiscoveryProject.maskURLStrict( - original.url + original.url, ); _log( - `Sanitized 'ref++${redPos}': ${original.url} -> ${msg.payload.red[redPos]}` + `Sanitized 'ref++${redPos}': ${original.url} -> ${msg.payload.red[redPos]}`, ); } } @@ -5515,7 +5545,7 @@ const WebDiscoveryProject = { var metricsAfter = paylobj["e"]; paylobj["e"] = WebDiscoveryProject.aggregateMetrics( metricsBefore, - metricsAfter + metricsAfter, ); var cloneObj = record; @@ -5561,7 +5591,7 @@ const WebDiscoveryProject = { fixed_url, (res, res2) => { callback(res); - } + }, ); }, processUnchecks: function (listOfUncheckedUrls) { @@ -5581,7 +5611,7 @@ const WebDiscoveryProject = { page_doc, ", page_struct_before:", page_struct_before, - ")" + ")", ); // only do doubleFetch for the same url 3 times in a row @@ -5612,7 +5642,7 @@ const WebDiscoveryProject = { JSON.stringify(obj), (result) => { _log("last-double-fetch saved:", result); - } + }, ); if (obj.count > WebDiscoveryProject.MAX_NUMBER_DOUBLEFETCH_ATTEMPS) { @@ -5620,7 +5650,7 @@ const WebDiscoveryProject = { } else { WebDiscoveryProject.doubleFetch(url, url_pagedocPair[url]); } - } + }, ); } }, @@ -5638,7 +5668,7 @@ const WebDiscoveryProject = { } const domain = cleanFinalUrl( WebDiscoveryProject.adDetails[clickedU].furl[0], - WebDiscoveryProject.adDetails[clickedU].furl[1] + WebDiscoveryProject.adDetails[clickedU].furl[1], ); const payload = { @@ -5702,7 +5732,7 @@ const WebDiscoveryProject = { }, }; WebDiscoveryProject.contentExtractor = new ContentExtractor( - WebDiscoveryProject + WebDiscoveryProject, ); export default WebDiscoveryProject; diff --git a/modules/web-discovery-project/tests/integration/doublefetch-test.es b/modules/web-discovery-project/tests/integration/doublefetch-test.es index 5af51915..dfaed885 100644 --- a/modules/web-discovery-project/tests/integration/doublefetch-test.es +++ b/modules/web-discovery-project/tests/integration/doublefetch-test.es @@ -19,8 +19,8 @@ export default function () { name: testCookieName, url: testUrl, }, - resolve - ) + resolve, + ), ); beforeEach(async () => { @@ -43,9 +43,9 @@ export default function () { name: testCookieName, url: testServer.getBaseUrl(testPath), }, - resolve - ) - ) + resolve, + ), + ), ); it("does not cause cookies to be set", async () => { diff --git a/modules/web-discovery-project/tests/integration/utility-regression-test.es b/modules/web-discovery-project/tests/integration/utility-regression-test.es index 501328b3..5fed4a44 100644 --- a/modules/web-discovery-project/tests/integration/utility-regression-test.es +++ b/modules/web-discovery-project/tests/integration/utility-regression-test.es @@ -10,7 +10,7 @@ import { getTab, testServer, waitFor, - testPageSources + testPageSources, } from "../../../tests/core/integration/helpers"; const test_urls = [ @@ -53,88 +53,108 @@ const test_urls = [ "https://www.csmonitor.com/Commentary/2022/1031/Inspiring-by-example?icid=rss", "https://www.democracynow.org/2022/10/26/pennsylvania_mehmet_oz_john_fetterman_debate", "https://www.spiegel.de/international/world/the-divided-village-mistrust-abounds-among-the-liberated-residents-of-ukrainian-village-a-a0c64575-da9d-46b6-ba07-26a72db4a316#ref=rss", - "https://www.politico.com/news/2022/10/11/liv-golf-nra-mckenna-associates-00061215" -] + "https://www.politico.com/news/2022/10/11/liv-golf-nra-mckenna-associates-00061215", +]; export default () => { - describe("UtilityRegression tests", () => { - const getSuffix = (path = "base") => `/${path}`; - const getUrl = (path = "base") => testServer.getBaseUrl(getSuffix(path)); + describe("UtilityRegression tests", () => { + const getSuffix = (path = "base") => `/${path}`; + const getUrl = (path = "base") => testServer.getBaseUrl(getSuffix(path)); - const WebDiscoveryProject = app.modules["web-discovery-project"].background.webDiscoveryProject; - const pipeline = app.modules["webrequest-pipeline"].background; + const WebDiscoveryProject = + app.modules["web-discovery-project"].background.webDiscoveryProject; + const pipeline = app.modules["webrequest-pipeline"].background; - const openTab = async (url) => { - const tabId = await newTab("about:blank"); - await waitFor( - () => - expect( - pipeline.pageStore.tabs.has(tabId), - `expect ${tabId} in ${JSON.stringify( - [...pipeline.pageStore.tabs.entries()], - null, - 2 - )}` - ).to.eql(true), - 2000 - ); - await updateTab(tabId, { url }); - await waitFor( - async () => expect((await getTab(tabId)).url).to.not.eql("about:blank"), - 2000 - ); - return tabId; - }; + const openTab = async (url) => { + const tabId = await newTab("about:blank"); + await waitFor( + () => + expect( + pipeline.pageStore.tabs.has(tabId), + `expect ${tabId} in ${JSON.stringify( + [...pipeline.pageStore.tabs.entries()], + null, + 2, + )}`, + ).to.eql(true), + 2000, + ); + await updateTab(tabId, { url }); + await waitFor( + async () => expect((await getTab(tabId)).url).to.not.eql("about:blank"), + 2000, + ); + return tabId; + }; - beforeEach(async () => { - await app.modules["web-discovery-project"].isReady(); - WebDiscoveryProject.debug = true; - WebDiscoveryProject.utility_regression_tests = true; + beforeEach(async () => { + await app.modules["web-discovery-project"].isReady(); + WebDiscoveryProject.debug = true; + WebDiscoveryProject.utility_regression_tests = true; - // Reload pipeline - pipeline.unload(); - await pipeline.init(); - }); + // Reload pipeline + pipeline.unload(); + await pipeline.init(); + }); - describe("utility-regression-test.base", () => { - it("mock_url appears in wdp state", async () => { - let page = testPageSources['pages'][0] - let path = page['url'] - await testServer.registerPathHandler(getSuffix(path), { - result: page['content'], - }); + describe("utility-regression-test.base", () => { + it("mock_url appears in wdp state", async () => { + let page = testPageSources["pages"][0]; + let path = page["url"]; + await testServer.registerPathHandler(getSuffix(path), { + result: page["content"], + }); - await openTab(getUrl(path)); - await waitFor(() => expect(Object.keys(WebDiscoveryProject.state.v)).to.include(getUrl(path)), 5000); - }); + await openTab(getUrl(path)); + await waitFor( + () => + expect(Object.keys(WebDiscoveryProject.state.v)).to.include( + getUrl(path), + ), + 5000, + ); }); + }); - describe("utility-regression-test.utility-regression", () => { - test_urls.forEach((url) => { - it(`'${url}' is allowed`, async () => { - // addPipeline(addCookiesToRequest); - await openTab(url); - await waitFor(async () => { - // getURL needs to be called on the canonical url - let canonical_url = null; - Object.values(WebDiscoveryProject.state.v).every((entry) => { - if (entry.url == url || (entry.red && entry.red[0] == url)) { - canonical_url = entry.url - return false; - } - return true; - }) - if (canonical_url != null) { - return (await new Promise((resolve) => WebDiscoveryProject.db.getURL(canonical_url, resolve))).length == 1 + describe("utility-regression-test.utility-regression", () => { + test_urls.forEach((url) => { + it(`'${url}' is allowed`, async () => { + // addPipeline(addCookiesToRequest); + await openTab(url); + await waitFor(async () => { + // getURL needs to be called on the canonical url + let canonical_url = null; + Object.values(WebDiscoveryProject.state.v).every((entry) => { + if (entry.url == url || (entry.red && entry.red[0] == url)) { + canonical_url = entry.url; + return false; } + return true; }); - await WebDiscoveryProject.forceDoubleFetch(url); - await waitFor(async () => (await new Promise((resolve) => WebDiscoveryProject.db.getURL(url, resolve))).length == 0); - WebDiscoveryProject.isAlreadyMarkedPrivate(url, (res) => { - expect(res.private, "url is marked as private!").equal(0); - }); + if (canonical_url != null) { + return ( + ( + await new Promise((resolve) => + WebDiscoveryProject.db.getURL(canonical_url, resolve), + ) + ).length == 1 + ); + } + }); + await WebDiscoveryProject.forceDoubleFetch(url); + await waitFor( + async () => + ( + await new Promise((resolve) => + WebDiscoveryProject.db.getURL(url, resolve), + ) + ).length == 0, + ); + WebDiscoveryProject.isAlreadyMarkedPrivate(url, (res) => { + expect(res.private, "url is marked as private!").equal(0); }); - }); }); + }); }); + }); }; diff --git a/modules/web-discovery-project/tests/integration/web-discovery-project-test.es b/modules/web-discovery-project/tests/integration/web-discovery-project-test.es index 54b74750..2cff74bf 100644 --- a/modules/web-discovery-project/tests/integration/web-discovery-project-test.es +++ b/modules/web-discovery-project/tests/integration/web-discovery-project-test.es @@ -114,7 +114,7 @@ export default function () { } else { done("storage test-failed"); } - } + }, ); }); }); diff --git a/modules/web-discovery-project/tests/unit/ad-detection-test.es b/modules/web-discovery-project/tests/unit/ad-detection-test.es index 836478ac..4d3f42bc 100644 --- a/modules/web-discovery-project/tests/unit/ad-detection-test.es +++ b/modules/web-discovery-project/tests/unit/ad-detection-test.es @@ -80,7 +80,7 @@ export default describeModule( const newKey = normalizeAclkUrl(url); if (keys[newKey]) { throw new Error( - `Both\n${keys[newKey]}\nand\n${url}\nhave been mapped to the same key:\n${newKey}` + `Both\n${keys[newKey]}\nand\n${url}\nhave been mapped to the same key:\n${newKey}`, ); } keys[newKey] = url; @@ -105,5 +105,5 @@ export default describeModule( expect(keys).to.have.lengthOf(1); }); }); - } + }, ); diff --git a/modules/web-discovery-project/tests/unit/content-extractor-test.es b/modules/web-discovery-project/tests/unit/content-extractor-test.es index 58adef47..43f3be77 100644 --- a/modules/web-discovery-project/tests/unit/content-extractor-test.es +++ b/modules/web-discovery-project/tests/unit/content-extractor-test.es @@ -27,7 +27,7 @@ const FIXTURES_BASE_PATH = function readFixtureFromDisk(_path) { const fixture = jsonParse( - fs.readFileSync(`${FIXTURES_BASE_PATH}/${_path}/scenario.json`, "utf8") + fs.readFileSync(`${FIXTURES_BASE_PATH}/${_path}/scenario.json`, "utf8"), ); fixture.html = zlib .gunzipSync(fs.readFileSync(`${FIXTURES_BASE_PATH}/${_path}/page.html.gz`)) @@ -63,10 +63,10 @@ function findAllFixtures() { */ const DEFAULT_PATTERNS = { normal: jsonParse( - fs.readFileSync(`${FIXTURES_BASE_PATH}/patterns.json`, "utf8") + fs.readFileSync(`${FIXTURES_BASE_PATH}/patterns.json`, "utf8"), ), strict: jsonParse( - fs.readFileSync(`${FIXTURES_BASE_PATH}/patterns-anon.json`, "utf8") + fs.readFileSync(`${FIXTURES_BASE_PATH}/patterns-anon.json`, "utf8"), ), }; @@ -132,12 +132,12 @@ export default describeModule( expect(args.length).to.equal(1); return args[0]; }), - R.groupBy((msg) => msg.action) + R.groupBy((msg) => msg.action), )(sinonSpy.args); } const messages = groupTelemetryCallsByAction( - WebDiscoveryProject.telemetry + WebDiscoveryProject.telemetry, ); // uncomment to export expectations: // fs.writeFileSync('/tmp/failing-test-expected-messages.json', JSON.stringify(messages)); @@ -160,15 +160,15 @@ export default describeModule( if (fixture.mustNotContain) { for (const check of fixture.mustNotContain) { const blacklist = new RegExp( - `^${check.action.replace("*", ".*")}$` + `^${check.action.replace("*", ".*")}$`, ); const matches = Object.keys(messages).filter((x) => - blacklist.test(x) + blacklist.test(x), ); if (matches.length > 0) { throw new Error( `Expected no messages with action '${check.action}' ` + - `but got messages for the following actions: [${matches}]` + `but got messages for the following actions: [${matches}]`, ); } } @@ -260,7 +260,7 @@ export default describeModule( expect(uut.isSearchEngineUrl("https://www.google.de/search?q=test")) .to.be.true; expect( - uut.isSearchEngineUrl("https://www.google.com/search?q=test") + uut.isSearchEngineUrl("https://www.google.com/search?q=test"), ).to.be.true; }); }); @@ -328,35 +328,36 @@ export default describeModule( it("should find search terms on search.brave.software", function () { expect( uut.tryExtractBraveSerpQuery( - "https://search.brave.software/search?lang=en&country=us&safe_search=on&q=harzer%20k%C3%A4se" - ) + "https://search.brave.software/search?lang=en&country=us&safe_search=on&q=harzer%20k%C3%A4se", + ), ).to.equal("harzer käse"); expect( uut.tryExtractBraveSerpQuery( - "https://search.brave.software/search?q=m%C3%BCnchen&lang=en&country=de" - ) + "https://search.brave.software/search?q=m%C3%BCnchen&lang=en&country=de", + ), ).to.equal("münchen"); }); it("should find search terms on search.brave.com", function () { expect( uut.tryExtractBraveSerpQuery( - "https://search.brave.com/search?lang=en&country=us&safe_search=on&q=harzer%20k%C3%A4se" - ) + "https://search.brave.com/search?lang=en&country=us&safe_search=on&q=harzer%20k%C3%A4se", + ), ).to.equal("harzer käse"); expect( uut.tryExtractBraveSerpQuery( - "https://search.brave.com/search?q=m%C3%BCnchen&lang=en&country=de" - ) + "https://search.brave.com/search?q=m%C3%BCnchen&lang=en&country=de", + ), ).to.equal("münchen"); }); it("should not find false positives", function () { - ["https://search.brave.software/", "https://example.test/?q=test"].forEach( - expectNotFound - ); + [ + "https://search.brave.software/", + "https://example.test/?q=test", + ].forEach(expectNotFound); }); it("should ignore broken URLs", function () { @@ -420,10 +421,10 @@ export default describeModule( it("should extract nested fields from JSON", function () { expect(_jsonPath('{ "a": { "nested": true } }', "a.nested")).to.equal( - "true" + "true", ); expect(_jsonPath('{ "a": { "b": { "c": "3" } } }', "a.b.c")).to.equal( - "3" + "3", ); }); @@ -440,13 +441,13 @@ export default describeModule( it("should extract non-trivial objects when enabled", function () { expect(JSON.parse(_jsonPath('{"a":[1,2,3]}', "a", true))).to.deep.equal( - [1, 2, 3] + [1, 2, 3], ); expect(JSON.parse(_jsonPath('{"a":[1,2,3]}', "a", true))).to.deep.equal( - [1, 2, 3] + [1, 2, 3], ); expect(JSON.parse(_jsonPath('{"a":{"b":1}}', "a", true))).to.deep.equal( - { b: 1 } + { b: 1 }, ); }); @@ -467,7 +468,7 @@ export default describeModule( it("should pass regression tests", function () { expect( - _mergeArr({ x: [1, 2, 3], y: [4, 5, 6], z: [7, 8, 9] }) + _mergeArr({ x: [1, 2, 3], y: [4, 5, 6], z: [7, 8, 9] }), ).to.deep.equal([ { x: 1, y: 4, z: 7 }, { x: 2, y: 5, z: 8 }, @@ -577,5 +578,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/web-discovery-project/tests/unit/content-test.es b/modules/web-discovery-project/tests/unit/content-test.es index 7c9d4b6f..ea6770ab 100644 --- a/modules/web-discovery-project/tests/unit/content-test.es +++ b/modules/web-discovery-project/tests/unit/content-test.es @@ -19,7 +19,7 @@ function loadFixture(name) { .gunzipSync(fs.readFileSync(`${FIXTURES_BASE_PATH}/${name}/page.html.gz`)) .toString(); const expectedAds = JSON.parse( - fs.readFileSync(`${FIXTURES_BASE_PATH}/${name}/expected-ads.json`, "utf8") + fs.readFileSync(`${FIXTURES_BASE_PATH}/${name}/expected-ads.json`, "utf8"), ); return { html, expectedAds }; } @@ -59,7 +59,7 @@ export default describeModule( beforeEach(function () { parseDom = this.module().parseDom; - mockWindow = new JSDOM(`

Test DOM

`).window; + mockWindow = new JSDOM(`

Test DOM

`).window; }); afterEach(function () { @@ -125,22 +125,22 @@ export default describeModule( if (unexpectedAds.length > 0) { const examples = R.take( numExamples, - R.sortWith([R.prop("key"), R.prop("url")], unexpectedAds) + R.sortWith([R.prop("key"), R.prop("url")], unexpectedAds), ); examples.forEach((example) => { errorMsg += `\n- This should not have detected: ${JSON.stringify( - example + example, )}`; }); } if (missingAds.length > 0) { const examples = R.take( numExamples, - R.sortWith([R.prop("key"), R.prop("url")], missingAds) + R.sortWith([R.prop("key"), R.prop("url")], missingAds), ); examples.forEach((example) => { errorMsg += `\n- This was overlooked: ${JSON.stringify( - example + example, )}`; }); } @@ -196,7 +196,7 @@ export default describeModule( it("Android user agent: page without ads", function () { checkDetectedAds( - loadFixture("android-user-agent-page-without-ads-2019-07-24") + loadFixture("android-user-agent-page-without-ads-2019-07-24"), ); }); @@ -228,9 +228,9 @@ export default describeModule( // it("(status quo) Android user agent: page with ads", function () { checkDetectedAds( - loadFixture("android-user-agent-page-with-ads-2019-07-24") + loadFixture("android-user-agent-page-with-ads-2019-07-24"), ); }); }); - } + }, ); diff --git a/modules/web-discovery-project/tests/unit/doublefetch-handler-test.es b/modules/web-discovery-project/tests/unit/doublefetch-handler-test.es index 65687da3..09c9a215 100644 --- a/modules/web-discovery-project/tests/unit/doublefetch-handler-test.es +++ b/modules/web-discovery-project/tests/unit/doublefetch-handler-test.es @@ -44,11 +44,11 @@ function resetMocks() { } else if (method === "removePipelineStep") { // here, "arg" is the name of the handler to be removed mocks._handlers[event] = mocks._handlers[event].filter( - (x) => x.name !== arg + (x) => x.name !== arg, ); } else { throw new Error( - `Unexpected communication with request-pipeline: ${method}, ${event}, ${arg}` + `Unexpected communication with request-pipeline: ${method}, ${event}, ${arg}`, ); } }), @@ -77,7 +77,7 @@ function scriptedRequests(scriptRequests, opts = {}) { const mkFakeRequestContext = ( url, requestInfo, - { includeResponse, requestCompleted } + { includeResponse, requestCompleted }, ) => { if (!requestInfo.requestId) { uniqueId += 1; @@ -151,7 +151,7 @@ function scriptedRequests(scriptRequests, opts = {}) { mkFakeRequestContext(otherUrl, scriptRequests[otherUrl], { includeResponse: false, }), - otherResponse + otherResponse, ); const wasCancelled = proceed === false || !!otherResponse.cancel; @@ -160,7 +160,7 @@ function scriptedRequests(scriptRequests, opts = {}) { } else if (scriptRequests[otherUrl].onHeadersSent) { scriptRequests[otherUrl].onHeadersSent( otherResponse.requestHeaders || - scriptRequests[otherUrl].requestHeaders + scriptRequests[otherUrl].requestHeaders, ); } } @@ -177,7 +177,7 @@ function scriptedRequests(scriptRequests, opts = {}) { } if (requestInfo.onHeadersSent) { requestInfo.onHeadersSent( - response.requestHeaders || requestInfo.requestHeaders + response.requestHeaders || requestInfo.requestHeaders, ); } } @@ -205,7 +205,7 @@ function scriptedRequests(scriptRequests, opts = {}) { includeResponse: true, requestCompleted: false, }), - otherResponse + otherResponse, ); const wasAborted = proceed === false || !!otherResponse.cancel; @@ -282,7 +282,7 @@ function scriptedRequests(scriptRequests, opts = {}) { { includeResponse: true, requestCompleted: true, - } + }, ); handler(otherFakeContext, otherResponse); } @@ -443,8 +443,10 @@ export default describeModule( }); it("should reject requests when state is DISABLED", function () { - expect(uut._state, "initial state should be DISABLED").to.equal(State.DISABLED); - uut.init = () => { }; // noop for the sake of this test + expect(uut._state, "initial state should be DISABLED").to.equal( + State.DISABLED, + ); + uut.init = () => {}; // noop for the sake of this test let sent = false; scriptedRequests({ @@ -638,7 +640,7 @@ export default describeModule( "https://api.brave.test/foo", "https://api.brave.test/bar", ], - } + }, ); uut.maxDoubleFetchSize = 10; @@ -685,7 +687,7 @@ export default describeModule( "https://api.brave.test/foo", "https://api.brave.test/bar", ], - } + }, ); uut.maxDoubleFetchSize = 10; @@ -921,7 +923,7 @@ export default describeModule( ], runOnCompletedHandlersAfterTheRequestIsResolved: runHandlerAfterRequest, - } + }, ); return uut @@ -943,5 +945,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/web-discovery-project/tests/unit/fallback-dns-test.es b/modules/web-discovery-project/tests/unit/fallback-dns-test.es index a4a8db9b..986270e7 100644 --- a/modules/web-discovery-project/tests/unit/fallback-dns-test.es +++ b/modules/web-discovery-project/tests/unit/fallback-dns-test.es @@ -42,10 +42,10 @@ export default describeModule( uut.cacheDnsResolution("example2.test", "127.0.0.2"); return Promise.all([ expect(uut.resolveHost("example1.test")).to.eventually.equal( - "127.0.0.1" + "127.0.0.1", ), expect(uut.resolveHost("example2.test")).to.eventually.equal( - "127.0.0.2" + "127.0.0.2", ), ]); }); @@ -66,5 +66,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/web-discovery-project/tests/unit/network-test.es b/modules/web-discovery-project/tests/unit/network-test.es index 32ee2c05..4d8b9d27 100644 --- a/modules/web-discovery-project/tests/unit/network-test.es +++ b/modules/web-discovery-project/tests/unit/network-test.es @@ -119,7 +119,7 @@ export default describeModule( it("should parse an URL with params", function () { expect( - parseURL("http://www.example.test/abc/def?param1=1¶m2=2") + parseURL("http://www.example.test/abc/def?param1=1¶m2=2"), ).to.eql({ protocol: "http", hostname: "www.example.test", @@ -209,10 +209,10 @@ export default describeModule( setupDns({ publicDomains: ["public.test"] }); await expect( - uut.isHostNamePrivate("https://public.test/") + uut.isHostNamePrivate("https://public.test/"), ).to.eventually.equal(false); await expect( - uut.isHostNamePrivate("https://public.test/some?dummy=param") + uut.isHostNamePrivate("https://public.test/some?dummy=param"), ).to.eventually.equal(false); }); @@ -220,10 +220,10 @@ export default describeModule( setupDns({ privateDomains: ["private.test"] }); await expect( - uut.isHostNamePrivate("https://private.test/") + uut.isHostNamePrivate("https://private.test/"), ).to.eventually.equal(true); await expect( - uut.isHostNamePrivate("https://private.test/some?dummy=param") + uut.isHostNamePrivate("https://private.test/some?dummy=param"), ).to.eventually.equal(true); }); @@ -255,7 +255,7 @@ export default describeModule( const msg = mkPageMessage(params); await expect( - uut.sanitizeUrlsWithPrivateDomains(msg) + uut.sanitizeUrlsWithPrivateDomains(msg), ).to.eventually.equal(null); }); @@ -316,5 +316,5 @@ export default describeModule( .and.deep.equal(expectedMessage); }); }); - } + }, ); diff --git a/modules/web-discovery-project/tests/unit/remote-resource-watcher-test.es b/modules/web-discovery-project/tests/unit/remote-resource-watcher-test.es index 338c6ad4..ecb354b5 100644 --- a/modules/web-discovery-project/tests/unit/remote-resource-watcher-test.es +++ b/modules/web-discovery-project/tests/unit/remote-resource-watcher-test.es @@ -113,7 +113,7 @@ const MOCKS = { let latency = minLatencyInMs; if (maxLatencyInMs > minLatencyInMs) { latency += Math.round( - Math.random() * (maxLatencyInMs - minLatencyInMs) + Math.random() * (maxLatencyInMs - minLatencyInMs), ); } const timeout = setTimeout(() => { @@ -160,7 +160,7 @@ class StorageStub { async load() { if (!this.isDefined) { throw new Error( - "all initial loads before the first write are expected to fail" + "all initial loads before the first write are expected to fail", ); } return this.content; @@ -202,8 +202,8 @@ function expectNoBursts(events, maxEvents, interval) { interval / 1000 } seconds ` + `but got ${eventsInInterval} (or more) during ${new Date( - events[start] - )} and ${new Date(events[end])})` + events[start], + )} and ${new Date(events[end])})`, ); } } @@ -401,7 +401,7 @@ export default describeModule( } reject(new Error("State was not properly persisted")); }; - } + }, ); await uut.init(); @@ -466,7 +466,7 @@ export default describeModule( uut = new RemoteResourceWatcher(options); await MOCKS.storage.save( - new Uint8Array(Buffer.from(CONTENT_FROM_DISK)) + new Uint8Array(Buffer.from(CONTENT_FROM_DISK)), ); const pendingInit = uut.init(); @@ -656,8 +656,8 @@ export default describeModule( if (tooOld()) { updateCalls.push( `too-old (last: ${new Date( - lastTimestamp - )}, now: ${new Date()})` + lastTimestamp, + )}, now: ${new Date()})`, ); done = true; } @@ -669,7 +669,7 @@ export default describeModule( const update = await updateCalls.get(); if (update.startsWith("too-old")) { chai.assert.fail( - `threshold exceeded: failed to see new updates fast enough: ${update}` + `threshold exceeded: failed to see new updates fast enough: ${update}`, ); } @@ -806,5 +806,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/web-discovery-project/tests/unit/signature-verifier-test.es b/modules/web-discovery-project/tests/unit/signature-verifier-test.es index d0e3f1ee..4dbb0b7f 100644 --- a/modules/web-discovery-project/tests/unit/signature-verifier-test.es +++ b/modules/web-discovery-project/tests/unit/signature-verifier-test.es @@ -25,10 +25,10 @@ AwIDAQAB const CRYPTO_MOCK = { message: new Uint8Array(Buffer.from("some test message")), goodSignature: Buffer.from("this signature will be accepted").toString( - "base64" + "base64", ), badSignature: Buffer.from("this signature will be rejected").toString( - "base64" + "base64", ), key: { @@ -127,7 +127,7 @@ export default describeModule( // it has to follow the same convention as the server expect(uut.resourceUrl).to.equal(resourceUrl); expect(uut.signatureUrl).to.equal( - "https://domain.test/patterns.gz-signed-with-2019-10-17-test-key.pub" + "https://domain.test/patterns.gz-signed-with-2019-10-17-test-key.pub", ); }); @@ -136,7 +136,7 @@ export default describeModule( const isValid = await uut.checkSignature( CRYPTO_MOCK.message, - CRYPTO_MOCK.goodSignature + CRYPTO_MOCK.goodSignature, ); expect(isValid).to.equal(true, "Expected signature to be good"); @@ -147,7 +147,7 @@ export default describeModule( const isValid = await uut.checkSignature( CRYPTO_MOCK.message, - CRYPTO_MOCK.badSignature + CRYPTO_MOCK.badSignature, ); expect(isValid).to.equal(false, "Expected signature to be rejected"); @@ -158,21 +158,21 @@ export default describeModule( { const isValid = await uut.checkSignature( CRYPTO_MOCK.message, - CRYPTO_MOCK.badSignature + CRYPTO_MOCK.badSignature, ); expect(isValid).to.equal( true, - "Expected verification error to be ignored" + "Expected verification error to be ignored", ); } { const isValid = await uut.checkSignature( CRYPTO_MOCK.message, - CRYPTO_MOCK.goodSignature + CRYPTO_MOCK.goodSignature, ); expect(isValid).to.equal( true, - "Good signatures should always be accepted" + "Good signatures should always be accepted", ); } }); @@ -207,9 +207,9 @@ export default describeModule( expect(() => parsePublicKeyPem("")).to.throw(); expect(() => parsePublicKeyPem("dummy text")).to.throw(); expect(() => - parsePublicKeyPem("-----BEGIN PUBLIC KEY-----") + parsePublicKeyPem("-----BEGIN PUBLIC KEY-----"), ).to.throw(); }); }); - } + }, ); diff --git a/modules/web-discovery-project/tests/unit/web-discovery-project-test.es b/modules/web-discovery-project/tests/unit/web-discovery-project-test.es index f4b02b30..592133b4 100644 --- a/modules/web-discovery-project/tests/unit/web-discovery-project-test.es +++ b/modules/web-discovery-project/tests/unit/web-discovery-project-test.es @@ -201,7 +201,7 @@ export default describeModule( redirects = WebDiscoveryProject.getRedirects( "https://d.test/", redirects, - maxLength + maxLength, ); expect(redirects).to.deep.equals([ "https://a.test/", @@ -234,7 +234,7 @@ export default describeModule( redirects = WebDiscoveryProject.getRedirects( "https://d.test/", redirects, - maxLength + maxLength, ); expect(redirects).to.deep.equals(["https://c.test/"]); }); @@ -255,7 +255,7 @@ export default describeModule( let redirects = []; redirects = WebDiscoveryProject.getRedirects( "https://example.test/redirected", - redirects + redirects, ); expect(redirects).to.deep.equals(["https://example.test/"]); }); @@ -276,7 +276,7 @@ export default describeModule( let redirects = []; redirects = WebDiscoveryProject.getRedirects( "https://example.test/", - redirects + redirects, ); expect(redirects).to.deep.equals([]); }); @@ -304,7 +304,7 @@ export default describeModule( let redirects = []; redirects = WebDiscoveryProject.getRedirects( "https://example.test/redirected", - redirects + redirects, ); expect(redirects).to.deep.equals(["https://example.test/"]); }); @@ -330,7 +330,7 @@ export default describeModule( redirects1 = WebDiscoveryProject.getRedirects( "https://foo.test/", redirects1, - maxLength + maxLength, ); expect(redirects1).to.deep.equals([ "https://foo.test/", @@ -341,7 +341,7 @@ export default describeModule( redirects2 = WebDiscoveryProject.getRedirects( "https://bar.test/", redirects2, - maxLength + maxLength, ); expect(redirects2).to.deep.equals([ "https://bar.test/", @@ -368,7 +368,7 @@ export default describeModule( it("overwrites suspicious query", function () { data.q = "wdp@brave.com"; return sanitizeResultTelemetry(data).then(({ query }) => - chai.expect(query).to.equal("(PROTECTED)") + chai.expect(query).to.equal("(PROTECTED)"), ); }); @@ -376,7 +376,7 @@ export default describeModule( it("overwrites dangerous query", function () { data.q = "http://www.abc.de?0123456789"; return sanitizeResultTelemetry(data).then(({ query }) => - chai.expect(query).to.equal("(PROTECTED)") + chai.expect(query).to.equal("(PROTECTED)"), ); }); @@ -386,7 +386,7 @@ export default describeModule( it("overwrites suspicious URL", function () { data.msg.u = "http://www.abc.de?0123456789"; return sanitizeResultTelemetry(data).then(({ url }) => - chai.expect(url).to.equal("(PROTECTED)") + chai.expect(url).to.equal("(PROTECTED)"), ); }); @@ -394,7 +394,7 @@ export default describeModule( it("overwrites dangerous URL", function () { data.msg.u = "wdp@brave.com"; return sanitizeResultTelemetry(data).then(({ url }) => - chai.expect(url).to.equal("(PROTECTED)") + chai.expect(url).to.equal("(PROTECTED)"), ); }); @@ -405,7 +405,7 @@ export default describeModule( chai.expect({ query, url }).to.eql({ query: "brave", url: "https://www.brave.com", - }) + }), ); }); @@ -415,11 +415,11 @@ export default describeModule( .be.true; expect( WebDiscoveryProject.checkForEmail( - "text with email@dummy.test address" - ) + "text with email@dummy.test address", + ), ).to.be.true; expect( - WebDiscoveryProject.checkForEmail("AnotherEmail@domain123.test") + WebDiscoveryProject.checkForEmail("AnotherEmail@domain123.test"), ).to.be.true; // counter examples: @@ -427,8 +427,8 @@ export default describeModule( expect(WebDiscoveryProject.checkForEmail("123456")).to.be.false; expect( WebDiscoveryProject.checkForEmail( - "some text without an email address" - ) + "some text without an email address", + ), ).to.be.false; }); }); @@ -475,14 +475,14 @@ export default describeModule( assumeFailsUrlChecks = (url) => { if (!failsDropLongURL(url)) { expect.fail( - `Assumption in the tests are outdated: It assumes ${url} is sensitive` + `Assumption in the tests are outdated: It assumes ${url} is sensitive`, ); } }; assumePassesUrlChecks = (url) => { if (failsDropLongURL(url)) { expect.fail( - `Assumption in the tests are outdated: It assumes ${url} is non-sensitive` + `Assumption in the tests are outdated: It assumes ${url} is non-sensitive`, ); } }; @@ -579,5 +579,5 @@ export default describeModule( }); }); }); - } + }, ); diff --git a/modules/webextension-specific/sources/background.es b/modules/webextension-specific/sources/background.es index f16c12c8..174fe03c 100644 --- a/modules/webextension-specific/sources/background.es +++ b/modules/webextension-specific/sources/background.es @@ -25,7 +25,7 @@ export default background({ this.onTabSelect = ({ tabId }) => { chrome.tabs.get(tabId, (tabInfo) => - events.pub("core:tab_select", { ...tabInfo, tabId }) + events.pub("core:tab_select", { ...tabInfo, tabId }), ); }; this.onTabClose = (tabId, removeInfo) => diff --git a/modules/webrequest-pipeline/sources/background.es b/modules/webrequest-pipeline/sources/background.es index be605105..54b3106c 100644 --- a/modules/webrequest-pipeline/sources/background.es +++ b/modules/webrequest-pipeline/sources/background.es @@ -17,7 +17,7 @@ import logger from "./logger"; function modifyHeaderByType(headers, name, value) { const lowerCaseName = name.toLowerCase(); const filteredHeaders = headers.filter( - (h) => h.name.toLowerCase() !== lowerCaseName + (h) => h.name.toLowerCase() !== lowerCaseName, ); if (!isWebExtension || value) { filteredHeaders.push({ name, value }); @@ -55,7 +55,7 @@ class BlockingResponse { this.requestHeaders = modifyHeaderByType( this.requestHeaders || this.details.requestHeaders || [], name, - value + value, ); } @@ -63,7 +63,7 @@ class BlockingResponse { this.responseHeaders = modifyHeaderByType( this.responseHeaders || this.details.responseHeaders || [], name, - value + value, ); } @@ -149,7 +149,7 @@ export default background({ const webRequestContext = WebRequestContext.fromDetails( details, this.pageStore, - event + event, ); // Request is not supported, so do not alter @@ -205,7 +205,7 @@ export default background({ if (pipeline === null) { logger.error( "WebRequest pipeline (remove) does not have stage", - stage + stage, ); } else { pipeline.removePipelineStep(name); diff --git a/modules/webrequest-pipeline/sources/pipeline.es b/modules/webrequest-pipeline/sources/pipeline.es index 3061f4f2..bea20d8f 100644 --- a/modules/webrequest-pipeline/sources/pipeline.es +++ b/modules/webrequest-pipeline/sources/pipeline.es @@ -68,7 +68,7 @@ export default class Pipeline { if (name === undefined) { throw new Error( - `Every step of the pipeline should be given a name in ${this.name}` + `Every step of the pipeline should be given a name in ${this.name}`, ); } @@ -83,19 +83,19 @@ export default class Pipeline { spec !== "break" ) { throw new Error( - `Every step of the pipeline should be given a valid spec (got ${spec}): ${this.name}.${name}` + `Every step of the pipeline should be given a valid spec (got ${spec}): ${this.name}.${name}`, ); } if (fn === undefined) { throw new Error( - `Every step of the pipeline should have a function ('fn' argument): ${this.name}.${name}` + `Every step of the pipeline should have a function ('fn' argument): ${this.name}.${name}`, ); } if (spec === "break" && !this.isBreakable) { throw new Error( - `Cannot add a break step '${name}' to an unbreakable pipeline` + `Cannot add a break step '${name}' to an unbreakable pipeline`, ); } @@ -120,8 +120,8 @@ export default class Pipeline { if (insertAt === -1) { throw new Error( `no step from 'after' list found, after=${JSON.stringify( - after - )}, pipeline=${this.name}` + after, + )}, pipeline=${this.name}`, ); } else if (insertAt === this.pipeline.length) { this.pipeline.push(step); @@ -225,7 +225,7 @@ export default class Pipeline { this.name, webRequestContext.url, "ignoring attempted break of unbreakable pipeline at", - name + name, ); } } diff --git a/modules/webrequest-pipeline/sources/webrequest-context.es b/modules/webrequest-pipeline/sources/webrequest-context.es index 0265d9d9..c4c58858 100644 --- a/modules/webrequest-pipeline/sources/webrequest-context.es +++ b/modules/webrequest-pipeline/sources/webrequest-context.es @@ -111,7 +111,7 @@ export default class WebRequestContext { getResponseHeader(name) { if (this._responseHeadersMap === null) { this._responseHeadersMap = createHeadersGetter( - this.responseHeaders || [] + this.responseHeaders || [], ); } diff --git a/modules/webrequest-pipeline/tests/integration/webrequest-pipeline-test.es b/modules/webrequest-pipeline/tests/integration/webrequest-pipeline-test.es index a12fac87..a45aa7f6 100644 --- a/modules/webrequest-pipeline/tests/integration/webrequest-pipeline-test.es +++ b/modules/webrequest-pipeline/tests/integration/webrequest-pipeline-test.es @@ -32,15 +32,15 @@ export default () => { `expect ${tabId} in ${JSON.stringify( [...pipeline.pageStore.tabs.entries()], null, - 2 - )}` + 2, + )}`, ).to.eql(true), - 2000 + 2000, ); await updateTab(tabId, { url }); await waitFor( async () => expect((await getTab(tabId)).url).to.not.eql("about:blank"), - 2000 + 2000, ); return tabId; }; @@ -67,7 +67,7 @@ export default () => { }); afterEach(() => - pipeline.actions.removePipelineStep("onBeforeRequest", "test") + pipeline.actions.removePipelineStep("onBeforeRequest", "test"), ); describe("details", () => { @@ -160,7 +160,7 @@ export default () => { }), testServer.registerPathHandler(getSuffix("js"), { result: ``, }), testServer.registerPathHandler(getSuffix("302"), { @@ -283,7 +283,7 @@ export default () => { testServer.registerPathHandler(getSuffix("landing"), { result: ``, }), @@ -296,9 +296,9 @@ export default () => { () => expect( details.filter((r) => r.url.endsWith("ready")), - `endsWithReady ${JSON.stringify(details, null, 2)}` + `endsWithReady ${JSON.stringify(details, null, 2)}`, ).to.have.length(1), - 2000 + 2000, ); // switch to the test page and wait for the first beacon to trigger updateTab(tabId, { url: getUrl() }); @@ -306,9 +306,9 @@ export default () => { () => expect( details.filter(filterBeacons).length, - `beacons ${JSON.stringify(details, null, 2)}` + `beacons ${JSON.stringify(details, null, 2)}`, ).to.be.at.least(1), - 2000 + 2000, ); // go back to the other page and wait for the beacons on page unload updateTab(tabId, { url: getUrl("landing") }); @@ -316,9 +316,9 @@ export default () => { () => expect( details.filter(filterBeacons).length, - `beacons ${JSON.stringify(details, null, 2)}` + `beacons ${JSON.stringify(details, null, 2)}`, ).to.be.at.least(3), - 10000 + 10000, ); const beacons = details.filter(filterBeacons); @@ -339,7 +339,7 @@ export default () => { await Promise.all([ testServer.registerPathHandler(getSuffix(), { result: ``, }), testServer.registerPathHandler(getSuffix("frame"), { @@ -349,8 +349,8 @@ export default () => { navigator.sendBeacon('${getSuffix("beacon")}', 'bar'); var client = new XMLHttpRequest(); client.open('GET', '${getSuffix("beacon")}', ${ - isChromium ? "true" : "false" - }); + isChromium ? "true" : "false" + }); client.send(null); }, false); `, @@ -364,7 +364,7 @@ export default () => { testServer.registerPathHandler(getSuffix("landing"), { result: ``, }), @@ -377,9 +377,9 @@ export default () => { () => expect( details.filter((r) => r.url.endsWith("ready")), - `endsWithReady ${JSON.stringify(details, null, 2)}` + `endsWithReady ${JSON.stringify(details, null, 2)}`, ).to.have.length(1), - 2000 + 2000, ); // switch to the test page and wait for the first beacon to trigger updateTab(tabId, { url: getUrl() }); @@ -387,9 +387,9 @@ export default () => { () => expect( details.filter(filterBeacons), - `beacons ${JSON.stringify(details, null, 2)}` + `beacons ${JSON.stringify(details, null, 2)}`, ).to.not.be.empty, - 2000 + 2000, ); // go to a new page on a different origin and wait for the beacons on page unload updateTab(tabId, { url: "http://example.com" }); @@ -397,9 +397,9 @@ export default () => { () => expect( details.filter(filterBeacons).length, - `beacons ${JSON.stringify(details, null, 2)}` + `beacons ${JSON.stringify(details, null, 2)}`, ).to.be.at.least(3), - 10000 + 10000, ); const beacons = details.filter(filterBeacons); expect(beacons).to.have.length(3); @@ -426,7 +426,7 @@ export default () => { `, - } + }, ), testServer.registerPathHandler(getSuffix(`${testScope}/index.js`), { result: ` @@ -461,15 +461,15 @@ export default () => { addPipeline(collectRequestDetails); // setup: load landing page to trigger SW-install and wait for it to be loaded const tabId = await newTab( - getUrl(`${testScope}/service-worker-test.html`) + getUrl(`${testScope}/service-worker-test.html`), ); await waitFor( () => expect( details.filter((d) => d.url.indexOf("sw.js") !== -1), - `sw.js ${JSON.stringify(details, null, 2)}` + `sw.js ${JSON.stringify(details, null, 2)}`, ).to.not.be.empty, - 10000 + 10000, ); await new Promise((resolve) => setTimeout(resolve, 2000)); details = []; @@ -482,14 +482,14 @@ export default () => { () => expect( details.filter(filterPings).length, - `pings ${JSON.stringify(details, null, 2)}` + `pings ${JSON.stringify(details, null, 2)}`, ).to.be.at.least(1), - 10000 + 10000, ); details.filter(filterPings).forEach((r) => { expect(r.tabUrl).to.equal( getUrl(`${testScope}/service-worker-from-cache.html`), - "tabUrl should match SW-served document" + "tabUrl should match SW-served document", ); }); }); diff --git a/modules/webrequest-pipeline/tests/unit/pipeline-test.es b/modules/webrequest-pipeline/tests/unit/pipeline-test.es index df294ed7..84215e9f 100644 --- a/modules/webrequest-pipeline/tests/unit/pipeline-test.es +++ b/modules/webrequest-pipeline/tests/unit/pipeline-test.es @@ -79,7 +79,7 @@ export default describeModule( name: "part1", spec: "blocking", fn: () => false, - }) + }), ) .to.throw(Error); }); @@ -154,7 +154,7 @@ export default describeModule( spec: "blocking", fn: () => true, after: ["part3"], - }) + }), ) .to.throw(Error); }); @@ -181,7 +181,7 @@ export default describeModule( fn: () => true, after: ["part1"], before: ["part3"], - }) + }), ) .to.throw(Error); }); @@ -276,5 +276,5 @@ export default describeModule( chai.expect(response.fn2).to.eql(-4); }); }); - } + }, ); diff --git a/platforms/webextension/web-discovery-project/doublefetch.es b/platforms/webextension/web-discovery-project/doublefetch.es index 2da56bbf..d2804f8f 100644 --- a/platforms/webextension/web-discovery-project/doublefetch.es +++ b/platforms/webextension/web-discovery-project/doublefetch.es @@ -9,7 +9,7 @@ import { fetch, AbortController, Headers } from "../fetch"; // There needs to proper implementation, to avoid cases like: // 1. Downloading streams. // 2. Origin in web-extension. -export function getRequest(url, headers) { +export function getRequest(url, headers, extra) { // eslint-disable-next-line no-async-promise-executor return new Promise(async (resolve, reject) => { let timeout; @@ -26,6 +26,7 @@ export function getRequest(url, headers) { cache: "no-cache", signal: abortController.signal, headers: new Headers(headers || {}), + ...(extra || {}), }); if (response.status !== 200 && response.status !== 0 /* local files */) { @@ -37,12 +38,9 @@ export function getRequest(url, headers) { !urlEquals(response.url, url) && !urlEquals( decodeURI(decodeURI(response.url)), - decodeURI(decodeURI(url)) + decodeURI(decodeURI(url)), ) && - !urlEquals( - url.replace(parse(url).hash, ""), - response.url - ) + !urlEquals(url.replace(parse(url).hash, ""), response.url) ) { // there has been a redirect, we cannot guarantee that cookies were // not sent, therefore fail and consider as private diff --git a/update-brave.sh b/update-brave.sh index 3b49720b..72cf17a9 100755 --- a/update-brave.sh +++ b/update-brave.sh @@ -3,4 +3,6 @@ rm -fr brave mkdir brave cd brave && wget 'https://github.com/brave/brave-browser/releases/download/v1.60.114/brave-browser-1.60.114-linux-amd64.zip' -O brave.zip && unzip brave.zip && rm brave.zip +sudo chown root:root ./brave/chrome-sandbox +sudo chmod 4755 ./brave/chrome-sandbox export BRAVE_PATH="./brave/brave"