From 7b4d93dfc1ab69188e84bc290a958e8c5447593c Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 12 Jul 2023 04:00:18 -0600 Subject: [PATCH 01/63] feat(mv3): :sparkles: Patching countly-sdk-web Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- patches/countly-sdk-web+23.2.2.patch | 468 +++++++++++++++++++++++++++ 1 file changed, 468 insertions(+) create mode 100644 patches/countly-sdk-web+23.2.2.patch diff --git a/patches/countly-sdk-web+23.2.2.patch b/patches/countly-sdk-web+23.2.2.patch new file mode 100644 index 000000000..f3be4e813 --- /dev/null +++ b/patches/countly-sdk-web+23.2.2.patch @@ -0,0 +1,468 @@ +diff --git a/node_modules/countly-sdk-web/lib/countly.js b/node_modules/countly-sdk-web/lib/countly.js +index da26eb6..2a5e1c0 100644 +--- a/node_modules/countly-sdk-web/lib/countly.js ++++ b/node_modules/countly-sdk-web/lib/countly.js +@@ -52,10 +52,26 @@ + else { + root.Countly = factory(root.Countly); + } +-}(typeof window !== "undefined" ? window : this, function(Countly) { ++}(typeof globalThis !== "undefined" ? globalThis : this, function (Countly) { ++ const stubbedDocumentImpl = new Proxy({}, { ++ get: (target, prop) => { ++ const domPropsFunctions = new Set([ ++ "setAttribute", ++ ]); ++ console.debug("stubbedDocumentImpl.get", prop, target, domPropsFunctions, domPropsFunctions.has(prop)); ++ if (domPropsFunctions.has(prop)) { ++ return (...args) => { ++ console.debug("stubbedDocumentImpl.get function", prop, target, args) ++ return stubbedDocumentImpl; ++ } ++ } ++ return stubbedDocumentImpl; ++ } ++ }); ++ document = stubbedDocumentImpl; + // Make sure the code is being run in a browser + // eslint-disable-next-line no-undef +- if (typeof (window) === "undefined") { ++ if (typeof (globalThis) === "undefined") { + // TODO: check if logging can be added here, like: + // console.error("Not running in browser"); + return; +@@ -347,12 +363,12 @@ + + checkIgnore(); + +- if (window.name && window.name.indexOf("cly:") === 0) { ++ if (globalThis.name && globalThis.name.indexOf("cly:") === 0) { + try { +- this.passed_data = JSON.parse(window.name.replace("cly:", "")); ++ this.passed_data = JSON.parse(globalThis.name.replace("cly:", "")); + } + catch (ex) { +- log(logLevelEnums.ERROR, "initialize, Could not parse name: " + window.name + ", error: " + ex); ++ log(logLevelEnums.ERROR, "initialize, Could not parse name: " + globalThis.name + ", error: " + ex); + } + } + else if (location.hash && location.hash.indexOf("#cly:") === 0) { +@@ -1028,7 +1044,7 @@ + if (this.enableOrientationTracking) { + // report orientation + this.report_orientation(); +- add_event(window, "resize", function() { ++ add_event(globalThis, "resize", function() { + self.report_orientation(); + }); + } +@@ -1618,11 +1634,11 @@ + log(logLevelEnums.INFO, "track_errors, Started tracking errors"); + // Indicated that for this instance of the countly error tracking is enabled + Countly.i[this.app_key].tracking_crashes = true; +- if (!window.cly_crashes) { +- window.cly_crashes = true; ++ if (!globalThis.cly_crashes) { ++ globalThis.cly_crashes = true; + crashSegments = segments; + // override global 'uncaught error' handler +- window.onerror = function errorBundler(msg, url, line, col, err) { ++ globalThis.onerror = function errorBundler(msg, url, line, col, err) { + // old browsers like IE 10 and Safari 9 won't give this value 'err' to us, but if it is provided we can trigger error recording immediately + if (err !== undefined && err !== null) { + // false indicates fatal error (as in non_fatal:false) +@@ -1630,7 +1646,7 @@ + } + // fallback if no error object is present for older browsers, we create it instead + else { +- col = col || (window.event && window.event.errorCharacter); ++ col = col || (globalThis.event && globalThis.event.errorCharacter); + var error = ""; + if (typeof msg !== "undefined") { + error += msg + "\n"; +@@ -1666,7 +1682,7 @@ + }; + + // error handling for 'uncaught rejections' +- window.addEventListener("unhandledrejection", function(event) { ++ globalThis.addEventListener("unhandledrejection", function(event) { + // true indicates non fatal error (as in non_fatal: true) + dispatchErrors(new Error("Unhandled rejection (reason: " + (event.reason && event.reason.stack ? event.reason.stack : event.reason) + ")."), true); + }); +@@ -1909,13 +1925,13 @@ + this.begin_session(); + this.start_time(); + // end session on unload +- add_event(window, "beforeunload", function() { ++ add_event(globalThis, "beforeunload", function() { + // empty the event queue + sendEventsForced(); + self.end_session(); + }); + +- // manage sessions on window visibility events ++ // manage sessions on globalThis visibility events + var hidden = "hidden"; + + /** +@@ -1931,17 +1947,17 @@ + } + + // add focus handling eventListeners +- add_event(window, "focus", onchange); +- add_event(window, "blur", onchange); ++ add_event(globalThis, "focus", onchange); ++ add_event(globalThis, "blur", onchange); + + // newer mobile compatible way +- add_event(window, "pageshow", onchange); +- add_event(window, "pagehide", onchange); ++ add_event(globalThis, "pageshow", onchange); ++ add_event(globalThis, "pagehide", onchange); + + // IE 9 and lower: + if ("onfocusin" in document) { +- add_event(window, "focusin", onchange); +- add_event(window, "focusout", onchange); ++ add_event(globalThis, "focusin", onchange); ++ add_event(globalThis, "focusout", onchange); + } + + // Page Visibility API for changing tabs and minimizing browser +@@ -1971,10 +1987,10 @@ + inactivityCounter = 0; + } + +- add_event(window, "mousemove", resetInactivity); +- add_event(window, "click", resetInactivity); +- add_event(window, "keydown", resetInactivity); +- add_event(window, "scroll", resetInactivity); ++ add_event(globalThis, "mousemove", resetInactivity); ++ add_event(globalThis, "click", resetInactivity); ++ add_event(globalThis, "keydown", resetInactivity); ++ add_event(globalThis, "scroll", resetInactivity); + + // track user inactivity + setInterval(function() { +@@ -2048,7 +2064,7 @@ + // truncate new segment + segments = truncateObject(segments, self.maxKeyLength, self.maxValueSize, self.maxSegmentationValues, "track_pageview", log); + if (this.track_domains) { +- segments.domain = window.location.hostname; ++ segments.domain = globalThis.location.hostname; + } + + if (useSessionCookie) { +@@ -2071,7 +2087,7 @@ + else if (typeof document.referrer !== "undefined" && document.referrer.length) { + var matches = urlParseRE.exec(document.referrer); + // do not report referrers of current website +- if (matches && matches[11] && matches[11] !== window.location.hostname) { ++ if (matches && matches[11] && matches[11] !== globalThis.location.hostname) { + segments.start = 1; + } + } +@@ -2147,7 +2163,7 @@ + // truncate new segment + segments = truncateObject(segments, self.maxKeyLength, self.maxValueSize, self.maxSegmentationValues, "processClick", log); + if (self.track_domains) { +- segments.domain = window.location.hostname; ++ segments.domain = globalThis.location.hostname; + } + add_cly_events({ + key: internalEventKeyEnums.ACTION, +@@ -2173,7 +2189,7 @@ + if (parent) { + log(logLevelEnums.INFO, "track_scrolls, Tracking the specified children"); + } +- parent = parent || window; ++ parent = parent || globalThis; + isScrollRegistryOpen = true; + trackingScrolls = true; + +@@ -2813,8 +2829,8 @@ + else { + var pages = widgets[i].target_pages; + for (var k = 0; k < pages.length; k++) { +- var isWildcardMatched = pages[k].substr(0, pages[k].length - 1) === window.location.pathname.substr(0, pages[k].length - 1); +- var isFullPathMatched = pages[k] === window.location.pathname; ++ var isWildcardMatched = pages[k].substr(0, pages[k].length - 1) === globalThis.location.pathname.substr(0, pages[k].length - 1); ++ var isFullPathMatched = pages[k] === globalThis.location.pathname; + var isContainAsterisk = pages[k].includes("*"); + if (((isContainAsterisk && isWildcardMatched) || isFullPathMatched) && !widgets[i].hide_sticker) { + processWidget(widgets[i], true); +@@ -3048,7 +3064,7 @@ + return; + } + +- var passedOrigin = window.origin || window.location.origin; ++ var passedOrigin = globalThis.origin || globalThis.location.origin; + var feedbackWidgetFamily; + + // set feedback widget family as ratings and load related style file when type is ratings +@@ -3170,7 +3186,7 @@ + wrapper.appendChild(iframe); + log(logLevelEnums.DEBUG, "present_feedback_widget, Appended the iframe"); + +- add_event(window, "message", function(e) { ++ add_event(globalThis, "message", function(e) { + var data = {}; + try { + data = JSON.parse(e.data); +@@ -3249,9 +3265,9 @@ + break; + + case "onScrollHalfwayDown": +- add_event(window, "scroll", function() { ++ add_event(globalThis, "scroll", function() { + if (!surveyShown) { +- var scrollY = Math.max(window.scrollY, document.body.scrollTop, document.documentElement.scrollTop); ++ var scrollY = Math.max(globalThis.scrollY, document.body.scrollTop, document.documentElement.scrollTop); + var documentHeight = getDocHeight(); + if (scrollY >= (documentHeight / 2)) { + surveyShown = true; +@@ -3841,13 +3857,13 @@ + var height = (screen.height) ? parseInt(screen.height) : 0; + if (width !== 0 && height !== 0) { + var iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform); +- if (iOS && window.devicePixelRatio) { ++ if (iOS && globalThis.devicePixelRatio) { + // ios provides dips, need to multiply +- width = Math.round(width * window.devicePixelRatio); +- height = Math.round(height * window.devicePixelRatio); ++ width = Math.round(width * globalThis.devicePixelRatio); ++ height = Math.round(height * globalThis.devicePixelRatio); + } + else { +- if (Math.abs(window.orientation) === 90) { ++ if (Math.abs(globalThis.orientation) === 90) { + // we have landscape orientation + // switch values for all except ios + var temp = width; +@@ -3860,8 +3876,8 @@ + } + + // getting density ratio +- if (window.devicePixelRatio) { +- metrics._density = metrics._density || window.devicePixelRatio; ++ if (globalThis.devicePixelRatio) { ++ metrics._density = metrics._density || globalThis.devicePixelRatio; + } + + // getting locale +@@ -3873,7 +3889,7 @@ + if (typeof document.referrer !== "undefined" && document.referrer.length) { + var matches = urlParseRE.exec(document.referrer); + // do not report referrers of current website +- if (matches && matches[11] && matches[11] !== window.location.hostname) { ++ if (matches && matches[11] && matches[11] !== globalThis.location.hostname) { + var ignoring = false; + if (ignoreReferrers && ignoreReferrers.length) { + for (var k = 0; k < ignoreReferrers.length; k++) { +@@ -3963,72 +3979,62 @@ + */ + function sendXmlHttpRequest(functionName, url, params, callback, useBroadResponseValidator) { + useBroadResponseValidator = useBroadResponseValidator || false; +- try { +- log(logLevelEnums.DEBUG, "Sending XML HTTP request"); +- var xhr = null; +- if (window.XMLHttpRequest) { +- xhr = new window.XMLHttpRequest(); +- } +- else if (window.ActiveXObject) { +- xhr = new window.ActiveXObject("Microsoft.XMLHTTP"); ++ log(logLevelEnums.DEBUG, "Sending XML HTTP request"); ++ params = params || {}; ++ var data = prepareParams(params); ++ var method = "GET"; ++ if (self.force_post || data.length >= 2000) { ++ method = "POST"; ++ } ++ const fetchUrl = method === "GET" ? url + "?" + data : url; ++ const fetchReq = fetch(fetchUrl, { ++ method: method, ++ headers: { ++ ...self.headers, ++ ...(method !== "" ? {} : { ++ "Content-type": "application/x-www-form-urlencoded", ++ }) + } +- params = params || {}; +- var data = prepareParams(params); +- var method = "GET"; +- if (self.force_post || data.length >= 2000) { +- method = "POST"; +- } +- if (method === "GET") { +- xhr.open("GET", url + "?" + data, true); +- } +- else { +- xhr.open("POST", url, true); +- xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); +- } +- for (var header in self.headers) { +- xhr.setRequestHeader(header, self.headers[header]); +- } +- // fallback on error +- xhr.onreadystatechange = function() { +- if (this.readyState === 4) { +- log(logLevelEnums.DEBUG, functionName + " HTTP request completed [" + this.status + "][" + this.responseText + "]"); +- // response validation function will be selected to also accept JSON arrays if useBroadResponseValidator is true +- var isResponseValidated; +- if (useBroadResponseValidator) { +- // JSON array/object both can pass +- isResponseValidated = isResponseValidBroad(this.status, this.responseText); +- } +- else { +- // only JSON object can pass +- isResponseValidated = isResponseValid(this.status, this.responseText); +- } +- if (isResponseValidated) { +- if (typeof callback === "function") { +- callback(false, params, this.responseText); +- } ++ }); ++ // fallback on error ++ fetchReq.then(async function (response) { ++ if (response.ok) { ++ const responseText = await response.text(); ++ log( ++ logLevelEnums.DEBUG, ++ `${functionName} HTTP request completed [${this.status}][${responseText}]` ++ ); ++ // response validation function will be selected to also accept JSON arrays if useBroadResponseValidator is true ++ var isResponseValidated; ++ if (useBroadResponseValidator) { ++ // JSON array/object both can pass ++ isResponseValidated = isResponseValidBroad(this.status, responseText); ++ } ++ else { ++ // only JSON object can pass ++ isResponseValidated = isResponseValid(this.status, responseText); ++ } ++ if (isResponseValidated) { ++ if (typeof callback === "function") { ++ callback(false, params, responseText); + } +- else { +- log(logLevelEnums.ERROR, functionName + " Failed Server XML HTTP request, ", this.status); +- if (typeof callback === "function") { +- callback(true, params); +- } ++ } ++ else { ++ log(logLevelEnums.ERROR, functionName + " Failed Server XML HTTP request, ", this.status); ++ if (typeof callback === "function") { ++ callback(true, params); + } + } +- }; +- if (method === "GET") { +- xhr.send(); ++ } else { ++ throw new Error(response.statusText); + } +- else { +- xhr.send(data); +- } +- } +- catch (e) { ++ }).catch(function (e) { + // fallback + log(logLevelEnums.ERROR, functionName + " Failed XML HTTP request: " + e); + if (typeof callback === "function") { + callback(true, params); + } +- } ++ }); + } + + /** +@@ -4105,7 +4111,7 @@ + * + */ + function processScroll() { +- scrollRegistryTopPosition = Math.max(scrollRegistryTopPosition, window.scrollY, document.body.scrollTop, document.documentElement.scrollTop); ++ scrollRegistryTopPosition = Math.max(scrollRegistryTopPosition, globalThis.scrollY, document.body.scrollTop, document.documentElement.scrollTop); + } + + /** +@@ -4131,7 +4137,7 @@ + // truncate new segment + segments = truncateObject(segments, self.maxKeyLength, self.maxValueSize, self.maxSegmentationValues, "processScrollView", log); + if (self.track_domains) { +- segments.domain = window.location.hostname; ++ segments.domain = globalThis.location.hostname; + } + add_cly_events({ + key: internalEventKeyEnums.ACTION, +@@ -4862,7 +4868,7 @@ + */ + var get_event_target = function(event) { + if (!event) { +- return window.event.srcElement; ++ return globalThis.event.srcElement; + } + if (typeof event.target !== "undefined") { + return event.target; +@@ -4924,7 +4930,7 @@ + var device = "desktop"; + + // regexps corresponding to tablets or phones that can be found in userAgent string +- var tabletCheck = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/; ++ var tabletCheck = /(ipad|tablet|(android(?!.*mobile))|(globalThiss(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/; + var phoneCheck = /(mobi|ipod|phone|blackberry|opera mini|fennec|minimo|symbian|psp|nintendo ds|archos|skyfire|puffin|blazer|bolt|gobrowser|iris|maemo|semc|teashark|uzard)/; + + // check whether the regexp values corresponds to something in the user agent string +@@ -5009,7 +5015,7 @@ + return Math.min( + Math.min(D.body.clientHeight, D.documentElement.clientHeight), + Math.min(D.body.offsetHeight, D.documentElement.offsetHeight), +- window.innerHeight ++ globalThis.innerHeight + ); + } + +@@ -5018,13 +5024,13 @@ + * @returns {String} device orientation + */ + function getOrientation() { +- return window.innerWidth > window.innerHeight ? "landscape" : "portrait"; ++ return globalThis.innerWidth > globalThis.innerHeight ? "landscape" : "portrait"; + } + + /** + * Monitor parallel storage changes like other opened tabs + */ +- window.addEventListener("storage", function(e) { ++ globalThis.addEventListener("storage", function(e) { + var parts = (e.key + "").split("/"); + var key = parts.pop(); + var appKey = parts.pop(); +@@ -5171,7 +5177,7 @@ + * @return {string} view name + * */ + Countly.getViewName = function() { +- return window.location.pathname; ++ return globalThis.location.pathname; + }; + + /** +@@ -5179,7 +5185,7 @@ + * @return {string} view url + * */ + Countly.getViewUrl = function() { +- return window.location.pathname; ++ return globalThis.location.pathname; + }; + + /** +@@ -5187,7 +5193,7 @@ + * @return {string} view url + * */ + Countly.getSearchQuery = function() { +- return window.location.search; ++ return globalThis.location.search; + }; + + /** From f3305fe21b81e2233eab595bb4d528de86e18946 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 12 Jul 2023 04:00:46 -0600 Subject: [PATCH 02/63] feat(mv3): :sparkles: Implementing Custom Async Store. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../WebExtensionStorageProvider.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 add-on/src/lib/storage-provider/WebExtensionStorageProvider.ts diff --git a/add-on/src/lib/storage-provider/WebExtensionStorageProvider.ts b/add-on/src/lib/storage-provider/WebExtensionStorageProvider.ts new file mode 100644 index 000000000..5b0959890 --- /dev/null +++ b/add-on/src/lib/storage-provider/WebExtensionStorageProvider.ts @@ -0,0 +1,40 @@ +import type { consentTypes } from '@ipfs-shipyard/ignite-metrics/typings/countly' +import type { StorageProviderInterface } from '@ipfs-shipyard/ignite-metrics/StorageProvider' +import browser from 'webextension-polyfill' + +export class WebExtensionStorageProvider implements StorageProviderInterface { + async setStore (consentArray: consentTypes[]): Promise { + try { + const jsonString = JSON.stringify(consentArray) + if ('localStorage' in globalThis) { + globalThis.localStorage.setItem('@ipfs-shipyard/ignite-metrics:consent', jsonString) + } else { + await browser.storage.local.set({ '@ipfs-shipyard/ignite-metrics:consent': jsonString }) + } + } catch (err) { + // eslint-disable-next-line no-console + console.error(err) + } + } + + async getStore (): Promise { + try { + let jsonString; + if ('localStorage' in globalThis) { + jsonString = globalThis.localStorage.getItem('@ipfs-shipyard/ignite-metrics:consent') + } else { + jsonString = (await browser.storage.local.get(['@ipfs-shipyard/ignite-metrics:consent']))['@ipfs-shipyard/ignite-metrics:consent'] + } + if (jsonString != null) { + return JSON.parse(jsonString) + } + } catch (err) { + // eslint-disable-next-line no-console + console.error(err) + } + /** + * Return minimal consent if there is nothing in the store. + */ + return ['minimal'] + } +} From 83af58f4588b40601375fa7accfe399f9be5e1be Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 12 Jul 2023 04:01:43 -0600 Subject: [PATCH 03/63] chore(mv3): :adhesive_bandage: Hooking everything up together. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- add-on/src/lib/ipfs-companion.js | 3 + add-on/src/lib/telemetry.js | 8 +- package-lock.json | 856 +++++++++++++++---------------- package.json | 3 +- 4 files changed, 433 insertions(+), 437 deletions(-) diff --git a/add-on/src/lib/ipfs-companion.js b/add-on/src/lib/ipfs-companion.js index 5bba5981c..163b4e157 100644 --- a/add-on/src/lib/ipfs-companion.js +++ b/add-on/src/lib/ipfs-companion.js @@ -24,6 +24,7 @@ import { guiURLString, migrateOptions, optionDefaults, safeURL, storeMissingOpti import { getExtraInfoSpec } from './redirect-handler/blockOrObserve.js' import createRuntimeChecks from './runtime-checks.js' import { initState, offlinePeerCount } from './state.js' +import { handleConsentFromState, trackView } from '../lib/telemetry.js' // this won't work in webworker context. Needs to be enabled manually // https://github.com/debug-js/debug/issues/916 @@ -65,7 +66,9 @@ export default async function init (inQuickImport = false) { if (state.active) { // It's ok for this to fail, node might be unavailable or mis-configured try { + handleConsentFromState(state) ipfs = await initIpfsClient(browser, state, inQuickImport) + trackView('init') } catch (err) { console.error('[ipfs-companion] Failed to init IPFS client', err) notify( diff --git a/add-on/src/lib/telemetry.js b/add-on/src/lib/telemetry.js index e532aaaca..eec136a05 100644 --- a/add-on/src/lib/telemetry.js +++ b/add-on/src/lib/telemetry.js @@ -1,13 +1,17 @@ import browser from 'webextension-polyfill' -import MetricsProvider from '@ipfs-shipyard/ignite-metrics/vanilla' +import MetricsProvider from '@ipfs-shipyard/ignite-metrics/MetricsProvider' +import PatchedCountly from 'countly-sdk-web' import debug from 'debug' +import { WebExtensionStorageProvider } from './storage-provider/WebExtensionStorageProvider.js' const log = debug('ipfs-companion:telemetry') const metricsProvider = new MetricsProvider({ appKey: '393f72eb264c28a1b59973da1e0a3938d60dc38a', autoTrack: false, - storageProvider: null + metricsService: PatchedCountly, + storage: 'none', + storageProvider: new WebExtensionStorageProvider() }) /** diff --git a/package-lock.json b/package-lock.json index e65640152..fb5803d6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.0.0", "license": "CC0-1.0", "dependencies": { - "@ipfs-shipyard/ignite-metrics": "1.3.0", + "@ipfs-shipyard/ignite-metrics": "https://github.com/ipfs-shipyard/ignite-metrics/tarball/b2086f0b07062873d55b874d2721ab0b0ed3b9b8", "@material/switch": "10.0.0", "assert": "2.0.0", "buffer": "6.0.3", @@ -53,6 +53,7 @@ "bufferutil": "^4.0.7", "c8": "7.12.0", "chai": "4.3.7", + "countly-sdk-web": "^23.2.2", "cross-env": "7.0.3", "css-loader": "6.7.2", "download-cli": "1.1.1", @@ -108,7 +109,6 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz", "integrity": "sha512-qRmjj8nj9qmLTQXXmaR1cck3UXSRMPrbsLJAasZpF+t3riI71BXed5ebIOYwQntykeZuhjsdweEc9BxH5Jc26w==", - "dev": true, "dependencies": { "@jridgewell/gen-mapping": "^0.1.0", "@jridgewell/trace-mapping": "^0.3.9" @@ -132,7 +132,6 @@ "version": "7.20.1", "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.20.1.tgz", "integrity": "sha512-EWZ4mE2diW3QALKvDMiXnbZpRvlj+nayZ112nK93SnhqOtpdsbVD4W+2tEoT3YNBAG9RBR0ISY758ZkOgsn6pQ==", - "dev": true, "engines": { "node": ">=6.9.0" } @@ -141,7 +140,6 @@ "version": "7.20.2", "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.20.2.tgz", "integrity": "sha512-w7DbG8DtMrJcFOi4VrLm+8QM4az8Mo+PuLBKLp2zrYRCow8W/f9xiXm5sN53C8HksCyDQwCKha9JiDoIyPjT2g==", - "dev": true, "dependencies": { "@ampproject/remapping": "^2.1.0", "@babel/code-frame": "^7.18.6", @@ -195,11 +193,11 @@ } }, "node_modules/@babel/helper-annotate-as-pure": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.18.6.tgz", - "integrity": "sha512-duORpUiYrEpzKIop6iNbjnwKLAKnJ47csTyRACyEmWj0QdUrm5aqNJGHSSEQSUAvNW0ojX0dOmK9dZduvkfeXA==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.22.5.tgz", + "integrity": "sha512-LvBTxu8bQSQkcyKOU+a1btnNFQ1dMAd0R6PyW3arXes06F6QLWLIrd681bxRPIXlrMGR3XYnW9JyML7dP3qgxg==", "dependencies": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" @@ -222,7 +220,6 @@ "version": "7.20.0", "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.20.0.tgz", "integrity": "sha512-0jp//vDGp9e8hZzBc6N/KwA5ZK3Wsm/pfm4CrY7vzegkVxc65SgSn6wYOnwHe9Js9HRQ1YTCKLGPzDtaS3RoLQ==", - "dev": true, "dependencies": { "@babel/compat-data": "^7.20.0", "@babel/helper-validator-option": "^7.18.6", @@ -347,11 +344,11 @@ } }, "node_modules/@babel/helper-module-imports": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.18.6.tgz", - "integrity": "sha512-0NFvs3VkuSYbFi1x2Vd6tKrywq+z/cLeYC/RJNFrIX/30Bf5aiGYbtvGXolEktzJH8o5E5KJ3tT+nkxuuZFVlA==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.22.5.tgz", + "integrity": "sha512-8Dl6+HD/cKifutF5qGd/8ZJi84QeAKh+CEe1sBzz8UayBBGg1dAIJrdHOcOM5b2MpzWL2yuotJTtGjETq0qjXg==", "dependencies": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" @@ -361,7 +358,6 @@ "version": "7.20.2", "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.20.2.tgz", "integrity": "sha512-zvBKyJXRbmK07XhMuujYoJ48B5yvvmM6+wcpv6Ivj4Yg6qO7NOZOSnvZN9CRl1zz1Z4cKf8YejmCMh8clOoOeA==", - "dev": true, "dependencies": { "@babel/helper-environment-visitor": "^7.18.9", "@babel/helper-module-imports": "^7.18.6", @@ -389,10 +385,9 @@ } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.20.2", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.20.2.tgz", - "integrity": "sha512-8RvlJG2mj4huQ4pZ+rU9lqKi9ZKiRmuvGuM2HlWmkmgOhbs6zEAw6IEiJ5cQqGbDzGZOhwuOQNtZMi/ENLjZoQ==", - "dev": true, + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz", + "integrity": "sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg==", "engines": { "node": ">=6.9.0" } @@ -436,7 +431,6 @@ "version": "7.20.2", "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.20.2.tgz", "integrity": "sha512-+0woI/WPq59IrqDYbVGfshjT5Dmk/nnbdpcF8SnMhhXObpTq2KNBdLFRFrkVdbDOyUmHBCxzm5FHV1rACIkIbA==", - "dev": true, "dependencies": { "@babel/types": "^7.20.2" }, @@ -468,17 +462,17 @@ } }, "node_modules/@babel/helper-string-parser": { - "version": "7.19.4", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.19.4.tgz", - "integrity": "sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", + "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", - "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz", + "integrity": "sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==", "engines": { "node": ">=6.9.0" } @@ -487,7 +481,6 @@ "version": "7.21.0", "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.21.0.tgz", "integrity": "sha512-rmL/B8/f0mKS2baE9ZpyTcTavvEuWhTTW8amjzXNvYG4AwBsqTLikfXsEofsJEfKHf+HQVQbFOHy6o+4cnC/fQ==", - "dev": true, "engines": { "node": ">=6.9.0" } @@ -511,7 +504,6 @@ "version": "7.20.1", "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.20.1.tgz", "integrity": "sha512-J77mUVaDTUJFZ5BpP6mMn6OIl3rEWymk2ZxDBQJUG3P+PbmyMcF3bYWvz0ma69Af1oobDqT/iAsvzhB58xhQUg==", - "dev": true, "dependencies": { "@babel/template": "^7.18.10", "@babel/traverse": "^7.20.1", @@ -916,6 +908,20 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-syntax-jsx": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.22.5.tgz", + "integrity": "sha512-gvyP4hZrgrs/wWMaocvxZ44Hw0b3W8Pe+cMxc8V1ULQ07oh8VNbIRaoD1LRZVTvD+0nieDKjfgKg89sD7rrKrg==", + "dependencies": { + "@babel/helper-plugin-utils": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-syntax-logical-assignment-operators": { "version": "7.10.4", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz", @@ -1675,12 +1681,12 @@ } }, "node_modules/@babel/types": { - "version": "7.21.3", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.21.3.tgz", - "integrity": "sha512-sBGdETxC+/M4o/zKC0sl6sjWv62WFR/uzxrJ6uYyMLZOUlPnwzw0tKgVHOXxaAd5l2g8pEDM5RZ495GPQI77kg==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.5.tgz", + "integrity": "sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA==", "dependencies": { - "@babel/helper-string-parser": "^7.19.4", - "@babel/helper-validator-identifier": "^7.19.1", + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.5", "to-fast-properties": "^2.0.0" }, "engines": { @@ -1779,17 +1785,17 @@ } }, "node_modules/@emotion/is-prop-valid": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-1.2.0.tgz", - "integrity": "sha512-3aDpDprjM0AwaxGE09bOPkNxHpBd+kA6jty3RnaEXdweX1DF1U3VQpPYb0g1IStAuK7SVQ1cy+bNBBKp4W3Fjg==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-1.2.1.tgz", + "integrity": "sha512-61Mf7Ufx4aDxx1xlDeOm8aFFigGHE4z+0sKCa+IHCeZKiyP9RLD0Mmx7m8b9/Cf37f7NAvQOOJAbQQGVr5uERw==", "dependencies": { - "@emotion/memoize": "^0.8.0" + "@emotion/memoize": "^0.8.1" } }, "node_modules/@emotion/memoize": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.8.0.tgz", - "integrity": "sha512-G/YwXTkv7Den9mXDO7AhLWkE3q+I92B+VqAE+dYG4NGPaHZGvt3G8Q0p9vmE+sq7rTGphUbAvmQ9YpbfMQGGlA==" + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.8.1.tgz", + "integrity": "sha512-W2P2c/VRW1/1tLox0mVUalvnWXxavmv/Oum2aPsRcoDJuob75FC3Y8FbpfLwUegRcxINtGUMPq0tFCvYNTBXNA==" }, "node_modules/@emotion/stylis": { "version": "0.8.5", @@ -1802,9 +1808,9 @@ "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" }, "node_modules/@esbuild/android-arm": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.5.tgz", - "integrity": "sha512-crmPUzgCmF+qZXfl1YkiFoUta2XAfixR1tEnr/gXIixE+WL8Z0BGqfydP5oox0EUOgQMMRgtATtakyAcClQVqQ==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.11.tgz", + "integrity": "sha512-q4qlUf5ucwbUJZXF5tEQ8LF7y0Nk4P58hOsGk3ucY0oCwgQqAnqXVbUuahCddVHfrxmpyewRpiTHwVHIETYu7Q==", "cpu": [ "arm" ], @@ -1818,9 +1824,9 @@ } }, "node_modules/@esbuild/android-arm64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.17.5.tgz", - "integrity": "sha512-KHWkDqYAMmKZjY4RAN1PR96q6UOtfkWlTS8uEwWxdLtkRt/0F/csUhXIrVfaSIFxnscIBMPynGfhsMwQDRIBQw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.11.tgz", + "integrity": "sha512-snieiq75Z1z5LJX9cduSAjUr7vEI1OdlzFPMw0HH5YI7qQHDd3qs+WZoMrWYDsfRJSq36lIA6mfZBkvL46KoIw==", "cpu": [ "arm64" ], @@ -1834,9 +1840,9 @@ } }, "node_modules/@esbuild/android-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.17.5.tgz", - "integrity": "sha512-8fI/AnIdmWz/+1iza2WrCw8kwXK9wZp/yZY/iS8ioC+U37yJCeppi9EHY05ewJKN64ASoBIseufZROtcFnX5GA==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.11.tgz", + "integrity": "sha512-iPuoxQEV34+hTF6FT7om+Qwziv1U519lEOvekXO9zaMMlT9+XneAhKL32DW3H7okrCOBQ44BMihE8dclbZtTuw==", "cpu": [ "x64" ], @@ -1865,9 +1871,9 @@ } }, "node_modules/@esbuild/darwin-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.5.tgz", - "integrity": "sha512-ha7QCJh1fuSwwCgoegfdaljowwWozwTDjBgjD3++WAy/qwee5uUi1gvOg2WENJC6EUyHBOkcd3YmLDYSZ2TPPA==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.11.tgz", + "integrity": "sha512-N15Vzy0YNHu6cfyDOjiyfJlRJCB/ngKOAvoBf1qybG3eOq0SL2Lutzz9N7DYUbb7Q23XtHPn6lMDF6uWbGv9Fw==", "cpu": [ "x64" ], @@ -1881,9 +1887,9 @@ } }, "node_modules/@esbuild/freebsd-arm64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.5.tgz", - "integrity": "sha512-VbdXJkn2aI2pQ/wxNEjEcnEDwPpxt3CWWMFYmO7CcdFBoOsABRy2W8F3kjbF9F/pecEUDcI3b5i2w+By4VQFPg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.11.tgz", + "integrity": "sha512-atEyuq6a3omEY5qAh5jIORWk8MzFnCpSTUruBgeyN9jZq1K/QI9uke0ATi3MHu4L8c59CnIi4+1jDKMuqmR71A==", "cpu": [ "arm64" ], @@ -1897,9 +1903,9 @@ } }, "node_modules/@esbuild/freebsd-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.17.5.tgz", - "integrity": "sha512-olgGYND1/XnnWxwhjtY3/ryjOG/M4WfcA6XH8dBTH1cxMeBemMODXSFhkw71Kf4TeZFFTN25YOomaNh0vq2iXg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.11.tgz", + "integrity": "sha512-XtuPrEfBj/YYYnAAB7KcorzzpGTvOr/dTtXPGesRfmflqhA4LMF0Gh/n5+a9JBzPuJ+CGk17CA++Hmr1F/gI0Q==", "cpu": [ "x64" ], @@ -1913,9 +1919,9 @@ } }, "node_modules/@esbuild/linux-arm": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.17.5.tgz", - "integrity": "sha512-YBdCyQwA3OQupi6W2/WO4FnI+NWFWe79cZEtlbqSESOHEg7a73htBIRiE6uHPQe7Yp5E4aALv+JxkRLGEUL7tw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.11.tgz", + "integrity": "sha512-Idipz+Taso/toi2ETugShXjQ3S59b6m62KmLHkJlSq/cBejixmIydqrtM2XTvNCywFl3VC7SreSf6NV0i6sRyg==", "cpu": [ "arm" ], @@ -1929,9 +1935,9 @@ } }, "node_modules/@esbuild/linux-arm64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.17.5.tgz", - "integrity": "sha512-8a0bqSwu3OlLCfu2FBbDNgQyBYdPJh1B9PvNX7jMaKGC9/KopgHs37t+pQqeMLzcyRqG6z55IGNQAMSlCpBuqg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.11.tgz", + "integrity": "sha512-c6Vh2WS9VFKxKZ2TvJdA7gdy0n6eSy+yunBvv4aqNCEhSWVor1TU43wNRp2YLO9Vng2G+W94aRz+ILDSwAiYog==", "cpu": [ "arm64" ], @@ -1945,9 +1951,9 @@ } }, "node_modules/@esbuild/linux-ia32": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.17.5.tgz", - "integrity": "sha512-uCwm1r/+NdP7vndctgq3PoZrnmhmnecWAr114GWMRwg2QMFFX+kIWnp7IO220/JLgnXK/jP7VKAFBGmeOYBQYQ==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.11.tgz", + "integrity": "sha512-S3hkIF6KUqRh9n1Q0dSyYcWmcVa9Cg+mSoZEfFuzoYXXsk6196qndrM+ZiHNwpZKi3XOXpShZZ+9dfN5ykqjjw==", "cpu": [ "ia32" ], @@ -1961,9 +1967,9 @@ } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.17.5.tgz", - "integrity": "sha512-3YxhSBl5Sb6TtBjJu+HP93poBruFzgXmf3PVfIe4xOXMj1XpxboYZyw3W8BhoX/uwxzZz4K1I99jTE/5cgDT1g==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.11.tgz", + "integrity": "sha512-MRESANOoObQINBA+RMZW+Z0TJWpibtE7cPFnahzyQHDCA9X9LOmGh68MVimZlM9J8n5Ia8lU773te6O3ILW8kw==", "cpu": [ "loong64" ], @@ -1977,9 +1983,9 @@ } }, "node_modules/@esbuild/linux-mips64el": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.17.5.tgz", - "integrity": "sha512-Hy5Z0YVWyYHdtQ5mfmfp8LdhVwGbwVuq8mHzLqrG16BaMgEmit2xKO+iDakHs+OetEx0EN/2mUzDdfdktI+Nmg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.11.tgz", + "integrity": "sha512-qVyPIZrXNMOLYegtD1u8EBccCrBVshxMrn5MkuFc3mEVsw7CCQHaqZ4jm9hbn4gWY95XFnb7i4SsT3eflxZsUg==", "cpu": [ "mips64el" ], @@ -1993,9 +1999,9 @@ } }, "node_modules/@esbuild/linux-ppc64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.17.5.tgz", - "integrity": "sha512-5dbQvBLbU/Y3Q4ABc9gi23hww1mQcM7KZ9KBqabB7qhJswYMf8WrDDOSw3gdf3p+ffmijMd28mfVMvFucuECyg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.11.tgz", + "integrity": "sha512-T3yd8vJXfPirZaUOoA9D2ZjxZX4Gr3QuC3GztBJA6PklLotc/7sXTOuuRkhE9W/5JvJP/K9b99ayPNAD+R+4qQ==", "cpu": [ "ppc64" ], @@ -2009,9 +2015,9 @@ } }, "node_modules/@esbuild/linux-riscv64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.17.5.tgz", - "integrity": "sha512-fp/KUB/ZPzEWGTEUgz9wIAKCqu7CjH1GqXUO2WJdik1UNBQ7Xzw7myIajpxztE4Csb9504ERiFMxZg5KZ6HlZQ==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.11.tgz", + "integrity": "sha512-evUoRPWiwuFk++snjH9e2cAjF5VVSTj+Dnf+rkO/Q20tRqv+644279TZlPK8nUGunjPAtQRCj1jQkDAvL6rm2w==", "cpu": [ "riscv64" ], @@ -2025,9 +2031,9 @@ } }, "node_modules/@esbuild/linux-s390x": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.17.5.tgz", - "integrity": "sha512-kRV3yw19YDqHTp8SfHXfObUFXlaiiw4o2lvT1XjsPZ++22GqZwSsYWJLjMi1Sl7j9qDlDUduWDze/nQx0d6Lzw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.11.tgz", + "integrity": "sha512-/SlRJ15XR6i93gRWquRxYCfhTeC5PdqEapKoLbX63PLCmAkXZHY2uQm2l9bN0oPHBsOw2IswRZctMYS0MijFcg==", "cpu": [ "s390x" ], @@ -2056,9 +2062,9 @@ } }, "node_modules/@esbuild/netbsd-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.17.5.tgz", - "integrity": "sha512-cigBpdiSx/vPy7doUyImsQQBnBjV5f1M99ZUlaJckDAJjgXWl6y9W17FIfJTy8TxosEF6MXq+fpLsitMGts2nA==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.11.tgz", + "integrity": "sha512-aSjMHj/F7BuS1CptSXNg6S3M4F3bLp5wfFPIJM+Km2NfIVfFKhdmfHF9frhiCLIGVzDziggqWll0B+9AUbud/Q==", "cpu": [ "x64" ], @@ -2072,9 +2078,9 @@ } }, "node_modules/@esbuild/openbsd-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.17.5.tgz", - "integrity": "sha512-VdqRqPVIjjZfkf40LrqOaVuhw9EQiAZ/GNCSM2UplDkaIzYVsSnycxcFfAnHdWI8Gyt6dO15KHikbpxwx+xHbw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.11.tgz", + "integrity": "sha512-tNBq+6XIBZtht0xJGv7IBB5XaSyvYPCm1PxJ33zLQONdZoLVM0bgGqUrXnJyiEguD9LU4AHiu+GCXy/Hm9LsdQ==", "cpu": [ "x64" ], @@ -2088,9 +2094,9 @@ } }, "node_modules/@esbuild/sunos-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.17.5.tgz", - "integrity": "sha512-ItxPaJ3MBLtI4nK+mALLEoUs6amxsx+J1ibnfcYMkqaCqHST1AkF4aENpBehty3czqw64r/XqL+W9WqU6kc2Qw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.11.tgz", + "integrity": "sha512-kxfbDOrH4dHuAAOhr7D7EqaYf+W45LsAOOhAet99EyuxxQmjbk8M9N4ezHcEiCYPaiW8Dj3K26Z2V17Gt6p3ng==", "cpu": [ "x64" ], @@ -2104,9 +2110,9 @@ } }, "node_modules/@esbuild/win32-arm64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.17.5.tgz", - "integrity": "sha512-4u2Q6qsJTYNFdS9zHoAi80spzf78C16m2wla4eJPh4kSbRv+BpXIfl6TmBSWupD8e47B1NrTfrOlEuco7mYQtg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.11.tgz", + "integrity": "sha512-Sh0dDRyk1Xi348idbal7lZyfSkjhJsdFeuC13zqdipsvMetlGiFQNdO+Yfp6f6B4FbyQm7qsk16yaZk25LChzg==", "cpu": [ "arm64" ], @@ -2120,9 +2126,9 @@ } }, "node_modules/@esbuild/win32-ia32": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.17.5.tgz", - "integrity": "sha512-KYlm+Xu9TXsfTWAcocLuISRtqxKp/Y9ZBVg6CEEj0O5J9mn7YvBKzAszo2j1ndyzUPk+op+Tie2PJeN+BnXGqQ==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.11.tgz", + "integrity": "sha512-o9JUIKF1j0rqJTFbIoF4bXj6rvrTZYOrfRcGyL0Vm5uJ/j5CkBD/51tpdxe9lXEDouhRgdr/BYzUrDOvrWwJpg==", "cpu": [ "ia32" ], @@ -2136,9 +2142,9 @@ } }, "node_modules/@esbuild/win32-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.5.tgz", - "integrity": "sha512-XgA9qWRqby7xdYXuF6KALsn37QGBMHsdhmnpjfZtYxKxbTOwfnDM6MYi2WuUku5poNaX2n9XGVr20zgT/2QwCw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.11.tgz", + "integrity": "sha512-rQI4cjLHd2hGsM1LqgDI7oOCYbQ6IBOVsX9ejuRMSze0GqXUG2ekwiKkiBU1pRGSeCqFFHxTrcEydB2Hyoz9CA==", "cpu": [ "x64" ], @@ -2296,8 +2302,9 @@ }, "node_modules/@ipfs-shipyard/ignite-metrics": { "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@ipfs-shipyard/ignite-metrics/-/ignite-metrics-1.3.0.tgz", - "integrity": "sha512-EKBgBHqIXIl82wlKN3pdIpOLC87cpIPtm7yrTGE8wSRsDe2ASEhu5wzbYYJ6InvtVA6AZsZ280VIuOubOG2usA==", + "resolved": "https://github.com/ipfs-shipyard/ignite-metrics/tarball/b2086f0b07062873d55b874d2721ab0b0ed3b9b8", + "integrity": "sha512-mpCxDqnelGBB3l4oPQjuMhMjoik+zK4MLTsYYBySZGnDnGaJDpEWXgd7NTg2FlvDhrpTVF0ff9QATaO08GR6hw==", + "license": "Apache-2.0 OR MIT", "dependencies": { "countly-sdk-nodejs": "^22.6.0", "countly-sdk-web": "^22.6.4", @@ -2321,6 +2328,11 @@ "react-dom": "^18.2.0" } }, + "node_modules/@ipfs-shipyard/ignite-metrics/node_modules/countly-sdk-web": { + "version": "22.6.5", + "resolved": "https://registry.npmjs.org/countly-sdk-web/-/countly-sdk-web-22.6.5.tgz", + "integrity": "sha512-KUTKWfdUbzfdKWnVJWVO4BNshWkflNVa4h/TQdOOUZqeTSpUVMnlugfTG7HfN4KioummarazcyaGUh3JIATlqg==" + }, "node_modules/@ipld/dag-cbor": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/@ipld/dag-cbor/-/dag-cbor-8.0.0.tgz", @@ -2437,7 +2449,6 @@ "version": "0.1.1", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.1.1.tgz", "integrity": "sha512-sQXCasFk+U8lWYEe66WxRDOE9PjVz4vSM51fTu3Hw+ClTpUSQb718772vH3pyS5pShp6lvQM7SxgIDXXXmOX7w==", - "dev": true, "dependencies": { "@jridgewell/set-array": "^1.0.0", "@jridgewell/sourcemap-codec": "^1.4.10" @@ -3058,9 +3069,9 @@ "dev": true }, "node_modules/@remix-run/router": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.3.1.tgz", - "integrity": "sha512-+eun1Wtf72RNRSqgU7qM2AMX/oHp+dnx7BHk1qhK5ZHzdHTUU4LA1mGG1vT+jMc8sbhG3orvsfOmryjzx2PzQw==", + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.7.1.tgz", + "integrity": "sha512-bgVQM4ZJ2u2CM8k1ey70o1ePFXsEzYVZoWghh6WjM8p59jQ7HxzbHW4SbnWFG7V9ig9chLawQxDTZ3xzOF8MkQ==", "engines": { "node": ">=14" } @@ -5131,15 +5142,15 @@ } }, "node_modules/babel-plugin-styled-components": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/babel-plugin-styled-components/-/babel-plugin-styled-components-2.0.7.tgz", - "integrity": "sha512-i7YhvPgVqRKfoQ66toiZ06jPNA3p6ierpfUuEWxNF+fV27Uv5gxBkf8KZLHUCc1nFA9j6+80pYoIpqCeyW3/bA==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/babel-plugin-styled-components/-/babel-plugin-styled-components-2.1.4.tgz", + "integrity": "sha512-Xgp9g+A/cG47sUyRwwYxGM4bR/jDRg5N6it/8+HxCnbT5XNKSKDT9xm4oag/osgqjC2It/vH0yXsomOG6k558g==", "dependencies": { - "@babel/helper-annotate-as-pure": "^7.16.0", - "@babel/helper-module-imports": "^7.16.0", - "babel-plugin-syntax-jsx": "^6.18.0", - "lodash": "^4.17.11", - "picomatch": "^2.3.0" + "@babel/helper-annotate-as-pure": "^7.22.5", + "@babel/helper-module-imports": "^7.22.5", + "@babel/plugin-syntax-jsx": "^7.22.5", + "lodash": "^4.17.21", + "picomatch": "^2.3.1" }, "peerDependencies": { "styled-components": ">= 2" @@ -5151,11 +5162,6 @@ "integrity": "sha512-EbciFN5Jb9iqU9bqaLmmFLx2G8pAUsvpWJ6OzOWBNrSY9qTohXj+7YfZx6Ug1Qqh7tCb1EA7Jvn9bMC1HBiucg==", "dev": true }, - "node_modules/babel-plugin-syntax-jsx": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz", - "integrity": "sha512-qrPaCSo9c8RHNRHIotaufGbuOBN8rtdC4QrrFFc43vyWCCz7Kl7GL1PGaXtMGQZUXrkCjNEgxDfmAuAabr/rlw==" - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -5485,7 +5491,6 @@ "version": "4.21.4", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.4.tgz", "integrity": "sha512-CBHJJdDmgjl3daYjN5Cp5kbTf1mUhZoS+beLklHIvkOWscs83YAhLlF3Wsh/lciQYAcbBJgTOD44VtG31ZM4Hw==", - "dev": true, "funding": [ { "type": "opencollective", @@ -5877,7 +5882,6 @@ "version": "1.0.30001434", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001434.tgz", "integrity": "sha512-aOBHrLmTQw//WFa2rcF1If9fa3ypkC1wzqqiKHgfdrXTWcU8C4gKVZT77eQAPWN1APys3+uQ0Df07rKauXGEYA==", - "dev": true, "funding": [ { "type": "opencollective", @@ -6591,9 +6595,10 @@ "integrity": "sha512-vw6YRGJJu6sq9oZEz00SyAL7oyru+w1ct3P6TS0avMPRSZ/mqEXYq3l+Wtl89L/HwXcDymh8gY7JOOAPnI7vEg==" }, "node_modules/countly-sdk-web": { - "version": "22.6.4", - "resolved": "https://registry.npmjs.org/countly-sdk-web/-/countly-sdk-web-22.6.4.tgz", - "integrity": "sha512-G2JWVqFrRHoEU4/G7D1EPn16jKzSaJD/mpWNK73+8JNPjuRhnSsdotCtekZnOAcT1yDM0r+NoXA9BKn0R87Jsw==" + "version": "23.2.2", + "resolved": "https://registry.npmjs.org/countly-sdk-web/-/countly-sdk-web-23.2.2.tgz", + "integrity": "sha512-Ply1KzgX05GBW8HeT0wDMG6JCmd1JwGxSXi4vFVkQN+VOhzR3Wf/6RFujwIzOitNkbOxEhyrUeT4lx9u2TknVQ==", + "dev": true }, "node_modules/create-require": { "version": "1.1.1", @@ -6738,9 +6743,9 @@ } }, "node_modules/css-to-react-native": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/css-to-react-native/-/css-to-react-native-3.1.0.tgz", - "integrity": "sha512-AryfkFA29b4I3vG7N4kxFboq15DxwSXzhXM37XNEjwJMgjYIc8BcqfiprpAqX0zadI5PMByEIwAMzXxk5Vcc4g==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/css-to-react-native/-/css-to-react-native-3.2.0.tgz", + "integrity": "sha512-e8RKaLXMOFii+02mOlqwjbD00KSEKqblnpO9e++1aXS1fPQOpS1YoqdVHBqPjHNoxeF2mimzVqawm2KCbEdtHQ==", "dependencies": { "camelize": "^1.0.0", "css-color-keywords": "^1.0.0", @@ -7400,8 +7405,7 @@ "node_modules/electron-to-chromium": { "version": "1.4.284", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.284.tgz", - "integrity": "sha512-M8WEXFuKXMYMVr45fo8mq0wUrrJHheiKZf6BArTKk9ZBYCKJEOU5H8cdWgDT+qCVZf7Na4lVUaZsA+h6uA9+PA==", - "dev": true + "integrity": "sha512-M8WEXFuKXMYMVr45fo8mq0wUrrJHheiKZf6BArTKk9ZBYCKJEOU5H8cdWgDT+qCVZf7Na4lVUaZsA+h6uA9+PA==" }, "node_modules/elegant-spinner": { "version": "1.0.1", @@ -7610,9 +7614,9 @@ } }, "node_modules/esbuild": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.5.tgz", - "integrity": "sha512-Bu6WLCc9NMsNoMJUjGl3yBzTjVLXdysMltxQWiLAypP+/vQrf+3L1Xe8fCXzxaECus2cEJ9M7pk4yKatEwQMqQ==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.11.tgz", + "integrity": "sha512-i8u6mQF0JKJUlGR3OdFLKldJQMMs8OqM9Cc3UCi9XXziJ9WERM5bfkHaEAy0YAvPRMgqSW55W7xYn84XtEFTtA==", "hasInstallScript": true, "peer": true, "bin": { @@ -7622,28 +7626,28 @@ "node": ">=12" }, "optionalDependencies": { - "@esbuild/android-arm": "0.17.5", - "@esbuild/android-arm64": "0.17.5", - "@esbuild/android-x64": "0.17.5", - "@esbuild/darwin-arm64": "0.17.5", - "@esbuild/darwin-x64": "0.17.5", - "@esbuild/freebsd-arm64": "0.17.5", - "@esbuild/freebsd-x64": "0.17.5", - "@esbuild/linux-arm": "0.17.5", - "@esbuild/linux-arm64": "0.17.5", - "@esbuild/linux-ia32": "0.17.5", - "@esbuild/linux-loong64": "0.17.5", - "@esbuild/linux-mips64el": "0.17.5", - "@esbuild/linux-ppc64": "0.17.5", - "@esbuild/linux-riscv64": "0.17.5", - "@esbuild/linux-s390x": "0.17.5", - "@esbuild/linux-x64": "0.17.5", - "@esbuild/netbsd-x64": "0.17.5", - "@esbuild/openbsd-x64": "0.17.5", - "@esbuild/sunos-x64": "0.17.5", - "@esbuild/win32-arm64": "0.17.5", - "@esbuild/win32-ia32": "0.17.5", - "@esbuild/win32-x64": "0.17.5" + "@esbuild/android-arm": "0.18.11", + "@esbuild/android-arm64": "0.18.11", + "@esbuild/android-x64": "0.18.11", + "@esbuild/darwin-arm64": "0.18.11", + "@esbuild/darwin-x64": "0.18.11", + "@esbuild/freebsd-arm64": "0.18.11", + "@esbuild/freebsd-x64": "0.18.11", + "@esbuild/linux-arm": "0.18.11", + "@esbuild/linux-arm64": "0.18.11", + "@esbuild/linux-ia32": "0.18.11", + "@esbuild/linux-loong64": "0.18.11", + "@esbuild/linux-mips64el": "0.18.11", + "@esbuild/linux-ppc64": "0.18.11", + "@esbuild/linux-riscv64": "0.18.11", + "@esbuild/linux-s390x": "0.18.11", + "@esbuild/linux-x64": "0.18.11", + "@esbuild/netbsd-x64": "0.18.11", + "@esbuild/openbsd-x64": "0.18.11", + "@esbuild/sunos-x64": "0.18.11", + "@esbuild/win32-arm64": "0.18.11", + "@esbuild/win32-ia32": "0.18.11", + "@esbuild/win32-x64": "0.18.11" } }, "node_modules/esbuild-css-modules-plugin": { @@ -7698,9 +7702,9 @@ } }, "node_modules/esbuild/node_modules/@esbuild/darwin-arm64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.5.tgz", - "integrity": "sha512-EAvaoyIySV6Iif3NQCglUNpnMfHSUgC5ugt2efl3+QDntucJe5spn0udNZjTgNi6tKVqSceOw9tQ32liNZc1Xw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.11.tgz", + "integrity": "sha512-Gm0QkI3k402OpfMKyQEEMG0RuW2LQsSmI6OeO4El2ojJMoF5NLYb3qMIjvbG/lbMeLOGiW6ooU8xqc+S0fgz2w==", "cpu": [ "arm64" ], @@ -7714,9 +7718,9 @@ } }, "node_modules/esbuild/node_modules/@esbuild/linux-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.5.tgz", - "integrity": "sha512-vnxuhh9e4pbtABNLbT2ANW4uwQ/zvcHRCm1JxaYkzSehugoFd5iXyC4ci1nhXU13mxEwCnrnTIiiSGwa/uAF1g==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.11.tgz", + "integrity": "sha512-xcncej+wF16WEmIwPtCHi0qmx1FweBqgsRtEL1mSHLFR6/mb3GEZfLQnx+pUDfRDEM4DQF8dpXIW7eDOZl1IbA==", "cpu": [ "x64" ], @@ -7733,7 +7737,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", - "dev": true, "engines": { "node": ">=6" } @@ -9528,7 +9531,6 @@ "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", - "dev": true, "engines": { "node": ">=6.9.0" } @@ -11985,7 +11987,6 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz", "integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==", - "dev": true, "bin": { "json5": "lib/cli.js" }, @@ -12256,9 +12257,9 @@ "dev": true }, "node_modules/lightningcss": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.18.0.tgz", - "integrity": "sha512-uk10tNxi5fhZqU93vtYiQgx/8a9f0Kvtj5AXIm+VlOXY+t/DWDmCZWJEkZJmmALgvbS6aAW8or+Kq85eJ6TDTw==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.21.5.tgz", + "integrity": "sha512-/pEUPeih2EwIx9n4T82aOG6CInN83tl/mWlw6B5gWLf36UplQi1L+5p3FUHsdt4fXVfOkkh9KIaM3owoq7ss8A==", "dependencies": { "detect-libc": "^1.0.3" }, @@ -12270,20 +12271,20 @@ "url": "https://opencollective.com/parcel" }, "optionalDependencies": { - "lightningcss-darwin-arm64": "1.18.0", - "lightningcss-darwin-x64": "1.18.0", - "lightningcss-linux-arm-gnueabihf": "1.18.0", - "lightningcss-linux-arm64-gnu": "1.18.0", - "lightningcss-linux-arm64-musl": "1.18.0", - "lightningcss-linux-x64-gnu": "1.18.0", - "lightningcss-linux-x64-musl": "1.18.0", - "lightningcss-win32-x64-msvc": "1.18.0" + "lightningcss-darwin-arm64": "1.21.5", + "lightningcss-darwin-x64": "1.21.5", + "lightningcss-linux-arm-gnueabihf": "1.21.5", + "lightningcss-linux-arm64-gnu": "1.21.5", + "lightningcss-linux-arm64-musl": "1.21.5", + "lightningcss-linux-x64-gnu": "1.21.5", + "lightningcss-linux-x64-musl": "1.21.5", + "lightningcss-win32-x64-msvc": "1.21.5" } }, "node_modules/lightningcss-darwin-arm64": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.18.0.tgz", - "integrity": "sha512-OqjydwtiNPgdH1ByIjA1YzqvDG/OMR6L3LPN6wRl1729LB0y4Mik7L06kmZaTb+pvUHr+NmDd2KCwnlrQ4zO3w==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.21.5.tgz", + "integrity": "sha512-z05hyLX85WY0UfhkFUOrWEFqD69lpVAmgl3aDzMKlIZJGygbhbegqb4PV8qfUrKKNBauut/qVNPKZglhTaDDxA==", "cpu": [ "arm64" ], @@ -12300,9 +12301,9 @@ } }, "node_modules/lightningcss-darwin-x64": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.18.0.tgz", - "integrity": "sha512-mNiuPHj89/JHZmJMp+5H8EZSt6EL5DZRWJ31O6k3DrLLnRIQjXuXdDdN8kP7LoIkeWI5xvyD60CsReJm+YWYAw==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.21.5.tgz", + "integrity": "sha512-MSJhmej/U9MrdPxDk7+FWhO8+UqVoZUHG4VvKT5RQ4RJtqtANTiWiI97LvoVNMtdMnHaKs1Pkji6wHUFxjJsHQ==", "cpu": [ "x64" ], @@ -12319,9 +12320,9 @@ } }, "node_modules/lightningcss-linux-arm-gnueabihf": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.18.0.tgz", - "integrity": "sha512-S+25JjI6601HiAVoTDXW6SqH+E94a+FHA7WQqseyNHunOgVWKcAkNEc2LJvVxgwTq6z41sDIb9/M3Z9wa9lk4A==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.21.5.tgz", + "integrity": "sha512-xN6+5/JsMrbZHL1lPl+MiNJ3Xza12ueBKPepiyDCFQzlhFRTj7D0LG+cfNTzPBTO8KcYQynLpl1iBB8LGp3Xtw==", "cpu": [ "arm" ], @@ -12338,9 +12339,9 @@ } }, "node_modules/lightningcss-linux-arm64-gnu": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.18.0.tgz", - "integrity": "sha512-JSqh4+21dCgBecIQUet35dtE4PhhSEMyqe3y0ZNQrAJQ5kyUPSQHiw81WXnPJcOSTTpG0TyMLiC8K//+BsFGQA==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.21.5.tgz", + "integrity": "sha512-KfzFNhC4XTbmG3ma/xcTs/IhCwieW89XALIusKmnV0N618ZDXEB0XjWOYQRCXeK9mfqPdbTBpurEHV/XZtkniQ==", "cpu": [ "arm64" ], @@ -12357,9 +12358,9 @@ } }, "node_modules/lightningcss-linux-arm64-musl": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.18.0.tgz", - "integrity": "sha512-2FWHa8iUhShnZnqhn2wfIcK5adJat9hAAaX7etNsoXJymlliDIOFuBQEsba2KBAZSM4QqfQtvRdR7m8i0I7ybQ==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.21.5.tgz", + "integrity": "sha512-bc0GytQO5Mn9QM6szaZ+31fQHNdidgpM1sSCwzPItz8hg3wOvKl8039rU0veMJV3ZgC9z0ypNRceLrSHeRHmXw==", "cpu": [ "arm64" ], @@ -12376,9 +12377,9 @@ } }, "node_modules/lightningcss-linux-x64-gnu": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.18.0.tgz", - "integrity": "sha512-plCPGQJtDZHcLVKVRLnQVF2XRsIC32WvuJhQ7fJ7F6BV98b/VZX0OlX05qUaOESD9dCDHjYSfxsgcvOKgCWh7A==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.21.5.tgz", + "integrity": "sha512-JwMbgypPQgc2kW2av3OwzZ8cbrEuIiDiXPJdXRE6aVxu67yHauJawQLqJKTGUhiAhy6iLDG8Wg0a3/ziL+m+Kw==", "cpu": [ "x64" ], @@ -12395,9 +12396,9 @@ } }, "node_modules/lightningcss-linux-x64-musl": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.18.0.tgz", - "integrity": "sha512-na+BGtVU6fpZvOHKhnlA0XHeibkT3/46nj6vLluG3kzdJYoBKU6dIl7DSOk++8jv4ybZyFJ0aOFMMSc8g2h58A==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.21.5.tgz", + "integrity": "sha512-Ib8b6IQ/OR/VrPU6YBgy4T3QnuHY7DUa95O+nz+cwrTkMSN6fuHcTcIaz4t8TJ6HI5pl3uxUOZjmtls2pyQWow==", "cpu": [ "x64" ], @@ -12414,9 +12415,9 @@ } }, "node_modules/lightningcss-win32-x64-msvc": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.18.0.tgz", - "integrity": "sha512-5qeAH4RMNy2yMNEl7e5TI6upt/7xD2ZpHWH4RkT8iJ7/6POS5mjHbXWUO9Q1hhDhqkdzGa76uAdMzEouIeCyNw==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.21.5.tgz", + "integrity": "sha512-A8cSi8lUpBeVmoF+DqqW7cd0FemDbCuKr490IXdjyeI+KL8adpSKUs8tcqO0OXPh1EoDqK7JNkD/dELmd4Iz5g==", "cpu": [ "x64" ], @@ -14071,8 +14072,7 @@ "node_modules/node-releases": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.6.tgz", - "integrity": "sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==", - "dev": true + "integrity": "sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==" }, "node_modules/normalize-html-whitespace": { "version": "0.2.0", @@ -16184,11 +16184,11 @@ } }, "node_modules/react-router": { - "version": "6.8.0", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.8.0.tgz", - "integrity": "sha512-760bk7y3QwabduExtudhWbd88IBbuD1YfwzpuDUAlJUJ7laIIcqhMvdhSVh1Fur1PE8cGl84L0dxhR3/gvHF7A==", + "version": "6.14.1", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.14.1.tgz", + "integrity": "sha512-U4PfgvG55LdvbQjg5Y9QRWyVxIdO1LlpYT7x+tMAxd9/vmiPuJhIwdxZuIQLN/9e3O4KFDHYfR9gzGeYMasW8g==", "dependencies": { - "@remix-run/router": "1.3.1" + "@remix-run/router": "1.7.1" }, "engines": { "node": ">=14" @@ -16198,12 +16198,12 @@ } }, "node_modules/react-router-dom": { - "version": "6.8.0", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.8.0.tgz", - "integrity": "sha512-hQouduSTywGJndE86CXJ2h7YEy4HYC6C/uh19etM+79FfQ6cFFFHnHyDlzO4Pq0eBUI96E4qVE5yUjA00yJZGQ==", + "version": "6.14.1", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.14.1.tgz", + "integrity": "sha512-ssF6M5UkQjHK70fgukCJyjlda0Dgono2QGwqGvuk7D+EDGHdacEN3Yke2LTMjkrpHuFwBfDFsEjGVXBDmL+bWw==", "dependencies": { - "@remix-run/router": "1.3.1", - "react-router": "6.8.0" + "@remix-run/router": "1.7.1", + "react-router": "6.14.1" }, "engines": { "node": ">=14" @@ -17002,7 +17002,6 @@ "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true, "bin": { "semver": "bin/semver.js" } @@ -18005,10 +18004,9 @@ } }, "node_modules/styled-components": { - "version": "5.3.6", - "resolved": "https://registry.npmjs.org/styled-components/-/styled-components-5.3.6.tgz", - "integrity": "sha512-hGTZquGAaTqhGWldX7hhfzjnIYBZ0IXQXkCYdvF1Sq3DsUaLx6+NTHC5Jj1ooM2F68sBiVz3lvhfwQs/S3l6qg==", - "hasInstallScript": true, + "version": "5.3.11", + "resolved": "https://registry.npmjs.org/styled-components/-/styled-components-5.3.11.tgz", + "integrity": "sha512-uuzIIfnVkagcVHv9nE0VPlHPSCmXIUGKfJ42LNjxCCTDTL5sgnJ8Z7GZBq0EnLYGln77tPpEpExt2+qa+cZqSw==", "dependencies": { "@babel/helper-module-imports": "^7.0.0", "@babel/traverse": "^7.4.5", @@ -20141,7 +20139,6 @@ "version": "1.0.10", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz", "integrity": "sha512-OztqDenkfFkbSG+tRxBeAnCVPckDBcvibKd35yDONx6OU8N7sqgwc7rCbkJ/WcYtVRZ4ba68d6byhC21GFh7sQ==", - "dev": true, "funding": [ { "type": "opencollective", @@ -21658,7 +21655,6 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz", "integrity": "sha512-qRmjj8nj9qmLTQXXmaR1cck3UXSRMPrbsLJAasZpF+t3riI71BXed5ebIOYwQntykeZuhjsdweEc9BxH5Jc26w==", - "dev": true, "requires": { "@jridgewell/gen-mapping": "^0.1.0", "@jridgewell/trace-mapping": "^0.3.9" @@ -21675,14 +21671,12 @@ "@babel/compat-data": { "version": "7.20.1", "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.20.1.tgz", - "integrity": "sha512-EWZ4mE2diW3QALKvDMiXnbZpRvlj+nayZ112nK93SnhqOtpdsbVD4W+2tEoT3YNBAG9RBR0ISY758ZkOgsn6pQ==", - "dev": true + "integrity": "sha512-EWZ4mE2diW3QALKvDMiXnbZpRvlj+nayZ112nK93SnhqOtpdsbVD4W+2tEoT3YNBAG9RBR0ISY758ZkOgsn6pQ==" }, "@babel/core": { "version": "7.20.2", "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.20.2.tgz", "integrity": "sha512-w7DbG8DtMrJcFOi4VrLm+8QM4az8Mo+PuLBKLp2zrYRCow8W/f9xiXm5sN53C8HksCyDQwCKha9JiDoIyPjT2g==", - "dev": true, "requires": { "@ampproject/remapping": "^2.1.0", "@babel/code-frame": "^7.18.6", @@ -21725,11 +21719,11 @@ } }, "@babel/helper-annotate-as-pure": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.18.6.tgz", - "integrity": "sha512-duORpUiYrEpzKIop6iNbjnwKLAKnJ47csTyRACyEmWj0QdUrm5aqNJGHSSEQSUAvNW0ojX0dOmK9dZduvkfeXA==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.22.5.tgz", + "integrity": "sha512-LvBTxu8bQSQkcyKOU+a1btnNFQ1dMAd0R6PyW3arXes06F6QLWLIrd681bxRPIXlrMGR3XYnW9JyML7dP3qgxg==", "requires": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" } }, "@babel/helper-builder-binary-assignment-operator-visitor": { @@ -21746,7 +21740,6 @@ "version": "7.20.0", "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.20.0.tgz", "integrity": "sha512-0jp//vDGp9e8hZzBc6N/KwA5ZK3Wsm/pfm4CrY7vzegkVxc65SgSn6wYOnwHe9Js9HRQ1YTCKLGPzDtaS3RoLQ==", - "dev": true, "requires": { "@babel/compat-data": "^7.20.0", "@babel/helper-validator-option": "^7.18.6", @@ -21835,18 +21828,17 @@ } }, "@babel/helper-module-imports": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.18.6.tgz", - "integrity": "sha512-0NFvs3VkuSYbFi1x2Vd6tKrywq+z/cLeYC/RJNFrIX/30Bf5aiGYbtvGXolEktzJH8o5E5KJ3tT+nkxuuZFVlA==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.22.5.tgz", + "integrity": "sha512-8Dl6+HD/cKifutF5qGd/8ZJi84QeAKh+CEe1sBzz8UayBBGg1dAIJrdHOcOM5b2MpzWL2yuotJTtGjETq0qjXg==", "requires": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" } }, "@babel/helper-module-transforms": { "version": "7.20.2", "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.20.2.tgz", "integrity": "sha512-zvBKyJXRbmK07XhMuujYoJ48B5yvvmM6+wcpv6Ivj4Yg6qO7NOZOSnvZN9CRl1zz1Z4cKf8YejmCMh8clOoOeA==", - "dev": true, "requires": { "@babel/helper-environment-visitor": "^7.18.9", "@babel/helper-module-imports": "^7.18.6", @@ -21868,10 +21860,9 @@ } }, "@babel/helper-plugin-utils": { - "version": "7.20.2", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.20.2.tgz", - "integrity": "sha512-8RvlJG2mj4huQ4pZ+rU9lqKi9ZKiRmuvGuM2HlWmkmgOhbs6zEAw6IEiJ5cQqGbDzGZOhwuOQNtZMi/ENLjZoQ==", - "dev": true + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz", + "integrity": "sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg==" }, "@babel/helper-remap-async-to-generator": { "version": "7.18.9", @@ -21903,7 +21894,6 @@ "version": "7.20.2", "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.20.2.tgz", "integrity": "sha512-+0woI/WPq59IrqDYbVGfshjT5Dmk/nnbdpcF8SnMhhXObpTq2KNBdLFRFrkVdbDOyUmHBCxzm5FHV1rACIkIbA==", - "dev": true, "requires": { "@babel/types": "^7.20.2" } @@ -21926,20 +21916,19 @@ } }, "@babel/helper-string-parser": { - "version": "7.19.4", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.19.4.tgz", - "integrity": "sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==" + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", + "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==" }, "@babel/helper-validator-identifier": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", - "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==" + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz", + "integrity": "sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==" }, "@babel/helper-validator-option": { "version": "7.21.0", "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.21.0.tgz", - "integrity": "sha512-rmL/B8/f0mKS2baE9ZpyTcTavvEuWhTTW8amjzXNvYG4AwBsqTLikfXsEofsJEfKHf+HQVQbFOHy6o+4cnC/fQ==", - "dev": true + "integrity": "sha512-rmL/B8/f0mKS2baE9ZpyTcTavvEuWhTTW8amjzXNvYG4AwBsqTLikfXsEofsJEfKHf+HQVQbFOHy6o+4cnC/fQ==" }, "@babel/helper-wrap-function": { "version": "7.19.0", @@ -21957,7 +21946,6 @@ "version": "7.20.1", "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.20.1.tgz", "integrity": "sha512-J77mUVaDTUJFZ5BpP6mMn6OIl3rEWymk2ZxDBQJUG3P+PbmyMcF3bYWvz0ma69Af1oobDqT/iAsvzhB58xhQUg==", - "dev": true, "requires": { "@babel/template": "^7.18.10", "@babel/traverse": "^7.20.1", @@ -22221,6 +22209,14 @@ "@babel/helper-plugin-utils": "^7.8.0" } }, + "@babel/plugin-syntax-jsx": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.22.5.tgz", + "integrity": "sha512-gvyP4hZrgrs/wWMaocvxZ44Hw0b3W8Pe+cMxc8V1ULQ07oh8VNbIRaoD1LRZVTvD+0nieDKjfgKg89sD7rrKrg==", + "requires": { + "@babel/helper-plugin-utils": "^7.22.5" + } + }, "@babel/plugin-syntax-logical-assignment-operators": { "version": "7.10.4", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz", @@ -22740,12 +22736,12 @@ } }, "@babel/types": { - "version": "7.21.3", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.21.3.tgz", - "integrity": "sha512-sBGdETxC+/M4o/zKC0sl6sjWv62WFR/uzxrJ6uYyMLZOUlPnwzw0tKgVHOXxaAd5l2g8pEDM5RZ495GPQI77kg==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.5.tgz", + "integrity": "sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA==", "requires": { - "@babel/helper-string-parser": "^7.19.4", - "@babel/helper-validator-identifier": "^7.19.1", + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.5", "to-fast-properties": "^2.0.0" } }, @@ -22824,17 +22820,17 @@ "dev": true }, "@emotion/is-prop-valid": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-1.2.0.tgz", - "integrity": "sha512-3aDpDprjM0AwaxGE09bOPkNxHpBd+kA6jty3RnaEXdweX1DF1U3VQpPYb0g1IStAuK7SVQ1cy+bNBBKp4W3Fjg==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-1.2.1.tgz", + "integrity": "sha512-61Mf7Ufx4aDxx1xlDeOm8aFFigGHE4z+0sKCa+IHCeZKiyP9RLD0Mmx7m8b9/Cf37f7NAvQOOJAbQQGVr5uERw==", "requires": { - "@emotion/memoize": "^0.8.0" + "@emotion/memoize": "^0.8.1" } }, "@emotion/memoize": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.8.0.tgz", - "integrity": "sha512-G/YwXTkv7Den9mXDO7AhLWkE3q+I92B+VqAE+dYG4NGPaHZGvt3G8Q0p9vmE+sq7rTGphUbAvmQ9YpbfMQGGlA==" + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.8.1.tgz", + "integrity": "sha512-W2P2c/VRW1/1tLox0mVUalvnWXxavmv/Oum2aPsRcoDJuob75FC3Y8FbpfLwUegRcxINtGUMPq0tFCvYNTBXNA==" }, "@emotion/stylis": { "version": "0.8.5", @@ -22847,23 +22843,23 @@ "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" }, "@esbuild/android-arm": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.5.tgz", - "integrity": "sha512-crmPUzgCmF+qZXfl1YkiFoUta2XAfixR1tEnr/gXIixE+WL8Z0BGqfydP5oox0EUOgQMMRgtATtakyAcClQVqQ==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.11.tgz", + "integrity": "sha512-q4qlUf5ucwbUJZXF5tEQ8LF7y0Nk4P58hOsGk3ucY0oCwgQqAnqXVbUuahCddVHfrxmpyewRpiTHwVHIETYu7Q==", "optional": true, "peer": true }, "@esbuild/android-arm64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.17.5.tgz", - "integrity": "sha512-KHWkDqYAMmKZjY4RAN1PR96q6UOtfkWlTS8uEwWxdLtkRt/0F/csUhXIrVfaSIFxnscIBMPynGfhsMwQDRIBQw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.11.tgz", + "integrity": "sha512-snieiq75Z1z5LJX9cduSAjUr7vEI1OdlzFPMw0HH5YI7qQHDd3qs+WZoMrWYDsfRJSq36lIA6mfZBkvL46KoIw==", "optional": true, "peer": true }, "@esbuild/android-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.17.5.tgz", - "integrity": "sha512-8fI/AnIdmWz/+1iza2WrCw8kwXK9wZp/yZY/iS8ioC+U37yJCeppi9EHY05ewJKN64ASoBIseufZROtcFnX5GA==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.11.tgz", + "integrity": "sha512-iPuoxQEV34+hTF6FT7om+Qwziv1U519lEOvekXO9zaMMlT9+XneAhKL32DW3H7okrCOBQ44BMihE8dclbZtTuw==", "optional": true, "peer": true }, @@ -22874,79 +22870,79 @@ "optional": true }, "@esbuild/darwin-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.5.tgz", - "integrity": "sha512-ha7QCJh1fuSwwCgoegfdaljowwWozwTDjBgjD3++WAy/qwee5uUi1gvOg2WENJC6EUyHBOkcd3YmLDYSZ2TPPA==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.11.tgz", + "integrity": "sha512-N15Vzy0YNHu6cfyDOjiyfJlRJCB/ngKOAvoBf1qybG3eOq0SL2Lutzz9N7DYUbb7Q23XtHPn6lMDF6uWbGv9Fw==", "optional": true, "peer": true }, "@esbuild/freebsd-arm64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.5.tgz", - "integrity": "sha512-VbdXJkn2aI2pQ/wxNEjEcnEDwPpxt3CWWMFYmO7CcdFBoOsABRy2W8F3kjbF9F/pecEUDcI3b5i2w+By4VQFPg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.11.tgz", + "integrity": "sha512-atEyuq6a3omEY5qAh5jIORWk8MzFnCpSTUruBgeyN9jZq1K/QI9uke0ATi3MHu4L8c59CnIi4+1jDKMuqmR71A==", "optional": true, "peer": true }, "@esbuild/freebsd-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.17.5.tgz", - "integrity": "sha512-olgGYND1/XnnWxwhjtY3/ryjOG/M4WfcA6XH8dBTH1cxMeBemMODXSFhkw71Kf4TeZFFTN25YOomaNh0vq2iXg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.11.tgz", + "integrity": "sha512-XtuPrEfBj/YYYnAAB7KcorzzpGTvOr/dTtXPGesRfmflqhA4LMF0Gh/n5+a9JBzPuJ+CGk17CA++Hmr1F/gI0Q==", "optional": true, "peer": true }, "@esbuild/linux-arm": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.17.5.tgz", - "integrity": "sha512-YBdCyQwA3OQupi6W2/WO4FnI+NWFWe79cZEtlbqSESOHEg7a73htBIRiE6uHPQe7Yp5E4aALv+JxkRLGEUL7tw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.11.tgz", + "integrity": "sha512-Idipz+Taso/toi2ETugShXjQ3S59b6m62KmLHkJlSq/cBejixmIydqrtM2XTvNCywFl3VC7SreSf6NV0i6sRyg==", "optional": true, "peer": true }, "@esbuild/linux-arm64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.17.5.tgz", - "integrity": "sha512-8a0bqSwu3OlLCfu2FBbDNgQyBYdPJh1B9PvNX7jMaKGC9/KopgHs37t+pQqeMLzcyRqG6z55IGNQAMSlCpBuqg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.11.tgz", + "integrity": "sha512-c6Vh2WS9VFKxKZ2TvJdA7gdy0n6eSy+yunBvv4aqNCEhSWVor1TU43wNRp2YLO9Vng2G+W94aRz+ILDSwAiYog==", "optional": true, "peer": true }, "@esbuild/linux-ia32": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.17.5.tgz", - "integrity": "sha512-uCwm1r/+NdP7vndctgq3PoZrnmhmnecWAr114GWMRwg2QMFFX+kIWnp7IO220/JLgnXK/jP7VKAFBGmeOYBQYQ==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.11.tgz", + "integrity": "sha512-S3hkIF6KUqRh9n1Q0dSyYcWmcVa9Cg+mSoZEfFuzoYXXsk6196qndrM+ZiHNwpZKi3XOXpShZZ+9dfN5ykqjjw==", "optional": true, "peer": true }, "@esbuild/linux-loong64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.17.5.tgz", - "integrity": "sha512-3YxhSBl5Sb6TtBjJu+HP93poBruFzgXmf3PVfIe4xOXMj1XpxboYZyw3W8BhoX/uwxzZz4K1I99jTE/5cgDT1g==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.11.tgz", + "integrity": "sha512-MRESANOoObQINBA+RMZW+Z0TJWpibtE7cPFnahzyQHDCA9X9LOmGh68MVimZlM9J8n5Ia8lU773te6O3ILW8kw==", "optional": true, "peer": true }, "@esbuild/linux-mips64el": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.17.5.tgz", - "integrity": "sha512-Hy5Z0YVWyYHdtQ5mfmfp8LdhVwGbwVuq8mHzLqrG16BaMgEmit2xKO+iDakHs+OetEx0EN/2mUzDdfdktI+Nmg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.11.tgz", + "integrity": "sha512-qVyPIZrXNMOLYegtD1u8EBccCrBVshxMrn5MkuFc3mEVsw7CCQHaqZ4jm9hbn4gWY95XFnb7i4SsT3eflxZsUg==", "optional": true, "peer": true }, "@esbuild/linux-ppc64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.17.5.tgz", - "integrity": "sha512-5dbQvBLbU/Y3Q4ABc9gi23hww1mQcM7KZ9KBqabB7qhJswYMf8WrDDOSw3gdf3p+ffmijMd28mfVMvFucuECyg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.11.tgz", + "integrity": "sha512-T3yd8vJXfPirZaUOoA9D2ZjxZX4Gr3QuC3GztBJA6PklLotc/7sXTOuuRkhE9W/5JvJP/K9b99ayPNAD+R+4qQ==", "optional": true, "peer": true }, "@esbuild/linux-riscv64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.17.5.tgz", - "integrity": "sha512-fp/KUB/ZPzEWGTEUgz9wIAKCqu7CjH1GqXUO2WJdik1UNBQ7Xzw7myIajpxztE4Csb9504ERiFMxZg5KZ6HlZQ==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.11.tgz", + "integrity": "sha512-evUoRPWiwuFk++snjH9e2cAjF5VVSTj+Dnf+rkO/Q20tRqv+644279TZlPK8nUGunjPAtQRCj1jQkDAvL6rm2w==", "optional": true, "peer": true }, "@esbuild/linux-s390x": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.17.5.tgz", - "integrity": "sha512-kRV3yw19YDqHTp8SfHXfObUFXlaiiw4o2lvT1XjsPZ++22GqZwSsYWJLjMi1Sl7j9qDlDUduWDze/nQx0d6Lzw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.11.tgz", + "integrity": "sha512-/SlRJ15XR6i93gRWquRxYCfhTeC5PdqEapKoLbX63PLCmAkXZHY2uQm2l9bN0oPHBsOw2IswRZctMYS0MijFcg==", "optional": true, "peer": true }, @@ -22957,44 +22953,44 @@ "optional": true }, "@esbuild/netbsd-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.17.5.tgz", - "integrity": "sha512-cigBpdiSx/vPy7doUyImsQQBnBjV5f1M99ZUlaJckDAJjgXWl6y9W17FIfJTy8TxosEF6MXq+fpLsitMGts2nA==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.11.tgz", + "integrity": "sha512-aSjMHj/F7BuS1CptSXNg6S3M4F3bLp5wfFPIJM+Km2NfIVfFKhdmfHF9frhiCLIGVzDziggqWll0B+9AUbud/Q==", "optional": true, "peer": true }, "@esbuild/openbsd-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.17.5.tgz", - "integrity": "sha512-VdqRqPVIjjZfkf40LrqOaVuhw9EQiAZ/GNCSM2UplDkaIzYVsSnycxcFfAnHdWI8Gyt6dO15KHikbpxwx+xHbw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.11.tgz", + "integrity": "sha512-tNBq+6XIBZtht0xJGv7IBB5XaSyvYPCm1PxJ33zLQONdZoLVM0bgGqUrXnJyiEguD9LU4AHiu+GCXy/Hm9LsdQ==", "optional": true, "peer": true }, "@esbuild/sunos-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.17.5.tgz", - "integrity": "sha512-ItxPaJ3MBLtI4nK+mALLEoUs6amxsx+J1ibnfcYMkqaCqHST1AkF4aENpBehty3czqw64r/XqL+W9WqU6kc2Qw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.11.tgz", + "integrity": "sha512-kxfbDOrH4dHuAAOhr7D7EqaYf+W45LsAOOhAet99EyuxxQmjbk8M9N4ezHcEiCYPaiW8Dj3K26Z2V17Gt6p3ng==", "optional": true, "peer": true }, "@esbuild/win32-arm64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.17.5.tgz", - "integrity": "sha512-4u2Q6qsJTYNFdS9zHoAi80spzf78C16m2wla4eJPh4kSbRv+BpXIfl6TmBSWupD8e47B1NrTfrOlEuco7mYQtg==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.11.tgz", + "integrity": "sha512-Sh0dDRyk1Xi348idbal7lZyfSkjhJsdFeuC13zqdipsvMetlGiFQNdO+Yfp6f6B4FbyQm7qsk16yaZk25LChzg==", "optional": true, "peer": true }, "@esbuild/win32-ia32": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.17.5.tgz", - "integrity": "sha512-KYlm+Xu9TXsfTWAcocLuISRtqxKp/Y9ZBVg6CEEj0O5J9mn7YvBKzAszo2j1ndyzUPk+op+Tie2PJeN+BnXGqQ==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.11.tgz", + "integrity": "sha512-o9JUIKF1j0rqJTFbIoF4bXj6rvrTZYOrfRcGyL0Vm5uJ/j5CkBD/51tpdxe9lXEDouhRgdr/BYzUrDOvrWwJpg==", "optional": true, "peer": true }, "@esbuild/win32-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.5.tgz", - "integrity": "sha512-XgA9qWRqby7xdYXuF6KALsn37QGBMHsdhmnpjfZtYxKxbTOwfnDM6MYi2WuUku5poNaX2n9XGVr20zgT/2QwCw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.11.tgz", + "integrity": "sha512-rQI4cjLHd2hGsM1LqgDI7oOCYbQ6IBOVsX9ejuRMSze0GqXUG2ekwiKkiBU1pRGSeCqFFHxTrcEydB2Hyoz9CA==", "optional": true, "peer": true }, @@ -23118,9 +23114,8 @@ "dev": true }, "@ipfs-shipyard/ignite-metrics": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@ipfs-shipyard/ignite-metrics/-/ignite-metrics-1.3.0.tgz", - "integrity": "sha512-EKBgBHqIXIl82wlKN3pdIpOLC87cpIPtm7yrTGE8wSRsDe2ASEhu5wzbYYJ6InvtVA6AZsZ280VIuOubOG2usA==", + "version": "https://github.com/ipfs-shipyard/ignite-metrics/tarball/b2086f0b07062873d55b874d2721ab0b0ed3b9b8", + "integrity": "sha512-mpCxDqnelGBB3l4oPQjuMhMjoik+zK4MLTsYYBySZGnDnGaJDpEWXgd7NTg2FlvDhrpTVF0ff9QATaO08GR6hw==", "requires": { "@esbuild/darwin-arm64": "^0.16.17", "@esbuild/linux-x64": "^0.16.17", @@ -23132,6 +23127,13 @@ "react-refresh": "^0.14.0", "react-router-dom": "^6.6.2", "styled-components": "^5.3.6" + }, + "dependencies": { + "countly-sdk-web": { + "version": "22.6.5", + "resolved": "https://registry.npmjs.org/countly-sdk-web/-/countly-sdk-web-22.6.5.tgz", + "integrity": "sha512-KUTKWfdUbzfdKWnVJWVO4BNshWkflNVa4h/TQdOOUZqeTSpUVMnlugfTG7HfN4KioummarazcyaGUh3JIATlqg==" + } } }, "@ipld/dag-cbor": { @@ -23223,7 +23225,6 @@ "version": "0.1.1", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.1.1.tgz", "integrity": "sha512-sQXCasFk+U8lWYEe66WxRDOE9PjVz4vSM51fTu3Hw+ClTpUSQb718772vH3pyS5pShp6lvQM7SxgIDXXXmOX7w==", - "dev": true, "requires": { "@jridgewell/set-array": "^1.0.0", "@jridgewell/sourcemap-codec": "^1.4.10" @@ -23729,9 +23730,9 @@ "dev": true }, "@remix-run/router": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.3.1.tgz", - "integrity": "sha512-+eun1Wtf72RNRSqgU7qM2AMX/oHp+dnx7BHk1qhK5ZHzdHTUU4LA1mGG1vT+jMc8sbhG3orvsfOmryjzx2PzQw==" + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.7.1.tgz", + "integrity": "sha512-bgVQM4ZJ2u2CM8k1ey70o1ePFXsEzYVZoWghh6WjM8p59jQ7HxzbHW4SbnWFG7V9ig9chLawQxDTZ3xzOF8MkQ==" }, "@samverschueren/stream-to-observable": { "version": "0.3.1", @@ -25289,15 +25290,15 @@ } }, "babel-plugin-styled-components": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/babel-plugin-styled-components/-/babel-plugin-styled-components-2.0.7.tgz", - "integrity": "sha512-i7YhvPgVqRKfoQ66toiZ06jPNA3p6ierpfUuEWxNF+fV27Uv5gxBkf8KZLHUCc1nFA9j6+80pYoIpqCeyW3/bA==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/babel-plugin-styled-components/-/babel-plugin-styled-components-2.1.4.tgz", + "integrity": "sha512-Xgp9g+A/cG47sUyRwwYxGM4bR/jDRg5N6it/8+HxCnbT5XNKSKDT9xm4oag/osgqjC2It/vH0yXsomOG6k558g==", "requires": { - "@babel/helper-annotate-as-pure": "^7.16.0", - "@babel/helper-module-imports": "^7.16.0", - "babel-plugin-syntax-jsx": "^6.18.0", - "lodash": "^4.17.11", - "picomatch": "^2.3.0" + "@babel/helper-annotate-as-pure": "^7.22.5", + "@babel/helper-module-imports": "^7.22.5", + "@babel/plugin-syntax-jsx": "^7.22.5", + "lodash": "^4.17.21", + "picomatch": "^2.3.1" } }, "babel-plugin-syntax-async-generators": { @@ -25306,11 +25307,6 @@ "integrity": "sha512-EbciFN5Jb9iqU9bqaLmmFLx2G8pAUsvpWJ6OzOWBNrSY9qTohXj+7YfZx6Ug1Qqh7tCb1EA7Jvn9bMC1HBiucg==", "dev": true }, - "babel-plugin-syntax-jsx": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz", - "integrity": "sha512-qrPaCSo9c8RHNRHIotaufGbuOBN8rtdC4QrrFFc43vyWCCz7Kl7GL1PGaXtMGQZUXrkCjNEgxDfmAuAabr/rlw==" - }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -25552,7 +25548,6 @@ "version": "4.21.4", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.4.tgz", "integrity": "sha512-CBHJJdDmgjl3daYjN5Cp5kbTf1mUhZoS+beLklHIvkOWscs83YAhLlF3Wsh/lciQYAcbBJgTOD44VtG31ZM4Hw==", - "dev": true, "requires": { "caniuse-lite": "^1.0.30001400", "electron-to-chromium": "^1.4.251", @@ -25827,8 +25822,7 @@ "caniuse-lite": { "version": "1.0.30001434", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001434.tgz", - "integrity": "sha512-aOBHrLmTQw//WFa2rcF1If9fa3ypkC1wzqqiKHgfdrXTWcU8C4gKVZT77eQAPWN1APys3+uQ0Df07rKauXGEYA==", - "dev": true + "integrity": "sha512-aOBHrLmTQw//WFa2rcF1If9fa3ypkC1wzqqiKHgfdrXTWcU8C4gKVZT77eQAPWN1APys3+uQ0Df07rKauXGEYA==" }, "caseless": { "version": "0.12.0", @@ -26367,9 +26361,10 @@ "integrity": "sha512-vw6YRGJJu6sq9oZEz00SyAL7oyru+w1ct3P6TS0avMPRSZ/mqEXYq3l+Wtl89L/HwXcDymh8gY7JOOAPnI7vEg==" }, "countly-sdk-web": { - "version": "22.6.4", - "resolved": "https://registry.npmjs.org/countly-sdk-web/-/countly-sdk-web-22.6.4.tgz", - "integrity": "sha512-G2JWVqFrRHoEU4/G7D1EPn16jKzSaJD/mpWNK73+8JNPjuRhnSsdotCtekZnOAcT1yDM0r+NoXA9BKn0R87Jsw==" + "version": "23.2.2", + "resolved": "https://registry.npmjs.org/countly-sdk-web/-/countly-sdk-web-23.2.2.tgz", + "integrity": "sha512-Ply1KzgX05GBW8HeT0wDMG6JCmd1JwGxSXi4vFVkQN+VOhzR3Wf/6RFujwIzOitNkbOxEhyrUeT4lx9u2TknVQ==", + "dev": true }, "create-require": { "version": "1.1.1", @@ -26469,9 +26464,9 @@ } }, "css-to-react-native": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/css-to-react-native/-/css-to-react-native-3.1.0.tgz", - "integrity": "sha512-AryfkFA29b4I3vG7N4kxFboq15DxwSXzhXM37XNEjwJMgjYIc8BcqfiprpAqX0zadI5PMByEIwAMzXxk5Vcc4g==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/css-to-react-native/-/css-to-react-native-3.2.0.tgz", + "integrity": "sha512-e8RKaLXMOFii+02mOlqwjbD00KSEKqblnpO9e++1aXS1fPQOpS1YoqdVHBqPjHNoxeF2mimzVqawm2KCbEdtHQ==", "requires": { "camelize": "^1.0.0", "css-color-keywords": "^1.0.0", @@ -26976,8 +26971,7 @@ "electron-to-chromium": { "version": "1.4.284", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.284.tgz", - "integrity": "sha512-M8WEXFuKXMYMVr45fo8mq0wUrrJHheiKZf6BArTKk9ZBYCKJEOU5H8cdWgDT+qCVZf7Na4lVUaZsA+h6uA9+PA==", - "dev": true + "integrity": "sha512-M8WEXFuKXMYMVr45fo8mq0wUrrJHheiKZf6BArTKk9ZBYCKJEOU5H8cdWgDT+qCVZf7Na4lVUaZsA+h6uA9+PA==" }, "elegant-spinner": { "version": "1.0.1", @@ -27144,46 +27138,46 @@ "dev": true }, "esbuild": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.5.tgz", - "integrity": "sha512-Bu6WLCc9NMsNoMJUjGl3yBzTjVLXdysMltxQWiLAypP+/vQrf+3L1Xe8fCXzxaECus2cEJ9M7pk4yKatEwQMqQ==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.11.tgz", + "integrity": "sha512-i8u6mQF0JKJUlGR3OdFLKldJQMMs8OqM9Cc3UCi9XXziJ9WERM5bfkHaEAy0YAvPRMgqSW55W7xYn84XtEFTtA==", "peer": true, "requires": { - "@esbuild/android-arm": "0.17.5", - "@esbuild/android-arm64": "0.17.5", - "@esbuild/android-x64": "0.17.5", - "@esbuild/darwin-arm64": "0.17.5", - "@esbuild/darwin-x64": "0.17.5", - "@esbuild/freebsd-arm64": "0.17.5", - "@esbuild/freebsd-x64": "0.17.5", - "@esbuild/linux-arm": "0.17.5", - "@esbuild/linux-arm64": "0.17.5", - "@esbuild/linux-ia32": "0.17.5", - "@esbuild/linux-loong64": "0.17.5", - "@esbuild/linux-mips64el": "0.17.5", - "@esbuild/linux-ppc64": "0.17.5", - "@esbuild/linux-riscv64": "0.17.5", - "@esbuild/linux-s390x": "0.17.5", - "@esbuild/linux-x64": "0.17.5", - "@esbuild/netbsd-x64": "0.17.5", - "@esbuild/openbsd-x64": "0.17.5", - "@esbuild/sunos-x64": "0.17.5", - "@esbuild/win32-arm64": "0.17.5", - "@esbuild/win32-ia32": "0.17.5", - "@esbuild/win32-x64": "0.17.5" + "@esbuild/android-arm": "0.18.11", + "@esbuild/android-arm64": "0.18.11", + "@esbuild/android-x64": "0.18.11", + "@esbuild/darwin-arm64": "0.18.11", + "@esbuild/darwin-x64": "0.18.11", + "@esbuild/freebsd-arm64": "0.18.11", + "@esbuild/freebsd-x64": "0.18.11", + "@esbuild/linux-arm": "0.18.11", + "@esbuild/linux-arm64": "0.18.11", + "@esbuild/linux-ia32": "0.18.11", + "@esbuild/linux-loong64": "0.18.11", + "@esbuild/linux-mips64el": "0.18.11", + "@esbuild/linux-ppc64": "0.18.11", + "@esbuild/linux-riscv64": "0.18.11", + "@esbuild/linux-s390x": "0.18.11", + "@esbuild/linux-x64": "0.18.11", + "@esbuild/netbsd-x64": "0.18.11", + "@esbuild/openbsd-x64": "0.18.11", + "@esbuild/sunos-x64": "0.18.11", + "@esbuild/win32-arm64": "0.18.11", + "@esbuild/win32-ia32": "0.18.11", + "@esbuild/win32-x64": "0.18.11" }, "dependencies": { "@esbuild/darwin-arm64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.5.tgz", - "integrity": "sha512-EAvaoyIySV6Iif3NQCglUNpnMfHSUgC5ugt2efl3+QDntucJe5spn0udNZjTgNi6tKVqSceOw9tQ32liNZc1Xw==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.11.tgz", + "integrity": "sha512-Gm0QkI3k402OpfMKyQEEMG0RuW2LQsSmI6OeO4El2ojJMoF5NLYb3qMIjvbG/lbMeLOGiW6ooU8xqc+S0fgz2w==", "optional": true, "peer": true }, "@esbuild/linux-x64": { - "version": "0.17.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.5.tgz", - "integrity": "sha512-vnxuhh9e4pbtABNLbT2ANW4uwQ/zvcHRCm1JxaYkzSehugoFd5iXyC4ci1nhXU13mxEwCnrnTIiiSGwa/uAF1g==", + "version": "0.18.11", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.11.tgz", + "integrity": "sha512-xcncej+wF16WEmIwPtCHi0qmx1FweBqgsRtEL1mSHLFR6/mb3GEZfLQnx+pUDfRDEM4DQF8dpXIW7eDOZl1IbA==", "optional": true, "peer": true } @@ -27231,8 +27225,7 @@ "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", - "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", - "dev": true + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==" }, "escape-goat": { "version": "4.0.0", @@ -28581,8 +28574,7 @@ "gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", - "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", - "dev": true + "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==" }, "get-caller-file": { "version": "2.0.5", @@ -30365,8 +30357,7 @@ "json5": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz", - "integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==", - "dev": true + "integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==" }, "jsonfile": { "version": "2.4.0", @@ -30597,67 +30588,67 @@ } }, "lightningcss": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.18.0.tgz", - "integrity": "sha512-uk10tNxi5fhZqU93vtYiQgx/8a9f0Kvtj5AXIm+VlOXY+t/DWDmCZWJEkZJmmALgvbS6aAW8or+Kq85eJ6TDTw==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.21.5.tgz", + "integrity": "sha512-/pEUPeih2EwIx9n4T82aOG6CInN83tl/mWlw6B5gWLf36UplQi1L+5p3FUHsdt4fXVfOkkh9KIaM3owoq7ss8A==", "requires": { "detect-libc": "^1.0.3", - "lightningcss-darwin-arm64": "1.18.0", - "lightningcss-darwin-x64": "1.18.0", - "lightningcss-linux-arm-gnueabihf": "1.18.0", - "lightningcss-linux-arm64-gnu": "1.18.0", - "lightningcss-linux-arm64-musl": "1.18.0", - "lightningcss-linux-x64-gnu": "1.18.0", - "lightningcss-linux-x64-musl": "1.18.0", - "lightningcss-win32-x64-msvc": "1.18.0" + "lightningcss-darwin-arm64": "1.21.5", + "lightningcss-darwin-x64": "1.21.5", + "lightningcss-linux-arm-gnueabihf": "1.21.5", + "lightningcss-linux-arm64-gnu": "1.21.5", + "lightningcss-linux-arm64-musl": "1.21.5", + "lightningcss-linux-x64-gnu": "1.21.5", + "lightningcss-linux-x64-musl": "1.21.5", + "lightningcss-win32-x64-msvc": "1.21.5" } }, "lightningcss-darwin-arm64": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.18.0.tgz", - "integrity": "sha512-OqjydwtiNPgdH1ByIjA1YzqvDG/OMR6L3LPN6wRl1729LB0y4Mik7L06kmZaTb+pvUHr+NmDd2KCwnlrQ4zO3w==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.21.5.tgz", + "integrity": "sha512-z05hyLX85WY0UfhkFUOrWEFqD69lpVAmgl3aDzMKlIZJGygbhbegqb4PV8qfUrKKNBauut/qVNPKZglhTaDDxA==", "optional": true }, "lightningcss-darwin-x64": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.18.0.tgz", - "integrity": "sha512-mNiuPHj89/JHZmJMp+5H8EZSt6EL5DZRWJ31O6k3DrLLnRIQjXuXdDdN8kP7LoIkeWI5xvyD60CsReJm+YWYAw==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.21.5.tgz", + "integrity": "sha512-MSJhmej/U9MrdPxDk7+FWhO8+UqVoZUHG4VvKT5RQ4RJtqtANTiWiI97LvoVNMtdMnHaKs1Pkji6wHUFxjJsHQ==", "optional": true }, "lightningcss-linux-arm-gnueabihf": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.18.0.tgz", - "integrity": "sha512-S+25JjI6601HiAVoTDXW6SqH+E94a+FHA7WQqseyNHunOgVWKcAkNEc2LJvVxgwTq6z41sDIb9/M3Z9wa9lk4A==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.21.5.tgz", + "integrity": "sha512-xN6+5/JsMrbZHL1lPl+MiNJ3Xza12ueBKPepiyDCFQzlhFRTj7D0LG+cfNTzPBTO8KcYQynLpl1iBB8LGp3Xtw==", "optional": true }, "lightningcss-linux-arm64-gnu": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.18.0.tgz", - "integrity": "sha512-JSqh4+21dCgBecIQUet35dtE4PhhSEMyqe3y0ZNQrAJQ5kyUPSQHiw81WXnPJcOSTTpG0TyMLiC8K//+BsFGQA==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.21.5.tgz", + "integrity": "sha512-KfzFNhC4XTbmG3ma/xcTs/IhCwieW89XALIusKmnV0N618ZDXEB0XjWOYQRCXeK9mfqPdbTBpurEHV/XZtkniQ==", "optional": true }, "lightningcss-linux-arm64-musl": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.18.0.tgz", - "integrity": "sha512-2FWHa8iUhShnZnqhn2wfIcK5adJat9hAAaX7etNsoXJymlliDIOFuBQEsba2KBAZSM4QqfQtvRdR7m8i0I7ybQ==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.21.5.tgz", + "integrity": "sha512-bc0GytQO5Mn9QM6szaZ+31fQHNdidgpM1sSCwzPItz8hg3wOvKl8039rU0veMJV3ZgC9z0ypNRceLrSHeRHmXw==", "optional": true }, "lightningcss-linux-x64-gnu": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.18.0.tgz", - "integrity": "sha512-plCPGQJtDZHcLVKVRLnQVF2XRsIC32WvuJhQ7fJ7F6BV98b/VZX0OlX05qUaOESD9dCDHjYSfxsgcvOKgCWh7A==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.21.5.tgz", + "integrity": "sha512-JwMbgypPQgc2kW2av3OwzZ8cbrEuIiDiXPJdXRE6aVxu67yHauJawQLqJKTGUhiAhy6iLDG8Wg0a3/ziL+m+Kw==", "optional": true }, "lightningcss-linux-x64-musl": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.18.0.tgz", - "integrity": "sha512-na+BGtVU6fpZvOHKhnlA0XHeibkT3/46nj6vLluG3kzdJYoBKU6dIl7DSOk++8jv4ybZyFJ0aOFMMSc8g2h58A==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.21.5.tgz", + "integrity": "sha512-Ib8b6IQ/OR/VrPU6YBgy4T3QnuHY7DUa95O+nz+cwrTkMSN6fuHcTcIaz4t8TJ6HI5pl3uxUOZjmtls2pyQWow==", "optional": true }, "lightningcss-win32-x64-msvc": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.18.0.tgz", - "integrity": "sha512-5qeAH4RMNy2yMNEl7e5TI6upt/7xD2ZpHWH4RkT8iJ7/6POS5mjHbXWUO9Q1hhDhqkdzGa76uAdMzEouIeCyNw==", + "version": "1.21.5", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.21.5.tgz", + "integrity": "sha512-A8cSi8lUpBeVmoF+DqqW7cd0FemDbCuKr490IXdjyeI+KL8adpSKUs8tcqO0OXPh1EoDqK7JNkD/dELmd4Iz5g==", "optional": true }, "lines-and-columns": { @@ -31963,8 +31954,7 @@ "node-releases": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.6.tgz", - "integrity": "sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==", - "dev": true + "integrity": "sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==" }, "normalize-html-whitespace": { "version": "0.2.0", @@ -33524,20 +33514,20 @@ "optional": true }, "react-router": { - "version": "6.8.0", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.8.0.tgz", - "integrity": "sha512-760bk7y3QwabduExtudhWbd88IBbuD1YfwzpuDUAlJUJ7laIIcqhMvdhSVh1Fur1PE8cGl84L0dxhR3/gvHF7A==", + "version": "6.14.1", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.14.1.tgz", + "integrity": "sha512-U4PfgvG55LdvbQjg5Y9QRWyVxIdO1LlpYT7x+tMAxd9/vmiPuJhIwdxZuIQLN/9e3O4KFDHYfR9gzGeYMasW8g==", "requires": { - "@remix-run/router": "1.3.1" + "@remix-run/router": "1.7.1" } }, "react-router-dom": { - "version": "6.8.0", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.8.0.tgz", - "integrity": "sha512-hQouduSTywGJndE86CXJ2h7YEy4HYC6C/uh19etM+79FfQ6cFFFHnHyDlzO4Pq0eBUI96E4qVE5yUjA00yJZGQ==", + "version": "6.14.1", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.14.1.tgz", + "integrity": "sha512-ssF6M5UkQjHK70fgukCJyjlda0Dgono2QGwqGvuk7D+EDGHdacEN3Yke2LTMjkrpHuFwBfDFsEjGVXBDmL+bWw==", "requires": { - "@remix-run/router": "1.3.1", - "react-router": "6.8.0" + "@remix-run/router": "1.7.1", + "react-router": "6.14.1" } }, "read-pkg": { @@ -34132,8 +34122,7 @@ "semver": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" }, "semver-diff": { "version": "4.0.0", @@ -34944,9 +34933,9 @@ "requires": {} }, "styled-components": { - "version": "5.3.6", - "resolved": "https://registry.npmjs.org/styled-components/-/styled-components-5.3.6.tgz", - "integrity": "sha512-hGTZquGAaTqhGWldX7hhfzjnIYBZ0IXQXkCYdvF1Sq3DsUaLx6+NTHC5Jj1ooM2F68sBiVz3lvhfwQs/S3l6qg==", + "version": "5.3.11", + "resolved": "https://registry.npmjs.org/styled-components/-/styled-components-5.3.11.tgz", + "integrity": "sha512-uuzIIfnVkagcVHv9nE0VPlHPSCmXIUGKfJ42LNjxCCTDTL5sgnJ8Z7GZBq0EnLYGln77tPpEpExt2+qa+cZqSw==", "requires": { "@babel/helper-module-imports": "^7.0.0", "@babel/traverse": "^7.4.5", @@ -36452,7 +36441,6 @@ "version": "1.0.10", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz", "integrity": "sha512-OztqDenkfFkbSG+tRxBeAnCVPckDBcvibKd35yDONx6OU8N7sqgwc7rCbkJ/WcYtVRZ4ba68d6byhC21GFh7sQ==", - "dev": true, "requires": { "escalade": "^3.1.1", "picocolors": "^1.0.0" diff --git a/package.json b/package.json index e3c7d459e..257b016dd 100644 --- a/package.json +++ b/package.json @@ -105,6 +105,7 @@ "bufferutil": "^4.0.7", "c8": "7.12.0", "chai": "4.3.7", + "countly-sdk-web": "^23.2.2", "cross-env": "7.0.3", "css-loader": "6.7.2", "download-cli": "1.1.1", @@ -152,7 +153,7 @@ "webpack-merge": "5.8.0" }, "dependencies": { - "@ipfs-shipyard/ignite-metrics": "1.3.0", + "@ipfs-shipyard/ignite-metrics": "https://github.com/ipfs-shipyard/ignite-metrics/tarball/b2086f0b07062873d55b874d2721ab0b0ed3b9b8", "@material/switch": "10.0.0", "assert": "2.0.0", "buffer": "6.0.3", From d504c71d33a70ef48711f5cf034062a010e173a3 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 13 Jul 2023 00:16:59 -0600 Subject: [PATCH 04/63] fix(mv3): Countly Patching + ignite-metrics@2.0.0 Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- package-lock.json | 378 +++++++++++++-------------- package.json | 2 +- patches/countly-sdk-web+23.2.2.patch | 84 +++--- 3 files changed, 229 insertions(+), 235 deletions(-) diff --git a/package-lock.json b/package-lock.json index fb5803d6c..80c09a974 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.0.0", "license": "CC0-1.0", "dependencies": { - "@ipfs-shipyard/ignite-metrics": "https://github.com/ipfs-shipyard/ignite-metrics/tarball/b2086f0b07062873d55b874d2721ab0b0ed3b9b8", + "@ipfs-shipyard/ignite-metrics": "^2.0.0", "@material/switch": "10.0.0", "assert": "2.0.0", "buffer": "6.0.3", @@ -1808,9 +1808,9 @@ "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" }, "node_modules/@esbuild/android-arm": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.11.tgz", - "integrity": "sha512-q4qlUf5ucwbUJZXF5tEQ8LF7y0Nk4P58hOsGk3ucY0oCwgQqAnqXVbUuahCddVHfrxmpyewRpiTHwVHIETYu7Q==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.12.tgz", + "integrity": "sha512-LIxaNIQfkFZbTLb4+cX7dozHlAbAshhFE5PKdro0l+FnCpx1GDJaQ2WMcqm+ToXKMt8p8Uojk/MFRuGyz3V5Sw==", "cpu": [ "arm" ], @@ -1824,9 +1824,9 @@ } }, "node_modules/@esbuild/android-arm64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.11.tgz", - "integrity": "sha512-snieiq75Z1z5LJX9cduSAjUr7vEI1OdlzFPMw0HH5YI7qQHDd3qs+WZoMrWYDsfRJSq36lIA6mfZBkvL46KoIw==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.12.tgz", + "integrity": "sha512-BMAlczRqC/LUt2P97E4apTBbkvS9JTJnp2DKFbCwpZ8vBvXVbNdqmvzW/OsdtI/+mGr+apkkpqGM8WecLkPgrA==", "cpu": [ "arm64" ], @@ -1840,9 +1840,9 @@ } }, "node_modules/@esbuild/android-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.11.tgz", - "integrity": "sha512-iPuoxQEV34+hTF6FT7om+Qwziv1U519lEOvekXO9zaMMlT9+XneAhKL32DW3H7okrCOBQ44BMihE8dclbZtTuw==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.12.tgz", + "integrity": "sha512-zU5MyluNsykf5cOJ0LZZZjgAHbhPJ1cWfdH1ZXVMXxVMhEV0VZiZXQdwBBVvmvbF28EizeK7obG9fs+fpmS0eQ==", "cpu": [ "x64" ], @@ -1871,9 +1871,9 @@ } }, "node_modules/@esbuild/darwin-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.11.tgz", - "integrity": "sha512-N15Vzy0YNHu6cfyDOjiyfJlRJCB/ngKOAvoBf1qybG3eOq0SL2Lutzz9N7DYUbb7Q23XtHPn6lMDF6uWbGv9Fw==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.12.tgz", + "integrity": "sha512-ohqLPc7i67yunArPj1+/FeeJ7AgwAjHqKZ512ADk3WsE3FHU9l+m5aa7NdxXr0HmN1bjDlUslBjWNbFlD9y12Q==", "cpu": [ "x64" ], @@ -1887,9 +1887,9 @@ } }, "node_modules/@esbuild/freebsd-arm64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.11.tgz", - "integrity": "sha512-atEyuq6a3omEY5qAh5jIORWk8MzFnCpSTUruBgeyN9jZq1K/QI9uke0ATi3MHu4L8c59CnIi4+1jDKMuqmR71A==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.12.tgz", + "integrity": "sha512-GIIHtQXqgeOOqdG16a/A9N28GpkvjJnjYMhOnXVbn3EDJcoItdR58v/pGN31CHjyXDc8uCcRnFWmqaJt24AYJg==", "cpu": [ "arm64" ], @@ -1903,9 +1903,9 @@ } }, "node_modules/@esbuild/freebsd-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.11.tgz", - "integrity": "sha512-XtuPrEfBj/YYYnAAB7KcorzzpGTvOr/dTtXPGesRfmflqhA4LMF0Gh/n5+a9JBzPuJ+CGk17CA++Hmr1F/gI0Q==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.12.tgz", + "integrity": "sha512-zK0b9a1/0wZY+6FdOS3BpZcPc1kcx2G5yxxfEJtEUzVxI6n/FrC2Phsxj/YblPuBchhBZ/1wwn7AyEBUyNSa6g==", "cpu": [ "x64" ], @@ -1919,9 +1919,9 @@ } }, "node_modules/@esbuild/linux-arm": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.11.tgz", - "integrity": "sha512-Idipz+Taso/toi2ETugShXjQ3S59b6m62KmLHkJlSq/cBejixmIydqrtM2XTvNCywFl3VC7SreSf6NV0i6sRyg==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.12.tgz", + "integrity": "sha512-y75OijvrBE/1XRrXq1jtrJfG26eHeMoqLJ2dwQNwviwTuTtHGCojsDO6BJNF8gU+3jTn1KzJEMETytwsFSvc+Q==", "cpu": [ "arm" ], @@ -1935,9 +1935,9 @@ } }, "node_modules/@esbuild/linux-arm64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.11.tgz", - "integrity": "sha512-c6Vh2WS9VFKxKZ2TvJdA7gdy0n6eSy+yunBvv4aqNCEhSWVor1TU43wNRp2YLO9Vng2G+W94aRz+ILDSwAiYog==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.12.tgz", + "integrity": "sha512-JKgG8Q/LL/9sw/iHHxQyVMoQYu3rU3+a5Z87DxC+wAu3engz+EmctIrV+FGOgI6gWG1z1+5nDDbXiRMGQZXqiw==", "cpu": [ "arm64" ], @@ -1951,9 +1951,9 @@ } }, "node_modules/@esbuild/linux-ia32": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.11.tgz", - "integrity": "sha512-S3hkIF6KUqRh9n1Q0dSyYcWmcVa9Cg+mSoZEfFuzoYXXsk6196qndrM+ZiHNwpZKi3XOXpShZZ+9dfN5ykqjjw==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.12.tgz", + "integrity": "sha512-yoRIAqc0B4lDIAAEFEIu9ttTRFV84iuAl0KNCN6MhKLxNPfzwCBvEMgwco2f71GxmpBcTtn7KdErueZaM2rEvw==", "cpu": [ "ia32" ], @@ -1967,9 +1967,9 @@ } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.11.tgz", - "integrity": "sha512-MRESANOoObQINBA+RMZW+Z0TJWpibtE7cPFnahzyQHDCA9X9LOmGh68MVimZlM9J8n5Ia8lU773te6O3ILW8kw==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.12.tgz", + "integrity": "sha512-qYgt3dHPVvf/MgbIBpJ4Sup/yb9DAopZ3a2JgMpNKIHUpOdnJ2eHBo/aQdnd8dJ21X/+sS58wxHtA9lEazYtXQ==", "cpu": [ "loong64" ], @@ -1983,9 +1983,9 @@ } }, "node_modules/@esbuild/linux-mips64el": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.11.tgz", - "integrity": "sha512-qVyPIZrXNMOLYegtD1u8EBccCrBVshxMrn5MkuFc3mEVsw7CCQHaqZ4jm9hbn4gWY95XFnb7i4SsT3eflxZsUg==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.12.tgz", + "integrity": "sha512-wHphlMLK4ufNOONqukELfVIbnGQJrHJ/mxZMMrP2jYrPgCRZhOtf0kC4yAXBwnfmULimV1qt5UJJOw4Kh13Yfg==", "cpu": [ "mips64el" ], @@ -1999,9 +1999,9 @@ } }, "node_modules/@esbuild/linux-ppc64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.11.tgz", - "integrity": "sha512-T3yd8vJXfPirZaUOoA9D2ZjxZX4Gr3QuC3GztBJA6PklLotc/7sXTOuuRkhE9W/5JvJP/K9b99ayPNAD+R+4qQ==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.12.tgz", + "integrity": "sha512-TeN//1Ft20ZZW41+zDSdOI/Os1bEq5dbvBvYkberB7PHABbRcsteeoNVZFlI0YLpGdlBqohEpjrn06kv8heCJg==", "cpu": [ "ppc64" ], @@ -2015,9 +2015,9 @@ } }, "node_modules/@esbuild/linux-riscv64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.11.tgz", - "integrity": "sha512-evUoRPWiwuFk++snjH9e2cAjF5VVSTj+Dnf+rkO/Q20tRqv+644279TZlPK8nUGunjPAtQRCj1jQkDAvL6rm2w==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.12.tgz", + "integrity": "sha512-AgUebVS4DoAblBgiB2ACQ/8l4eGE5aWBb8ZXtkXHiET9mbj7GuWt3OnsIW/zX+XHJt2RYJZctbQ2S/mDjbp0UA==", "cpu": [ "riscv64" ], @@ -2031,9 +2031,9 @@ } }, "node_modules/@esbuild/linux-s390x": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.11.tgz", - "integrity": "sha512-/SlRJ15XR6i93gRWquRxYCfhTeC5PdqEapKoLbX63PLCmAkXZHY2uQm2l9bN0oPHBsOw2IswRZctMYS0MijFcg==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.12.tgz", + "integrity": "sha512-dJ3Rb3Ei2u/ysSXd6pzleGtfDdc2MuzKt8qc6ls8vreP1G3B7HInX3i7gXS4BGeVd24pp0yqyS7bJ5NHaI9ing==", "cpu": [ "s390x" ], @@ -2062,9 +2062,9 @@ } }, "node_modules/@esbuild/netbsd-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.11.tgz", - "integrity": "sha512-aSjMHj/F7BuS1CptSXNg6S3M4F3bLp5wfFPIJM+Km2NfIVfFKhdmfHF9frhiCLIGVzDziggqWll0B+9AUbud/Q==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.12.tgz", + "integrity": "sha512-55FzVCAiwE9FK8wWeCRuvjazNRJ1QqLCYGZVB6E8RuQuTeStSwotpSW4xoRGwp3a1wUsaVCdYcj5LGCASVJmMg==", "cpu": [ "x64" ], @@ -2078,9 +2078,9 @@ } }, "node_modules/@esbuild/openbsd-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.11.tgz", - "integrity": "sha512-tNBq+6XIBZtht0xJGv7IBB5XaSyvYPCm1PxJ33zLQONdZoLVM0bgGqUrXnJyiEguD9LU4AHiu+GCXy/Hm9LsdQ==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.12.tgz", + "integrity": "sha512-qnluf8rfb6Y5Lw2tirfK2quZOBbVqmwxut7GPCIJsM8lc4AEUj9L8y0YPdLaPK0TECt4IdyBdBD/KRFKorlK3g==", "cpu": [ "x64" ], @@ -2094,9 +2094,9 @@ } }, "node_modules/@esbuild/sunos-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.11.tgz", - "integrity": "sha512-kxfbDOrH4dHuAAOhr7D7EqaYf+W45LsAOOhAet99EyuxxQmjbk8M9N4ezHcEiCYPaiW8Dj3K26Z2V17Gt6p3ng==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.12.tgz", + "integrity": "sha512-+RkKpVQR7bICjTOPUpkTBTaJ4TFqQBX5Ywyd/HSdDkQGn65VPkTsR/pL4AMvuMWy+wnXgIl4EY6q4mVpJal8Kg==", "cpu": [ "x64" ], @@ -2110,9 +2110,9 @@ } }, "node_modules/@esbuild/win32-arm64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.11.tgz", - "integrity": "sha512-Sh0dDRyk1Xi348idbal7lZyfSkjhJsdFeuC13zqdipsvMetlGiFQNdO+Yfp6f6B4FbyQm7qsk16yaZk25LChzg==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.12.tgz", + "integrity": "sha512-GNHuciv0mFM7ouzsU0+AwY+7eV4Mgo5WnbhfDCQGtpvOtD1vbOiRjPYG6dhmMoFyBjj+pNqQu2X+7DKn0KQ/Gw==", "cpu": [ "arm64" ], @@ -2126,9 +2126,9 @@ } }, "node_modules/@esbuild/win32-ia32": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.11.tgz", - "integrity": "sha512-o9JUIKF1j0rqJTFbIoF4bXj6rvrTZYOrfRcGyL0Vm5uJ/j5CkBD/51tpdxe9lXEDouhRgdr/BYzUrDOvrWwJpg==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.12.tgz", + "integrity": "sha512-kR8cezhYipbbypGkaqCTWIeu4zID17gamC8YTPXYtcN3E5BhhtTnwKBn9I0PJur/T6UVwIEGYzkffNL0lFvxEw==", "cpu": [ "ia32" ], @@ -2142,9 +2142,9 @@ } }, "node_modules/@esbuild/win32-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.11.tgz", - "integrity": "sha512-rQI4cjLHd2hGsM1LqgDI7oOCYbQ6IBOVsX9ejuRMSze0GqXUG2ekwiKkiBU1pRGSeCqFFHxTrcEydB2Hyoz9CA==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.12.tgz", + "integrity": "sha512-O0UYQVkvfM/jO8a4OwoV0mAKSJw+mjWTAd1MJd/1FCX6uiMdLmMRPK/w6e9OQ0ob2WGxzIm9va/KG0Ja4zIOgg==", "cpu": [ "x64" ], @@ -2301,10 +2301,9 @@ "dev": true }, "node_modules/@ipfs-shipyard/ignite-metrics": { - "version": "1.3.0", - "resolved": "https://github.com/ipfs-shipyard/ignite-metrics/tarball/b2086f0b07062873d55b874d2721ab0b0ed3b9b8", - "integrity": "sha512-mpCxDqnelGBB3l4oPQjuMhMjoik+zK4MLTsYYBySZGnDnGaJDpEWXgd7NTg2FlvDhrpTVF0ff9QATaO08GR6hw==", - "license": "Apache-2.0 OR MIT", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@ipfs-shipyard/ignite-metrics/-/ignite-metrics-2.0.0.tgz", + "integrity": "sha512-Iu8HY5PjKulmwFYmg6tdORyfxL5AygpEi2vRemf2i+npI975qS7L3BbLBnzbxQSU/s+D014wDjRfLJuekklneQ==", "dependencies": { "countly-sdk-nodejs": "^22.6.0", "countly-sdk-web": "^22.6.4", @@ -7614,9 +7613,9 @@ } }, "node_modules/esbuild": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.11.tgz", - "integrity": "sha512-i8u6mQF0JKJUlGR3OdFLKldJQMMs8OqM9Cc3UCi9XXziJ9WERM5bfkHaEAy0YAvPRMgqSW55W7xYn84XtEFTtA==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.12.tgz", + "integrity": "sha512-XuOVLDdtsDslXStStduT41op21Ytmf4/BDS46aa3xPJ7X5h2eMWBF1oAe3QjUH3bDksocNXgzGUZ7XHIBya6Tg==", "hasInstallScript": true, "peer": true, "bin": { @@ -7626,28 +7625,28 @@ "node": ">=12" }, "optionalDependencies": { - "@esbuild/android-arm": "0.18.11", - "@esbuild/android-arm64": "0.18.11", - "@esbuild/android-x64": "0.18.11", - "@esbuild/darwin-arm64": "0.18.11", - "@esbuild/darwin-x64": "0.18.11", - "@esbuild/freebsd-arm64": "0.18.11", - "@esbuild/freebsd-x64": "0.18.11", - "@esbuild/linux-arm": "0.18.11", - "@esbuild/linux-arm64": "0.18.11", - "@esbuild/linux-ia32": "0.18.11", - "@esbuild/linux-loong64": "0.18.11", - "@esbuild/linux-mips64el": "0.18.11", - "@esbuild/linux-ppc64": "0.18.11", - "@esbuild/linux-riscv64": "0.18.11", - "@esbuild/linux-s390x": "0.18.11", - "@esbuild/linux-x64": "0.18.11", - "@esbuild/netbsd-x64": "0.18.11", - "@esbuild/openbsd-x64": "0.18.11", - "@esbuild/sunos-x64": "0.18.11", - "@esbuild/win32-arm64": "0.18.11", - "@esbuild/win32-ia32": "0.18.11", - "@esbuild/win32-x64": "0.18.11" + "@esbuild/android-arm": "0.18.12", + "@esbuild/android-arm64": "0.18.12", + "@esbuild/android-x64": "0.18.12", + "@esbuild/darwin-arm64": "0.18.12", + "@esbuild/darwin-x64": "0.18.12", + "@esbuild/freebsd-arm64": "0.18.12", + "@esbuild/freebsd-x64": "0.18.12", + "@esbuild/linux-arm": "0.18.12", + "@esbuild/linux-arm64": "0.18.12", + "@esbuild/linux-ia32": "0.18.12", + "@esbuild/linux-loong64": "0.18.12", + "@esbuild/linux-mips64el": "0.18.12", + "@esbuild/linux-ppc64": "0.18.12", + "@esbuild/linux-riscv64": "0.18.12", + "@esbuild/linux-s390x": "0.18.12", + "@esbuild/linux-x64": "0.18.12", + "@esbuild/netbsd-x64": "0.18.12", + "@esbuild/openbsd-x64": "0.18.12", + "@esbuild/sunos-x64": "0.18.12", + "@esbuild/win32-arm64": "0.18.12", + "@esbuild/win32-ia32": "0.18.12", + "@esbuild/win32-x64": "0.18.12" } }, "node_modules/esbuild-css-modules-plugin": { @@ -7702,9 +7701,9 @@ } }, "node_modules/esbuild/node_modules/@esbuild/darwin-arm64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.11.tgz", - "integrity": "sha512-Gm0QkI3k402OpfMKyQEEMG0RuW2LQsSmI6OeO4El2ojJMoF5NLYb3qMIjvbG/lbMeLOGiW6ooU8xqc+S0fgz2w==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.12.tgz", + "integrity": "sha512-zUZMep7YONnp6954QOOwEBwFX9svlKd3ov6PkxKd53LGTHsp/gy7vHaPGhhjBmEpqXEXShi6dddjIkmd+NgMsA==", "cpu": [ "arm64" ], @@ -7718,9 +7717,9 @@ } }, "node_modules/esbuild/node_modules/@esbuild/linux-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.11.tgz", - "integrity": "sha512-xcncej+wF16WEmIwPtCHi0qmx1FweBqgsRtEL1mSHLFR6/mb3GEZfLQnx+pUDfRDEM4DQF8dpXIW7eDOZl1IbA==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.12.tgz", + "integrity": "sha512-OrNJMGQbPaVyHHcDF8ybNSwu7TDOfX8NGpXCbetwOSP6txOJiWlgQnRymfC9ocR1S0Y5PW0Wb1mV6pUddqmvmQ==", "cpu": [ "x64" ], @@ -22843,23 +22842,23 @@ "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" }, "@esbuild/android-arm": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.11.tgz", - "integrity": "sha512-q4qlUf5ucwbUJZXF5tEQ8LF7y0Nk4P58hOsGk3ucY0oCwgQqAnqXVbUuahCddVHfrxmpyewRpiTHwVHIETYu7Q==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.12.tgz", + "integrity": "sha512-LIxaNIQfkFZbTLb4+cX7dozHlAbAshhFE5PKdro0l+FnCpx1GDJaQ2WMcqm+ToXKMt8p8Uojk/MFRuGyz3V5Sw==", "optional": true, "peer": true }, "@esbuild/android-arm64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.11.tgz", - "integrity": "sha512-snieiq75Z1z5LJX9cduSAjUr7vEI1OdlzFPMw0HH5YI7qQHDd3qs+WZoMrWYDsfRJSq36lIA6mfZBkvL46KoIw==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.12.tgz", + "integrity": "sha512-BMAlczRqC/LUt2P97E4apTBbkvS9JTJnp2DKFbCwpZ8vBvXVbNdqmvzW/OsdtI/+mGr+apkkpqGM8WecLkPgrA==", "optional": true, "peer": true }, "@esbuild/android-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.11.tgz", - "integrity": "sha512-iPuoxQEV34+hTF6FT7om+Qwziv1U519lEOvekXO9zaMMlT9+XneAhKL32DW3H7okrCOBQ44BMihE8dclbZtTuw==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.12.tgz", + "integrity": "sha512-zU5MyluNsykf5cOJ0LZZZjgAHbhPJ1cWfdH1ZXVMXxVMhEV0VZiZXQdwBBVvmvbF28EizeK7obG9fs+fpmS0eQ==", "optional": true, "peer": true }, @@ -22870,79 +22869,79 @@ "optional": true }, "@esbuild/darwin-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.11.tgz", - "integrity": "sha512-N15Vzy0YNHu6cfyDOjiyfJlRJCB/ngKOAvoBf1qybG3eOq0SL2Lutzz9N7DYUbb7Q23XtHPn6lMDF6uWbGv9Fw==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.12.tgz", + "integrity": "sha512-ohqLPc7i67yunArPj1+/FeeJ7AgwAjHqKZ512ADk3WsE3FHU9l+m5aa7NdxXr0HmN1bjDlUslBjWNbFlD9y12Q==", "optional": true, "peer": true }, "@esbuild/freebsd-arm64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.11.tgz", - "integrity": "sha512-atEyuq6a3omEY5qAh5jIORWk8MzFnCpSTUruBgeyN9jZq1K/QI9uke0ATi3MHu4L8c59CnIi4+1jDKMuqmR71A==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.12.tgz", + "integrity": "sha512-GIIHtQXqgeOOqdG16a/A9N28GpkvjJnjYMhOnXVbn3EDJcoItdR58v/pGN31CHjyXDc8uCcRnFWmqaJt24AYJg==", "optional": true, "peer": true }, "@esbuild/freebsd-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.11.tgz", - "integrity": "sha512-XtuPrEfBj/YYYnAAB7KcorzzpGTvOr/dTtXPGesRfmflqhA4LMF0Gh/n5+a9JBzPuJ+CGk17CA++Hmr1F/gI0Q==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.12.tgz", + "integrity": "sha512-zK0b9a1/0wZY+6FdOS3BpZcPc1kcx2G5yxxfEJtEUzVxI6n/FrC2Phsxj/YblPuBchhBZ/1wwn7AyEBUyNSa6g==", "optional": true, "peer": true }, "@esbuild/linux-arm": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.11.tgz", - "integrity": "sha512-Idipz+Taso/toi2ETugShXjQ3S59b6m62KmLHkJlSq/cBejixmIydqrtM2XTvNCywFl3VC7SreSf6NV0i6sRyg==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.12.tgz", + "integrity": "sha512-y75OijvrBE/1XRrXq1jtrJfG26eHeMoqLJ2dwQNwviwTuTtHGCojsDO6BJNF8gU+3jTn1KzJEMETytwsFSvc+Q==", "optional": true, "peer": true }, "@esbuild/linux-arm64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.11.tgz", - "integrity": "sha512-c6Vh2WS9VFKxKZ2TvJdA7gdy0n6eSy+yunBvv4aqNCEhSWVor1TU43wNRp2YLO9Vng2G+W94aRz+ILDSwAiYog==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.12.tgz", + "integrity": "sha512-JKgG8Q/LL/9sw/iHHxQyVMoQYu3rU3+a5Z87DxC+wAu3engz+EmctIrV+FGOgI6gWG1z1+5nDDbXiRMGQZXqiw==", "optional": true, "peer": true }, "@esbuild/linux-ia32": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.11.tgz", - "integrity": "sha512-S3hkIF6KUqRh9n1Q0dSyYcWmcVa9Cg+mSoZEfFuzoYXXsk6196qndrM+ZiHNwpZKi3XOXpShZZ+9dfN5ykqjjw==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.12.tgz", + "integrity": "sha512-yoRIAqc0B4lDIAAEFEIu9ttTRFV84iuAl0KNCN6MhKLxNPfzwCBvEMgwco2f71GxmpBcTtn7KdErueZaM2rEvw==", "optional": true, "peer": true }, "@esbuild/linux-loong64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.11.tgz", - "integrity": "sha512-MRESANOoObQINBA+RMZW+Z0TJWpibtE7cPFnahzyQHDCA9X9LOmGh68MVimZlM9J8n5Ia8lU773te6O3ILW8kw==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.12.tgz", + "integrity": "sha512-qYgt3dHPVvf/MgbIBpJ4Sup/yb9DAopZ3a2JgMpNKIHUpOdnJ2eHBo/aQdnd8dJ21X/+sS58wxHtA9lEazYtXQ==", "optional": true, "peer": true }, "@esbuild/linux-mips64el": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.11.tgz", - "integrity": "sha512-qVyPIZrXNMOLYegtD1u8EBccCrBVshxMrn5MkuFc3mEVsw7CCQHaqZ4jm9hbn4gWY95XFnb7i4SsT3eflxZsUg==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.12.tgz", + "integrity": "sha512-wHphlMLK4ufNOONqukELfVIbnGQJrHJ/mxZMMrP2jYrPgCRZhOtf0kC4yAXBwnfmULimV1qt5UJJOw4Kh13Yfg==", "optional": true, "peer": true }, "@esbuild/linux-ppc64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.11.tgz", - "integrity": "sha512-T3yd8vJXfPirZaUOoA9D2ZjxZX4Gr3QuC3GztBJA6PklLotc/7sXTOuuRkhE9W/5JvJP/K9b99ayPNAD+R+4qQ==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.12.tgz", + "integrity": "sha512-TeN//1Ft20ZZW41+zDSdOI/Os1bEq5dbvBvYkberB7PHABbRcsteeoNVZFlI0YLpGdlBqohEpjrn06kv8heCJg==", "optional": true, "peer": true }, "@esbuild/linux-riscv64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.11.tgz", - "integrity": "sha512-evUoRPWiwuFk++snjH9e2cAjF5VVSTj+Dnf+rkO/Q20tRqv+644279TZlPK8nUGunjPAtQRCj1jQkDAvL6rm2w==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.12.tgz", + "integrity": "sha512-AgUebVS4DoAblBgiB2ACQ/8l4eGE5aWBb8ZXtkXHiET9mbj7GuWt3OnsIW/zX+XHJt2RYJZctbQ2S/mDjbp0UA==", "optional": true, "peer": true }, "@esbuild/linux-s390x": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.11.tgz", - "integrity": "sha512-/SlRJ15XR6i93gRWquRxYCfhTeC5PdqEapKoLbX63PLCmAkXZHY2uQm2l9bN0oPHBsOw2IswRZctMYS0MijFcg==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.12.tgz", + "integrity": "sha512-dJ3Rb3Ei2u/ysSXd6pzleGtfDdc2MuzKt8qc6ls8vreP1G3B7HInX3i7gXS4BGeVd24pp0yqyS7bJ5NHaI9ing==", "optional": true, "peer": true }, @@ -22953,44 +22952,44 @@ "optional": true }, "@esbuild/netbsd-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.11.tgz", - "integrity": "sha512-aSjMHj/F7BuS1CptSXNg6S3M4F3bLp5wfFPIJM+Km2NfIVfFKhdmfHF9frhiCLIGVzDziggqWll0B+9AUbud/Q==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.12.tgz", + "integrity": "sha512-55FzVCAiwE9FK8wWeCRuvjazNRJ1QqLCYGZVB6E8RuQuTeStSwotpSW4xoRGwp3a1wUsaVCdYcj5LGCASVJmMg==", "optional": true, "peer": true }, "@esbuild/openbsd-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.11.tgz", - "integrity": "sha512-tNBq+6XIBZtht0xJGv7IBB5XaSyvYPCm1PxJ33zLQONdZoLVM0bgGqUrXnJyiEguD9LU4AHiu+GCXy/Hm9LsdQ==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.12.tgz", + "integrity": "sha512-qnluf8rfb6Y5Lw2tirfK2quZOBbVqmwxut7GPCIJsM8lc4AEUj9L8y0YPdLaPK0TECt4IdyBdBD/KRFKorlK3g==", "optional": true, "peer": true }, "@esbuild/sunos-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.11.tgz", - "integrity": "sha512-kxfbDOrH4dHuAAOhr7D7EqaYf+W45LsAOOhAet99EyuxxQmjbk8M9N4ezHcEiCYPaiW8Dj3K26Z2V17Gt6p3ng==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.12.tgz", + "integrity": "sha512-+RkKpVQR7bICjTOPUpkTBTaJ4TFqQBX5Ywyd/HSdDkQGn65VPkTsR/pL4AMvuMWy+wnXgIl4EY6q4mVpJal8Kg==", "optional": true, "peer": true }, "@esbuild/win32-arm64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.11.tgz", - "integrity": "sha512-Sh0dDRyk1Xi348idbal7lZyfSkjhJsdFeuC13zqdipsvMetlGiFQNdO+Yfp6f6B4FbyQm7qsk16yaZk25LChzg==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.12.tgz", + "integrity": "sha512-GNHuciv0mFM7ouzsU0+AwY+7eV4Mgo5WnbhfDCQGtpvOtD1vbOiRjPYG6dhmMoFyBjj+pNqQu2X+7DKn0KQ/Gw==", "optional": true, "peer": true }, "@esbuild/win32-ia32": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.11.tgz", - "integrity": "sha512-o9JUIKF1j0rqJTFbIoF4bXj6rvrTZYOrfRcGyL0Vm5uJ/j5CkBD/51tpdxe9lXEDouhRgdr/BYzUrDOvrWwJpg==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.12.tgz", + "integrity": "sha512-kR8cezhYipbbypGkaqCTWIeu4zID17gamC8YTPXYtcN3E5BhhtTnwKBn9I0PJur/T6UVwIEGYzkffNL0lFvxEw==", "optional": true, "peer": true }, "@esbuild/win32-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.11.tgz", - "integrity": "sha512-rQI4cjLHd2hGsM1LqgDI7oOCYbQ6IBOVsX9ejuRMSze0GqXUG2ekwiKkiBU1pRGSeCqFFHxTrcEydB2Hyoz9CA==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.12.tgz", + "integrity": "sha512-O0UYQVkvfM/jO8a4OwoV0mAKSJw+mjWTAd1MJd/1FCX6uiMdLmMRPK/w6e9OQ0ob2WGxzIm9va/KG0Ja4zIOgg==", "optional": true, "peer": true }, @@ -23114,8 +23113,9 @@ "dev": true }, "@ipfs-shipyard/ignite-metrics": { - "version": "https://github.com/ipfs-shipyard/ignite-metrics/tarball/b2086f0b07062873d55b874d2721ab0b0ed3b9b8", - "integrity": "sha512-mpCxDqnelGBB3l4oPQjuMhMjoik+zK4MLTsYYBySZGnDnGaJDpEWXgd7NTg2FlvDhrpTVF0ff9QATaO08GR6hw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@ipfs-shipyard/ignite-metrics/-/ignite-metrics-2.0.0.tgz", + "integrity": "sha512-Iu8HY5PjKulmwFYmg6tdORyfxL5AygpEi2vRemf2i+npI975qS7L3BbLBnzbxQSU/s+D014wDjRfLJuekklneQ==", "requires": { "@esbuild/darwin-arm64": "^0.16.17", "@esbuild/linux-x64": "^0.16.17", @@ -27138,46 +27138,46 @@ "dev": true }, "esbuild": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.11.tgz", - "integrity": "sha512-i8u6mQF0JKJUlGR3OdFLKldJQMMs8OqM9Cc3UCi9XXziJ9WERM5bfkHaEAy0YAvPRMgqSW55W7xYn84XtEFTtA==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.12.tgz", + "integrity": "sha512-XuOVLDdtsDslXStStduT41op21Ytmf4/BDS46aa3xPJ7X5h2eMWBF1oAe3QjUH3bDksocNXgzGUZ7XHIBya6Tg==", "peer": true, "requires": { - "@esbuild/android-arm": "0.18.11", - "@esbuild/android-arm64": "0.18.11", - "@esbuild/android-x64": "0.18.11", - "@esbuild/darwin-arm64": "0.18.11", - "@esbuild/darwin-x64": "0.18.11", - "@esbuild/freebsd-arm64": "0.18.11", - "@esbuild/freebsd-x64": "0.18.11", - "@esbuild/linux-arm": "0.18.11", - "@esbuild/linux-arm64": "0.18.11", - "@esbuild/linux-ia32": "0.18.11", - "@esbuild/linux-loong64": "0.18.11", - "@esbuild/linux-mips64el": "0.18.11", - "@esbuild/linux-ppc64": "0.18.11", - "@esbuild/linux-riscv64": "0.18.11", - "@esbuild/linux-s390x": "0.18.11", - "@esbuild/linux-x64": "0.18.11", - "@esbuild/netbsd-x64": "0.18.11", - "@esbuild/openbsd-x64": "0.18.11", - "@esbuild/sunos-x64": "0.18.11", - "@esbuild/win32-arm64": "0.18.11", - "@esbuild/win32-ia32": "0.18.11", - "@esbuild/win32-x64": "0.18.11" + "@esbuild/android-arm": "0.18.12", + "@esbuild/android-arm64": "0.18.12", + "@esbuild/android-x64": "0.18.12", + "@esbuild/darwin-arm64": "0.18.12", + "@esbuild/darwin-x64": "0.18.12", + "@esbuild/freebsd-arm64": "0.18.12", + "@esbuild/freebsd-x64": "0.18.12", + "@esbuild/linux-arm": "0.18.12", + "@esbuild/linux-arm64": "0.18.12", + "@esbuild/linux-ia32": "0.18.12", + "@esbuild/linux-loong64": "0.18.12", + "@esbuild/linux-mips64el": "0.18.12", + "@esbuild/linux-ppc64": "0.18.12", + "@esbuild/linux-riscv64": "0.18.12", + "@esbuild/linux-s390x": "0.18.12", + "@esbuild/linux-x64": "0.18.12", + "@esbuild/netbsd-x64": "0.18.12", + "@esbuild/openbsd-x64": "0.18.12", + "@esbuild/sunos-x64": "0.18.12", + "@esbuild/win32-arm64": "0.18.12", + "@esbuild/win32-ia32": "0.18.12", + "@esbuild/win32-x64": "0.18.12" }, "dependencies": { "@esbuild/darwin-arm64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.11.tgz", - "integrity": "sha512-Gm0QkI3k402OpfMKyQEEMG0RuW2LQsSmI6OeO4El2ojJMoF5NLYb3qMIjvbG/lbMeLOGiW6ooU8xqc+S0fgz2w==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.12.tgz", + "integrity": "sha512-zUZMep7YONnp6954QOOwEBwFX9svlKd3ov6PkxKd53LGTHsp/gy7vHaPGhhjBmEpqXEXShi6dddjIkmd+NgMsA==", "optional": true, "peer": true }, "@esbuild/linux-x64": { - "version": "0.18.11", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.11.tgz", - "integrity": "sha512-xcncej+wF16WEmIwPtCHi0qmx1FweBqgsRtEL1mSHLFR6/mb3GEZfLQnx+pUDfRDEM4DQF8dpXIW7eDOZl1IbA==", + "version": "0.18.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.12.tgz", + "integrity": "sha512-OrNJMGQbPaVyHHcDF8ybNSwu7TDOfX8NGpXCbetwOSP6txOJiWlgQnRymfC9ocR1S0Y5PW0Wb1mV6pUddqmvmQ==", "optional": true, "peer": true } diff --git a/package.json b/package.json index 257b016dd..a0280d833 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "webpack-merge": "5.8.0" }, "dependencies": { - "@ipfs-shipyard/ignite-metrics": "https://github.com/ipfs-shipyard/ignite-metrics/tarball/b2086f0b07062873d55b874d2721ab0b0ed3b9b8", + "@ipfs-shipyard/ignite-metrics": "^2.0.0", "@material/switch": "10.0.0", "assert": "2.0.0", "buffer": "6.0.3", diff --git a/patches/countly-sdk-web+23.2.2.patch b/patches/countly-sdk-web+23.2.2.patch index f3be4e813..a1e49df65 100644 --- a/patches/countly-sdk-web+23.2.2.patch +++ b/patches/countly-sdk-web+23.2.2.patch @@ -1,27 +1,21 @@ diff --git a/node_modules/countly-sdk-web/lib/countly.js b/node_modules/countly-sdk-web/lib/countly.js -index da26eb6..2a5e1c0 100644 +index da26eb6..0d82fd1 100644 --- a/node_modules/countly-sdk-web/lib/countly.js +++ b/node_modules/countly-sdk-web/lib/countly.js -@@ -52,10 +52,26 @@ +@@ -52,10 +52,20 @@ else { root.Countly = factory(root.Countly); } -}(typeof window !== "undefined" ? window : this, function(Countly) { +}(typeof globalThis !== "undefined" ? globalThis : this, function (Countly) { ++ const blackHoleProxy = handler => (target, ...args) => { ++ console.debug('Countly:Debug', handler, target, ...args); ++ return stubbedDocumentImpl; ++ }; + const stubbedDocumentImpl = new Proxy({}, { -+ get: (target, prop) => { -+ const domPropsFunctions = new Set([ -+ "setAttribute", -+ ]); -+ console.debug("stubbedDocumentImpl.get", prop, target, domPropsFunctions, domPropsFunctions.has(prop)); -+ if (domPropsFunctions.has(prop)) { -+ return (...args) => { -+ console.debug("stubbedDocumentImpl.get function", prop, target, args) -+ return stubbedDocumentImpl; -+ } -+ } -+ return stubbedDocumentImpl; -+ } ++ get: blackHoleProxy("stubbedDocumentImpl.get"), ++ apply: blackHoleProxy("stubbedDocumentImpl.apply"), ++ set: blackHoleProxy("stubbedDocumentImpl.set"), + }); + document = stubbedDocumentImpl; // Make sure the code is being run in a browser @@ -31,7 +25,7 @@ index da26eb6..2a5e1c0 100644 // TODO: check if logging can be added here, like: // console.error("Not running in browser"); return; -@@ -347,12 +363,12 @@ +@@ -347,12 +357,12 @@ checkIgnore(); @@ -47,7 +41,7 @@ index da26eb6..2a5e1c0 100644 } } else if (location.hash && location.hash.indexOf("#cly:") === 0) { -@@ -1028,7 +1044,7 @@ +@@ -1028,7 +1038,7 @@ if (this.enableOrientationTracking) { // report orientation this.report_orientation(); @@ -56,7 +50,7 @@ index da26eb6..2a5e1c0 100644 self.report_orientation(); }); } -@@ -1618,11 +1634,11 @@ +@@ -1618,11 +1628,11 @@ log(logLevelEnums.INFO, "track_errors, Started tracking errors"); // Indicated that for this instance of the countly error tracking is enabled Countly.i[this.app_key].tracking_crashes = true; @@ -71,7 +65,7 @@ index da26eb6..2a5e1c0 100644 // old browsers like IE 10 and Safari 9 won't give this value 'err' to us, but if it is provided we can trigger error recording immediately if (err !== undefined && err !== null) { // false indicates fatal error (as in non_fatal:false) -@@ -1630,7 +1646,7 @@ +@@ -1630,7 +1640,7 @@ } // fallback if no error object is present for older browsers, we create it instead else { @@ -80,7 +74,7 @@ index da26eb6..2a5e1c0 100644 var error = ""; if (typeof msg !== "undefined") { error += msg + "\n"; -@@ -1666,7 +1682,7 @@ +@@ -1666,7 +1676,7 @@ }; // error handling for 'uncaught rejections' @@ -89,7 +83,7 @@ index da26eb6..2a5e1c0 100644 // true indicates non fatal error (as in non_fatal: true) dispatchErrors(new Error("Unhandled rejection (reason: " + (event.reason && event.reason.stack ? event.reason.stack : event.reason) + ")."), true); }); -@@ -1909,13 +1925,13 @@ +@@ -1909,13 +1919,13 @@ this.begin_session(); this.start_time(); // end session on unload @@ -105,7 +99,7 @@ index da26eb6..2a5e1c0 100644 var hidden = "hidden"; /** -@@ -1931,17 +1947,17 @@ +@@ -1931,17 +1941,17 @@ } // add focus handling eventListeners @@ -129,7 +123,7 @@ index da26eb6..2a5e1c0 100644 } // Page Visibility API for changing tabs and minimizing browser -@@ -1971,10 +1987,10 @@ +@@ -1971,10 +1981,10 @@ inactivityCounter = 0; } @@ -144,7 +138,7 @@ index da26eb6..2a5e1c0 100644 // track user inactivity setInterval(function() { -@@ -2048,7 +2064,7 @@ +@@ -2048,7 +2058,7 @@ // truncate new segment segments = truncateObject(segments, self.maxKeyLength, self.maxValueSize, self.maxSegmentationValues, "track_pageview", log); if (this.track_domains) { @@ -153,7 +147,7 @@ index da26eb6..2a5e1c0 100644 } if (useSessionCookie) { -@@ -2071,7 +2087,7 @@ +@@ -2071,7 +2081,7 @@ else if (typeof document.referrer !== "undefined" && document.referrer.length) { var matches = urlParseRE.exec(document.referrer); // do not report referrers of current website @@ -162,7 +156,7 @@ index da26eb6..2a5e1c0 100644 segments.start = 1; } } -@@ -2147,7 +2163,7 @@ +@@ -2147,7 +2157,7 @@ // truncate new segment segments = truncateObject(segments, self.maxKeyLength, self.maxValueSize, self.maxSegmentationValues, "processClick", log); if (self.track_domains) { @@ -171,7 +165,7 @@ index da26eb6..2a5e1c0 100644 } add_cly_events({ key: internalEventKeyEnums.ACTION, -@@ -2173,7 +2189,7 @@ +@@ -2173,7 +2183,7 @@ if (parent) { log(logLevelEnums.INFO, "track_scrolls, Tracking the specified children"); } @@ -180,7 +174,7 @@ index da26eb6..2a5e1c0 100644 isScrollRegistryOpen = true; trackingScrolls = true; -@@ -2813,8 +2829,8 @@ +@@ -2813,8 +2823,8 @@ else { var pages = widgets[i].target_pages; for (var k = 0; k < pages.length; k++) { @@ -191,7 +185,7 @@ index da26eb6..2a5e1c0 100644 var isContainAsterisk = pages[k].includes("*"); if (((isContainAsterisk && isWildcardMatched) || isFullPathMatched) && !widgets[i].hide_sticker) { processWidget(widgets[i], true); -@@ -3048,7 +3064,7 @@ +@@ -3048,7 +3058,7 @@ return; } @@ -200,7 +194,7 @@ index da26eb6..2a5e1c0 100644 var feedbackWidgetFamily; // set feedback widget family as ratings and load related style file when type is ratings -@@ -3170,7 +3186,7 @@ +@@ -3170,7 +3180,7 @@ wrapper.appendChild(iframe); log(logLevelEnums.DEBUG, "present_feedback_widget, Appended the iframe"); @@ -209,7 +203,7 @@ index da26eb6..2a5e1c0 100644 var data = {}; try { data = JSON.parse(e.data); -@@ -3249,9 +3265,9 @@ +@@ -3249,9 +3259,9 @@ break; case "onScrollHalfwayDown": @@ -221,7 +215,7 @@ index da26eb6..2a5e1c0 100644 var documentHeight = getDocHeight(); if (scrollY >= (documentHeight / 2)) { surveyShown = true; -@@ -3841,13 +3857,13 @@ +@@ -3841,13 +3851,13 @@ var height = (screen.height) ? parseInt(screen.height) : 0; if (width !== 0 && height !== 0) { var iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform); @@ -239,7 +233,7 @@ index da26eb6..2a5e1c0 100644 // we have landscape orientation // switch values for all except ios var temp = width; -@@ -3860,8 +3876,8 @@ +@@ -3860,8 +3870,8 @@ } // getting density ratio @@ -250,7 +244,7 @@ index da26eb6..2a5e1c0 100644 } // getting locale -@@ -3873,7 +3889,7 @@ +@@ -3873,7 +3883,7 @@ if (typeof document.referrer !== "undefined" && document.referrer.length) { var matches = urlParseRE.exec(document.referrer); // do not report referrers of current website @@ -259,7 +253,7 @@ index da26eb6..2a5e1c0 100644 var ignoring = false; if (ignoreReferrers && ignoreReferrers.length) { for (var k = 0; k < ignoreReferrers.length; k++) { -@@ -3963,72 +3979,62 @@ +@@ -3963,72 +3973,62 @@ */ function sendXmlHttpRequest(functionName, url, params, callback, useBroadResponseValidator) { useBroadResponseValidator = useBroadResponseValidator || false; @@ -283,7 +277,7 @@ index da26eb6..2a5e1c0 100644 + method: method, + headers: { + ...self.headers, -+ ...(method !== "" ? {} : { ++ ...(method !== "POST" ? {} : { + "Content-type": "application/x-www-form-urlencoded", + }) } @@ -378,7 +372,7 @@ index da26eb6..2a5e1c0 100644 } /** -@@ -4105,7 +4111,7 @@ +@@ -4105,7 +4105,7 @@ * */ function processScroll() { @@ -387,7 +381,7 @@ index da26eb6..2a5e1c0 100644 } /** -@@ -4131,7 +4137,7 @@ +@@ -4131,7 +4131,7 @@ // truncate new segment segments = truncateObject(segments, self.maxKeyLength, self.maxValueSize, self.maxSegmentationValues, "processScrollView", log); if (self.track_domains) { @@ -396,7 +390,7 @@ index da26eb6..2a5e1c0 100644 } add_cly_events({ key: internalEventKeyEnums.ACTION, -@@ -4862,7 +4868,7 @@ +@@ -4862,7 +4862,7 @@ */ var get_event_target = function(event) { if (!event) { @@ -405,7 +399,7 @@ index da26eb6..2a5e1c0 100644 } if (typeof event.target !== "undefined") { return event.target; -@@ -4924,7 +4930,7 @@ +@@ -4924,7 +4924,7 @@ var device = "desktop"; // regexps corresponding to tablets or phones that can be found in userAgent string @@ -414,7 +408,7 @@ index da26eb6..2a5e1c0 100644 var phoneCheck = /(mobi|ipod|phone|blackberry|opera mini|fennec|minimo|symbian|psp|nintendo ds|archos|skyfire|puffin|blazer|bolt|gobrowser|iris|maemo|semc|teashark|uzard)/; // check whether the regexp values corresponds to something in the user agent string -@@ -5009,7 +5015,7 @@ +@@ -5009,7 +5009,7 @@ return Math.min( Math.min(D.body.clientHeight, D.documentElement.clientHeight), Math.min(D.body.offsetHeight, D.documentElement.offsetHeight), @@ -423,7 +417,7 @@ index da26eb6..2a5e1c0 100644 ); } -@@ -5018,13 +5024,13 @@ +@@ -5018,13 +5018,13 @@ * @returns {String} device orientation */ function getOrientation() { @@ -439,7 +433,7 @@ index da26eb6..2a5e1c0 100644 var parts = (e.key + "").split("/"); var key = parts.pop(); var appKey = parts.pop(); -@@ -5171,7 +5177,7 @@ +@@ -5171,7 +5171,7 @@ * @return {string} view name * */ Countly.getViewName = function() { @@ -448,7 +442,7 @@ index da26eb6..2a5e1c0 100644 }; /** -@@ -5179,7 +5185,7 @@ +@@ -5179,7 +5179,7 @@ * @return {string} view url * */ Countly.getViewUrl = function() { @@ -457,7 +451,7 @@ index da26eb6..2a5e1c0 100644 }; /** -@@ -5187,7 +5193,7 @@ +@@ -5187,7 +5187,7 @@ * @return {string} view url * */ Countly.getSearchQuery = function() { From 4fab16a298388c5114d3b5af4f0ac16734025887 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 13 Jul 2023 03:33:54 -0600 Subject: [PATCH 05/63] fix(mv3): :adhesive_bandage: Patching the Patch Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- patches/countly-sdk-web+23.2.2.patch | 152 ++++++++++++++------------- 1 file changed, 77 insertions(+), 75 deletions(-) diff --git a/patches/countly-sdk-web+23.2.2.patch b/patches/countly-sdk-web+23.2.2.patch index a1e49df65..2bac8a1d0 100644 --- a/patches/countly-sdk-web+23.2.2.patch +++ b/patches/countly-sdk-web+23.2.2.patch @@ -1,23 +1,25 @@ diff --git a/node_modules/countly-sdk-web/lib/countly.js b/node_modules/countly-sdk-web/lib/countly.js -index da26eb6..0d82fd1 100644 +index da26eb6..a715a3b 100644 --- a/node_modules/countly-sdk-web/lib/countly.js +++ b/node_modules/countly-sdk-web/lib/countly.js -@@ -52,10 +52,20 @@ +@@ -52,10 +52,22 @@ else { root.Countly = factory(root.Countly); } -}(typeof window !== "undefined" ? window : this, function(Countly) { +}(typeof globalThis !== "undefined" ? globalThis : this, function (Countly) { -+ const blackHoleProxy = handler => (target, ...args) => { -+ console.debug('Countly:Debug', handler, target, ...args); -+ return stubbedDocumentImpl; -+ }; -+ const stubbedDocumentImpl = new Proxy({}, { -+ get: blackHoleProxy("stubbedDocumentImpl.get"), -+ apply: blackHoleProxy("stubbedDocumentImpl.apply"), -+ set: blackHoleProxy("stubbedDocumentImpl.set"), -+ }); -+ document = stubbedDocumentImpl; ++ // Blackhole proxy for document object ++ // This proxy is designed to swallow weird quirkiness of DOM and chaining. ++ // This is certainly not fool-proof, but does a decent job of allowing weird chains like: ++ // a.b.c().e().d think document.body.getElementsByTagName("div").item(0).innerHTML ++ // it's absolutely crucial that the target is () => '', if it is {} then the chain will break ++ // as at certain point it won't be callable, it also cannot be () => {} as it won't be chainable. ++ const blackholeProxy = new Proxy(() => '', { ++ get: () => blackholeProxy, ++ apply: () => blackholeProxy, ++ set: () => blackholeProxy ++ }) ++ document = blackholeProxy // Make sure the code is being run in a browser // eslint-disable-next-line no-undef - if (typeof (window) === "undefined") { @@ -25,10 +27,10 @@ index da26eb6..0d82fd1 100644 // TODO: check if logging can be added here, like: // console.error("Not running in browser"); return; -@@ -347,12 +357,12 @@ - +@@ -347,12 +359,12 @@ + checkIgnore(); - + - if (window.name && window.name.indexOf("cly:") === 0) { + if (globalThis.name && globalThis.name.indexOf("cly:") === 0) { try { @@ -41,7 +43,7 @@ index da26eb6..0d82fd1 100644 } } else if (location.hash && location.hash.indexOf("#cly:") === 0) { -@@ -1028,7 +1038,7 @@ +@@ -1028,7 +1040,7 @@ if (this.enableOrientationTracking) { // report orientation this.report_orientation(); @@ -50,7 +52,7 @@ index da26eb6..0d82fd1 100644 self.report_orientation(); }); } -@@ -1618,11 +1628,11 @@ +@@ -1618,11 +1630,11 @@ log(logLevelEnums.INFO, "track_errors, Started tracking errors"); // Indicated that for this instance of the countly error tracking is enabled Countly.i[this.app_key].tracking_crashes = true; @@ -65,7 +67,7 @@ index da26eb6..0d82fd1 100644 // old browsers like IE 10 and Safari 9 won't give this value 'err' to us, but if it is provided we can trigger error recording immediately if (err !== undefined && err !== null) { // false indicates fatal error (as in non_fatal:false) -@@ -1630,7 +1640,7 @@ +@@ -1630,7 +1642,7 @@ } // fallback if no error object is present for older browsers, we create it instead else { @@ -74,16 +76,16 @@ index da26eb6..0d82fd1 100644 var error = ""; if (typeof msg !== "undefined") { error += msg + "\n"; -@@ -1666,7 +1676,7 @@ +@@ -1666,7 +1678,7 @@ }; - + // error handling for 'uncaught rejections' - window.addEventListener("unhandledrejection", function(event) { + globalThis.addEventListener("unhandledrejection", function(event) { // true indicates non fatal error (as in non_fatal: true) dispatchErrors(new Error("Unhandled rejection (reason: " + (event.reason && event.reason.stack ? event.reason.stack : event.reason) + ")."), true); }); -@@ -1909,13 +1919,13 @@ +@@ -1909,13 +1921,13 @@ this.begin_session(); this.start_time(); // end session on unload @@ -93,27 +95,27 @@ index da26eb6..0d82fd1 100644 sendEventsForced(); self.end_session(); }); - + - // manage sessions on window visibility events + // manage sessions on globalThis visibility events var hidden = "hidden"; - + /** -@@ -1931,17 +1941,17 @@ +@@ -1931,17 +1943,17 @@ } - + // add focus handling eventListeners - add_event(window, "focus", onchange); - add_event(window, "blur", onchange); + add_event(globalThis, "focus", onchange); + add_event(globalThis, "blur", onchange); - + // newer mobile compatible way - add_event(window, "pageshow", onchange); - add_event(window, "pagehide", onchange); + add_event(globalThis, "pageshow", onchange); + add_event(globalThis, "pagehide", onchange); - + // IE 9 and lower: if ("onfocusin" in document) { - add_event(window, "focusin", onchange); @@ -121,12 +123,12 @@ index da26eb6..0d82fd1 100644 + add_event(globalThis, "focusin", onchange); + add_event(globalThis, "focusout", onchange); } - + // Page Visibility API for changing tabs and minimizing browser -@@ -1971,10 +1981,10 @@ +@@ -1971,10 +1983,10 @@ inactivityCounter = 0; } - + - add_event(window, "mousemove", resetInactivity); - add_event(window, "click", resetInactivity); - add_event(window, "keydown", resetInactivity); @@ -135,19 +137,19 @@ index da26eb6..0d82fd1 100644 + add_event(globalThis, "click", resetInactivity); + add_event(globalThis, "keydown", resetInactivity); + add_event(globalThis, "scroll", resetInactivity); - + // track user inactivity setInterval(function() { -@@ -2048,7 +2058,7 @@ +@@ -2048,7 +2060,7 @@ // truncate new segment segments = truncateObject(segments, self.maxKeyLength, self.maxValueSize, self.maxSegmentationValues, "track_pageview", log); if (this.track_domains) { - segments.domain = window.location.hostname; + segments.domain = globalThis.location.hostname; } - + if (useSessionCookie) { -@@ -2071,7 +2081,7 @@ +@@ -2071,7 +2083,7 @@ else if (typeof document.referrer !== "undefined" && document.referrer.length) { var matches = urlParseRE.exec(document.referrer); // do not report referrers of current website @@ -156,7 +158,7 @@ index da26eb6..0d82fd1 100644 segments.start = 1; } } -@@ -2147,7 +2157,7 @@ +@@ -2147,7 +2159,7 @@ // truncate new segment segments = truncateObject(segments, self.maxKeyLength, self.maxValueSize, self.maxSegmentationValues, "processClick", log); if (self.track_domains) { @@ -165,7 +167,7 @@ index da26eb6..0d82fd1 100644 } add_cly_events({ key: internalEventKeyEnums.ACTION, -@@ -2173,7 +2183,7 @@ +@@ -2173,7 +2185,7 @@ if (parent) { log(logLevelEnums.INFO, "track_scrolls, Tracking the specified children"); } @@ -173,8 +175,8 @@ index da26eb6..0d82fd1 100644 + parent = parent || globalThis; isScrollRegistryOpen = true; trackingScrolls = true; - -@@ -2813,8 +2823,8 @@ + +@@ -2813,8 +2825,8 @@ else { var pages = widgets[i].target_pages; for (var k = 0; k < pages.length; k++) { @@ -185,27 +187,27 @@ index da26eb6..0d82fd1 100644 var isContainAsterisk = pages[k].includes("*"); if (((isContainAsterisk && isWildcardMatched) || isFullPathMatched) && !widgets[i].hide_sticker) { processWidget(widgets[i], true); -@@ -3048,7 +3058,7 @@ +@@ -3048,7 +3060,7 @@ return; } - + - var passedOrigin = window.origin || window.location.origin; + var passedOrigin = globalThis.origin || globalThis.location.origin; var feedbackWidgetFamily; - + // set feedback widget family as ratings and load related style file when type is ratings -@@ -3170,7 +3180,7 @@ +@@ -3170,7 +3182,7 @@ wrapper.appendChild(iframe); log(logLevelEnums.DEBUG, "present_feedback_widget, Appended the iframe"); - + - add_event(window, "message", function(e) { + add_event(globalThis, "message", function(e) { var data = {}; try { data = JSON.parse(e.data); -@@ -3249,9 +3259,9 @@ +@@ -3249,9 +3261,9 @@ break; - + case "onScrollHalfwayDown": - add_event(window, "scroll", function() { + add_event(globalThis, "scroll", function() { @@ -215,7 +217,7 @@ index da26eb6..0d82fd1 100644 var documentHeight = getDocHeight(); if (scrollY >= (documentHeight / 2)) { surveyShown = true; -@@ -3841,13 +3851,13 @@ +@@ -3841,13 +3853,13 @@ var height = (screen.height) ? parseInt(screen.height) : 0; if (width !== 0 && height !== 0) { var iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform); @@ -233,18 +235,18 @@ index da26eb6..0d82fd1 100644 // we have landscape orientation // switch values for all except ios var temp = width; -@@ -3860,8 +3870,8 @@ +@@ -3860,8 +3872,8 @@ } - + // getting density ratio - if (window.devicePixelRatio) { - metrics._density = metrics._density || window.devicePixelRatio; + if (globalThis.devicePixelRatio) { + metrics._density = metrics._density || globalThis.devicePixelRatio; } - + // getting locale -@@ -3873,7 +3883,7 @@ +@@ -3873,7 +3885,7 @@ if (typeof document.referrer !== "undefined" && document.referrer.length) { var matches = urlParseRE.exec(document.referrer); // do not report referrers of current website @@ -253,7 +255,7 @@ index da26eb6..0d82fd1 100644 var ignoring = false; if (ignoreReferrers && ignoreReferrers.length) { for (var k = 0; k < ignoreReferrers.length; k++) { -@@ -3963,72 +3973,62 @@ +@@ -3963,72 +3975,62 @@ */ function sendXmlHttpRequest(functionName, url, params, callback, useBroadResponseValidator) { useBroadResponseValidator = useBroadResponseValidator || false; @@ -265,6 +267,12 @@ index da26eb6..0d82fd1 100644 - } - else if (window.ActiveXObject) { - xhr = new window.ActiveXObject("Microsoft.XMLHTTP"); +- } +- params = params || {}; +- var data = prepareParams(params); +- var method = "GET"; +- if (self.force_post || data.length >= 2000) { +- method = "POST"; + log(logLevelEnums.DEBUG, "Sending XML HTTP request"); + params = params || {}; + var data = prepareParams(params); @@ -281,12 +289,6 @@ index da26eb6..0d82fd1 100644 + "Content-type": "application/x-www-form-urlencoded", + }) } -- params = params || {}; -- var data = prepareParams(params); -- var method = "GET"; -- if (self.force_post || data.length >= 2000) { -- method = "POST"; -- } - if (method === "GET") { - xhr.open("GET", url + "?" + data, true); - } @@ -370,18 +372,18 @@ index da26eb6..0d82fd1 100644 - } + }); } - + /** -@@ -4105,7 +4105,7 @@ +@@ -4105,7 +4107,7 @@ * */ function processScroll() { - scrollRegistryTopPosition = Math.max(scrollRegistryTopPosition, window.scrollY, document.body.scrollTop, document.documentElement.scrollTop); + scrollRegistryTopPosition = Math.max(scrollRegistryTopPosition, globalThis.scrollY, document.body.scrollTop, document.documentElement.scrollTop); } - + /** -@@ -4131,7 +4131,7 @@ +@@ -4131,7 +4133,7 @@ // truncate new segment segments = truncateObject(segments, self.maxKeyLength, self.maxValueSize, self.maxSegmentationValues, "processScrollView", log); if (self.track_domains) { @@ -390,7 +392,7 @@ index da26eb6..0d82fd1 100644 } add_cly_events({ key: internalEventKeyEnums.ACTION, -@@ -4862,7 +4862,7 @@ +@@ -4862,7 +4864,7 @@ */ var get_event_target = function(event) { if (!event) { @@ -399,16 +401,16 @@ index da26eb6..0d82fd1 100644 } if (typeof event.target !== "undefined") { return event.target; -@@ -4924,7 +4924,7 @@ +@@ -4924,7 +4926,7 @@ var device = "desktop"; - + // regexps corresponding to tablets or phones that can be found in userAgent string - var tabletCheck = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/; + var tabletCheck = /(ipad|tablet|(android(?!.*mobile))|(globalThiss(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/; var phoneCheck = /(mobi|ipod|phone|blackberry|opera mini|fennec|minimo|symbian|psp|nintendo ds|archos|skyfire|puffin|blazer|bolt|gobrowser|iris|maemo|semc|teashark|uzard)/; - + // check whether the regexp values corresponds to something in the user agent string -@@ -5009,7 +5009,7 @@ +@@ -5009,7 +5011,7 @@ return Math.min( Math.min(D.body.clientHeight, D.documentElement.clientHeight), Math.min(D.body.offsetHeight, D.documentElement.offsetHeight), @@ -416,15 +418,15 @@ index da26eb6..0d82fd1 100644 + globalThis.innerHeight ); } - -@@ -5018,13 +5018,13 @@ + +@@ -5018,13 +5020,13 @@ * @returns {String} device orientation */ function getOrientation() { - return window.innerWidth > window.innerHeight ? "landscape" : "portrait"; + return globalThis.innerWidth > globalThis.innerHeight ? "landscape" : "portrait"; } - + /** * Monitor parallel storage changes like other opened tabs */ @@ -433,30 +435,30 @@ index da26eb6..0d82fd1 100644 var parts = (e.key + "").split("/"); var key = parts.pop(); var appKey = parts.pop(); -@@ -5171,7 +5171,7 @@ +@@ -5171,7 +5173,7 @@ * @return {string} view name * */ Countly.getViewName = function() { - return window.location.pathname; + return globalThis.location.pathname; }; - + /** -@@ -5179,7 +5179,7 @@ +@@ -5179,7 +5181,7 @@ * @return {string} view url * */ Countly.getViewUrl = function() { - return window.location.pathname; + return globalThis.location.pathname; }; - + /** -@@ -5187,7 +5187,7 @@ +@@ -5187,7 +5189,7 @@ * @return {string} view url * */ Countly.getSearchQuery = function() { - return window.location.search; + return globalThis.location.search; }; - + /** From f02d6a23fb8d46adda92a9293853edb7d86901e7 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 13 Jul 2023 03:34:02 -0600 Subject: [PATCH 06/63] fix: tests Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- test/functional/lib/ipfs-companion.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/functional/lib/ipfs-companion.test.js b/test/functional/lib/ipfs-companion.test.js index 31bb4deb4..d7c65dc4a 100644 --- a/test/functional/lib/ipfs-companion.test.js +++ b/test/functional/lib/ipfs-companion.test.js @@ -23,6 +23,8 @@ describe('lib/ipfs-companion.js', function () { global.localStorage = global.localStorage || {} global.URL = global.URL || URL global.screen = { width: 1024, height: 720 } + global.addEventListener = () => { } + global.location = { hostname: 'test' } browser.runtime.getManifest.returns({ version: '0.0.0' }) // on-installed.js }) From dbab08ce298ef6a01d669f73159d8ffe3db90bb3 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 13 Jul 2023 03:50:34 -0600 Subject: [PATCH 07/63] fix: lint Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- add-on/src/lib/storage-provider/WebExtensionStorageProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-on/src/lib/storage-provider/WebExtensionStorageProvider.ts b/add-on/src/lib/storage-provider/WebExtensionStorageProvider.ts index 5b0959890..c0d59acc9 100644 --- a/add-on/src/lib/storage-provider/WebExtensionStorageProvider.ts +++ b/add-on/src/lib/storage-provider/WebExtensionStorageProvider.ts @@ -19,7 +19,7 @@ export class WebExtensionStorageProvider implements StorageProviderInterface { async getStore (): Promise { try { - let jsonString; + let jsonString if ('localStorage' in globalThis) { jsonString = globalThis.localStorage.getItem('@ipfs-shipyard/ignite-metrics:consent') } else { From 394b13bc0b006e627d9bea8b772937bfcb537b79 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Tue, 18 Jul 2023 02:21:24 -0600 Subject: [PATCH 08/63] fix(mv3): :recycle: Refactoring `supportsBlock` Checks. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- add-on/src/lib/ipfs-request.js | 2 +- .../src/lib/redirect-handler/blockOrObserve.ts | 18 +++++++++++------- .../redirect-handler/blockOrObserve.test.ts | 16 +++++++++++----- .../declarativeNetRequest.mock.ts | 1 + 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/add-on/src/lib/ipfs-request.js b/add-on/src/lib/ipfs-request.js index 480870ffa..dd6e184a6 100644 --- a/add-on/src/lib/ipfs-request.js +++ b/add-on/src/lib/ipfs-request.js @@ -480,7 +480,7 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida */ function handleRedirection ({ originUrl, redirectUrl }) { if (redirectUrl !== '' && originUrl !== '' && redirectUrl !== originUrl) { - if (supportsBlock) { + if (supportsBlock()) { return { redirectUrl } } diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index dcb31d107..f9ac2df34 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -24,7 +24,11 @@ interface messageToSelf { // We need to check if the browser supports the declarativeNetRequest API. // TODO: replace with check for `Blocking` in `chrome.webRequest.OnBeforeRequestOptions` // which is currently a bug https://bugs.chromium.org/p/chromium/issues/detail?id=1427952 -export const supportsBlock = !(browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES === 5000) +// this needs to be a function call, because in tests we mock browser.declarativeNetRequest +// the way sinon ends up stubbing it, it's not directly available in the global scope on import +// rather it gets replaced dynamically when the module is imported. Which means, we can't +// just check for the existence of the property, we need to call the browser instance at that point. +export const supportsBlock = (): boolean => !(browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES === 5000) export const GLOBAL_STATE_CHANGE = 'GLOBAL_STATE_CHANGE' export const GLOBAL_STATE_OPTION_CHANGE = 'GLOBAL_STATE_OPTION_CHANGE' @@ -51,7 +55,7 @@ export async function notifyOptionChange (): Promise { */ async function sendMessageToSelf (msg: typeof GLOBAL_STATE_CHANGE | typeof GLOBAL_STATE_OPTION_CHANGE): Promise { // this check ensures we don't send messages to ourselves if blocking mode is enabled. - if (!supportsBlock) { + if (!supportsBlock()) { const message: messageToSelf = { type: msg } await browser.runtime.sendMessage(message) } @@ -87,7 +91,7 @@ export function isLocalHost (url: string): boolean { * @param str URL string to escape * @returns */ -function escapeURLRegex (str: string): string { +export function escapeURLRegex (str: string): string { // these characters are allowed in the URL, but not in the regex. // eslint-disable-next-line no-useless-escape const ALLOWED_CHARS_URL_REGEX = /([:\/\?#\[\]@!$&'\(\ )\*\+,;=-_\.~])/g @@ -137,7 +141,7 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) // If the browser supports the declarativeNetRequest API, we can block the request. export function getExtraInfoSpec (additionalParams: T[] = []): T[] { - if (supportsBlock) { + if (supportsBlock()) { return ['blocking' as T, ...additionalParams] } return additionalParams @@ -222,7 +226,7 @@ async function reconcileRulesAndRemoveOld (state: CompanionState): Promise if (rules.length === 0) { // we need to populate old rules. for (const [regexFilter, { regexSubstitution, id }] of savedRegexFilters.entries()) { - addRules.push(generateRule(id, regexFilter, regexSubstitution)) + addRules.push(generateAddRule(id, regexFilter, regexSubstitution)) } } @@ -259,7 +263,7 @@ function saveAndGenerateRule ( const id = Math.floor(Math.random() * 29999) // We need to save the regex filter and ID to check if the rule already exists later. savedRegexFilters.set(regexFilter, { id, regexSubstitution }) - return generateRule(id, regexFilter, regexSubstitution, excludedInitiatorDomains) + return generateAddRule(id, regexFilter, regexSubstitution, excludedInitiatorDomains) } /** @@ -270,7 +274,7 @@ function saveAndGenerateRule ( * @param excludedInitiatorDomains - The domains that are excluded from the rule. * @returns */ -function generateRule ( +export function generateAddRule ( id: number, regexFilter: string, regexSubstitution: string, diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.ts index 7a11911b9..e71ab7515 100644 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.ts +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.ts @@ -1,11 +1,11 @@ -import {expect} from 'chai' -import {before, describe, it} from 'mocha' +import { expect } from 'chai' +import { before, describe, it } from 'mocha' import sinon from 'sinon' import browserMock from 'sinon-chrome' -import {optionDefaults} from '../../../../add-on/src/lib/options.js' -import {addRuleToDynamicRuleSetGenerator, cleanupRules, isLocalHost} from '../../../../add-on/src/lib/redirect-handler/blockOrObserve' -import {initState} from '../../../../add-on/src/lib/state.js' +import { optionDefaults } from '../../../../add-on/src/lib/options.js' +import { addRuleToDynamicRuleSetGenerator, cleanupRules, isLocalHost, supportsBlock } from '../../../../add-on/src/lib/redirect-handler/blockOrObserve' +import { initState } from '../../../../add-on/src/lib/state.js' import DeclarativeNetRequestMock from './declarativeNetRequest.mock.js' const dynamicRulesConditions = (regexFilter) => ({ @@ -53,6 +53,12 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) }) + describe('supportsBlock', () => { + it('should return false for chrome', () => { + expect(supportsBlock()).to.be.false + }) + }) + describe('addRuleToDynamicRuleSetGenerator', () => { let addRuleToDynamicRuleSet let state diff --git a/test/functional/lib/redirect-handler/declarativeNetRequest.mock.ts b/test/functional/lib/redirect-handler/declarativeNetRequest.mock.ts index 8ffcf537d..c9c3eb4a5 100644 --- a/test/functional/lib/redirect-handler/declarativeNetRequest.mock.ts +++ b/test/functional/lib/redirect-handler/declarativeNetRequest.mock.ts @@ -12,6 +12,7 @@ class DeclarativeNetRequestMock implements browser.DeclarativeNetRequest.Static constructor() { this.dynamicRules = new Map() + this.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES = 5000 } async getDynamicRules(): Promise { From cbb4ac667d1edaa38d42017bf307a72b72f7ef32 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Tue, 18 Jul 2023 03:56:06 -0600 Subject: [PATCH 09/63] fix(mv3): Regex Bug Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- add-on/src/lib/redirect-handler/blockOrObserve.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index f9ac2df34..7c4aa82c3 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -91,10 +91,10 @@ export function isLocalHost (url: string): boolean { * @param str URL string to escape * @returns */ -export function escapeURLRegex (str: string): string { +function escapeURLRegex (str: string): string { // these characters are allowed in the URL, but not in the regex. // eslint-disable-next-line no-useless-escape - const ALLOWED_CHARS_URL_REGEX = /([:\/\?#\[\]@!$&'\(\ )\*\+,;=-_\.~])/g + const ALLOWED_CHARS_URL_REGEX = /([:\/\?#\[\]@!$&'\(\ )\*\+,;=\-_\.~])/g return str.replace(ALLOWED_CHARS_URL_REGEX, '\\$1') } From 5794aeacd6634984dd279e838ea775228a8b5efa Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Tue, 18 Jul 2023 03:56:39 -0600 Subject: [PATCH 10/63] feat: Migrating blocking redirection test to observing redirection test Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../ipfs-request-gateway-redirect.mv3.test.js | 376 ++++++++++++++++++ 1 file changed, 376 insertions(+) create mode 100644 test/functional/lib/ipfs-request-gateway-redirect.mv3.test.js diff --git a/test/functional/lib/ipfs-request-gateway-redirect.mv3.test.js b/test/functional/lib/ipfs-request-gateway-redirect.mv3.test.js new file mode 100644 index 000000000..aa782bce6 --- /dev/null +++ b/test/functional/lib/ipfs-request-gateway-redirect.mv3.test.js @@ -0,0 +1,376 @@ +'use strict' +import { expect } from 'chai' +import { after, before, beforeEach, describe, it } from 'mocha' +import sinon from 'sinon' +import browser from 'sinon-chrome' +import { URL } from 'url' +import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' +import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' +import { createRequestModifier, redirectOptOutHint } from '../../../add-on/src/lib/ipfs-request.js' +import { optionDefaults } from '../../../add-on/src/lib/options.js' +import { generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' +import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' +import { initState } from '../../../add-on/src/lib/state.js' +import DeclarativeNetRequestMock from './redirect-handler/declarativeNetRequest.mock.js' + +const url2request = (string) => { + return { url: string, type: 'main_frame' } +} + +const fakeRequestId = () => { + return Math.floor(Math.random() * 100000).toString() +} + +const expectNoRedirect = async (modifyRequest, request, browser) => { + await modifyRequest.onBeforeRequest(request) + sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + await modifyRequest.onHeadersReceived(request) + sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) +} + +const regexRuleEnding = '((?:[^\\.]|$).*)$' +const nodeTypes = ['external'] +const sinonSandbox = sinon.createSandbox() + +describe('[MV3] modifyRequest.onBeforeRequest:', function () { + let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime + + before(function () { + global.URL = URL + browser.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) + browser.runtime.id = 'testid' + browser.runtime.getURL.returns('chrome-extension://testid/') + global.browser = browser + }) + + beforeEach(async function () { + state = Object.assign(initState(optionDefaults), { + ipfsNodeType: 'external', + peerCount: 1, + redirect: true, + dnslinkPolicy: false, // dnslink test suite is in ipfs-request-dnslink.test.js + catchUnhandledProtocols: true, + gwURLString: 'http://localhost:8080', + gwURL: new URL('http://localhost:8080'), + pubGwURLString: 'https://ipfs.io', + pubGwURL: new URL('https://ipfs.io'), + pubSubdomainGwURLString: 'https://dweb.link', + pubSubdomainGwURL: new URL('https://dweb.link') + }) + const getState = () => state + const getIpfs = () => { } + dnslinkResolver = createDnslinkResolver(getState) + runtime = Object.assign({}, await createRuntimeChecks(browser)) // make it mutable for tests + ipfsPathValidator = createIpfsPathValidator(getState, getIpfs, dnslinkResolver) + modifyRequest = createRequestModifier(getState, dnslinkResolver, ipfsPathValidator, runtime) + }) + + afterEach(async function () { + sinonSandbox.reset() + }) + + describe('request for a path matching /ipfs/{CIDv0}', function () { + describe('with external node', function () { + let sinonSandbox + beforeEach(function () { + state.ipfsNodeType = 'external' + }) + it('should be served from custom gateway if redirect is enabled', async function () { + const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + // MV2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, + 'http://localhost:8080\\1' + )], + removeRuleIds: [] + }) + }) + }) + describe('with every node type', function () { + // tests in which results should be the same for all node types + nodeTypes.forEach(function (nodeType) { + beforeEach(function () { + state.ipfsNodeType = nodeType + }) + it(`should be left untouched if redirect is disabled (${nodeType} node)`, async function () { + state.redirect = false + const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await expectNoRedirect(modifyRequest, request, browser) + }) + it(`should be left untouched if redirect is enabled but global active flag is OFF (${nodeType} node)`, async function () { + state.active = false + state.redirect = true + const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await expectNoRedirect(modifyRequest, request, browser) + }) + it(`should be left untouched if URL includes opt-out hint (${nodeType} node)`, async function () { + // A safe way for preloading data at arbitrary gateways - it should arrive at original destination + const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?x-ipfs-companion-no-redirect#hashTest') + await expectNoRedirect(modifyRequest, request, browser) + }) + it(`should be left untouched if request is for subresource on a page loaded from URL that includes opt-out hint (${nodeType} node)`, async function () { + // ensure opt-out works for subresources (Firefox only for now) + const subRequest = { + type: 'script', + url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + originUrl: 'https://example.com/?x-ipfs-companion-no-redirect#hashTest' + } + await expectNoRedirect(modifyRequest, subRequest, browser) + }) + it(`should be left untouched if CID is invalid (${nodeType} node)`, async function () { + const request = url2request('https://google.com/ipfs/notacid?argTest#hashTest') + await expectNoRedirect(modifyRequest, request, browser) + }) + it(`should be left untouched if its is a HEAD preload with explicit opt-out in URL hash (${nodeType} node)`, async function () { + // HTTP HEAD is a popular way for preloading data at arbitrary gateways, so we have a dedicated test to make sure it works as expected + const headRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#x-ipfs-companion-no-redirect', method: 'HEAD' } + await expectNoRedirect(modifyRequest, headRequest, browser) + }) + }) + }) + }) + + describe('XHR request for a path matching /ipfs/{CIDv0} coming from 3rd party Origin', function () { + describe('with external node', function () { + beforeEach(function () { + state.ipfsNodeType = 'external' + }) + it('should be served from custom gateway if fetched from the same origin and redirect is enabled in Chromium', async function () { + const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://google.com/' } + // MV2 + // expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await modifyRequest.onBeforeRequest(xhrRequest) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, + 'http://127.0.0.1:8080\\1' + )], + removeRuleIds: [] + }) + }) + }) + }) + + describe('request for a path matching /ipns/{path}', function () { + describe('with external node', function () { + beforeEach(function () { + state.ipfsNodeType = 'external' + }) + afterEach(function () { + sinonSandbox.restore() + }) + + it('should be served from custom gateway if {path} points to a FQDN with existing dnslink', async function () { + const request = url2request('https://google.com/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest') + // stub the existence of valid dnslink + const fqdn = 'en.wikipedia-on-ipfs.org' + dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().withArgs(fqdn).resolves('/ipfs/Qmazvovg6Sic3m9igZMKoAPjkiVZsvbWWc8ZvgjjK1qMss') + // pretend API is online and we can do dns lookups with it + state.peerCount = 1 + // MV2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, + 'http://localhost:8080\\1' + )], + removeRuleIds: [] + }) + }) + it('should be served from custom gateway if {path} starts with a valid PeerID', async function () { + const request = url2request('https://google.com/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest') + dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().resolves(false) + // MV2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + console.log(browser.declarativeNetRequest.updateDynamicRules.calls) + }) + }) + + describe('with every node type', function () { + // tests in which results should be the same for all node types + nodeTypes.forEach(function (nodeType) { + beforeEach(function () { + state.ipfsNodeType = nodeType + }) + it(`should be left untouched if redirect is disabled' (${nodeType} node)`, async function () { + state.redirect = false + const request = url2request('https://google.com/ipns/ipfs.io?argTest#hashTest') + await expectNoRedirect(modifyRequest, request, browser) + }) + it(`should be left untouched if FQDN is not a real domain nor a valid CID (${nodeType} node)`, async function () { + const request = url2request('https://google.com/ipns/notafqdnorcid?argTest#hashTest') + dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().resolves(false) + await expectNoRedirect(modifyRequest, request, browser) + }) + }) + }) + }) + + describe('request to a subdomain gateway', function () { + const cid = 'bafybeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge' + const peerid = 'bafzbeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge' + + // Tests use different CID in X-Ipfs-Path header just to ensure it does not + // override the one from path + const fakeXIpfsPathHdrVal = '/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ' + + describe('with external node', function () { + beforeEach(function () { + state.ipfsNodeType = 'external' + // dweb.link is the default subdomain gw + }) + it('should be redirected to localhost gateway (*.ipfs on default gw)', async function () { + state.redirect = true + const request = url2request(`https://${cid}.ipfs.dweb.link/`) + + /// We expect redirect to path-based gateway because go-ipfs >=0.5 will + // return redirect to a subdomain, and we don't want to break users + // running older versions of go-ipfs by loading subdomain first and + // failing. + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + // .to.equal(`http://localhost:8080/ipfs/${cid}/`) + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/${cid}\\.ipfs\\.dweb\\.link${regexRuleEnding}`, + `http://localhost:8080/ipfs/${cid}\\1` + )], + removeRuleIds: [] + }) + }) + it('should be redirected to localhost gateway (*.ipfs on 3rd party gw)', async function () { + state.redirect = true + const request = url2request(`https://${cid}.ipfs.cf-ipfs.com/`) + // MV2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal(`http://localhost:8080/ipfs/${cid}/`) + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/${cid}\\.ipfs\\.cf-ipfs\\.com${regexRuleEnding}`, + `http://localhost:8080/ipfs/${cid}\\1` + )], + removeRuleIds: [] + }) + }) + it('should be redirected to localhost gateway and keep URL encoding of original path', async function () { + state.redirect = true + const request = url2request('https://bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy.ipfs.dweb.link/%3Ffilename=test.jpg?arg=val') + // MV2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + // .to.equal('http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy/%3Ffilename=test.jpg?arg=val') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\.ipfs\\.dweb\\.link${regexRuleEnding}`, + `http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\1` + )], + removeRuleIds: [] + }) + }) + it('should be redirected to localhost gateway (*.ipns on default gw)', async function () { + state.redirect = true + const request = url2request(`https://${peerid}.ipns.dweb.link/`) + // MV2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + // .to.equal(`http://localhost:8080/ipns/${peerid}/`) + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/${peerid}\\.ipns\\.dweb\\.link${regexRuleEnding}`, + `http://localhost:8080/ipns/${peerid}\\1` + )], + removeRuleIds: [] + }) + }) + }) + }) + + describe('Recovers Page if node is unreachable', function () { + beforeEach(function () { + global.browser = browser + state.ipfsNodeType = 'external' + state.redirect = true + state.peerCount = -1 // this simulates Kubo RPC being offline + state.gwURLString = 'http://localhost:8080' + state.gwURL = new URL('http://localhost:8080') + state.pubGwURLString = 'https://ipfs.io' + state.pubGwURL = new URL('https://ipfs.io') + }) + it('should present recovery page if node is offline and redirect is enabled', async function () { + expect(state.nodeActive).to.be.equal(false) + state.redirect = true + const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + + expect(args.addRules[0]).to.deep.equal(generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/${regexRuleEnding}`, + `chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1` + )) + }) + it('should present recovery page if node is offline and redirect is disabled', async function () { + expect(state.nodeActive).to.be.equal(false) + state.redirect = false + const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + + expect(args.addRules[0]).to.deep.equal(generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/${regexRuleEnding}`, + `chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1` + )) + }) + it('should not show recovery page if node is offline, redirect is enabled, but non-gateway URL failed to load from the same port', async function () { + // this covers https://github.com/ipfs/ipfs-companion/issues/1162 and https://twitter.com/unicomp21/status/1626244123102679041 + state.redirect = true + expect(state.nodeActive).to.be.equal(false) + const request = url2request('https://localhost:8080/') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + await expectNoRedirect(modifyRequest, request, browser) + }) + it('should not show recovery page if extension is disabled', async function () { + // allows user to quickly avoid anything similar to https://github.com/ipfs/ipfs-companion/issues/1162 + state.active = false + expect(state.nodeActive).to.be.equal(false) + const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + await expectNoRedirect(modifyRequest, request, browser) + }) + }) + + after(function () { + delete global.URL + delete global.browser + sinonSandbox.restore() + browser.flush() + }) +}) From 0b0af764973e860a5a4578e3cf62f146aaffc346 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Tue, 18 Jul 2023 16:24:12 -0600 Subject: [PATCH 11/63] fix(mv3): :wrench: Fixing the mocha-setup. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- package.json | 3 ++- test/functional/lib/ipfs-companion.test.js | 21 +++++++++++-------- ...ipfs-request-gateway-redirect.test.mv3.js} | 15 ++++--------- test/functional/lib/mocha-setup.js | 11 ++++++++++ test/functional/lib/mocha-setup.mv3.js | 21 +++++++++++++++++++ .../blockOrObserve.test.mv3.ts | 13 ++++++++++++ .../redirect-handler/blockOrObserve.test.ts | 4 ++-- 7 files changed, 65 insertions(+), 23 deletions(-) rename test/functional/lib/{ipfs-request-gateway-redirect.mv3.test.js => ipfs-request-gateway-redirect.test.mv3.js} (97%) create mode 100644 test/functional/lib/mocha-setup.js create mode 100644 test/functional/lib/mocha-setup.mv3.js create mode 100644 test/functional/lib/redirect-handler/blockOrObserve.test.mv3.ts diff --git a/package.json b/package.json index a0280d833..db56f11f6 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,9 @@ "watch:js:webpack": "webpack --watch --mode development --devtool inline-source-map --config ./webpack.config.js", "test": "run-s test:*", "test:e2e": "mocha --timeout 300000 \"test/e2e/**/*.test.js\"", - "test:functional": "c8 mocha --timeout 5000 \"test/functional/**/*.test.js\" \"test/functional/**/*.test.ts\"", + "test:functional": "c8 mocha --timeout 5000 --file \"test/functional/lib/mocha-setup.js\" \"test/functional/**/*.test.js\" \"test/functional/**/*.test.ts\"", "lint": "run-s lint:*", + "test:functional_MV3": "mocha --timeout 5000 --file \"test/functional/lib/mocha-setup.mv3.js\" \"test/functional/**/*.test.mv3.js\"", "lint:standard": "ts-standard -v \"*.js\" \"add-on/src/**/*.js\" \"add-on/src/**/*.ts\" \"test/**/*.js\" \"scripts/**/*.js\"", "lint:web-ext": "shx cat add-on/manifest.common.json add-on/manifest.chromium.json add-on/manifest.firefox-beta.json | json --deep-merge > add-on/manifest.json && web-ext lint --firefox-preview", "fix:lint": "run-s fix:lint:*", diff --git a/test/functional/lib/ipfs-companion.test.js b/test/functional/lib/ipfs-companion.test.js index d7c65dc4a..e23c95161 100644 --- a/test/functional/lib/ipfs-companion.test.js +++ b/test/functional/lib/ipfs-companion.test.js @@ -4,20 +4,23 @@ import browser from 'sinon-chrome' import AbortController from 'abort-controller' import { URL } from 'url' import { optionDefaults } from '../../../add-on/src/lib/options.js' -browser.runtime.id = 'testid' -global.browser = browser -global.AbortController = AbortController -global.chrome = browser -global.navigator = { - clipboard: { - writeText: () => {} - } -} + // We need to do this because global is not mapped otherwise, we need to stub browser and chrome runtime // so that the webextension-polyfill does not complain about the test runner not being a browser instance. const init = async () => (await import('../../../add-on/src/lib/ipfs-companion.js')).default() describe('lib/ipfs-companion.js', function () { + before(function () { + browser.runtime.id = 'testid' + global.browser = browser + global.AbortController = AbortController + global.chrome = browser + global.navigator = { + clipboard: { + writeText: () => {} + } + } + }) describe('init', function () { before(function () { global.localStorage = global.localStorage || {} diff --git a/test/functional/lib/ipfs-request-gateway-redirect.mv3.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js similarity index 97% rename from test/functional/lib/ipfs-request-gateway-redirect.mv3.test.js rename to test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js index aa782bce6..49c54dc7d 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.mv3.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js @@ -6,12 +6,11 @@ import browser from 'sinon-chrome' import { URL } from 'url' import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' -import { createRequestModifier, redirectOptOutHint } from '../../../add-on/src/lib/ipfs-request.js' +import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' -import { generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' -import DeclarativeNetRequestMock from './redirect-handler/declarativeNetRequest.mock.js' +import { generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' const url2request = (string) => { return { url: string, type: 'main_frame' } @@ -35,12 +34,9 @@ const sinonSandbox = sinon.createSandbox() describe('[MV3] modifyRequest.onBeforeRequest:', function () { let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime - before(function () { + before(async function () { global.URL = URL - browser.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) - browser.runtime.id = 'testid' browser.runtime.getURL.returns('chrome-extension://testid/') - global.browser = browser }) beforeEach(async function () { @@ -163,9 +159,6 @@ describe('[MV3] modifyRequest.onBeforeRequest:', function () { beforeEach(function () { state.ipfsNodeType = 'external' }) - afterEach(function () { - sinonSandbox.restore() - }) it('should be served from custom gateway if {path} points to a FQDN with existing dnslink', async function () { const request = url2request('https://google.com/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest') @@ -261,7 +254,7 @@ describe('[MV3] modifyRequest.onBeforeRequest:', function () { expect(args).to.deep.equal({ addRules: [generateAddRule( args.addRules[0].id, - `^https?\\:\\/\\/${cid}\\.ipfs\\.cf-ipfs\\.com${regexRuleEnding}`, + `^https?\\:\\/\\/${cid}\\.ipfs\\.cf\\-ipfs\\.com${regexRuleEnding}`, `http://localhost:8080/ipfs/${cid}\\1` )], removeRuleIds: [] diff --git a/test/functional/lib/mocha-setup.js b/test/functional/lib/mocha-setup.js new file mode 100644 index 000000000..1eb01abba --- /dev/null +++ b/test/functional/lib/mocha-setup.js @@ -0,0 +1,11 @@ +import browser from 'sinon-chrome' +import AbortController from 'abort-controller' +browser.runtime.id = 'testid' +global.browser = browser +global.AbortController = AbortController +global.chrome = browser +global.navigator = { + clipboard: { + writeText: () => {} + } +} diff --git a/test/functional/lib/mocha-setup.mv3.js b/test/functional/lib/mocha-setup.mv3.js new file mode 100644 index 000000000..261681e5b --- /dev/null +++ b/test/functional/lib/mocha-setup.mv3.js @@ -0,0 +1,21 @@ +import browser from 'sinon-chrome' +import AbortController from 'abort-controller' +import DeclarativeNetRequestMock from './redirect-handler/declarativeNetRequest.mock.js' +import sinon from 'sinon' + +browser.runtime.id = 'testid' +global.browser = browser +global.AbortController = AbortController +global.chrome = browser +global.navigator = { + clipboard: { + writeText: () => {} + } +} +const sinonSandbox = sinon.createSandbox() +global.browser.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) + +afterEach(function () { + sinonSandbox.resetHistory() + browser.flush() +}) diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.mv3.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.mv3.ts new file mode 100644 index 000000000..68807064b --- /dev/null +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.mv3.ts @@ -0,0 +1,13 @@ +import { expect } from 'chai' +import { before, describe, it } from 'mocha' +import browserMock from 'sinon-chrome' + +import { supportsBlock } from '../../../../add-on/src/lib/redirect-handler/blockOrObserve.js' + +describe('lib/redirect-handler/blockOrObserve', () => { + describe('supportsBlock', () => { + it('should return false for MV3', () => { + expect(supportsBlock()).to.be.false + }) + }) +}) diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.ts index e71ab7515..176e71080 100644 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.ts +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.ts @@ -54,8 +54,8 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) describe('supportsBlock', () => { - it('should return false for chrome', () => { - expect(supportsBlock()).to.be.false + it('should return true for MV2', () => { + expect(supportsBlock()).to.be.true }) }) From 0de2e894038437e02f2034bf03e1e9f3743bdda3 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Tue, 18 Jul 2023 23:27:21 -0600 Subject: [PATCH 12/63] fix(mv3): :recycle: Moving Setup Files. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- package.json | 4 ++-- test/{functional/lib => setup}/mocha-setup.js | 0 test/{functional/lib => setup}/mocha-setup.mv3.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename test/{functional/lib => setup}/mocha-setup.js (100%) rename test/{functional/lib => setup}/mocha-setup.mv3.js (82%) diff --git a/package.json b/package.json index db56f11f6..3c0fef568 100644 --- a/package.json +++ b/package.json @@ -46,9 +46,9 @@ "watch:js:webpack": "webpack --watch --mode development --devtool inline-source-map --config ./webpack.config.js", "test": "run-s test:*", "test:e2e": "mocha --timeout 300000 \"test/e2e/**/*.test.js\"", - "test:functional": "c8 mocha --timeout 5000 --file \"test/functional/lib/mocha-setup.js\" \"test/functional/**/*.test.js\" \"test/functional/**/*.test.ts\"", + "test:functional": "c8 mocha --timeout 5000 --file \"test/setup/mocha-setup.js\" \"test/functional/**/*.test.js\" \"test/functional/**/*.test.ts\"", "lint": "run-s lint:*", - "test:functional_MV3": "mocha --timeout 5000 --file \"test/functional/lib/mocha-setup.mv3.js\" \"test/functional/**/*.test.mv3.js\"", + "test:functional_MV3": "mocha --timeout 5000 --file \"test/setup/mocha-setup.mv3.js\" \"test/functional/**/*.test.mv3.js\"", "lint:standard": "ts-standard -v \"*.js\" \"add-on/src/**/*.js\" \"add-on/src/**/*.ts\" \"test/**/*.js\" \"scripts/**/*.js\"", "lint:web-ext": "shx cat add-on/manifest.common.json add-on/manifest.chromium.json add-on/manifest.firefox-beta.json | json --deep-merge > add-on/manifest.json && web-ext lint --firefox-preview", "fix:lint": "run-s fix:lint:*", diff --git a/test/functional/lib/mocha-setup.js b/test/setup/mocha-setup.js similarity index 100% rename from test/functional/lib/mocha-setup.js rename to test/setup/mocha-setup.js diff --git a/test/functional/lib/mocha-setup.mv3.js b/test/setup/mocha-setup.mv3.js similarity index 82% rename from test/functional/lib/mocha-setup.mv3.js rename to test/setup/mocha-setup.mv3.js index 261681e5b..832b0125a 100644 --- a/test/functional/lib/mocha-setup.mv3.js +++ b/test/setup/mocha-setup.mv3.js @@ -1,6 +1,6 @@ import browser from 'sinon-chrome' import AbortController from 'abort-controller' -import DeclarativeNetRequestMock from './redirect-handler/declarativeNetRequest.mock.js' +import DeclarativeNetRequestMock from '../functional/lib/redirect-handler/declarativeNetRequest.mock.js' import sinon from 'sinon' browser.runtime.id = 'testid' From 1d46a57f056422e52e9a0a207f8c5164302187f9 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 19 Jul 2023 00:40:06 -0600 Subject: [PATCH 13/63] fix(mv3): gateway-redirect tests now fixed. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/ipfs-request-gateway-redirect.test.mv3.js | 9 +++++---- test/setup/mocha-setup.mv3.js | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js b/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js index 49c54dc7d..d0c16fbf6 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js @@ -10,15 +10,12 @@ import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' -import { generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' +import { cleanupRules, generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' const url2request = (string) => { return { url: string, type: 'main_frame' } } -const fakeRequestId = () => { - return Math.floor(Math.random() * 100000).toString() -} const expectNoRedirect = async (modifyRequest, request, browser) => { await modifyRequest.onBeforeRequest(request) @@ -39,6 +36,10 @@ describe('[MV3] modifyRequest.onBeforeRequest:', function () { browser.runtime.getURL.returns('chrome-extension://testid/') }) + afterEach(async function () { + await cleanupRules(true) + }) + beforeEach(async function () { state = Object.assign(initState(optionDefaults), { ipfsNodeType: 'external', diff --git a/test/setup/mocha-setup.mv3.js b/test/setup/mocha-setup.mv3.js index 832b0125a..503ea0a27 100644 --- a/test/setup/mocha-setup.mv3.js +++ b/test/setup/mocha-setup.mv3.js @@ -17,5 +17,4 @@ global.browser.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetReques afterEach(function () { sinonSandbox.resetHistory() - browser.flush() }) From 44653de429f18fb12d5714f0e2ae37d2a9d43399 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 19 Jul 2023 00:49:08 -0600 Subject: [PATCH 14/63] fix: :adhesive_bandage: Patching error messages Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- patches/countly-sdk-web+23.2.2.patch | 63 ++++++++++++++-------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/patches/countly-sdk-web+23.2.2.patch b/patches/countly-sdk-web+23.2.2.patch index 2bac8a1d0..7050e89b8 100644 --- a/patches/countly-sdk-web+23.2.2.patch +++ b/patches/countly-sdk-web+23.2.2.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/countly-sdk-web/lib/countly.js b/node_modules/countly-sdk-web/lib/countly.js -index da26eb6..a715a3b 100644 +index da26eb6..9cf44ee 100644 --- a/node_modules/countly-sdk-web/lib/countly.js +++ b/node_modules/countly-sdk-web/lib/countly.js @@ -52,10 +52,22 @@ @@ -28,9 +28,9 @@ index da26eb6..a715a3b 100644 // console.error("Not running in browser"); return; @@ -347,12 +359,12 @@ - + checkIgnore(); - + - if (window.name && window.name.indexOf("cly:") === 0) { + if (globalThis.name && globalThis.name.indexOf("cly:") === 0) { try { @@ -78,7 +78,7 @@ index da26eb6..a715a3b 100644 error += msg + "\n"; @@ -1666,7 +1678,7 @@ }; - + // error handling for 'uncaught rejections' - window.addEventListener("unhandledrejection", function(event) { + globalThis.addEventListener("unhandledrejection", function(event) { @@ -95,27 +95,27 @@ index da26eb6..a715a3b 100644 sendEventsForced(); self.end_session(); }); - + - // manage sessions on window visibility events + // manage sessions on globalThis visibility events var hidden = "hidden"; - + /** @@ -1931,17 +1943,17 @@ } - + // add focus handling eventListeners - add_event(window, "focus", onchange); - add_event(window, "blur", onchange); + add_event(globalThis, "focus", onchange); + add_event(globalThis, "blur", onchange); - + // newer mobile compatible way - add_event(window, "pageshow", onchange); - add_event(window, "pagehide", onchange); + add_event(globalThis, "pageshow", onchange); + add_event(globalThis, "pagehide", onchange); - + // IE 9 and lower: if ("onfocusin" in document) { - add_event(window, "focusin", onchange); @@ -123,12 +123,12 @@ index da26eb6..a715a3b 100644 + add_event(globalThis, "focusin", onchange); + add_event(globalThis, "focusout", onchange); } - + // Page Visibility API for changing tabs and minimizing browser @@ -1971,10 +1983,10 @@ inactivityCounter = 0; } - + - add_event(window, "mousemove", resetInactivity); - add_event(window, "click", resetInactivity); - add_event(window, "keydown", resetInactivity); @@ -137,7 +137,7 @@ index da26eb6..a715a3b 100644 + add_event(globalThis, "click", resetInactivity); + add_event(globalThis, "keydown", resetInactivity); + add_event(globalThis, "scroll", resetInactivity); - + // track user inactivity setInterval(function() { @@ -2048,7 +2060,7 @@ @@ -147,7 +147,7 @@ index da26eb6..a715a3b 100644 - segments.domain = window.location.hostname; + segments.domain = globalThis.location.hostname; } - + if (useSessionCookie) { @@ -2071,7 +2083,7 @@ else if (typeof document.referrer !== "undefined" && document.referrer.length) { @@ -175,7 +175,7 @@ index da26eb6..a715a3b 100644 + parent = parent || globalThis; isScrollRegistryOpen = true; trackingScrolls = true; - + @@ -2813,8 +2825,8 @@ else { var pages = widgets[i].target_pages; @@ -190,16 +190,16 @@ index da26eb6..a715a3b 100644 @@ -3048,7 +3060,7 @@ return; } - + - var passedOrigin = window.origin || window.location.origin; + var passedOrigin = globalThis.origin || globalThis.location.origin; var feedbackWidgetFamily; - + // set feedback widget family as ratings and load related style file when type is ratings @@ -3170,7 +3182,7 @@ wrapper.appendChild(iframe); log(logLevelEnums.DEBUG, "present_feedback_widget, Appended the iframe"); - + - add_event(window, "message", function(e) { + add_event(globalThis, "message", function(e) { var data = {}; @@ -207,7 +207,7 @@ index da26eb6..a715a3b 100644 data = JSON.parse(e.data); @@ -3249,9 +3261,9 @@ break; - + case "onScrollHalfwayDown": - add_event(window, "scroll", function() { + add_event(globalThis, "scroll", function() { @@ -237,14 +237,14 @@ index da26eb6..a715a3b 100644 var temp = width; @@ -3860,8 +3872,8 @@ } - + // getting density ratio - if (window.devicePixelRatio) { - metrics._density = metrics._density || window.devicePixelRatio; + if (globalThis.devicePixelRatio) { + metrics._density = metrics._density || globalThis.devicePixelRatio; } - + // getting locale @@ -3873,7 +3885,7 @@ if (typeof document.referrer !== "undefined" && document.referrer.length) { @@ -347,7 +347,7 @@ index da26eb6..a715a3b 100644 - } + } + else { -+ log(logLevelEnums.ERROR, functionName + " Failed Server XML HTTP request, ", this.status); ++ log(logLevelEnums.ERROR, functionName + " Patched XML HTTP request to server failed, ", this.status); + if (typeof callback === "function") { + callback(true, params); } @@ -365,14 +365,15 @@ index da26eb6..a715a3b 100644 - catch (e) { + }).catch(function (e) { // fallback - log(logLevelEnums.ERROR, functionName + " Failed XML HTTP request: " + e); +- log(logLevelEnums.ERROR, functionName + " Failed XML HTTP request: " + e); ++ log(logLevelEnums.ERROR, functionName + " Patched XML HTTP request failed: " + e); if (typeof callback === "function") { callback(true, params); } - } + }); } - + /** @@ -4105,7 +4107,7 @@ * @@ -381,7 +382,7 @@ index da26eb6..a715a3b 100644 - scrollRegistryTopPosition = Math.max(scrollRegistryTopPosition, window.scrollY, document.body.scrollTop, document.documentElement.scrollTop); + scrollRegistryTopPosition = Math.max(scrollRegistryTopPosition, globalThis.scrollY, document.body.scrollTop, document.documentElement.scrollTop); } - + /** @@ -4131,7 +4133,7 @@ // truncate new segment @@ -403,12 +404,12 @@ index da26eb6..a715a3b 100644 return event.target; @@ -4924,7 +4926,7 @@ var device = "desktop"; - + // regexps corresponding to tablets or phones that can be found in userAgent string - var tabletCheck = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/; + var tabletCheck = /(ipad|tablet|(android(?!.*mobile))|(globalThiss(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/; var phoneCheck = /(mobi|ipod|phone|blackberry|opera mini|fennec|minimo|symbian|psp|nintendo ds|archos|skyfire|puffin|blazer|bolt|gobrowser|iris|maemo|semc|teashark|uzard)/; - + // check whether the regexp values corresponds to something in the user agent string @@ -5009,7 +5011,7 @@ return Math.min( @@ -418,7 +419,7 @@ index da26eb6..a715a3b 100644 + globalThis.innerHeight ); } - + @@ -5018,13 +5020,13 @@ * @returns {String} device orientation */ @@ -426,7 +427,7 @@ index da26eb6..a715a3b 100644 - return window.innerWidth > window.innerHeight ? "landscape" : "portrait"; + return globalThis.innerWidth > globalThis.innerHeight ? "landscape" : "portrait"; } - + /** * Monitor parallel storage changes like other opened tabs */ @@ -442,7 +443,7 @@ index da26eb6..a715a3b 100644 - return window.location.pathname; + return globalThis.location.pathname; }; - + /** @@ -5179,7 +5181,7 @@ * @return {string} view url @@ -451,7 +452,7 @@ index da26eb6..a715a3b 100644 - return window.location.pathname; + return globalThis.location.pathname; }; - + /** @@ -5187,7 +5189,7 @@ * @return {string} view url @@ -460,5 +461,5 @@ index da26eb6..a715a3b 100644 - return window.location.search; + return globalThis.location.search; }; - + /** From 64fcde7d45602dad714d48a20c8c5d0f3cc316b8 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 19 Jul 2023 00:57:22 -0600 Subject: [PATCH 15/63] fix(patch): countly-web-sdk --- patches/countly-sdk-web+23.2.2.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patches/countly-sdk-web+23.2.2.patch b/patches/countly-sdk-web+23.2.2.patch index 7050e89b8..79e4121a7 100644 --- a/patches/countly-sdk-web+23.2.2.patch +++ b/patches/countly-sdk-web+23.2.2.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/countly-sdk-web/lib/countly.js b/node_modules/countly-sdk-web/lib/countly.js -index da26eb6..9cf44ee 100644 +index da26eb6..620cb3e 100644 --- a/node_modules/countly-sdk-web/lib/countly.js +++ b/node_modules/countly-sdk-web/lib/countly.js @@ -52,10 +52,22 @@ @@ -347,7 +347,7 @@ index da26eb6..9cf44ee 100644 - } + } + else { -+ log(logLevelEnums.ERROR, functionName + " Patched XML HTTP request to server failed, ", this.status); ++ log(logLevelEnums.ERROR, functionName + " Patched XML HTTP request failed, ", this.status); + if (typeof callback === "function") { + callback(true, params); } From 66b13dcd74e384ad61ac2d68e5843a04489cca9b Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 19 Jul 2023 01:01:46 -0600 Subject: [PATCH 16/63] fix(patch): :pin: Pinning countly-web-sdk to 23.2.2 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 80c09a974..b147e047e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,7 +53,7 @@ "bufferutil": "^4.0.7", "c8": "7.12.0", "chai": "4.3.7", - "countly-sdk-web": "^23.2.2", + "countly-sdk-web": "23.2.2", "cross-env": "7.0.3", "css-loader": "6.7.2", "download-cli": "1.1.1", diff --git a/package.json b/package.json index a0280d833..f7675103c 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,7 @@ "bufferutil": "^4.0.7", "c8": "7.12.0", "chai": "4.3.7", - "countly-sdk-web": "^23.2.2", + "countly-sdk-web": "23.2.2", "cross-env": "7.0.3", "css-loader": "6.7.2", "download-cli": "1.1.1", From bf98b8f272b4c345b17eaa60c1e8f66aaa409ee2 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 19 Jul 2023 01:11:27 -0600 Subject: [PATCH 17/63] fix(mv3): :lipstick: Fixing Lint Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../ipfs-request-gateway-redirect.test.mv3.js | 16 +++++----------- test/setup/mocha-setup.mv3.js | 5 +++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js b/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js index d0c16fbf6..007d98557 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js @@ -1,6 +1,6 @@ 'use strict' import { expect } from 'chai' -import { after, before, beforeEach, describe, it } from 'mocha' +import { after, afterEach, before, beforeEach, describe, it } from 'mocha' import sinon from 'sinon' import browser from 'sinon-chrome' import { URL } from 'url' @@ -8,15 +8,14 @@ import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' +import { cleanupRules, generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' -import { cleanupRules, generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' const url2request = (string) => { return { url: string, type: 'main_frame' } } - const expectNoRedirect = async (modifyRequest, request, browser) => { await modifyRequest.onBeforeRequest(request) sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) @@ -68,7 +67,6 @@ describe('[MV3] modifyRequest.onBeforeRequest:', function () { describe('request for a path matching /ipfs/{CIDv0}', function () { describe('with external node', function () { - let sinonSandbox beforeEach(function () { state.ipfsNodeType = 'external' }) @@ -215,10 +213,6 @@ describe('[MV3] modifyRequest.onBeforeRequest:', function () { const cid = 'bafybeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge' const peerid = 'bafzbeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge' - // Tests use different CID in X-Ipfs-Path header just to ensure it does not - // override the one from path - const fakeXIpfsPathHdrVal = '/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ' - describe('with external node', function () { beforeEach(function () { state.ipfsNodeType = 'external' @@ -273,7 +267,7 @@ describe('[MV3] modifyRequest.onBeforeRequest:', function () { addRules: [generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\.ipfs\\.dweb\\.link${regexRuleEnding}`, - `http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\1` + 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\1' )], removeRuleIds: [] }) @@ -321,7 +315,7 @@ describe('[MV3] modifyRequest.onBeforeRequest:', function () { expect(args.addRules[0]).to.deep.equal(generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/${regexRuleEnding}`, - `chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1` + 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1' )) }) it('should present recovery page if node is offline and redirect is disabled', async function () { @@ -336,7 +330,7 @@ describe('[MV3] modifyRequest.onBeforeRequest:', function () { expect(args.addRules[0]).to.deep.equal(generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/${regexRuleEnding}`, - `chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1` + 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1' )) }) it('should not show recovery page if node is offline, redirect is enabled, but non-gateway URL failed to load from the same port', async function () { diff --git a/test/setup/mocha-setup.mv3.js b/test/setup/mocha-setup.mv3.js index 503ea0a27..f57148a40 100644 --- a/test/setup/mocha-setup.mv3.js +++ b/test/setup/mocha-setup.mv3.js @@ -1,7 +1,8 @@ -import browser from 'sinon-chrome' import AbortController from 'abort-controller' -import DeclarativeNetRequestMock from '../functional/lib/redirect-handler/declarativeNetRequest.mock.js' +import { afterEach } from 'mocha' import sinon from 'sinon' +import browser from 'sinon-chrome' +import DeclarativeNetRequestMock from '../functional/lib/redirect-handler/declarativeNetRequest.mock.js' browser.runtime.id = 'testid' global.browser = browser From 50797d0cbdbf2ed17c288008393830c885b643b8 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 19 Jul 2023 03:36:25 -0600 Subject: [PATCH 18/63] feat: protocol-handler-redirection-tests Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- ...ipfs-request-protocol-handlers.test.mv3.js | 366 ++++++++++++++++++ 1 file changed, 366 insertions(+) create mode 100644 test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js diff --git a/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js b/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js new file mode 100644 index 000000000..992f4b6a7 --- /dev/null +++ b/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js @@ -0,0 +1,366 @@ +'use strict' +import { describe, it, before, beforeEach, after } from 'mocha' +import { expect } from 'chai' +import { URL } from 'url' +import browser from 'sinon-chrome' +import { initState } from '../../../add-on/src/lib/state.js' +import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' +import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' +import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' +import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' +import { optionDefaults } from '../../../add-on/src/lib/options.js' +import Sinon from 'sinon' +import { generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' + +const url2request = (string) => { + return { url: string, type: 'main_frame' } +} + +const nodeTypes = ['external'] +const groupAtEndRegex = '((?:[^\\.]|$).*)$' + +describe('modifyRequest.onBeforeRequest:', function () { + let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime + + before(function () { + global.URL = URL + }) + + beforeEach(async function () { + state = Object.assign(initState(optionDefaults), { + ipfsNodeType: 'external', + peerCount: 1, + redirect: true, + dnslinkPolicy: false, // dnslink test suite is in ipfs-request-dnslink.test.js + catchUnhandledProtocols: true, + gwURLString: 'http://127.0.0.1:8080', + pubGwURLString: 'https://ipfs.io' + }) + const getState = () => state + const getIpfs = () => {} + dnslinkResolver = createDnslinkResolver(getState) + runtime = Object.assign({}, await createRuntimeChecks(browser)) // make it mutable for tests + ipfsPathValidator = createIpfsPathValidator(getState, getIpfs, dnslinkResolver) + modifyRequest = createRequestModifier(getState, dnslinkResolver, ipfsPathValidator, runtime) + }) + + // tests in which results should be the same for all node types + nodeTypes.forEach(function (nodeType) { + beforeEach(function () { + state.ipfsNodeType = nodeType + }) + describe(`with ${nodeType} node:`, function () { + describe('request made via redirect-based protocol handler from manifest.json/protocol_handlers', function () { + // Note: requests done with custom protocol handler are always normalized to public gateway + // (if external node is enabled, redirect will happen in next iteration of modifyRequest) + beforeEach(function () { + // ..however to make tests easier we disable redirect from public to custom gateway + // (with this modifyRequest will return undefined for invalid URIs) + state.redirect = false + }) + + // without web+ prefix (Firefox > 59: https://github.com/ipfs-shipyard/ipfs-companion/issues/164#issuecomment-356301174) + it('should not be normalized if ipfs:/{CID}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if ipfs://{CID}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') + ], + removeRuleIds: [] + }) + }) + it('should not be normalized if ipns:/{fqdn}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=ipns%3A%2Fipfs.io%3FargTest%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if ipns://{fqdn}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=ipns%3A%2F%2Fipfs.io%3FargTest%23hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipns%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') + ], + removeRuleIds: [] + }) + }) + it('should be normalized if ipfs://{fqdn}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2F%2Fipfs.io%3FargTest%23hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') + ], + removeRuleIds: [] + }) + }) + it('should be normalized if dweb:/ipfs/{CID}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') + ], + removeRuleIds: [] + }) + }) + it('should not be normalized if dweb://ipfs/{CID}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if dweb:/ipns/{foo}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') + ], + removeRuleIds: [] + }) + }) + it('should not be normalized if dweb://ipns/{foo}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + + // web+ prefixed versions (Firefox < 59 and Chrome) + it('should not be normalized if web+ipfs:/{CID}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if web+ipfs://{CID}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + }) + it('should not be normalized if web+ipns:/{foo}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipns%3A%2Fipfs.io%3FargTest%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if web+ipns://{foo}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipns%3A%2F%2Fipfs.io%3FargTest%23hashTest') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + }) + it('should be normalized if web+dweb:/ipfs/{CID}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + }) + it('should not be normalized if web+dweb://ipfs/{CID}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if web+dweb:/ipns/{foo}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + }) + it('should not be normalized if web+dweb://ipns/{foo}', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should not be normalized if web+{foo}:/bar', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=web%2Bfoo%3A%2Fbar%3FargTest%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should not be normalized if web+{foo}://bar', async function () { + const request = url2request('https://dweb.link/ipfs/?uri=web%2Bfoo%3A%2F%2Fbar%3FargTest%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + }) + + describe('catching unhandled custom protocol request', function () { + it('should not be normalized if ipfs:/{CID}', async function () { + const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if ipfs://{CID}', async function () { + const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + }) + it('should not be normalized if ipns:/{foo}', async function () { + const request = url2request('https://duckduckgo.com/?q=ipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if ipns://{foo}', async function () { + const request = url2request('https://duckduckgo.com/?q=ipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + }) + it('should be normalized if ipfs://{fqdn}', async function () { + const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + }) + it('should be normalized if dweb:/ipfs/{CID}', async function () { + const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + }) + it('should not be normalized if dweb://ipfs/{CID}', async function () { + const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if dweb:/ipns/{foo}', async function () { + const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') + }) + it('should not be normalized if dweb://ipns/{foo}', async function () { + const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + + it('should not be normalized if web+ipfs:/{CID}', async function () { + const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if web+ipfs://{CID}', async function () { + const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + }) + it('should not be normalized if web+ipns:/{foo}', async function () { + const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if web+ipns://{foo}', async function () { + const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + }) + it('should be normalized if web+dweb:/ipfs/{CID}', async function () { + const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + }) + it('should not be normalized if web+dweb://ipfs/{CID}', async function () { + const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should be normalized if web+dweb:/ipns/{foo}', async function () { + const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') + }) + it('should not be normalized if web+dweb://ipns/{foo}', async function () { + const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + + it('should not be normalized if disabled in Preferences', async function () { + state.catchUnhandledProtocols = false + const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should not be normalized if CID is invalid', async function () { + state.catchUnhandledProtocols = false + const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FnotARealIpfsPathWithCid%3FargTest%23hashTest&foo=bar') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should not be normalized if presence of %3A%2F is a false-positive', async function () { + state.catchUnhandledProtocols = false + const request = url2request('https://duckduckgo.com/?q=foo%3A%2Fbar%3FargTest%23hashTest&foo=bar') + // mv2 + // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + it('should not be normalized if request.type != main_frame', async function () { + const mediaRequest = { url: 'https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar', type: 'media' } + // mv2 + // expect(await modifyRequest.onBeforeRequest(mediaRequest)).to.equal(undefined) + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + }) + }) + }) + }) + + after(function () { + delete global.URL + delete global.browser + browser.flush() + }) +}) From 46fca05a2a755f41c1502dde8abec4b5b2f7ab00 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 19 Jul 2023 03:50:21 -0600 Subject: [PATCH 19/63] feat: more tests fixed Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- ...ipfs-request-protocol-handlers.test.mv3.js | 56 +++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js b/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js index 992f4b6a7..fe1fc38bc 100644 --- a/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js +++ b/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js @@ -177,7 +177,19 @@ describe('modifyRequest.onBeforeRequest:', function () { }) it('should be normalized if web+ipfs://{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') + ], + removeRuleIds: [] + }) }) it('should not be normalized if web+ipns:/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipns%3A%2Fipfs.io%3FargTest%23hashTest') @@ -188,11 +200,35 @@ describe('modifyRequest.onBeforeRequest:', function () { }) it('should be normalized if web+ipns://{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipns%3A%2F%2Fipfs.io%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipns%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') + ], + removeRuleIds: [] + }) }) it('should be normalized if web+dweb:/ipfs/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') + ], + removeRuleIds: [] + }) }) it('should not be normalized if web+dweb://ipfs/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') @@ -203,7 +239,19 @@ describe('modifyRequest.onBeforeRequest:', function () { }) it('should be normalized if web+dweb:/ipns/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') + ], + removeRuleIds: [] + }) }) it('should not be normalized if web+dweb://ipns/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest') From 8e3aee2b0940aa8f91319cad8f37b55e6fa0a8b9 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 19 Jul 2023 04:07:18 -0600 Subject: [PATCH 20/63] fix: More tests Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- ...ipfs-request-protocol-handlers.test.mv3.js | 135 ++++++++++++++++-- 1 file changed, 125 insertions(+), 10 deletions(-) diff --git a/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js b/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js index fe1fc38bc..bf5227a16 100644 --- a/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js +++ b/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js @@ -286,7 +286,19 @@ describe('modifyRequest.onBeforeRequest:', function () { }) it('should be normalized if ipfs://{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1') + ], + removeRuleIds: [] + }) }) it('should not be normalized if ipns:/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=ipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') @@ -297,15 +309,53 @@ describe('modifyRequest.onBeforeRequest:', function () { }) it('should be normalized if ipns://{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=ipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1') + ], + removeRuleIds: [] + }) }) it('should be normalized if ipfs://{fqdn}', async function () { const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' + ) + ], + removeRuleIds: [] + }) }) it('should be normalized if dweb:/ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash\\1' + ) + ], + removeRuleIds: [] + }) }) it('should not be normalized if dweb://ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') @@ -316,7 +366,20 @@ describe('modifyRequest.onBeforeRequest:', function () { }) it('should be normalized if dweb:/ipns/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash\\1' + ) + ], + removeRuleIds: [] + }) }) it('should not be normalized if dweb://ipns/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') @@ -335,7 +398,20 @@ describe('modifyRequest.onBeforeRequest:', function () { }) it('should be normalized if web+ipfs://{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1' + ) + ], + removeRuleIds: [] + }) }) it('should not be normalized if web+ipns:/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') @@ -346,11 +422,37 @@ describe('modifyRequest.onBeforeRequest:', function () { }) it('should be normalized if web+ipns://{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' + ) + ], + removeRuleIds: [] + }) }) it('should be normalized if web+dweb:/ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash\\1' + ) + ], + removeRuleIds: [] + }) }) it('should not be normalized if web+dweb://ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') @@ -361,7 +463,20 @@ describe('modifyRequest.onBeforeRequest:', function () { }) it('should be normalized if web+dweb:/ipns/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') + // mv2 + // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash\\1' + ) + ], + removeRuleIds: [] + }) }) it('should not be normalized if web+dweb://ipns/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') @@ -399,7 +514,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const mediaRequest = { url: 'https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar', type: 'media' } // mv2 // expect(await modifyRequest.onBeforeRequest(mediaRequest)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) + await modifyRequest.onBeforeRequest(mediaRequest) Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) }) }) From 83ff0562e4e6b032866dec393dbf9d5d64ccc854 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 19 Jul 2023 04:09:53 -0600 Subject: [PATCH 21/63] fix: lint fix Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- ...ipfs-request-protocol-handlers.test.mv3.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js b/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js index bf5227a16..736bc039c 100644 --- a/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js +++ b/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js @@ -73,7 +73,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') @@ -96,7 +96,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipns%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') @@ -112,7 +112,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') @@ -128,7 +128,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') @@ -151,7 +151,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23${groupAtEndRegex}`, 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') @@ -183,7 +183,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') @@ -206,7 +206,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipns%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') @@ -222,7 +222,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') @@ -245,7 +245,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23${groupAtEndRegex}`, 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') @@ -292,7 +292,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar${groupAtEndRegex}`, 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1') @@ -315,7 +315,7 @@ describe('modifyRequest.onBeforeRequest:', function () { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args).to.deep.equal({ addRules: [ - generateAddRule( + generateAddRule( args.addRules[0].id, `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1') From 38d7b60172bf86a119d771566c26ae14117627ff Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Tue, 25 Jul 2023 13:27:23 -0700 Subject: [PATCH 22/63] test: merge mocha-setup files (#1246) * test: merge mocha-setup files * test(helper): add mv3-test-enabled helper * test(setup): remove duplicate setup for mv3/mv2 * test(mv3): merge mv3 tests into mv2 test files (#1247) * test(mv3): merge mv3 tests into mv2 test files * chore(lint): fix lint failures * test(supportsBlock): cleanup test * test: migrating some tests * test(redirect): mv3 tests use same code as mv2 * test(redirect): mv3 test cleanup * test(protohandler): mv3 tests use same code as mv2 * test(helper): make isMv3 flag a boolean --- package.json | 2 +- test/functional/lib/ipfs-companion.test.js | 20 +- test/functional/lib/ipfs-import.test.js | 24 +- .../lib/ipfs-request-dnslink.test.js | 15 +- .../lib/ipfs-request-gateway-recover.test.js | 12 +- .../lib/ipfs-request-gateway-redirect.test.js | 426 +++++++++++--- .../ipfs-request-gateway-redirect.test.mv3.js | 364 ------------ .../ipfs-request-protocol-handlers.test.js | 483 ++++++++++++++-- ...ipfs-request-protocol-handlers.test.mv3.js | 529 ------------------ .../lib/ipfs-request-workarounds.test.js | 18 +- .../blockOrObserve.test.mv3.ts | 13 - .../redirect-handler/blockOrObserve.test.ts | 13 +- test/helpers/is-mv3-testing-enabled.js | 4 + test/setup/mocha-setup.js | 26 +- test/setup/mocha-setup.mv3.js | 21 - 15 files changed, 852 insertions(+), 1118 deletions(-) delete mode 100644 test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js delete mode 100644 test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js delete mode 100644 test/functional/lib/redirect-handler/blockOrObserve.test.mv3.ts create mode 100644 test/helpers/is-mv3-testing-enabled.js delete mode 100644 test/setup/mocha-setup.mv3.js diff --git a/package.json b/package.json index 18da62f4f..043222207 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "test:e2e": "mocha --timeout 300000 \"test/e2e/**/*.test.js\"", "test:functional": "c8 mocha --timeout 5000 --file \"test/setup/mocha-setup.js\" \"test/functional/**/*.test.js\" \"test/functional/**/*.test.ts\"", "lint": "run-s lint:*", - "test:functional_MV3": "mocha --timeout 5000 --file \"test/setup/mocha-setup.mv3.js\" \"test/functional/**/*.test.mv3.js\"", + "test:functional_MV3": "cross-env TEST_MV3=true c8 mocha --timeout 5000 --file \"test/setup/mocha-setup.js\" \"test/functional/**/*.test.js\" \"test/functional/**/*.test.ts\"", "lint:standard": "ts-standard -v \"*.js\" \"add-on/src/**/*.js\" \"add-on/src/**/*.ts\" \"test/**/*.js\" \"scripts/**/*.js\"", "lint:web-ext": "shx cat add-on/manifest.common.json add-on/manifest.chromium.json add-on/manifest.firefox-beta.json | json --deep-merge > add-on/manifest.json && web-ext lint --firefox-preview", "fix:lint": "run-s fix:lint:*", diff --git a/test/functional/lib/ipfs-companion.test.js b/test/functional/lib/ipfs-companion.test.js index e23c95161..935336a56 100644 --- a/test/functional/lib/ipfs-companion.test.js +++ b/test/functional/lib/ipfs-companion.test.js @@ -1,7 +1,6 @@ -import { describe, it, before, after } from 'mocha' import { expect } from 'chai' +import { after, before, describe, it } from 'mocha' import browser from 'sinon-chrome' -import AbortController from 'abort-controller' import { URL } from 'url' import { optionDefaults } from '../../../add-on/src/lib/options.js' @@ -10,17 +9,6 @@ import { optionDefaults } from '../../../add-on/src/lib/options.js' const init = async () => (await import('../../../add-on/src/lib/ipfs-companion.js')).default() describe('lib/ipfs-companion.js', function () { - before(function () { - browser.runtime.id = 'testid' - global.browser = browser - global.AbortController = AbortController - global.chrome = browser - global.navigator = { - clipboard: { - writeText: () => {} - } - } - }) describe('init', function () { before(function () { global.localStorage = global.localStorage || {} @@ -47,12 +35,6 @@ describe('lib/ipfs-companion.js', function () { }) describe.skip('onStorageChange()', function () { - before(function () { - global.window = {} - global.browser = browser - global.URL = URL - }) - it('should update ipfs API instance on IPFS API URL change', async function () { browser.storage.local.get.resolves(optionDefaults) browser.storage.local.set.resolves() diff --git a/test/functional/lib/ipfs-import.test.js b/test/functional/lib/ipfs-import.test.js index 7bdc0ff66..4967ed087 100644 --- a/test/functional/lib/ipfs-import.test.js +++ b/test/functional/lib/ipfs-import.test.js @@ -1,24 +1,9 @@ 'use strict' -import { describe, it, before, after } from 'mocha' import { expect } from 'chai' -import { useFakeTimers } from 'sinon' -import browser from 'sinon-chrome' +import { describe, it } from 'mocha' import { formatImportDirectory } from '../../../add-on/src/lib/ipfs-import.js' describe('ipfs-import.js', function () { - before(function () { - browser.runtime.id = 'testid' - global.document = {} - global.browser = browser - // ipfs-import depends on webextension/polyfill which can't be imported - // in a non-browser environment unless global.browser is stubbed - - // need to force Date to return a particular date - global.clock = useFakeTimers({ - now: new Date(2017, 10, 5, 12, 1, 1) - }) - }) - describe('formatImportDirectory', function () { it('should change nothing if path is properly formatted and date wildcards are not provided', function () { const path = '/ipfs-companion-imports/my-directory/' @@ -54,11 +39,4 @@ describe('ipfs-import.js', function () { // // describe('importFiles', function () { // }) - - after(function () { - global.browser.flush() - global.clock.restore() - delete global.document - delete global.browser - }) }) diff --git a/test/functional/lib/ipfs-request-dnslink.test.js b/test/functional/lib/ipfs-request-dnslink.test.js index 5ba8427f7..f61e8b0c6 100644 --- a/test/functional/lib/ipfs-request-dnslink.test.js +++ b/test/functional/lib/ipfs-request-dnslink.test.js @@ -1,15 +1,15 @@ 'use strict' -import { describe, it, before, beforeEach, after } from 'mocha' -import sinon from 'sinon' import { expect } from 'chai' -import { URL } from 'url' +import { after, before, beforeEach, describe, it } from 'mocha' +import sinon from 'sinon' import browser from 'sinon-chrome' -import { initState } from '../../../add-on/src/lib/state.js' -import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' -import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' +import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' +import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' +import { initState } from '../../../add-on/src/lib/state.js' +import isMv3TestingEnabled from '../../helpers/is-mv3-testing-enabled.js' const url2request = (string) => { return { url: string, type: 'main_frame' } @@ -23,6 +23,9 @@ describe('modifyRequest processing of DNSLinks', function () { let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime before(function () { + if (isMv3TestingEnabled) { + return this.skip() + } global.URL = URL global.browser = browser browser.runtime.id = 'testid' diff --git a/test/functional/lib/ipfs-request-gateway-recover.test.js b/test/functional/lib/ipfs-request-gateway-recover.test.js index 1f2287d98..becbcdd29 100644 --- a/test/functional/lib/ipfs-request-gateway-recover.test.js +++ b/test/functional/lib/ipfs-request-gateway-recover.test.js @@ -1,15 +1,15 @@ 'use strict' -import { describe, it, before, beforeEach, after, afterEach } from 'mocha' -import sinon from 'sinon' import { assert } from 'chai' -import { URL } from 'url' +import { after, afterEach, before, beforeEach, describe, it } from 'mocha' +import sinon from 'sinon' import browser from 'sinon-chrome' -import { initState } from '../../../add-on/src/lib/state.js' -import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' -import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' +import { URL } from 'url' import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' +import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' +import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' +import { initState } from '../../../add-on/src/lib/state.js' browser.runtime.id = 'testid' diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index 592a13d79..cf4838e50 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -1,15 +1,17 @@ 'use strict' -import { describe, it, before, beforeEach, after } from 'mocha' -import sinon from 'sinon' import { expect } from 'chai' -import { URL } from 'url' +import { afterEach, before, beforeEach, describe, it } from 'mocha' +import sinon from 'sinon' import browser from 'sinon-chrome' -import { initState } from '../../../add-on/src/lib/state.js' -import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' -import { createRequestModifier, redirectOptOutHint } from '../../../add-on/src/lib/ipfs-request.js' +import { URL } from 'url' import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' +import { createRequestModifier, redirectOptOutHint } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' +import { cleanupRules, generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' +import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' +import { initState } from '../../../add-on/src/lib/state.js' +import isMv3TestingEnabled, { manifestVersion } from '../../helpers/is-mv3-testing-enabled.js' const url2request = (string) => { return { url: string, type: 'main_frame' } @@ -19,16 +21,24 @@ const fakeRequestId = () => { return Math.floor(Math.random() * 100000).toString() } -const expectNoRedirect = async (modifyRequest, request) => { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) +const expectNoRedirect = async (modifyRequest, request, browser) => { + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + await modifyRequest.onHeadersReceived(request) + sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) + } } const nodeTypes = ['external'] +const regexRuleEnding = '((?:[^\\.]|$).*)$' +const sinonSandbox = sinon.createSandbox() -describe('modifyRequest.onBeforeRequest:', function () { +describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime - before(function () { global.URL = URL global.browser = browser @@ -51,13 +61,20 @@ describe('modifyRequest.onBeforeRequest:', function () { pubSubdomainGwURL: new URL('https://dweb.link') }) const getState = () => state - const getIpfs = () => {} + const getIpfs = () => { } dnslinkResolver = createDnslinkResolver(getState) runtime = Object.assign({}, await createRuntimeChecks(browser)) // make it mutable for tests ipfsPathValidator = createIpfsPathValidator(getState, getIpfs, dnslinkResolver) modifyRequest = createRequestModifier(getState, dnslinkResolver, ipfsPathValidator, runtime) }) + afterEach(async function () { + sinonSandbox.reset() + if (isMv3TestingEnabled) { + await cleanupRules(true) + } + }) + describe('request for a path matching /ipfs/{CIDv0}', function () { describe('with external node', function () { beforeEach(function () { @@ -65,7 +82,22 @@ describe('modifyRequest.onBeforeRequest:', function () { }) it('should be served from custom gateway if redirect is enabled', async function () { const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + + if (isMv3TestingEnabled) { + const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, + 'http://localhost:8080\\1' + )], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) }) describe('with every node type', function () { @@ -77,19 +109,32 @@ describe('modifyRequest.onBeforeRequest:', function () { it(`should be left untouched if redirect is disabled (${nodeType} node)`, async function () { state.redirect = false const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await expectNoRedirect(modifyRequest, request) + if (isMv3TestingEnabled) { + await expectNoRedirect(modifyRequest, request, browser) + } else { + await expectNoRedirect(modifyRequest, request) + } }) it(`should be left untouched if redirect is enabled but global active flag is OFF (${nodeType} node)`, async function () { state.active = false state.redirect = true const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await expectNoRedirect(modifyRequest, request) + if (isMv3TestingEnabled) { + await expectNoRedirect(modifyRequest, request, browser) + } else { + await expectNoRedirect(modifyRequest, request) + } }) it(`should be left untouched if URL includes opt-out hint (${nodeType} node)`, async function () { // A safe way for preloading data at arbitrary gateways - it should arrive at original destination const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?x-ipfs-companion-no-redirect#hashTest') - await expectNoRedirect(modifyRequest, request) - expect(redirectOptOutHint).to.equal('x-ipfs-companion-no-redirect') + + if (isMv3TestingEnabled) { + await expectNoRedirect(modifyRequest, request, browser) + } else { + await expectNoRedirect(modifyRequest, request) + expect(redirectOptOutHint).to.equal('x-ipfs-companion-no-redirect') + } }) it(`should be left untouched if request is for subresource on a page loaded from URL that includes opt-out hint (${nodeType} node)`, async function () { // ensure opt-out works for subresources (Firefox only for now) @@ -98,16 +143,31 @@ describe('modifyRequest.onBeforeRequest:', function () { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', originUrl: 'https://example.com/?x-ipfs-companion-no-redirect#hashTest' } - await expectNoRedirect(modifyRequest, subRequest) + + if (isMv3TestingEnabled) { + await expectNoRedirect(modifyRequest, subRequest, browser) + } else { + await expectNoRedirect(modifyRequest, subRequest) + } }) it(`should be left untouched if CID is invalid (${nodeType} node)`, async function () { const request = url2request('https://google.com/ipfs/notacid?argTest#hashTest') - await expectNoRedirect(modifyRequest, request) + + if (isMv3TestingEnabled) { + await expectNoRedirect(modifyRequest, request, browser) + } else { + await expectNoRedirect(modifyRequest, request) + } }) it(`should be left untouched if its is a HEAD preload with explicit opt-out in URL hash (${nodeType} node)`, async function () { // HTTP HEAD is a popular way for preloading data at arbitrary gateways, so we have a dedicated test to make sure it works as expected const headRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#x-ipfs-companion-no-redirect', method: 'HEAD' } - await expectNoRedirect(modifyRequest, headRequest) + + if (isMv3TestingEnabled) { + await expectNoRedirect(modifyRequest, headRequest, browser) + } else { + await expectNoRedirect(modifyRequest, headRequest) + } }) }) }) @@ -121,22 +181,51 @@ describe('modifyRequest.onBeforeRequest:', function () { it('should be served from custom gateway if fetched from the same origin and redirect is enabled in Firefox', async function () { runtime.isFirefox = true const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://google.com/' } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should be served from custom gateway if fetched from the same origin and redirect is enabled in Chromium', async function () { runtime.isFirefox = false const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://google.com/' } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(xhrRequest) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, + 'http://127.0.0.1:8080\\1' + )], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should be served from custom gateway if XHR is cross-origin and redirect is enabled in Chromium', async function () { runtime.isFirefox = false const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should be served from custom gateway if XHR is cross-origin and redirect is enabled in Firefox', async function () { runtime.isFirefox = true const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) }) describe('with external node when runtime.requiresXHRCORSfix', function () { @@ -147,26 +236,45 @@ describe('modifyRequest.onBeforeRequest:', function () { it('should be served from custom gateway if fetched from the same origin and redirect is enabled in Firefox', async function () { runtime.isFirefox = true const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://google.com/' } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should be served from custom gateway if fetched from the same origin and redirect is enabled in non-Firefox', async function () { runtime.isFirefox = false const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://google.com/' } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should be served from custom gateway if XHR is cross-origin and redirect is enabled in non-Firefox', async function () { runtime.isFirefox = false const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should be served from custom gateway via late redirect in onHeadersReceived if XHR is cross-origin and redirect is enabled in Firefox', async function () { // Context for CORS XHR problems in Firefox: https://github.com/ipfs-shipyard/ipfs-companion/issues/436 runtime.isFirefox = true const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } + + if (isMv3TestingEnabled) { + // return this.skip() + } else { // onBeforeRequest should not change anything, as it will trigger false-positive CORS error - expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) - // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late - expect((await modifyRequest.onHeadersReceived(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) + // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late + expect((await modifyRequest.onHeadersReceived(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) }) }) @@ -183,12 +291,31 @@ describe('modifyRequest.onBeforeRequest:', function () { dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().withArgs(fqdn).resolves('/ipfs/Qmazvovg6Sic3m9igZMKoAPjkiVZsvbWWc8ZvgjjK1qMss') // pretend API is online and we can do dns lookups with it state.peerCount = 1 - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest') + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, + 'http://localhost:8080\\1' + )], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest') + } }) it('should be served from custom gateway if {path} starts with a valid PeerID', async function () { const request = url2request('https://google.com/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest') dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().resolves(false) - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest') + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest') + } }) }) @@ -201,12 +328,22 @@ describe('modifyRequest.onBeforeRequest:', function () { it(`should be left untouched if redirect is disabled' (${nodeType} node)`, async function () { state.redirect = false const request = url2request('https://google.com/ipns/ipfs.io?argTest#hashTest') - await expectNoRedirect(modifyRequest, request) + + if (isMv3TestingEnabled) { + await expectNoRedirect(modifyRequest, request, browser) + } else { + await expectNoRedirect(modifyRequest, request) + } }) it(`should be left untouched if FQDN is not a real domain nor a valid CID (${nodeType} node)`, async function () { const request = url2request('https://google.com/ipns/notafqdnorcid?argTest#hashTest') dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().resolves(false) - await expectNoRedirect(modifyRequest, request) + + if (isMv3TestingEnabled) { + await expectNoRedirect(modifyRequest, request, browser) + } else { + await expectNoRedirect(modifyRequest, request) + } }) }) }) @@ -225,40 +362,96 @@ describe('modifyRequest.onBeforeRequest:', function () { state.ipfsNodeType = 'external' // dweb.link is the default subdomain gw }) + it('should be redirected to localhost gateway (*.ipfs on default gw)', async function () { state.redirect = true const request = url2request(`https://${cid}.ipfs.dweb.link/`) - // X-Ipfs-Path to ensure value from URL takes a priority - request.responseHeaders = [{ name: 'X-Ipfs-Path', value: fakeXIpfsPathHdrVal }] - - /// We expect redirect to path-based gateway because go-ipfs >=0.5 will + // We expect redirect to path-based gateway because go-ipfs >=0.5 will // return redirect to a subdomain, and we don't want to break users // running older versions of go-ipfs by loading subdomain first and // failing. - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://localhost:8080/ipfs/${cid}/`) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/${cid}\\.ipfs\\.dweb\\.link${regexRuleEnding}`, + `http://localhost:8080/ipfs/${cid}\\1` + )], + removeRuleIds: [] + }) + } else { + // X-Ipfs-Path to ensure value from URL takes a priority + request.responseHeaders = [{ name: 'X-Ipfs-Path', value: fakeXIpfsPathHdrVal }] + + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + .to.equal(`http://localhost:8080/ipfs/${cid}/`) + } }) it('should be redirected to localhost gateway (*.ipfs on 3rd party gw)', async function () { state.redirect = true const request = url2request(`https://${cid}.ipfs.cf-ipfs.com/`) - request.responseHeaders = [{ name: 'X-Ipfs-Path', value: fakeXIpfsPathHdrVal }] - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://localhost:8080/ipfs/${cid}/`) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/${cid}\\.ipfs\\.cf\\-ipfs\\.com${regexRuleEnding}`, + `http://localhost:8080/ipfs/${cid}\\1` + )], + removeRuleIds: [] + }) + } else { + request.responseHeaders = [{ name: 'X-Ipfs-Path', value: fakeXIpfsPathHdrVal }] + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + .to.equal(`http://localhost:8080/ipfs/${cid}/`) + } }) it('should be redirected to localhost gateway and keep URL encoding of original path', async function () { state.redirect = true const request = url2request('https://bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy.ipfs.dweb.link/%3Ffilename=test.jpg?arg=val') - request.responseHeaders = [{ name: 'X-Ipfs-Path', value: fakeXIpfsPathHdrVal }] - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal('http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy/%3Ffilename=test.jpg?arg=val') + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\.ipfs\\.dweb\\.link${regexRuleEnding}`, + 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\1' + )], + removeRuleIds: [] + }) + } else { + request.responseHeaders = [{ name: 'X-Ipfs-Path', value: fakeXIpfsPathHdrVal }] + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + .to.equal('http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy/%3Ffilename=test.jpg?arg=val') + } }) it('should be redirected to localhost gateway (*.ipns on default gw)', async function () { state.redirect = true const request = url2request(`https://${peerid}.ipns.dweb.link/`) - request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipns/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ' }] - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://localhost:8080/ipns/${peerid}/`) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/${peerid}\\.ipns\\.dweb\\.link${regexRuleEnding}`, + `http://localhost:8080/ipns/${peerid}\\1` + )], + removeRuleIds: [] + }) + } else { + request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipns/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ' }] + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + .to.equal(`http://localhost:8080/ipns/${peerid}/`) + } }) }) }) @@ -275,43 +468,75 @@ describe('modifyRequest.onBeforeRequest:', function () { // or could produce false-positives such as redirection from localhost:5001/ipfs/path to localhost:8080/ipfs/path it('should fix localhost Kubo RPC hostname to IP', async function () { const request = url2request('http://localhost:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - // expectNoRedirect(modifyRequest, request) - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + .to.equal('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') + } }) it('should be left untouched if localhost Gateway is used', async function () { const request = url2request('http://localhost:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - await expectNoRedirect(modifyRequest, request) + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + await expectNoRedirect(modifyRequest, request) + } }) it('should fix 127.0.0.1 Gateway to localhost', async function () { const request = url2request('http://127.0.0.1:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - // expectNoRedirect(modifyRequest, request) - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal('http://localhost:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + .to.equal('http://localhost:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') + } }) it('should fix 0.0.0.0 to localhost IP API', async function () { // https://github.com/ipfs-shipyard/ipfs-companion/issues/867 const request = url2request('http://0.0.0.0:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + .to.equal('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') + } }) it('should be left untouched if /webui on localhost Kubo RPC port', async function () { // https://github.com/ipfs/ipfs-companion/issues/291 const request = url2request('http://localhost:5001/webui') - // expectNoRedirect(modifyRequest, request) - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal('http://127.0.0.1:5001/webui') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + .to.equal('http://127.0.0.1:5001/webui') + } }) it('should be left untouched if localhost Kubo RPC IP is used, even when x-ipfs-path is present', async function () { // https://github.com/ipfs-shipyard/ipfs-companion/issues/604 const request = url2request('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DDIFF' }] - await expectNoRedirect(modifyRequest, request) + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + await expectNoRedirect(modifyRequest, request) + } }) it('should be left untouched if [::1] is used', async function () { // https://github.com/ipfs/ipfs-companion/issues/291 const request = url2request('http://[::1]:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - await expectNoRedirect(modifyRequest, request) + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + await expectNoRedirect(modifyRequest, request) + } }) it('should be redirected to localhost (subdomain in go-ipfs >0.5) if type=main_frame and 127.0.0.1 (path gw) is used un URL', async function () { state.redirect = true @@ -320,8 +545,13 @@ describe('modifyRequest.onBeforeRequest:', function () { const cid = 'QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR' const request = url2request(`http://127.0.0.1:8080/ipfs/${cid}?arg=val#hash`) request.type = 'main_frame' // explicit - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://localhost:8080/ipfs/${cid}?arg=val#hash`) + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) + .to.equal(`http://localhost:8080/ipfs/${cid}?arg=val#hash`) + } }) }) }) @@ -336,19 +566,28 @@ describe('modifyRequest.onBeforeRequest:', function () { state.gwURLString = 'http://foo:80/' state.gwURL = new URL(state.gwURLString) const request = url2request('https://bar.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should work for HTTPS GW without explicit port in URL', async function () { state.gwURLString = 'https://foo:443/' state.gwURL = new URL(state.gwURLString) const request = url2request('https://bar.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + + if (isMv3TestingEnabled) { + // return this.skip() + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) }) describe('Recovers Page if node is unreachable', function () { beforeEach(function () { - global.browser = browser state.ipfsNodeType = 'external' state.redirect = true state.peerCount = -1 // this simulates Kubo RPC being offline @@ -357,37 +596,68 @@ describe('modifyRequest.onBeforeRequest:', function () { state.pubGwURLString = 'https://ipfs.io' state.pubGwURL = new URL('https://ipfs.io') }) + it('should present recovery page if node is offline and redirect is enabled', async function () { expect(state.nodeActive).to.be.equal(false) state.redirect = true const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + + expect(args.addRules[0]).to.deep.equal(generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/${regexRuleEnding}`, + 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1' + )) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar') + } }) + it('should present recovery page if node is offline and redirect is disabled', async function () { expect(state.nodeActive).to.be.equal(false) state.redirect = false const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + console.log('args: ', args) + + expect(args.addRules[0]).to.deep.equal(generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/${regexRuleEnding}`, + 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1' + )) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar') + } }) + it('should not show recovery page if node is offline, redirect is enabled, but non-gateway URL failed to load from the same port', async function () { // this covers https://github.com/ipfs/ipfs-companion/issues/1162 and https://twitter.com/unicomp21/status/1626244123102679041 state.redirect = true expect(state.nodeActive).to.be.equal(false) const request = url2request('https://localhost:8080/') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + await expectNoRedirect(modifyRequest, request, browser) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) + it('should not show recovery page if extension is disabled', async function () { // allows user to quickly avoid anything similar to https://github.com/ipfs/ipfs-companion/issues/1162 state.active = false expect(state.nodeActive).to.be.equal(false) const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + await expectNoRedirect(modifyRequest, request, browser) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) }) - - after(function () { - delete global.URL - delete global.browser - browser.flush() - }) }) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js b/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js deleted file mode 100644 index 007d98557..000000000 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.mv3.js +++ /dev/null @@ -1,364 +0,0 @@ -'use strict' -import { expect } from 'chai' -import { after, afterEach, before, beforeEach, describe, it } from 'mocha' -import sinon from 'sinon' -import browser from 'sinon-chrome' -import { URL } from 'url' -import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' -import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' -import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' -import { optionDefaults } from '../../../add-on/src/lib/options.js' -import { cleanupRules, generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' -import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' -import { initState } from '../../../add-on/src/lib/state.js' - -const url2request = (string) => { - return { url: string, type: 'main_frame' } -} - -const expectNoRedirect = async (modifyRequest, request, browser) => { - await modifyRequest.onBeforeRequest(request) - sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - await modifyRequest.onHeadersReceived(request) - sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) -} - -const regexRuleEnding = '((?:[^\\.]|$).*)$' -const nodeTypes = ['external'] -const sinonSandbox = sinon.createSandbox() - -describe('[MV3] modifyRequest.onBeforeRequest:', function () { - let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime - - before(async function () { - global.URL = URL - browser.runtime.getURL.returns('chrome-extension://testid/') - }) - - afterEach(async function () { - await cleanupRules(true) - }) - - beforeEach(async function () { - state = Object.assign(initState(optionDefaults), { - ipfsNodeType: 'external', - peerCount: 1, - redirect: true, - dnslinkPolicy: false, // dnslink test suite is in ipfs-request-dnslink.test.js - catchUnhandledProtocols: true, - gwURLString: 'http://localhost:8080', - gwURL: new URL('http://localhost:8080'), - pubGwURLString: 'https://ipfs.io', - pubGwURL: new URL('https://ipfs.io'), - pubSubdomainGwURLString: 'https://dweb.link', - pubSubdomainGwURL: new URL('https://dweb.link') - }) - const getState = () => state - const getIpfs = () => { } - dnslinkResolver = createDnslinkResolver(getState) - runtime = Object.assign({}, await createRuntimeChecks(browser)) // make it mutable for tests - ipfsPathValidator = createIpfsPathValidator(getState, getIpfs, dnslinkResolver) - modifyRequest = createRequestModifier(getState, dnslinkResolver, ipfsPathValidator, runtime) - }) - - afterEach(async function () { - sinonSandbox.reset() - }) - - describe('request for a path matching /ipfs/{CIDv0}', function () { - describe('with external node', function () { - beforeEach(function () { - state.ipfsNodeType = 'external' - }) - it('should be served from custom gateway if redirect is enabled', async function () { - const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - // MV2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, - 'http://localhost:8080\\1' - )], - removeRuleIds: [] - }) - }) - }) - describe('with every node type', function () { - // tests in which results should be the same for all node types - nodeTypes.forEach(function (nodeType) { - beforeEach(function () { - state.ipfsNodeType = nodeType - }) - it(`should be left untouched if redirect is disabled (${nodeType} node)`, async function () { - state.redirect = false - const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await expectNoRedirect(modifyRequest, request, browser) - }) - it(`should be left untouched if redirect is enabled but global active flag is OFF (${nodeType} node)`, async function () { - state.active = false - state.redirect = true - const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await expectNoRedirect(modifyRequest, request, browser) - }) - it(`should be left untouched if URL includes opt-out hint (${nodeType} node)`, async function () { - // A safe way for preloading data at arbitrary gateways - it should arrive at original destination - const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?x-ipfs-companion-no-redirect#hashTest') - await expectNoRedirect(modifyRequest, request, browser) - }) - it(`should be left untouched if request is for subresource on a page loaded from URL that includes opt-out hint (${nodeType} node)`, async function () { - // ensure opt-out works for subresources (Firefox only for now) - const subRequest = { - type: 'script', - url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', - originUrl: 'https://example.com/?x-ipfs-companion-no-redirect#hashTest' - } - await expectNoRedirect(modifyRequest, subRequest, browser) - }) - it(`should be left untouched if CID is invalid (${nodeType} node)`, async function () { - const request = url2request('https://google.com/ipfs/notacid?argTest#hashTest') - await expectNoRedirect(modifyRequest, request, browser) - }) - it(`should be left untouched if its is a HEAD preload with explicit opt-out in URL hash (${nodeType} node)`, async function () { - // HTTP HEAD is a popular way for preloading data at arbitrary gateways, so we have a dedicated test to make sure it works as expected - const headRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#x-ipfs-companion-no-redirect', method: 'HEAD' } - await expectNoRedirect(modifyRequest, headRequest, browser) - }) - }) - }) - }) - - describe('XHR request for a path matching /ipfs/{CIDv0} coming from 3rd party Origin', function () { - describe('with external node', function () { - beforeEach(function () { - state.ipfsNodeType = 'external' - }) - it('should be served from custom gateway if fetched from the same origin and redirect is enabled in Chromium', async function () { - const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://google.com/' } - // MV2 - // expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await modifyRequest.onBeforeRequest(xhrRequest) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, - 'http://127.0.0.1:8080\\1' - )], - removeRuleIds: [] - }) - }) - }) - }) - - describe('request for a path matching /ipns/{path}', function () { - describe('with external node', function () { - beforeEach(function () { - state.ipfsNodeType = 'external' - }) - - it('should be served from custom gateway if {path} points to a FQDN with existing dnslink', async function () { - const request = url2request('https://google.com/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest') - // stub the existence of valid dnslink - const fqdn = 'en.wikipedia-on-ipfs.org' - dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().withArgs(fqdn).resolves('/ipfs/Qmazvovg6Sic3m9igZMKoAPjkiVZsvbWWc8ZvgjjK1qMss') - // pretend API is online and we can do dns lookups with it - state.peerCount = 1 - // MV2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, - 'http://localhost:8080\\1' - )], - removeRuleIds: [] - }) - }) - it('should be served from custom gateway if {path} starts with a valid PeerID', async function () { - const request = url2request('https://google.com/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest') - dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().resolves(false) - // MV2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - console.log(browser.declarativeNetRequest.updateDynamicRules.calls) - }) - }) - - describe('with every node type', function () { - // tests in which results should be the same for all node types - nodeTypes.forEach(function (nodeType) { - beforeEach(function () { - state.ipfsNodeType = nodeType - }) - it(`should be left untouched if redirect is disabled' (${nodeType} node)`, async function () { - state.redirect = false - const request = url2request('https://google.com/ipns/ipfs.io?argTest#hashTest') - await expectNoRedirect(modifyRequest, request, browser) - }) - it(`should be left untouched if FQDN is not a real domain nor a valid CID (${nodeType} node)`, async function () { - const request = url2request('https://google.com/ipns/notafqdnorcid?argTest#hashTest') - dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().resolves(false) - await expectNoRedirect(modifyRequest, request, browser) - }) - }) - }) - }) - - describe('request to a subdomain gateway', function () { - const cid = 'bafybeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge' - const peerid = 'bafzbeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge' - - describe('with external node', function () { - beforeEach(function () { - state.ipfsNodeType = 'external' - // dweb.link is the default subdomain gw - }) - it('should be redirected to localhost gateway (*.ipfs on default gw)', async function () { - state.redirect = true - const request = url2request(`https://${cid}.ipfs.dweb.link/`) - - /// We expect redirect to path-based gateway because go-ipfs >=0.5 will - // return redirect to a subdomain, and we don't want to break users - // running older versions of go-ipfs by loading subdomain first and - // failing. - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - // .to.equal(`http://localhost:8080/ipfs/${cid}/`) - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/${cid}\\.ipfs\\.dweb\\.link${regexRuleEnding}`, - `http://localhost:8080/ipfs/${cid}\\1` - )], - removeRuleIds: [] - }) - }) - it('should be redirected to localhost gateway (*.ipfs on 3rd party gw)', async function () { - state.redirect = true - const request = url2request(`https://${cid}.ipfs.cf-ipfs.com/`) - // MV2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal(`http://localhost:8080/ipfs/${cid}/`) - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/${cid}\\.ipfs\\.cf\\-ipfs\\.com${regexRuleEnding}`, - `http://localhost:8080/ipfs/${cid}\\1` - )], - removeRuleIds: [] - }) - }) - it('should be redirected to localhost gateway and keep URL encoding of original path', async function () { - state.redirect = true - const request = url2request('https://bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy.ipfs.dweb.link/%3Ffilename=test.jpg?arg=val') - // MV2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - // .to.equal('http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy/%3Ffilename=test.jpg?arg=val') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\.ipfs\\.dweb\\.link${regexRuleEnding}`, - 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\1' - )], - removeRuleIds: [] - }) - }) - it('should be redirected to localhost gateway (*.ipns on default gw)', async function () { - state.redirect = true - const request = url2request(`https://${peerid}.ipns.dweb.link/`) - // MV2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - // .to.equal(`http://localhost:8080/ipns/${peerid}/`) - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/${peerid}\\.ipns\\.dweb\\.link${regexRuleEnding}`, - `http://localhost:8080/ipns/${peerid}\\1` - )], - removeRuleIds: [] - }) - }) - }) - }) - - describe('Recovers Page if node is unreachable', function () { - beforeEach(function () { - global.browser = browser - state.ipfsNodeType = 'external' - state.redirect = true - state.peerCount = -1 // this simulates Kubo RPC being offline - state.gwURLString = 'http://localhost:8080' - state.gwURL = new URL('http://localhost:8080') - state.pubGwURLString = 'https://ipfs.io' - state.pubGwURL = new URL('https://ipfs.io') - }) - it('should present recovery page if node is offline and redirect is enabled', async function () { - expect(state.nodeActive).to.be.equal(false) - state.redirect = true - const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - - expect(args.addRules[0]).to.deep.equal(generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/${regexRuleEnding}`, - 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1' - )) - }) - it('should present recovery page if node is offline and redirect is disabled', async function () { - expect(state.nodeActive).to.be.equal(false) - state.redirect = false - const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - - expect(args.addRules[0]).to.deep.equal(generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/${regexRuleEnding}`, - 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1' - )) - }) - it('should not show recovery page if node is offline, redirect is enabled, but non-gateway URL failed to load from the same port', async function () { - // this covers https://github.com/ipfs/ipfs-companion/issues/1162 and https://twitter.com/unicomp21/status/1626244123102679041 - state.redirect = true - expect(state.nodeActive).to.be.equal(false) - const request = url2request('https://localhost:8080/') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - await expectNoRedirect(modifyRequest, request, browser) - }) - it('should not show recovery page if extension is disabled', async function () { - // allows user to quickly avoid anything similar to https://github.com/ipfs/ipfs-companion/issues/1162 - state.active = false - expect(state.nodeActive).to.be.equal(false) - const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - await expectNoRedirect(modifyRequest, request, browser) - }) - }) - - after(function () { - delete global.URL - delete global.browser - sinonSandbox.restore() - browser.flush() - }) -}) diff --git a/test/functional/lib/ipfs-request-protocol-handlers.test.js b/test/functional/lib/ipfs-request-protocol-handlers.test.js index faf5ee4f5..1883839b8 100644 --- a/test/functional/lib/ipfs-request-protocol-handlers.test.js +++ b/test/functional/lib/ipfs-request-protocol-handlers.test.js @@ -1,20 +1,24 @@ 'use strict' -import { describe, it, before, beforeEach, after } from 'mocha' import { expect } from 'chai' -import { URL } from 'url' +import { after, before, beforeEach, describe, it } from 'mocha' +import Sinon from 'sinon' import browser from 'sinon-chrome' -import { initState } from '../../../add-on/src/lib/state.js' -import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' -import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' +import { URL } from 'url' import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' +import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' +import { generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' +import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' +import { initState } from '../../../add-on/src/lib/state.js' +import isMv3TestingEnabled from '../../helpers/is-mv3-testing-enabled.js' const url2request = (string) => { return { url: string, type: 'main_frame' } } const nodeTypes = ['external'] +const groupAtEndRegex = '((?:[^\\.]|$).*)$' describe('modifyRequest.onBeforeRequest:', function () { let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime @@ -61,173 +65,558 @@ describe('modifyRequest.onBeforeRequest:', function () { // without web+ prefix (Firefox > 59: https://github.com/ipfs-shipyard/ipfs-companion/issues/164#issuecomment-356301174) it('should not be normalized if ipfs:/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if ipfs://{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should not be normalized if ipns:/{fqdn}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=ipns%3A%2Fipfs.io%3FargTest%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if ipns://{fqdn}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=ipns%3A%2F%2Fipfs.io%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipns%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + } }) it('should be normalized if ipfs://{fqdn}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2F%2Fipfs.io%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + } }) it('should be normalized if dweb:/ipfs/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should not be normalized if dweb://ipfs/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if dweb:/ipns/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + } }) it('should not be normalized if dweb://ipns/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) // web+ prefixed versions (Firefox < 59 and Chrome) it('should not be normalized if web+ipfs:/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if web+ipfs://{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should not be normalized if web+ipns:/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipns%3A%2Fipfs.io%3FargTest%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if web+ipns://{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipns%3A%2F%2Fipfs.io%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipns%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + } }) it('should be normalized if web+dweb:/ipfs/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should not be normalized if web+dweb://ipfs/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if web+dweb:/ipns/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + } }) it('should not be normalized if web+dweb://ipns/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should not be normalized if web+{foo}:/bar', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bfoo%3A%2Fbar%3FargTest%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should not be normalized if web+{foo}://bar', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bfoo%3A%2F%2Fbar%3FargTest%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) }) describe('catching unhandled custom protocol request', function () { it('should not be normalized if ipfs:/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if ipfs://{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should not be normalized if ipns:/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=ipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if ipns://{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=ipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1') + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + } }) it('should be normalized if ipfs://{fqdn}', async function () { const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' + ) + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + } }) it('should be normalized if dweb:/ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash\\1' + ) + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + } }) it('should not be normalized if dweb://ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if dweb:/ipns/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash\\1' + ) + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') + } }) it('should not be normalized if dweb://ipns/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should not be normalized if web+ipfs:/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if web+ipfs://{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1' + ) + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + } }) it('should not be normalized if web+ipns:/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if web+ipns://{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' + ) + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + } }) it('should be normalized if web+dweb:/ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software${groupAtEndRegex}`, + 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash\\1' + ) + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + } }) it('should not be normalized if web+dweb://ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should be normalized if web+dweb:/ipns/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - }) - it('should not be normalized if web+dweb://ipns/{foo}', async function () { + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args).to.deep.equal({ + addRules: [ + generateAddRule( + args.addRules[0].id, + `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web${groupAtEndRegex}`, + 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash\\1' + ) + ], + removeRuleIds: [] + }) + } else { + expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') + } + }) + it('should not be normalized if web+dweb://ipns/{foo}2', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should not be normalized if disabled in Preferences', async function () { state.catchUnhandledProtocols = false const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should not be normalized if CID is invalid', async function () { state.catchUnhandledProtocols = false const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FnotARealIpfsPathWithCid%3FargTest%23hashTest&foo=bar') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should not be normalized if presence of %3A%2F is a false-positive', async function () { state.catchUnhandledProtocols = false const request = url2request('https://duckduckgo.com/?q=foo%3A%2Fbar%3FargTest%23hashTest&foo=bar') - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + } }) it('should not be normalized if request.type != main_frame', async function () { const mediaRequest = { url: 'https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar', type: 'media' } - expect(await modifyRequest.onBeforeRequest(mediaRequest)).to.equal(undefined) + + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(mediaRequest) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(mediaRequest)).to.equal(undefined) + } }) }) }) diff --git a/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js b/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js deleted file mode 100644 index 736bc039c..000000000 --- a/test/functional/lib/ipfs-request-protocol-handlers.test.mv3.js +++ /dev/null @@ -1,529 +0,0 @@ -'use strict' -import { describe, it, before, beforeEach, after } from 'mocha' -import { expect } from 'chai' -import { URL } from 'url' -import browser from 'sinon-chrome' -import { initState } from '../../../add-on/src/lib/state.js' -import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' -import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' -import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' -import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' -import { optionDefaults } from '../../../add-on/src/lib/options.js' -import Sinon from 'sinon' -import { generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' - -const url2request = (string) => { - return { url: string, type: 'main_frame' } -} - -const nodeTypes = ['external'] -const groupAtEndRegex = '((?:[^\\.]|$).*)$' - -describe('modifyRequest.onBeforeRequest:', function () { - let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime - - before(function () { - global.URL = URL - }) - - beforeEach(async function () { - state = Object.assign(initState(optionDefaults), { - ipfsNodeType: 'external', - peerCount: 1, - redirect: true, - dnslinkPolicy: false, // dnslink test suite is in ipfs-request-dnslink.test.js - catchUnhandledProtocols: true, - gwURLString: 'http://127.0.0.1:8080', - pubGwURLString: 'https://ipfs.io' - }) - const getState = () => state - const getIpfs = () => {} - dnslinkResolver = createDnslinkResolver(getState) - runtime = Object.assign({}, await createRuntimeChecks(browser)) // make it mutable for tests - ipfsPathValidator = createIpfsPathValidator(getState, getIpfs, dnslinkResolver) - modifyRequest = createRequestModifier(getState, dnslinkResolver, ipfsPathValidator, runtime) - }) - - // tests in which results should be the same for all node types - nodeTypes.forEach(function (nodeType) { - beforeEach(function () { - state.ipfsNodeType = nodeType - }) - describe(`with ${nodeType} node:`, function () { - describe('request made via redirect-based protocol handler from manifest.json/protocol_handlers', function () { - // Note: requests done with custom protocol handler are always normalized to public gateway - // (if external node is enabled, redirect will happen in next iteration of modifyRequest) - beforeEach(function () { - // ..however to make tests easier we disable redirect from public to custom gateway - // (with this modifyRequest will return undefined for invalid URIs) - state.redirect = false - }) - - // without web+ prefix (Firefox > 59: https://github.com/ipfs-shipyard/ipfs-companion/issues/164#issuecomment-356301174) - it('should not be normalized if ipfs:/{CID}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if ipfs://{CID}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if ipns:/{fqdn}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=ipns%3A%2Fipfs.io%3FargTest%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if ipns://{fqdn}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=ipns%3A%2F%2Fipfs.io%3FargTest%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipns%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') - ], - removeRuleIds: [] - }) - }) - it('should be normalized if ipfs://{fqdn}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2F%2Fipfs.io%3FargTest%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') - ], - removeRuleIds: [] - }) - }) - it('should be normalized if dweb:/ipfs/{CID}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if dweb://ipfs/{CID}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if dweb:/ipns/{foo}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if dweb://ipns/{foo}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - - // web+ prefixed versions (Firefox < 59 and Chrome) - it('should not be normalized if web+ipfs:/{CID}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if web+ipfs://{CID}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if web+ipns:/{foo}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipns%3A%2Fipfs.io%3FargTest%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if web+ipns://{foo}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipns%3A%2F%2Fipfs.io%3FargTest%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipns%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') - ], - removeRuleIds: [] - }) - }) - it('should be normalized if web+dweb:/ipfs/{CID}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if web+dweb://ipfs/{CID}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if web+dweb:/ipns/{foo}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if web+dweb://ipns/{foo}', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should not be normalized if web+{foo}:/bar', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=web%2Bfoo%3A%2Fbar%3FargTest%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should not be normalized if web+{foo}://bar', async function () { - const request = url2request('https://dweb.link/ipfs/?uri=web%2Bfoo%3A%2F%2Fbar%3FargTest%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - }) - - describe('catching unhandled custom protocol request', function () { - it('should not be normalized if ipfs:/{CID}', async function () { - const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if ipfs://{CID}', async function () { - const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1') - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if ipns:/{foo}', async function () { - const request = url2request('https://duckduckgo.com/?q=ipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if ipns://{foo}', async function () { - const request = url2request('https://duckduckgo.com/?q=ipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1') - ], - removeRuleIds: [] - }) - }) - it('should be normalized if ipfs://{fqdn}', async function () { - const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' - ) - ], - removeRuleIds: [] - }) - }) - it('should be normalized if dweb:/ipfs/{CID}', async function () { - const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash\\1' - ) - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if dweb://ipfs/{CID}', async function () { - const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if dweb:/ipns/{foo}', async function () { - const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash\\1' - ) - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if dweb://ipns/{foo}', async function () { - const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - - it('should not be normalized if web+ipfs:/{CID}', async function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if web+ipfs://{CID}', async function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1' - ) - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if web+ipns:/{foo}', async function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if web+ipns://{foo}', async function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' - ) - ], - removeRuleIds: [] - }) - }) - it('should be normalized if web+dweb:/ipfs/{CID}', async function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash\\1' - ) - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if web+dweb://ipfs/{CID}', async function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should be normalized if web+dweb:/ipns/{foo}', async function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - // mv2 - // expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash\\1' - ) - ], - removeRuleIds: [] - }) - }) - it('should not be normalized if web+dweb://ipns/{foo}', async function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - - it('should not be normalized if disabled in Preferences', async function () { - state.catchUnhandledProtocols = false - const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should not be normalized if CID is invalid', async function () { - state.catchUnhandledProtocols = false - const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FnotARealIpfsPathWithCid%3FargTest%23hashTest&foo=bar') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should not be normalized if presence of %3A%2F is a false-positive', async function () { - state.catchUnhandledProtocols = false - const request = url2request('https://duckduckgo.com/?q=foo%3A%2Fbar%3FargTest%23hashTest&foo=bar') - // mv2 - // expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - it('should not be normalized if request.type != main_frame', async function () { - const mediaRequest = { url: 'https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar', type: 'media' } - // mv2 - // expect(await modifyRequest.onBeforeRequest(mediaRequest)).to.equal(undefined) - await modifyRequest.onBeforeRequest(mediaRequest) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - }) - }) - }) - }) - - after(function () { - delete global.URL - delete global.browser - browser.flush() - }) -}) diff --git a/test/functional/lib/ipfs-request-workarounds.test.js b/test/functional/lib/ipfs-request-workarounds.test.js index ecf75840e..140ea819a 100644 --- a/test/functional/lib/ipfs-request-workarounds.test.js +++ b/test/functional/lib/ipfs-request-workarounds.test.js @@ -1,21 +1,25 @@ 'use strict' -import { describe, it, before, beforeEach, after } from 'mocha' -import { expect, assert } from 'chai' -import { URL } from 'url' // URL implementation with support for .origin attribute +import { assert, expect } from 'chai' +import { after, before, beforeEach, describe, it } from 'mocha' import browser from 'sinon-chrome' -import { initState } from '../../../add-on/src/lib/state.js' -import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' -import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' +import { URL } from 'url' // URL implementation with support for .origin attribute import createDNSLinkResolver from '../../../add-on/src/lib/dnslink.js' +import { braveNodeType } from '../../../add-on/src/lib/ipfs-client/brave.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' +import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' -import { braveNodeType } from '../../../add-on/src/lib/ipfs-client/brave.js' +import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' +import { initState } from '../../../add-on/src/lib/state.js' +import isMv3TestingEnabled from '../../helpers/is-mv3-testing-enabled.js' import { spoofDnsTxtRecord } from './dnslink.test.js' describe('modifyRequest processing', function () { let state, getState, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime before(function () { + if (isMv3TestingEnabled) { + return this.skip() + } global.URL = URL global.browser = browser browser.runtime.id = 'testid' diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.mv3.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.mv3.ts deleted file mode 100644 index 68807064b..000000000 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.mv3.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { expect } from 'chai' -import { before, describe, it } from 'mocha' -import browserMock from 'sinon-chrome' - -import { supportsBlock } from '../../../../add-on/src/lib/redirect-handler/blockOrObserve.js' - -describe('lib/redirect-handler/blockOrObserve', () => { - describe('supportsBlock', () => { - it('should return false for MV3', () => { - expect(supportsBlock()).to.be.false - }) - }) -}) diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.ts index 176e71080..e14bad8ec 100644 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.ts +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.ts @@ -6,6 +6,7 @@ import browserMock from 'sinon-chrome' import { optionDefaults } from '../../../../add-on/src/lib/options.js' import { addRuleToDynamicRuleSetGenerator, cleanupRules, isLocalHost, supportsBlock } from '../../../../add-on/src/lib/redirect-handler/blockOrObserve' import { initState } from '../../../../add-on/src/lib/state.js' +import isMv3TestingEnabled, { manifestVersion } from '../../../helpers/is-mv3-testing-enabled.js' import DeclarativeNetRequestMock from './declarativeNetRequest.mock.js' const dynamicRulesConditions = (regexFilter) => ({ @@ -30,6 +31,8 @@ const dynamicRulesConditions = (regexFilter) => ({ ] }) +const manifestVeresion = isMv3TestingEnabled ? 'MV3' : 'MV2' + describe('lib/redirect-handler/blockOrObserve', () => { before(function () { browserMock.runtime.id = 'testid' @@ -53,9 +56,13 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) }) - describe('supportsBlock', () => { - it('should return true for MV2', () => { - expect(supportsBlock()).to.be.true + describe(`supportsBlock on ${manifestVersion}` , () => { + it(`should return ${isMv3TestingEnabled ? false : true} for ${manifestVersion}`, function () { + if (isMv3TestingEnabled) { + expect(supportsBlock()).to.be.false + } else { + expect(supportsBlock()).to.be.true + } }) }) diff --git a/test/helpers/is-mv3-testing-enabled.js b/test/helpers/is-mv3-testing-enabled.js new file mode 100644 index 000000000..30cc985c7 --- /dev/null +++ b/test/helpers/is-mv3-testing-enabled.js @@ -0,0 +1,4 @@ + +const isMv3TestingEnabled = process.env.TEST_MV3 === 'true' +export const manifestVersion = isMv3TestingEnabled ? 'MV3' : 'MV2' +export default isMv3TestingEnabled diff --git a/test/setup/mocha-setup.js b/test/setup/mocha-setup.js index 1eb01abba..30f277162 100644 --- a/test/setup/mocha-setup.js +++ b/test/setup/mocha-setup.js @@ -1,5 +1,10 @@ -import browser from 'sinon-chrome' import AbortController from 'abort-controller' +import { afterEach } from 'mocha' +import sinon, { useFakeTimers } from 'sinon' +import browser from 'sinon-chrome' +import DeclarativeNetRequestMock from '../functional/lib/redirect-handler/declarativeNetRequest.mock.js' +import isMv3TestingEnabled from '../helpers/is-mv3-testing-enabled.js' + browser.runtime.id = 'testid' global.browser = browser global.AbortController = AbortController @@ -9,3 +14,22 @@ global.navigator = { writeText: () => {} } } + +global.URL = URL +browser.tabs = { ...browser.tabs, getCurrent: sinon.stub().resolves({ id: 20 }) } + +// need to force Date to return a particular date +global.clock = useFakeTimers({ + now: new Date(2017, 10, 5, 12, 1, 1) +}) + +if (isMv3TestingEnabled) { + const sinonSandbox = sinon.createSandbox() + global.browser.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) + + afterEach(function () { + sinonSandbox.resetHistory() + }) +} else { + // nothing needed here? +} diff --git a/test/setup/mocha-setup.mv3.js b/test/setup/mocha-setup.mv3.js deleted file mode 100644 index f57148a40..000000000 --- a/test/setup/mocha-setup.mv3.js +++ /dev/null @@ -1,21 +0,0 @@ -import AbortController from 'abort-controller' -import { afterEach } from 'mocha' -import sinon from 'sinon' -import browser from 'sinon-chrome' -import DeclarativeNetRequestMock from '../functional/lib/redirect-handler/declarativeNetRequest.mock.js' - -browser.runtime.id = 'testid' -global.browser = browser -global.AbortController = AbortController -global.chrome = browser -global.navigator = { - clipboard: { - writeText: () => {} - } -} -const sinonSandbox = sinon.createSandbox() -global.browser.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) - -afterEach(function () { - sinonSandbox.resetHistory() -}) From dd86afa51edf4c3188524f4ea208a9aff9d1d5c7 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Tue, 25 Jul 2023 14:39:36 -0700 Subject: [PATCH 23/63] test: fix after merge --- .../lib/ipfs-request-gateway-redirect.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index cf4838e50..64234a4ee 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -1,6 +1,6 @@ 'use strict' import { expect } from 'chai' -import { afterEach, before, beforeEach, describe, it } from 'mocha' +import { afterEach, beforeEach, describe, it } from 'mocha' import sinon from 'sinon' import browser from 'sinon-chrome' import { URL } from 'url' @@ -39,12 +39,12 @@ const sinonSandbox = sinon.createSandbox() describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime - before(function () { - global.URL = URL - global.browser = browser - browser.runtime.id = 'testid' - browser.runtime.getURL.returns('chrome-extension://testid/') - }) + // before(function () { + // global.URL = URL + // global.browser = browser + // browser.runtime.id = 'testid' + // browser.runtime.getURL.returns('chrome-extension://testid/') + // }) beforeEach(async function () { state = Object.assign(initState(optionDefaults), { From 0e316a206e9fa60b6ce37f838137ddd83c9be94d Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Tue, 25 Jul 2023 14:53:10 -0700 Subject: [PATCH 24/63] test: fix after merge --- .../redirect-handler/blockOrObserve.test.ts | 172 +++++------------- test/setup/mocha-setup.js | 8 +- 2 files changed, 54 insertions(+), 126 deletions(-) diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.ts index 14c2ebc1a..0f0b6b90e 100644 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.ts +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.ts @@ -32,58 +32,10 @@ const dynamicRulesConditions = (regexFilter) => ({ }) const manifestVeresion = isMv3TestingEnabled ? 'MV3' : 'MV2' -const TEST_TAB_ID = 1234 -const LAST_GROUP_REGEX = '((?:[^\\.]|$).*)$' - -/** - * Ensures that the tab is redirected to the given url on the first request. - * - * @param url - */ -function ensureTabRedirected (url): void { - expect(browserMock.tabs.query.called).to.be.true - expect(browserMock.tabs.update.called).to.be.true - expect(browserMock.tabs.update.lastCall.args).to.deep.equal([TEST_TAB_ID, { url }]) -} - -/** - * Ensures that the declarativeNetRequest API is called with the expected rule. - * @param expectedCondition - * @param regexSubstitution - */ -function ensureDeclrativeNetRequetRuleIsAdded ({ - addRuleLength = 1, - callIndex = 0, - expectedCondition, - regexSubstitution, - removedRulesIds = [], -}: { - addRuleLength?: number - callIndex?: number - expectedCondition: string - regexSubstitution: string - removedRulesIds?: number[] -}): void { - if (callIndex < 0) { - callIndex = browserMock.declarativeNetRequest.updateDynamicRules.getCalls().length + callIndex - } - expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true - const [{ addRules, removeRuleIds }] = browserMock.declarativeNetRequest.updateDynamicRules.getCall(callIndex).args - expect(removeRuleIds).to.deep.equal(removedRulesIds) - if (addRuleLength > 0) { - expect(addRules).to.have.lengthOf(addRuleLength) - const [{ id, priority, action, condition }] = addRules - expect(id).to.be.a('number') - expect(priority).to.equal(1) - expect(action).to.deep.equal({ type: 'redirect', redirect: { regexSubstitution } }) - expect(condition).to.deep.equal(dynamicRulesConditions(expectedCondition)) - } -} describe('lib/redirect-handler/blockOrObserve', () => { before(function () { browserMock.runtime.id = 'testid' - browserMock.tabs.query.resolves([{id: TEST_TAB_ID}]) }) describe('isLocalHost', () => { @@ -129,7 +81,6 @@ describe('lib/redirect-handler/blockOrObserve', () => { sinonSandbox.restore() browserMock.tabs.query.resetHistory() browserMock.tabs.reload.resetHistory() - browserMock.tabs.update.resetHistory() browserMock.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) // this cleans up the rules from the previous test stored in memory. await cleanupRules(true) @@ -145,7 +96,6 @@ describe('lib/redirect-handler/blockOrObserve', () => { // when redirectUrl is different from originUrl, but both are localhost. await addRuleToDynamicRuleSet({ originUrl: 'http://localhost:9001/foo', redirectUrl: 'http://localhost:9001/bar' }) expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.false - expect (browserMock.tabs.query.called).to.be.false }) it('Should allow pages to be recovered', async () => { @@ -154,11 +104,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { originUrl: 'http://localhost:8080', redirectUrl: 'chrome-extension://some-path/dist/recover/recovery.html' }) - ensureTabRedirected('chrome-extension://some-path/dist/recover/recovery.html') - ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/localhost\\:8080${LAST_GROUP_REGEX}`, - regexSubstitution: 'chrome-extension://some-path/dist/recover/recovery.html\\1', - }) + expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true }) it('Should add redirect rules for local gateway', async () => { @@ -166,11 +112,15 @@ describe('lib/redirect-handler/blockOrObserve', () => { originUrl: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org', redirectUrl: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org' }) - ensureTabRedirected('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org') - ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/ipfs\\.io${LAST_GROUP_REGEX}`, - regexSubstitution: 'http://localhost:8080\\1' - }) + expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true + const [{ addRules, removeRuleIds }] = browserMock.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(removeRuleIds).to.deep.equal([]) + expect(addRules).to.have.lengthOf(1) + const [{ id, priority, action, condition }] = addRules + expect(id).to.be.a('number') + expect(priority).to.equal(1) + expect(action).to.deep.equal({ type: 'redirect', redirect: { "regexSubstitution": "http://localhost:8080\\1" } }) + expect(condition).to.deep.equal(dynamicRulesConditions('^https?\\:\\/\\/ipfs\\.io((?:[^\\.]|$).*)$')) }) it('Should add redirect for local gateway where originUrl is similar to redirectUrl', async () => { @@ -178,11 +128,19 @@ describe('lib/redirect-handler/blockOrObserve', () => { originUrl: 'https://docs.ipfs.tech', redirectUrl: 'http://localhost:8080/ipns/docs.ipfs.tech' }) - ensureTabRedirected('http://localhost:8080/ipns/docs.ipfs.tech') - ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, - regexSubstitution: 'http://localhost:8080/ipns/docs.ipfs.tech\\1' - }) + expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true + const [{ addRules, removeRuleIds }] = browserMock.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(removeRuleIds).to.deep.equal([]) + expect(addRules).to.have.lengthOf(1) + const [{ id, priority, action, condition }] = addRules + expect(id).to.be.a('number') + expect(priority).to.equal(1) + expect(action).to.deep.equal({ + type: 'redirect', redirect: { + "regexSubstitution": "http://localhost:8080/ipns/docs.ipfs.tech\\1" + } + }) + expect(condition).to.deep.equal(dynamicRulesConditions('^https?\\:\\/\\/docs\\.ipfs\\.tech((?:[^\\.]|$).*)$')) }) it('Should add redirect for local gateway where originUrl is similar to redirectUrl and is not https', async () => { @@ -190,68 +148,34 @@ describe('lib/redirect-handler/blockOrObserve', () => { originUrl: 'http://docs.ipfs.tech', redirectUrl: 'http://localhost:8080/ipns/docs.ipfs.tech' }) - ensureTabRedirected('http://localhost:8080/ipns/docs.ipfs.tech') - ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, - regexSubstitution: 'http://localhost:8080/ipns/docs.ipfs.tech\\1' - }) - }) - - it('Should remove the old rule when redirect changes for local gateway', async () => { - await addRuleToDynamicRuleSet({ - originUrl: 'http://docs.ipfs.tech', - redirectUrl: 'http://localhost:8080/ipns/docs.ipfs.tech' - }) - ensureTabRedirected('http://localhost:8080/ipns/docs.ipfs.tech') - ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, - regexSubstitution: 'http://localhost:8080/ipns/docs.ipfs.tech\\1' - }) - const [{ addRules }] = browserMock.declarativeNetRequest.updateDynamicRules.firstCall.args - - await browserMock.declarativeNetRequest.updateDynamicRules.resetHistory() - // assuming the localhost changed or the redirectURL changed. - await addRuleToDynamicRuleSet({ - originUrl: 'http://docs.ipfs.tech', - redirectUrl: 'http://localhost:8081/ipns/docs.ipfs.tech' - }) - ensureTabRedirected('http://localhost:8081/ipns/docs.ipfs.tech') - ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, - regexSubstitution: 'http://localhost:8081/ipns/docs.ipfs.tech\\1', - removedRulesIds: [addRules[0].id] - }) + expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true + const [{ addRules, removeRuleIds }] = browserMock.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(removeRuleIds).to.deep.equal([]) + expect(addRules).to.have.lengthOf(1) + const [{ id, priority, action, condition }] = addRules + expect(id).to.be.a('number') + expect(priority).to.equal(1) + expect(action).to.deep.equal({ + type: 'redirect', redirect: { + "regexSubstitution": "http://localhost:8080/ipns/docs.ipfs.tech\\1" + } + }) + expect(condition).to.deep.equal(dynamicRulesConditions('^https?\\:\\/\\/docs\\.ipfs\\.tech((?:[^\\.]|$).*)$')) }) - it('Should remove the old rules when companion is no longer in active state', async () => { - // first redirect - const getRuleIdsAddedSoFar = () => browserMock.declarativeNetRequest.updateDynamicRules.getCalls().map(({args}) => args[0]?.addRules.map(rule => rule.id).flat()).flat() - - await addRuleToDynamicRuleSet({ - originUrl: 'http://docs.ipfs.tech', - redirectUrl: 'http://localhost:8080/ipns/docs.ipfs.tech' - }) - - await addRuleToDynamicRuleSet({ - originUrl: 'http://awesome.ipfs.io', - redirectUrl: 'http://localhost:8080/ipns/awesome.ipfs.io' - }) - - state.active = false - await addRuleToDynamicRuleSet({ - originUrl: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org', - redirectUrl: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org' - }) - - ensureTabRedirected('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org') - ensureDeclrativeNetRequetRuleIsAdded({ - addRuleLength: 0, - callIndex: -1, - expectedCondition: `^https?\\:\\/\\/ipfs\\.io${LAST_GROUP_REGEX}`, - regexSubstitution: 'http://localhost:8080\\1', - removedRulesIds: getRuleIdsAddedSoFar() - }) + it('Should refresh the tab when redirect URL is added', async () => { + if (!isMv3TestingEnabled) { + // TODO + } else { + browserMock.tabs.query.resolves([{id: 1234}]) + await addRuleToDynamicRuleSet({ + originUrl: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org', + redirectUrl: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org' + }) + sinon.assert.calledWith(browserMock.tabs.query, { url: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org*' }) + sinon.assert.calledWith(browserMock.tabs.reload, 1234) + } }) }) }) diff --git a/test/setup/mocha-setup.js b/test/setup/mocha-setup.js index 30f277162..45ccd3dbe 100644 --- a/test/setup/mocha-setup.js +++ b/test/setup/mocha-setup.js @@ -25,11 +25,15 @@ global.clock = useFakeTimers({ if (isMv3TestingEnabled) { const sinonSandbox = sinon.createSandbox() - global.browser.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) + beforeEach(function () { + global.browser.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) + }) afterEach(function () { sinonSandbox.resetHistory() }) } else { - // nothing needed here? + beforeEach(function () { + browser.runtime.getURL.returns('chrome-extension://testid/') + }) } From 7b94054842d0cdcb429fd6b54d2e097fc35c2619 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Tue, 25 Jul 2023 16:07:00 -0600 Subject: [PATCH 25/63] fix: typerrors for localstorage Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- test/functional/lib/ipfs-companion.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/functional/lib/ipfs-companion.test.js b/test/functional/lib/ipfs-companion.test.js index 935336a56..96af893ad 100644 --- a/test/functional/lib/ipfs-companion.test.js +++ b/test/functional/lib/ipfs-companion.test.js @@ -11,7 +11,6 @@ const init = async () => (await import('../../../add-on/src/lib/ipfs-companion.j describe('lib/ipfs-companion.js', function () { describe('init', function () { before(function () { - global.localStorage = global.localStorage || {} global.URL = global.URL || URL global.screen = { width: 1024, height: 720 } global.addEventListener = () => { } From 8d95a1f5bac52b7769b5b2c2e6509170b4f6915f Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 26 Jul 2023 00:00:56 -0600 Subject: [PATCH 26/63] fix: Updating test:functional_MV3 command. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 043222207..79fa3129e 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "test:e2e": "mocha --timeout 300000 \"test/e2e/**/*.test.js\"", "test:functional": "c8 mocha --timeout 5000 --file \"test/setup/mocha-setup.js\" \"test/functional/**/*.test.js\" \"test/functional/**/*.test.ts\"", "lint": "run-s lint:*", - "test:functional_MV3": "cross-env TEST_MV3=true c8 mocha --timeout 5000 --file \"test/setup/mocha-setup.js\" \"test/functional/**/*.test.js\" \"test/functional/**/*.test.ts\"", + "test:functional_MV3": "cross-env TEST_MV3=true npm run test:functional", "lint:standard": "ts-standard -v \"*.js\" \"add-on/src/**/*.js\" \"add-on/src/**/*.ts\" \"test/**/*.js\" \"scripts/**/*.js\"", "lint:web-ext": "shx cat add-on/manifest.common.json add-on/manifest.chromium.json add-on/manifest.firefox-beta.json | json --deep-merge > add-on/manifest.json && web-ext lint --firefox-preview", "fix:lint": "run-s fix:lint:*", From 9bbf27164aa9644ece1a82c246e4c1f5eaae734f Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 26 Jul 2023 00:03:23 -0600 Subject: [PATCH 27/63] fix: setup Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- test/helpers/is-mv3-testing-enabled.js | 1 - test/setup/mocha-setup.js | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/helpers/is-mv3-testing-enabled.js b/test/helpers/is-mv3-testing-enabled.js index 30cc985c7..d74eea66e 100644 --- a/test/helpers/is-mv3-testing-enabled.js +++ b/test/helpers/is-mv3-testing-enabled.js @@ -1,4 +1,3 @@ - const isMv3TestingEnabled = process.env.TEST_MV3 === 'true' export const manifestVersion = isMv3TestingEnabled ? 'MV3' : 'MV2' export default isMv3TestingEnabled diff --git a/test/setup/mocha-setup.js b/test/setup/mocha-setup.js index 45ccd3dbe..09ed0fe9d 100644 --- a/test/setup/mocha-setup.js +++ b/test/setup/mocha-setup.js @@ -26,7 +26,14 @@ global.clock = useFakeTimers({ if (isMv3TestingEnabled) { const sinonSandbox = sinon.createSandbox() beforeEach(function () { - global.browser.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) + browser.runtime.getURL.returns('chrome-extension://testid/') + browser.tabs = { + ...browser.tabs, + getCurrent: sinonSandbox.stub().resolves({ id: 20 }), + query: sinonSandbox.stub().resolves([{ id: 40 }]), + update: sinonSandbox.stub().resolves() + } + browser.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) }) afterEach(function () { From 5ce5de820bc87bbebfe2e1b1a7666cf9c22d245e Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 26 Jul 2023 00:03:41 -0600 Subject: [PATCH 28/63] fix(test): Fixing tests Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- add-on/src/lib/ipfs-request.js | 6 +++--- .../lib/ipfs-request-gateway-redirect.test.js | 12 +----------- .../lib/redirect-handler/blockOrObserve.test.ts | 7 ++++--- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/add-on/src/lib/ipfs-request.js b/add-on/src/lib/ipfs-request.js index dd6e184a6..d2d92fe49 100644 --- a/add-on/src/lib/ipfs-request.js +++ b/add-on/src/lib/ipfs-request.js @@ -181,7 +181,7 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida } // poor-mans protocol handlers - https://github.com/ipfs/ipfs-companion/issues/164#issuecomment-328374052 if (state.catchUnhandledProtocols && mayContainUnhandledIpfsProtocol(request)) { - const fix = normalizedUnhandledIpfsProtocol(request, state.pubGwURLString) + const fix = await normalizedUnhandledIpfsProtocol(request, state.pubGwURLString) if (fix) { return fix } @@ -478,14 +478,14 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida * @param {object} input contains originUrl and redirectUrl. * @returns */ -function handleRedirection ({ originUrl, redirectUrl }) { +async function handleRedirection ({ originUrl, redirectUrl }) { if (redirectUrl !== '' && originUrl !== '' && redirectUrl !== originUrl) { if (supportsBlock()) { return { redirectUrl } } // Let browser handle redirection MV3 style. - addRuleToDynamicRuleSet({ originUrl, redirectUrl }) + await addRuleToDynamicRuleSet({ originUrl, redirectUrl }) } } diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index 64234a4ee..911cdfd20 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -35,16 +35,9 @@ const expectNoRedirect = async (modifyRequest, request, browser) => { const nodeTypes = ['external'] const regexRuleEnding = '((?:[^\\.]|$).*)$' -const sinonSandbox = sinon.createSandbox() describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime - // before(function () { - // global.URL = URL - // global.browser = browser - // browser.runtime.id = 'testid' - // browser.runtime.getURL.returns('chrome-extension://testid/') - // }) beforeEach(async function () { state = Object.assign(initState(optionDefaults), { @@ -61,7 +54,7 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { pubSubdomainGwURL: new URL('https://dweb.link') }) const getState = () => state - const getIpfs = () => { } + const getIpfs = () => {} dnslinkResolver = createDnslinkResolver(getState) runtime = Object.assign({}, await createRuntimeChecks(browser)) // make it mutable for tests ipfsPathValidator = createIpfsPathValidator(getState, getIpfs, dnslinkResolver) @@ -69,7 +62,6 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { }) afterEach(async function () { - sinonSandbox.reset() if (isMv3TestingEnabled) { await cleanupRules(true) } @@ -599,7 +591,6 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it('should present recovery page if node is offline and redirect is enabled', async function () { expect(state.nodeActive).to.be.equal(false) - state.redirect = true const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') if (isMv3TestingEnabled) { await modifyRequest.onBeforeRequest(request) @@ -622,7 +613,6 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { if (isMv3TestingEnabled) { await modifyRequest.onBeforeRequest(request) const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - console.log('args: ', args) expect(args.addRules[0]).to.deep.equal(generateAddRule( args.addRules[0].id, diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.ts index 0f0b6b90e..d665b3f1a 100644 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.ts +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.ts @@ -35,6 +35,9 @@ const manifestVeresion = isMv3TestingEnabled ? 'MV3' : 'MV2' describe('lib/redirect-handler/blockOrObserve', () => { before(function () { + if (!isMv3TestingEnabled) { + return this.skip() + } browserMock.runtime.id = 'testid' }) @@ -79,8 +82,6 @@ describe('lib/redirect-handler/blockOrObserve', () => { beforeEach(async () => { sinonSandbox.restore() - browserMock.tabs.query.resetHistory() - browserMock.tabs.reload.resetHistory() browserMock.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) // this cleans up the rules from the previous test stored in memory. await cleanupRules(true) @@ -174,7 +175,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { redirectUrl: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org' }) sinon.assert.calledWith(browserMock.tabs.query, { url: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org*' }) - sinon.assert.calledWith(browserMock.tabs.reload, 1234) + sinon.assert.calledWith(browserMock.tabs.update, 1234, { url: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org' }) } }) }) From e5d42e0340f282c366f2751069fe49634668bc7c Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 26 Jul 2023 00:10:56 -0600 Subject: [PATCH 29/63] fix(lint): Becuase Ofcourse --- test/setup/mocha-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/setup/mocha-setup.js b/test/setup/mocha-setup.js index 09ed0fe9d..082162bab 100644 --- a/test/setup/mocha-setup.js +++ b/test/setup/mocha-setup.js @@ -1,5 +1,5 @@ import AbortController from 'abort-controller' -import { afterEach } from 'mocha' +import { afterEach, beforeEach } from 'mocha' import sinon, { useFakeTimers } from 'sinon' import browser from 'sinon-chrome' import DeclarativeNetRequestMock from '../functional/lib/redirect-handler/declarativeNetRequest.mock.js' From a260eb9e3ebd1d82780c701f32cb014fa78c64a9 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 02:08:23 -0600 Subject: [PATCH 30/63] feat(test): scaffolding mv3 + mv2 calls in a single check. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- test/helpers/mv3-test-helper.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/helpers/mv3-test-helper.ts diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts new file mode 100644 index 000000000..fbf5fae2a --- /dev/null +++ b/test/helpers/mv3-test-helper.ts @@ -0,0 +1,30 @@ +import { expect } from 'chai' +import isMv3TestingEnabled from './is-mv3-testing-enabled' +import browser from 'sinon-chrome' +import { generateAddRule } from '../../add-on/src/lib/redirect-handler/blockOrObserve' + +export const regexRuleEnding = '((?:[^\\.]|$).*)$' + +export function ensureCallRedirected ({ + modifiedRequestCallResp, + MV2Expectation, + MV3Expectation +}: { + modifiedRequestCallResp: { redirectUrl: string }, + MV2Expectation: string, + MV3Expectation: { + origin: string, + destination: string + } +}) { + if (isMv3TestingEnabled) { + const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args + expect(args.addRules[0]).to.deep.equal(generateAddRule( + args.addRules[0].id, + MV3Expectation.origin + regexRuleEnding, + MV3Expectation.destination + '\\1' + )) + } else { + expect(modifiedRequestCallResp.redirectUrl).to.equal(MV2Expectation) + } +} From eb8fea000fd4883ebe257aad48e5674605903d3e Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 02:08:56 -0600 Subject: [PATCH 31/63] feat(test): unskipping and upgrading dnslink tests to mv3 Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/ipfs-request-dnslink.test.js | 130 +++++++++++++++--- 1 file changed, 113 insertions(+), 17 deletions(-) diff --git a/test/functional/lib/ipfs-request-dnslink.test.js b/test/functional/lib/ipfs-request-dnslink.test.js index f61e8b0c6..35891b15d 100644 --- a/test/functional/lib/ipfs-request-dnslink.test.js +++ b/test/functional/lib/ipfs-request-dnslink.test.js @@ -1,15 +1,17 @@ 'use strict' import { expect } from 'chai' -import { after, before, beforeEach, describe, it } from 'mocha' +import { after, afterEach, before, beforeEach, describe, it } from 'mocha' import sinon from 'sinon' import browser from 'sinon-chrome' import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' +import { cleanupRules } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' import isMv3TestingEnabled from '../../helpers/is-mv3-testing-enabled.js' +import { ensureCallRedirected } from '../../helpers/mv3-test-helper.js' const url2request = (string) => { return { url: string, type: 'main_frame' } @@ -23,9 +25,6 @@ describe('modifyRequest processing of DNSLinks', function () { let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime before(function () { - if (isMv3TestingEnabled) { - return this.skip() - } global.URL = URL global.browser = browser browser.runtime.id = 'testid' @@ -48,6 +47,12 @@ describe('modifyRequest processing of DNSLinks', function () { modifyRequest = createRequestModifier(getState, dnslinkResolver, ipfsPathValidator, runtime) }) + afterEach(async function () { + if (isMv3TestingEnabled) { + await cleanupRules(true) + } + }) + describe('a request to FQDN with dnslinkPolicy=false', function () { let activeGateway beforeEach(function () { @@ -121,7 +126,14 @@ describe('modifyRequest processing of DNSLinks', function () { // simulate presence of x-ipfs-path header returned by HTTP gateway request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] // onHeadersReceived should redirect to value from X-Ipfs-Path - expect((await modifyRequest.onHeadersReceived(request)).redirectUrl).to.equal(activeGateway + '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onHeadersReceived(request), + MV2Expectation: `${activeGateway}/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io\\/index\\.html', + destination: `${activeGateway}/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd` + } + }) }) it('should ignore DNS TXT record and also ignore /ipns/ path from x-ipfs-path if both are present', async function () { // enable detection of x-ipfs-path to ensure it is not enough without dnslinkPolicy=detectIpfsPathHeader @@ -161,7 +173,14 @@ describe('modifyRequest processing of DNSLinks', function () { dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().withArgs(fqdn).resolves('/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd') // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) it('should redirect in onBeforeRequest if DNS TXT record exists, XHR is cross-origin and runtime is Chromium', async function () { // stub existence of a valid DNS record @@ -171,7 +190,14 @@ describe('modifyRequest processing of DNSLinks', function () { runtime.isFirefox = false // Chrome uses 'initiator' for origin const xhrRequest = { url: 'http://explore.ipld.io/index.html?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) it('should redirect in onBeforeRequest if dnslink exists, XHR is cross-origin and runtime is Firefox', async function () { // stub existence of a valid DNS record @@ -181,7 +207,14 @@ describe('modifyRequest processing of DNSLinks', function () { runtime.isFirefox = true // Firefox uses 'originUrl' for origin const xhrRequest = { url: 'http://explore.ipld.io/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) it('should redirect later in onHeadersReceived if dnslink exists, XHR is cross-origin and runtime is Firefox <69', async function () { // stub existence of a valid DNS record @@ -195,7 +228,14 @@ describe('modifyRequest processing of DNSLinks', function () { // onBeforeRequest should not change anything, as it will trigger false-positive CORS error expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late - expect((await modifyRequest.onHeadersReceived(xhrRequest)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onHeadersReceived(xhrRequest), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) it('should do nothing if dnslink does not exist and XHR is cross-origin in Firefox', async function () { // stub no dnslink @@ -242,7 +282,14 @@ describe('modifyRequest processing of DNSLinks', function () { // simulate presence of x-ipfs-path header returned by HTTP gateway request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] // DNSLink is present, so we ignore hash from X-Ipfs-Path header and redirect to nice /ipns/ address - expect((await modifyRequest.onHeadersReceived(request)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onHeadersReceived(request), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) it('should redirect in onHeadersReceived if DNS TXT record is missing but x-ipfs-path header is present', async function () { // clear dnslink cache to ensure miss @@ -257,7 +304,14 @@ describe('modifyRequest processing of DNSLinks', function () { // simulate presence of x-ipfs-path header returned by HTTP gateway request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] // Note that DNSLink is missing, so a path from x-ipfs-path is used - expect((await modifyRequest.onHeadersReceived(request)).redirectUrl).to.equal(activeGateway + '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onHeadersReceived(request), + MV2Expectation: `${activeGateway}/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io\\/index\\.html', + destination: `${activeGateway}/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd` + } + }) }) it('should do nothing if DNS TXT record exists but there is no x-ipfs-path header', async function () { // clear dnslink cache to ensure miss @@ -282,7 +336,14 @@ describe('modifyRequest processing of DNSLinks', function () { const xhrRequest = { url: 'http://explore.ipld.io/index.html?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) xhrRequest.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] - expect((await modifyRequest.onHeadersReceived(xhrRequest)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onHeadersReceived(xhrRequest), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) // Test makes more sense for dnslinkPolicy=enabled, but we keep it here for completeness it('should redirect in onHeadersReceived if XHR is cross-origin and runtime is Firefox', async function () { @@ -297,7 +358,14 @@ describe('modifyRequest processing of DNSLinks', function () { expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late xhrRequest.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] - expect((await modifyRequest.onHeadersReceived(xhrRequest)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onHeadersReceived(xhrRequest), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) it('should redirect later in onHeadersReceived if XHR is cross-origin and runtime is Firefox <69', async function () { // stub existence of a valid DNS record @@ -310,7 +378,14 @@ describe('modifyRequest processing of DNSLinks', function () { // onBeforeRequest should not change anything, as it will trigger false-positive CORS error expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late - expect((await modifyRequest.onHeadersReceived(xhrRequest)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onHeadersReceived(xhrRequest), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) // Test makes more sense for dnslinkPolicy=enabled, but we keep it here for completeness it('should do nothing if DNS TXT record is missing and XHR is cross-origin in Firefox', async function () { @@ -335,7 +410,14 @@ describe('modifyRequest processing of DNSLinks', function () { dnslinkResolver.setDnslink(fqdn, '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd') // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) describe('(XHR CORS scenario)', function () { it('should redirect in onBeforeRequest if XHR is cross-origin and runtime is not Firefox', async function () { @@ -345,7 +427,14 @@ describe('modifyRequest processing of DNSLinks', function () { // runtime.isFirefox = false const xhrRequest = { url: 'http://explore.ipld.io/index.html?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) it('should redirect in onBeforeRequest if XHR is cross-origin and runtime is Firefox', async function () { // stub existence of a valid DNS record @@ -355,7 +444,14 @@ describe('modifyRequest processing of DNSLinks', function () { // Context for CORS XHR problems in Firefox: https://github.com/ipfs-shipyard/ipfs-companion/issues/436 runtime.isFirefox = true const xhrRequest = { url: 'http://explore.ipld.io/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal(activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest') + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, + MV3Expectation: { + origin: '^https?\\:\\/\\/explore\\.ipld\\.io', + destination: `${activeGateway}/ipns/explore.ipld.io` + } + }) }) it('should do nothing if DNS TXT record is missing and XHR is cross-origin in Firefox', async function () { // stub cached info about lack of dnslink From cc109b0f8fbeafa2e8f5b66cd52bf298c95d4426 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 02:23:05 -0600 Subject: [PATCH 32/63] feat(test): Upgrading workaround tests to MV3 Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/ipfs-request-workarounds.test.js | 71 ++++++++++++++----- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/test/functional/lib/ipfs-request-workarounds.test.js b/test/functional/lib/ipfs-request-workarounds.test.js index 140ea819a..06277126e 100644 --- a/test/functional/lib/ipfs-request-workarounds.test.js +++ b/test/functional/lib/ipfs-request-workarounds.test.js @@ -1,6 +1,6 @@ 'use strict' import { assert, expect } from 'chai' -import { after, before, beforeEach, describe, it } from 'mocha' +import { after, afterEach, before, beforeEach, describe, it } from 'mocha' import browser from 'sinon-chrome' import { URL } from 'url' // URL implementation with support for .origin attribute import createDNSLinkResolver from '../../../add-on/src/lib/dnslink.js' @@ -8,18 +8,17 @@ import { braveNodeType } from '../../../add-on/src/lib/ipfs-client/brave.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' +import { cleanupRules } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' import isMv3TestingEnabled from '../../helpers/is-mv3-testing-enabled.js' +import { ensureCallRedirected } from '../../helpers/mv3-test-helper.js' import { spoofDnsTxtRecord } from './dnslink.test.js' describe('modifyRequest processing', function () { let state, getState, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime before(function () { - if (isMv3TestingEnabled) { - return this.skip() - } global.URL = URL global.browser = browser browser.runtime.id = 'testid' @@ -36,6 +35,12 @@ describe('modifyRequest processing', function () { modifyRequest = createRequestModifier(getState, dnslinkResolver, ipfsPathValidator, runtime) }) + afterEach(async function () { + if (isMv3TestingEnabled) { + await cleanupRules(true) + } + }) + // Additional handling is required for redirected IPFS subresources on regular HTTPS pages // (eg. image embedded from public gateway on HTTPS website) describe('a subresource request on HTTPS website', function () { @@ -48,8 +53,14 @@ describe('modifyRequest processing', function () { url: `https://ipfs.io/ipfs/${cid}`, initiator: 'https://some-website.example.com' // Chromium } - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://127.0.0.1:8080/ipfs/${cid}`) + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: `http://127.0.0.1:8080/ipfs/${cid}`, + MV3Expectation: { + origin: '^https?\\:\\/\\/ipfs\\.io', + destination: 'http://127.0.0.1:8080' + } + }) }) it('should be routed to "localhost" gw in Chromium if not a subresource', async function () { runtime.isFirefox = false @@ -59,8 +70,14 @@ describe('modifyRequest processing', function () { url: `https://ipfs.io/ipfs/${cid}`, initiator: 'https://some-website.example.com' // Chromium } - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://localhost:8080/ipfs/${cid}`) + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: `http://localhost:8080/ipfs/${cid}`, + MV3Expectation: { + origin: '^https?\\:\\/\\/ipfs\\.io', + destination: 'http://localhost:8080' + } + }) }) it('should be routed to "127.0.0.1" gw to avoid mixed content warning in Firefox', async function () { runtime.isFirefox = true @@ -70,8 +87,14 @@ describe('modifyRequest processing', function () { url: `https://ipfs.io/ipfs/${cid}`, originUrl: 'https://some-website.example.com/some/page.html' // FF only } - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://127.0.0.1:8080/ipfs/${cid}`) + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: `http://127.0.0.1:8080/ipfs/${cid}`, + MV3Expectation: { + origin: '^https?\\:\\/\\/ipfs\\.io', + destination: 'http://127.0.0.1:8080' + } + }) }) it('should be routed to "localhost" gw in Firefox if not a subresource', async function () { runtime.isFirefox = true @@ -81,8 +104,14 @@ describe('modifyRequest processing', function () { url: `https://ipfs.io/ipfs/${cid}`, originUrl: 'https://some-website.example.com/some/page.html' // FF only } - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://localhost:8080/ipfs/${cid}`) + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: `http://localhost:8080/ipfs/${cid}`, + MV3Expectation: { + origin: '^https?\\:\\/\\/ipfs\\.io', + destination: 'http://localhost:8080' + } + }) }) }) @@ -292,11 +321,11 @@ describe('modifyRequest processing', function () { type: 'main_frame', url: brokenDNSLinkUrl } - browser.tabs.update.flush() + browser.tabs.update.resetHistory() assert.ok(browser.tabs.update.withArgs(request.tabId, { url: fixedDNSLinkUrl }).notCalled) await modifyRequest.onCompleted(request) assert.ok(browser.tabs.update.withArgs(request.tabId, { url: fixedDNSLinkUrl }).calledOnce) - browser.tabs.update.flush() + browser.tabs.update.resetHistory() }) }) @@ -317,11 +346,11 @@ describe('modifyRequest processing', function () { type: 'main_frame', url: httpDNSLinkUrl } - browser.tabs.update.flush() + browser.tabs.update.resetHistory() assert.ok(browser.tabs.update.withArgs(request.tabId, { url: nativeDNSLinkUri }).notCalled) await modifyRequest.onBeforeRequest(request) assert.ok(browser.tabs.update.withArgs(request.tabId, { url: nativeDNSLinkUri }).calledOnce) - browser.tabs.update.flush() + browser.tabs.update.resetHistory() }) }) @@ -349,8 +378,14 @@ describe('modifyRequest processing', function () { url: `https://ipfs.io/ipfs/${cid}`, initiator: 'https://some-website.example.com' // Brave (built on Chromium) } - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://localhost:8080/ipfs/${cid}`) + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: `http://localhost:8080/ipfs/${cid}`, + MV3Expectation: { + origin: '^https?\\:\\/\\/ipfs\\.io', + destination: 'http://localhost:8080' + } + }) }) }) From 441191e18148b7dabba610e663ecf6c223e0d794 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 02:54:13 -0600 Subject: [PATCH 33/63] fix(test): removing all skips with better checks. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/ipfs-request-gateway-redirect.test.js | 172 ++++++++++-------- 1 file changed, 94 insertions(+), 78 deletions(-) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index 911cdfd20..a1a5cf0ca 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -12,6 +12,7 @@ import { cleanupRules, generateAddRule } from '../../../add-on/src/lib/redirect- import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' import isMv3TestingEnabled, { manifestVersion } from '../../helpers/is-mv3-testing-enabled.js' +import { ensureCallRedirected } from '../../helpers/mv3-test-helper.js' const url2request = (string) => { return { url: string, type: 'main_frame' } @@ -174,11 +175,14 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { runtime.isFirefox = true const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://google.com/' } - if (isMv3TestingEnabled) { - // return this.skip() - } else { - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://127.0.0.1:8080' + } + }) }) it('should be served from custom gateway if fetched from the same origin and redirect is enabled in Chromium', async function () { runtime.isFirefox = false @@ -203,21 +207,27 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { runtime.isFirefox = false const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - if (isMv3TestingEnabled) { - // return this.skip() - } else { - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://127.0.0.1:8080' + } + }) }) it('should be served from custom gateway if XHR is cross-origin and redirect is enabled in Firefox', async function () { runtime.isFirefox = true const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - if (isMv3TestingEnabled) { - // return this.skip() - } else { - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://127.0.0.1:8080' + } + }) }) }) describe('with external node when runtime.requiresXHRCORSfix', function () { @@ -228,45 +238,58 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it('should be served from custom gateway if fetched from the same origin and redirect is enabled in Firefox', async function () { runtime.isFirefox = true const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://google.com/' } - if (isMv3TestingEnabled) { - // return this.skip() - } else { - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://127.0.0.1:8080' + } + }) }) it('should be served from custom gateway if fetched from the same origin and redirect is enabled in non-Firefox', async function () { runtime.isFirefox = false const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://google.com/' } - if (isMv3TestingEnabled) { - // return this.skip() - } else { - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://127.0.0.1:8080' + } + }) }) it('should be served from custom gateway if XHR is cross-origin and redirect is enabled in non-Firefox', async function () { runtime.isFirefox = false const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - if (isMv3TestingEnabled) { - // return this.skip() - } else { - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://127.0.0.1:8080' + } + }) }) it('should be served from custom gateway via late redirect in onHeadersReceived if XHR is cross-origin and redirect is enabled in Firefox', async function () { // Context for CORS XHR problems in Firefox: https://github.com/ipfs-shipyard/ipfs-companion/issues/436 runtime.isFirefox = true const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - if (isMv3TestingEnabled) { - // return this.skip() - } else { // onBeforeRequest should not change anything, as it will trigger false-positive CORS error - expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) - // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late - expect((await modifyRequest.onHeadersReceived(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onHeadersReceived(xhrRequest), + MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://127.0.0.1:8080' + } + }) }) }) }) @@ -461,9 +484,8 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it('should fix localhost Kubo RPC hostname to IP', async function () { const request = url2request('http://localhost:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - if (isMv3TestingEnabled) { - // return this.skip() - } else { + if (!isMv3TestingEnabled) { + // this is set as a default rule in MV3 expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) .to.equal('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') } @@ -471,18 +493,13 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it('should be left untouched if localhost Gateway is used', async function () { const request = url2request('http://localhost:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - if (isMv3TestingEnabled) { - // return this.skip() - } else { - await expectNoRedirect(modifyRequest, request) - } + await expectNoRedirect(modifyRequest, request, browser) }) it('should fix 127.0.0.1 Gateway to localhost', async function () { const request = url2request('http://127.0.0.1:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - if (isMv3TestingEnabled) { - // return this.skip() - } else { + if (!isMv3TestingEnabled) { + // this is set as a default rule in MV3. expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) .to.equal('http://localhost:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') } @@ -491,19 +508,21 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { // https://github.com/ipfs-shipyard/ipfs-companion/issues/867 const request = url2request('http://0.0.0.0:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - if (isMv3TestingEnabled) { - // return this.skip() - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/', + MV3Expectation: { + origin: '^https?\\:\\/\\/0\\.0\\.0\\.0', + destination: 'http://127.0.0.1' + } + }) }) it('should be left untouched if /webui on localhost Kubo RPC port', async function () { // https://github.com/ipfs/ipfs-companion/issues/291 const request = url2request('http://localhost:5001/webui') if (isMv3TestingEnabled) { - // return this.skip() + sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) } else { expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) .to.equal('http://127.0.0.1:5001/webui') @@ -514,21 +533,13 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { const request = url2request('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DDIFF' }] - if (isMv3TestingEnabled) { - // return this.skip() - } else { - await expectNoRedirect(modifyRequest, request) - } + await expectNoRedirect(modifyRequest, request, browser) }) it('should be left untouched if [::1] is used', async function () { // https://github.com/ipfs/ipfs-companion/issues/291 const request = url2request('http://[::1]:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - if (isMv3TestingEnabled) { - // return this.skip() - } else { - await expectNoRedirect(modifyRequest, request) - } + await expectNoRedirect(modifyRequest, request, browser) }) it('should be redirected to localhost (subdomain in go-ipfs >0.5) if type=main_frame and 127.0.0.1 (path gw) is used un URL', async function () { state.redirect = true @@ -538,9 +549,8 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { const request = url2request(`http://127.0.0.1:8080/ipfs/${cid}?arg=val#hash`) request.type = 'main_frame' // explicit - if (isMv3TestingEnabled) { - // return this.skip() - } else { + if (!isMv3TestingEnabled) { + // this is set as a default rule in MV3. expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) .to.equal(`http://localhost:8080/ipfs/${cid}?arg=val#hash`) } @@ -559,22 +569,28 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { state.gwURL = new URL(state.gwURLString) const request = url2request('https://bar.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - if (isMv3TestingEnabled) { - // return this.skip() - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'http://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/bar\\.com', + destination: 'http://foo' + } + }) }) it('should work for HTTPS GW without explicit port in URL', async function () { state.gwURLString = 'https://foo:443/' state.gwURL = new URL(state.gwURLString) const request = url2request('https://bar.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - if (isMv3TestingEnabled) { - // return this.skip() - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/bar\\.com', + destination: 'https://foo' + } + }) }) }) From 5ac8417ba8124a2ddf17ac30d29850010bd421e2 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 03:32:33 -0600 Subject: [PATCH 34/63] fix(test): :recycle: Refactoring tests and removing redundant calls. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../ipfs-request-protocol-handlers.test.js | 605 ++++++------------ test/helpers/mv3-test-helper.ts | 11 +- 2 files changed, 201 insertions(+), 415 deletions(-) diff --git a/test/functional/lib/ipfs-request-protocol-handlers.test.js b/test/functional/lib/ipfs-request-protocol-handlers.test.js index 1883839b8..1ba252fd1 100644 --- a/test/functional/lib/ipfs-request-protocol-handlers.test.js +++ b/test/functional/lib/ipfs-request-protocol-handlers.test.js @@ -1,24 +1,20 @@ 'use strict' -import { expect } from 'chai' import { after, before, beforeEach, describe, it } from 'mocha' -import Sinon from 'sinon' import browser from 'sinon-chrome' import { URL } from 'url' import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' import { createRequestModifier } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' -import { generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' -import isMv3TestingEnabled from '../../helpers/is-mv3-testing-enabled.js' +import { ensureCallRedirected, ensureRequestUntouched } from '../../helpers/mv3-test-helper.js' const url2request = (string) => { return { url: string, type: 'main_frame' } } const nodeTypes = ['external'] -const groupAtEndRegex = '((?:[^\\.]|$).*)$' describe('modifyRequest.onBeforeRequest:', function () { let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime @@ -65,558 +61,339 @@ describe('modifyRequest.onBeforeRequest:', function () { // without web+ prefix (Firefox > 59: https://github.com/ipfs-shipyard/ipfs-companion/issues/164#issuecomment-356301174) it('should not be normalized if ipfs:/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if ipfs://{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23', + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#' + } + }) }) it('should not be normalized if ipns:/{fqdn}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=ipns%3A%2Fipfs.io%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if ipns://{fqdn}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=ipns%3A%2F%2Fipfs.io%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipns%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipns/ipfs.io?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipns%3A%2F%2Fipfs\\.io%3FargTest%23', + destination: 'https://ipfs.io/ipns/ipfs.io?argTest#' + } + }) }) it('should be normalized if ipfs://{fqdn}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=ipfs%3A%2F%2Fipfs.io%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipns/ipfs.io?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2Fipfs\\.io%3FargTest%23', + destination: 'https://ipfs.io/ipns/ipfs.io?argTest#' + } + }) }) it('should be normalized if dweb:/ipfs/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23', + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#' + } + }) }) it('should not be normalized if dweb://ipfs/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if dweb:/ipns/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipns/ipfs.io?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23', + destination: 'https://ipfs.io/ipns/ipfs.io?argTest#' + } + }) }) it('should not be normalized if dweb://ipns/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=dweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) // web+ prefixed versions (Firefox < 59 and Chrome) it('should not be normalized if web+ipfs:/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if web+ipfs://{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23', + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#' + } + }) }) it('should not be normalized if web+ipns:/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipns%3A%2Fipfs.io%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if web+ipns://{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bipns%3A%2F%2Fipfs.io%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipns%3A%2F%2Fipfs\\.io%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipns/ipfs.io?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipns%3A%2F%2Fipfs\\.io%3FargTest%23', + destination: 'https://ipfs.io/ipns/ipfs.io?argTest#' + } + }) }) it('should be normalized if web+dweb:/ipfs/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23', + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#' + } + }) }) it('should not be normalized if web+dweb://ipfs/{CID}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if web+dweb:/ipns/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io?argTest#\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipns/ipfs.io?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23', + destination: 'https://ipfs.io/ipns/ipfs.io?argTest#' + } + }) }) it('should not be normalized if web+dweb://ipns/{foo}', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bdweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should not be normalized if web+{foo}:/bar', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bfoo%3A%2Fbar%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should not be normalized if web+{foo}://bar', async function () { const request = url2request('https://dweb.link/ipfs/?uri=web%2Bfoo%3A%2F%2Fbar%3FargTest%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) }) describe('catching unhandled custom protocol request', function () { it('should not be normalized if ipfs:/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if ipfs://{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar', + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' + } + }) }) it('should not be normalized if ipns:/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=ipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if ipns://{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=ipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1') - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23', + destination: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#' + } + }) }) it('should be normalized if ipfs://{fqdn}', async function () { const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' - ) - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23', + destination: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#' + } + }) }) it('should be normalized if dweb:/ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash\\1' - ) - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash', + MV3Expectation: { + origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software', + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash' + } + }) }) it('should not be normalized if dweb://ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if dweb:/ipns/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash\\1' - ) - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash', + MV3Expectation: { + origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web', + destination: 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash' + } + }) }) it('should not be normalized if dweb://ipns/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should not be normalized if web+ipfs:/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if web+ipfs://{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1' - ) - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar', + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' + } + }) }) it('should not be normalized if web+ipns:/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if web+ipns://{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' - ) - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23', + destination: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#' + } + }) }) it('should be normalized if web+dweb:/ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software${groupAtEndRegex}`, - 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash\\1' - ) - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash', + MV3Expectation: { + origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software', + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash' + } + }) }) it('should not be normalized if web+dweb://ipfs/{CID}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should be normalized if web+dweb:/ipns/{foo}', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [ - generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web${groupAtEndRegex}`, - 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash\\1' - ) - ], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash', + MV3Expectation: { + origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web', + destination: 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash' + } + }) }) it('should not be normalized if web+dweb://ipns/{foo}2', async function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should not be normalized if disabled in Preferences', async function () { state.catchUnhandledProtocols = false const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should not be normalized if CID is invalid', async function () { state.catchUnhandledProtocols = false const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FnotARealIpfsPathWithCid%3FargTest%23hashTest&foo=bar') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should not be normalized if presence of %3A%2F is a false-positive', async function () { state.catchUnhandledProtocols = false const request = url2request('https://duckduckgo.com/?q=foo%3A%2Fbar%3FargTest%23hashTest&foo=bar') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should not be normalized if request.type != main_frame', async function () { const mediaRequest = { url: 'https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar', type: 'media' } - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(mediaRequest) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(mediaRequest)).to.equal(undefined) - } + ensureRequestUntouched(await modifyRequest.onBeforeRequest(mediaRequest)) }) }) }) diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts index fbf5fae2a..1d8522cef 100644 --- a/test/helpers/mv3-test-helper.ts +++ b/test/helpers/mv3-test-helper.ts @@ -1,7 +1,8 @@ import { expect } from 'chai' -import isMv3TestingEnabled from './is-mv3-testing-enabled' +import Sinon from 'sinon' import browser from 'sinon-chrome' import { generateAddRule } from '../../add-on/src/lib/redirect-handler/blockOrObserve' +import isMv3TestingEnabled from './is-mv3-testing-enabled' export const regexRuleEnding = '((?:[^\\.]|$).*)$' @@ -28,3 +29,11 @@ export function ensureCallRedirected ({ expect(modifiedRequestCallResp.redirectUrl).to.equal(MV2Expectation) } } + +export function ensureRequestUntouched (resp): void { + if (isMv3TestingEnabled) { + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(resp).to.equal(undefined) + } +} From 02042cb6eb881d7f553112efb5e1d49c137f1f6c Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 04:04:00 -0600 Subject: [PATCH 35/63] fix(test): More Dryer Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/ipfs-request-gateway-redirect.test.js | 284 ++++++------------ test/helpers/mv3-test-helper.ts | 12 + 2 files changed, 102 insertions(+), 194 deletions(-) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index a1a5cf0ca..f92574397 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -12,7 +12,7 @@ import { cleanupRules, generateAddRule } from '../../../add-on/src/lib/redirect- import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' import isMv3TestingEnabled, { manifestVersion } from '../../helpers/is-mv3-testing-enabled.js' -import { ensureCallRedirected } from '../../helpers/mv3-test-helper.js' +import { ensureCallRedirected, ensureRequestUntouched, expectNoRedirect } from '../../helpers/mv3-test-helper.js' const url2request = (string) => { return { url: string, type: 'main_frame' } @@ -22,18 +22,6 @@ const fakeRequestId = () => { return Math.floor(Math.random() * 100000).toString() } -const expectNoRedirect = async (modifyRequest, request, browser) => { - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - await modifyRequest.onHeadersReceived(request) - sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) - } -} - const nodeTypes = ['external'] const regexRuleEnding = '((?:[^\\.]|$).*)$' @@ -76,21 +64,14 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it('should be served from custom gateway if redirect is enabled', async function () { const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - if (isMv3TestingEnabled) { - const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, - 'http://localhost:8080\\1' - )], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'http://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://localhost:8080' + } + }) }) }) describe('with every node type', function () { @@ -102,32 +83,22 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it(`should be left untouched if redirect is disabled (${nodeType} node)`, async function () { state.redirect = false const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - if (isMv3TestingEnabled) { - await expectNoRedirect(modifyRequest, request, browser) - } else { - await expectNoRedirect(modifyRequest, request) - } + + await expectNoRedirect(modifyRequest, request, browser) }) it(`should be left untouched if redirect is enabled but global active flag is OFF (${nodeType} node)`, async function () { state.active = false state.redirect = true const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - if (isMv3TestingEnabled) { - await expectNoRedirect(modifyRequest, request, browser) - } else { - await expectNoRedirect(modifyRequest, request) - } + + await expectNoRedirect(modifyRequest, request, browser) }) it(`should be left untouched if URL includes opt-out hint (${nodeType} node)`, async function () { // A safe way for preloading data at arbitrary gateways - it should arrive at original destination const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?x-ipfs-companion-no-redirect#hashTest') - if (isMv3TestingEnabled) { - await expectNoRedirect(modifyRequest, request, browser) - } else { - await expectNoRedirect(modifyRequest, request) - expect(redirectOptOutHint).to.equal('x-ipfs-companion-no-redirect') - } + await expectNoRedirect(modifyRequest, request, browser) + expect(redirectOptOutHint).to.equal('x-ipfs-companion-no-redirect') }) it(`should be left untouched if request is for subresource on a page loaded from URL that includes opt-out hint (${nodeType} node)`, async function () { // ensure opt-out works for subresources (Firefox only for now) @@ -137,30 +108,18 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { originUrl: 'https://example.com/?x-ipfs-companion-no-redirect#hashTest' } - if (isMv3TestingEnabled) { - await expectNoRedirect(modifyRequest, subRequest, browser) - } else { - await expectNoRedirect(modifyRequest, subRequest) - } + await expectNoRedirect(modifyRequest, subRequest, browser) }) it(`should be left untouched if CID is invalid (${nodeType} node)`, async function () { const request = url2request('https://google.com/ipfs/notacid?argTest#hashTest') - if (isMv3TestingEnabled) { - await expectNoRedirect(modifyRequest, request, browser) - } else { - await expectNoRedirect(modifyRequest, request) - } + await expectNoRedirect(modifyRequest, request, browser) }) it(`should be left untouched if its is a HEAD preload with explicit opt-out in URL hash (${nodeType} node)`, async function () { // HTTP HEAD is a popular way for preloading data at arbitrary gateways, so we have a dedicated test to make sure it works as expected const headRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#x-ipfs-companion-no-redirect', method: 'HEAD' } - if (isMv3TestingEnabled) { - await expectNoRedirect(modifyRequest, headRequest, browser) - } else { - await expectNoRedirect(modifyRequest, headRequest) - } + await expectNoRedirect(modifyRequest, headRequest, browser) }) }) }) @@ -307,30 +266,27 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { // pretend API is online and we can do dns lookups with it state.peerCount = 1 - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, - 'http://localhost:8080\\1' - )], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://localhost:8080' + } + }) }) it('should be served from custom gateway if {path} starts with a valid PeerID', async function () { const request = url2request('https://google.com/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest') dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().resolves(false) - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('http://localhost:8080/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'http://localhost:8080/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://localhost:8080' + } + }) }) }) @@ -344,21 +300,13 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { state.redirect = false const request = url2request('https://google.com/ipns/ipfs.io?argTest#hashTest') - if (isMv3TestingEnabled) { - await expectNoRedirect(modifyRequest, request, browser) - } else { - await expectNoRedirect(modifyRequest, request) - } + await expectNoRedirect(modifyRequest, request, browser) }) it(`should be left untouched if FQDN is not a real domain nor a valid CID (${nodeType} node)`, async function () { const request = url2request('https://google.com/ipns/notafqdnorcid?argTest#hashTest') dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().resolves(false) - if (isMv3TestingEnabled) { - await expectNoRedirect(modifyRequest, request, browser) - } else { - await expectNoRedirect(modifyRequest, request) - } + await expectNoRedirect(modifyRequest, request, browser) }) }) }) @@ -368,10 +316,6 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { const cid = 'bafybeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge' const peerid = 'bafzbeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge' - // Tests use different CID in X-Ipfs-Path header just to ensure it does not - // override the one from path - const fakeXIpfsPathHdrVal = '/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ' - describe('with external node', function () { beforeEach(function () { state.ipfsNodeType = 'external' @@ -386,87 +330,53 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { // return redirect to a subdomain, and we don't want to break users // running older versions of go-ipfs by loading subdomain first and // failing. - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/${cid}\\.ipfs\\.dweb\\.link${regexRuleEnding}`, - `http://localhost:8080/ipfs/${cid}\\1` - )], - removeRuleIds: [] - }) - } else { - // X-Ipfs-Path to ensure value from URL takes a priority - request.responseHeaders = [{ name: 'X-Ipfs-Path', value: fakeXIpfsPathHdrVal }] - - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://localhost:8080/ipfs/${cid}/`) - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: `http://localhost:8080/ipfs/${cid}/`, + MV3Expectation: { + origin: `^https?\\:\\/\\/${cid}\\.ipfs\\.dweb\\.link`, + destination: `http://localhost:8080/ipfs/${cid}` + } + }) }) it('should be redirected to localhost gateway (*.ipfs on 3rd party gw)', async function () { state.redirect = true const request = url2request(`https://${cid}.ipfs.cf-ipfs.com/`) - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/${cid}\\.ipfs\\.cf\\-ipfs\\.com${regexRuleEnding}`, - `http://localhost:8080/ipfs/${cid}\\1` - )], - removeRuleIds: [] - }) - } else { - request.responseHeaders = [{ name: 'X-Ipfs-Path', value: fakeXIpfsPathHdrVal }] - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://localhost:8080/ipfs/${cid}/`) - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: `http://localhost:8080/ipfs/${cid}/`, + MV3Expectation: { + origin: `^https?\\:\\/\\/${cid}\\.ipfs\\.cf\\-ipfs\\.com`, + destination: `http://localhost:8080/ipfs/${cid}` + } + }) }) it('should be redirected to localhost gateway and keep URL encoding of original path', async function () { state.redirect = true const request = url2request('https://bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy.ipfs.dweb.link/%3Ffilename=test.jpg?arg=val') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\.ipfs\\.dweb\\.link${regexRuleEnding}`, - 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\1' - )], - removeRuleIds: [] - }) - } else { - request.responseHeaders = [{ name: 'X-Ipfs-Path', value: fakeXIpfsPathHdrVal }] - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal('http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy/%3Ffilename=test.jpg?arg=val') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy/%3Ffilename=test.jpg?arg=val', + MV3Expectation: { + origin: '^https?\\:\\/\\/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\.ipfs\\.dweb\\.link', + destination: 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy' + } + }) }) it('should be redirected to localhost gateway (*.ipns on default gw)', async function () { state.redirect = true const request = url2request(`https://${peerid}.ipns.dweb.link/`) - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/${peerid}\\.ipns\\.dweb\\.link${regexRuleEnding}`, - `http://localhost:8080/ipns/${peerid}\\1` - )], - removeRuleIds: [] - }) - } else { - request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipns/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ' }] - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) - .to.equal(`http://localhost:8080/ipns/${peerid}/`) - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: `http://localhost:8080/ipns/${peerid}/`, + MV3Expectation: { + origin: `^https?\\:\\/\\/${peerid}\\.ipns\\.dweb\\.link`, + destination: `http://localhost:8080/ipns/${peerid}` + } + }) }) }) }) @@ -608,36 +518,30 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it('should present recovery page if node is offline and redirect is enabled', async function () { expect(state.nodeActive).to.be.equal(false) const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - - expect(args.addRules[0]).to.deep.equal(generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/${regexRuleEnding}`, - 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1' - )) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar', + MV3Expectation: { + origin: '^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/', + destination: 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F' + } + }) }) it('should present recovery page if node is offline and redirect is disabled', async function () { expect(state.nodeActive).to.be.equal(false) state.redirect = false const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - - expect(args.addRules[0]).to.deep.equal(generateAddRule( - args.addRules[0].id, - `^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/${regexRuleEnding}`, - 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1' - )) - } else { - expect((await modifyRequest.onBeforeRequest(request)).redirectUrl).to.equal('chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar') - } + + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), + MV2Expectation: 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar', + MV3Expectation: { + origin: '^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/', + destination: 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F' + } + }) }) it('should not show recovery page if node is offline, redirect is enabled, but non-gateway URL failed to load from the same port', async function () { @@ -645,12 +549,8 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { state.redirect = true expect(state.nodeActive).to.be.equal(false) const request = url2request('https://localhost:8080/') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - await expectNoRedirect(modifyRequest, request, browser) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) it('should not show recovery page if extension is disabled', async function () { @@ -658,12 +558,8 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { state.active = false expect(state.nodeActive).to.be.equal(false) const request = url2request('https://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR/foo/bar') - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(request) - await expectNoRedirect(modifyRequest, request, browser) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - } + + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) }) }) }) diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts index 1d8522cef..8d7059df0 100644 --- a/test/helpers/mv3-test-helper.ts +++ b/test/helpers/mv3-test-helper.ts @@ -37,3 +37,15 @@ export function ensureRequestUntouched (resp): void { expect(resp).to.equal(undefined) } } + +export async function expectNoRedirect (modifyRequest, request, browser): Promise { + if (isMv3TestingEnabled) { + await modifyRequest.onBeforeRequest(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + await modifyRequest.onHeadersReceived(request) + Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) + } else { + expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) + } +} From f3d4605d87f20063c2c2e65ac85b8cdec7b55400 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 04:07:15 -0600 Subject: [PATCH 36/63] fix(test): one more Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/ipfs-request-gateway-redirect.test.js | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index f92574397..04dfc4cf9 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -147,20 +147,14 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { runtime.isFirefox = false const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://google.com/' } - if (isMv3TestingEnabled) { - await modifyRequest.onBeforeRequest(xhrRequest) - const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args).to.deep.equal({ - addRules: [generateAddRule( - args.addRules[0].id, - `${'^https?\\:\\/\\/google\\.com'}${regexRuleEnding}`, - 'http://127.0.0.1:8080\\1' - )], - removeRuleIds: [] - }) - } else { - expect((await modifyRequest.onBeforeRequest(xhrRequest)).redirectUrl).to.equal('http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - } + ensureCallRedirected({ + modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), + MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', + MV3Expectation: { + origin: '^https?\\:\\/\\/google\\.com', + destination: 'http://127.0.0.1:8080' + } + }) }) it('should be served from custom gateway if XHR is cross-origin and redirect is enabled in Chromium', async function () { runtime.isFirefox = false From 47d72f8ff5c99937d3b7d59bf82765cf32ea8500 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 04:10:19 -0600 Subject: [PATCH 37/63] fix(test): :pencil2: Renaming isMv3TestingEnabled -> isManifestV3 Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- test/functional/lib/ipfs-request-dnslink.test.js | 4 ++-- .../lib/ipfs-request-gateway-redirect.test.js | 15 +++++++-------- .../lib/ipfs-request-workarounds.test.js | 4 ++-- .../lib/redirect-handler/blockOrObserve.test.ts | 12 ++++++------ test/helpers/is-mv3-testing-enabled.js | 6 +++--- test/helpers/mv3-test-helper.ts | 8 ++++---- test/setup/mocha-setup.js | 4 ++-- 7 files changed, 26 insertions(+), 27 deletions(-) diff --git a/test/functional/lib/ipfs-request-dnslink.test.js b/test/functional/lib/ipfs-request-dnslink.test.js index 35891b15d..7cc52abb6 100644 --- a/test/functional/lib/ipfs-request-dnslink.test.js +++ b/test/functional/lib/ipfs-request-dnslink.test.js @@ -10,7 +10,7 @@ import { optionDefaults } from '../../../add-on/src/lib/options.js' import { cleanupRules } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' -import isMv3TestingEnabled from '../../helpers/is-mv3-testing-enabled.js' +import isManifestV3 from '../../helpers/is-mv3-testing-enabled.js' import { ensureCallRedirected } from '../../helpers/mv3-test-helper.js' const url2request = (string) => { @@ -48,7 +48,7 @@ describe('modifyRequest processing of DNSLinks', function () { }) afterEach(async function () { - if (isMv3TestingEnabled) { + if (isManifestV3) { await cleanupRules(true) } }) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index 04dfc4cf9..a414f3693 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -8,10 +8,10 @@ import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' import { createIpfsPathValidator } from '../../../add-on/src/lib/ipfs-path.js' import { createRequestModifier, redirectOptOutHint } from '../../../add-on/src/lib/ipfs-request.js' import { optionDefaults } from '../../../add-on/src/lib/options.js' -import { cleanupRules, generateAddRule } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' +import { cleanupRules } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' -import isMv3TestingEnabled, { manifestVersion } from '../../helpers/is-mv3-testing-enabled.js' +import isManifestV3, { manifestVersion } from '../../helpers/is-mv3-testing-enabled.js' import { ensureCallRedirected, ensureRequestUntouched, expectNoRedirect } from '../../helpers/mv3-test-helper.js' const url2request = (string) => { @@ -23,7 +23,6 @@ const fakeRequestId = () => { } const nodeTypes = ['external'] -const regexRuleEnding = '((?:[^\\.]|$).*)$' describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime @@ -51,7 +50,7 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { }) afterEach(async function () { - if (isMv3TestingEnabled) { + if (isManifestV3) { await cleanupRules(true) } }) @@ -388,7 +387,7 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it('should fix localhost Kubo RPC hostname to IP', async function () { const request = url2request('http://localhost:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - if (!isMv3TestingEnabled) { + if (!isManifestV3) { // this is set as a default rule in MV3 expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) .to.equal('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') @@ -402,7 +401,7 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it('should fix 127.0.0.1 Gateway to localhost', async function () { const request = url2request('http://127.0.0.1:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - if (!isMv3TestingEnabled) { + if (!isManifestV3) { // this is set as a default rule in MV3. expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) .to.equal('http://localhost:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') @@ -425,7 +424,7 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { // https://github.com/ipfs/ipfs-companion/issues/291 const request = url2request('http://localhost:5001/webui') - if (isMv3TestingEnabled) { + if (isManifestV3) { sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) } else { expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) @@ -453,7 +452,7 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { const request = url2request(`http://127.0.0.1:8080/ipfs/${cid}?arg=val#hash`) request.type = 'main_frame' // explicit - if (!isMv3TestingEnabled) { + if (!isManifestV3) { // this is set as a default rule in MV3. expect((await modifyRequest.onBeforeRequest(request)).redirectUrl) .to.equal(`http://localhost:8080/ipfs/${cid}?arg=val#hash`) diff --git a/test/functional/lib/ipfs-request-workarounds.test.js b/test/functional/lib/ipfs-request-workarounds.test.js index 06277126e..0263d13a8 100644 --- a/test/functional/lib/ipfs-request-workarounds.test.js +++ b/test/functional/lib/ipfs-request-workarounds.test.js @@ -11,7 +11,7 @@ import { optionDefaults } from '../../../add-on/src/lib/options.js' import { cleanupRules } from '../../../add-on/src/lib/redirect-handler/blockOrObserve.js' import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' -import isMv3TestingEnabled from '../../helpers/is-mv3-testing-enabled.js' +import isManifestV3 from '../../helpers/is-mv3-testing-enabled.js' import { ensureCallRedirected } from '../../helpers/mv3-test-helper.js' import { spoofDnsTxtRecord } from './dnslink.test.js' @@ -36,7 +36,7 @@ describe('modifyRequest processing', function () { }) afterEach(async function () { - if (isMv3TestingEnabled) { + if (isManifestV3) { await cleanupRules(true) } }) diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.ts index d665b3f1a..e8a5298e8 100644 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.ts +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.ts @@ -6,7 +6,7 @@ import browserMock from 'sinon-chrome' import { optionDefaults } from '../../../../add-on/src/lib/options.js' import { addRuleToDynamicRuleSetGenerator, cleanupRules, isLocalHost, supportsBlock } from '../../../../add-on/src/lib/redirect-handler/blockOrObserve' import { initState } from '../../../../add-on/src/lib/state.js' -import isMv3TestingEnabled, { manifestVersion } from '../../../helpers/is-mv3-testing-enabled.js' +import isManifestV3, { manifestVersion } from '../../../helpers/is-mv3-testing-enabled.js' import DeclarativeNetRequestMock from './declarativeNetRequest.mock.js' const dynamicRulesConditions = (regexFilter) => ({ @@ -31,11 +31,11 @@ const dynamicRulesConditions = (regexFilter) => ({ ] }) -const manifestVeresion = isMv3TestingEnabled ? 'MV3' : 'MV2' +const manifestVeresion = isManifestV3 ? 'MV3' : 'MV2' describe('lib/redirect-handler/blockOrObserve', () => { before(function () { - if (!isMv3TestingEnabled) { + if (!isManifestV3) { return this.skip() } browserMock.runtime.id = 'testid' @@ -60,8 +60,8 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) describe(`supportsBlock on ${manifestVersion}` , () => { - it(`should return ${isMv3TestingEnabled ? false : true} for ${manifestVersion}`, function () { - if (isMv3TestingEnabled) { + it(`should return ${isManifestV3 ? false : true} for ${manifestVersion}`, function () { + if (isManifestV3) { expect(supportsBlock()).to.be.false } else { expect(supportsBlock()).to.be.true @@ -165,7 +165,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) it('Should refresh the tab when redirect URL is added', async () => { - if (!isMv3TestingEnabled) { + if (!isManifestV3) { // TODO } else { diff --git a/test/helpers/is-mv3-testing-enabled.js b/test/helpers/is-mv3-testing-enabled.js index d74eea66e..7bab8af97 100644 --- a/test/helpers/is-mv3-testing-enabled.js +++ b/test/helpers/is-mv3-testing-enabled.js @@ -1,3 +1,3 @@ -const isMv3TestingEnabled = process.env.TEST_MV3 === 'true' -export const manifestVersion = isMv3TestingEnabled ? 'MV3' : 'MV2' -export default isMv3TestingEnabled +const isManifestV3 = process.env.TEST_MV3 === 'true' +export const manifestVersion = isManifestV3 ? 'MV3' : 'MV2' +export default isManifestV3 diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts index 8d7059df0..ead69ae4f 100644 --- a/test/helpers/mv3-test-helper.ts +++ b/test/helpers/mv3-test-helper.ts @@ -2,7 +2,7 @@ import { expect } from 'chai' import Sinon from 'sinon' import browser from 'sinon-chrome' import { generateAddRule } from '../../add-on/src/lib/redirect-handler/blockOrObserve' -import isMv3TestingEnabled from './is-mv3-testing-enabled' +import isManifestV3 from './is-mv3-testing-enabled' export const regexRuleEnding = '((?:[^\\.]|$).*)$' @@ -18,7 +18,7 @@ export function ensureCallRedirected ({ destination: string } }) { - if (isMv3TestingEnabled) { + if (isManifestV3) { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args.addRules[0]).to.deep.equal(generateAddRule( args.addRules[0].id, @@ -31,7 +31,7 @@ export function ensureCallRedirected ({ } export function ensureRequestUntouched (resp): void { - if (isMv3TestingEnabled) { + if (isManifestV3) { Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) } else { expect(resp).to.equal(undefined) @@ -39,7 +39,7 @@ export function ensureRequestUntouched (resp): void { } export async function expectNoRedirect (modifyRequest, request, browser): Promise { - if (isMv3TestingEnabled) { + if (isManifestV3) { await modifyRequest.onBeforeRequest(request) Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) await modifyRequest.onHeadersReceived(request) diff --git a/test/setup/mocha-setup.js b/test/setup/mocha-setup.js index 082162bab..68c12d901 100644 --- a/test/setup/mocha-setup.js +++ b/test/setup/mocha-setup.js @@ -3,7 +3,7 @@ import { afterEach, beforeEach } from 'mocha' import sinon, { useFakeTimers } from 'sinon' import browser from 'sinon-chrome' import DeclarativeNetRequestMock from '../functional/lib/redirect-handler/declarativeNetRequest.mock.js' -import isMv3TestingEnabled from '../helpers/is-mv3-testing-enabled.js' +import isManifestV3 from '../helpers/is-mv3-testing-enabled.js' browser.runtime.id = 'testid' global.browser = browser @@ -23,7 +23,7 @@ global.clock = useFakeTimers({ now: new Date(2017, 10, 5, 12, 1, 1) }) -if (isMv3TestingEnabled) { +if (isManifestV3) { const sinonSandbox = sinon.createSandbox() beforeEach(function () { browser.runtime.getURL.returns('chrome-extension://testid/') From 239984df7ed367a264b28478b2d62ee38f0e81fb Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 10:03:46 -0600 Subject: [PATCH 38/63] fix(test): refactor expectNoRedirect Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/ipfs-request-gateway-redirect.test.js | 22 +++++++++---------- test/helpers/mv3-test-helper.ts | 15 +++++-------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index a414f3693..f16a985a0 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -83,20 +83,20 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { state.redirect = false const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await expectNoRedirect(modifyRequest, request, browser) + await expectNoRedirect(modifyRequest, request) }) it(`should be left untouched if redirect is enabled but global active flag is OFF (${nodeType} node)`, async function () { state.active = false state.redirect = true const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await expectNoRedirect(modifyRequest, request, browser) + await expectNoRedirect(modifyRequest, request) }) it(`should be left untouched if URL includes opt-out hint (${nodeType} node)`, async function () { // A safe way for preloading data at arbitrary gateways - it should arrive at original destination const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?x-ipfs-companion-no-redirect#hashTest') - await expectNoRedirect(modifyRequest, request, browser) + await expectNoRedirect(modifyRequest, request) expect(redirectOptOutHint).to.equal('x-ipfs-companion-no-redirect') }) it(`should be left untouched if request is for subresource on a page loaded from URL that includes opt-out hint (${nodeType} node)`, async function () { @@ -107,18 +107,18 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { originUrl: 'https://example.com/?x-ipfs-companion-no-redirect#hashTest' } - await expectNoRedirect(modifyRequest, subRequest, browser) + await expectNoRedirect(modifyRequest, subRequest) }) it(`should be left untouched if CID is invalid (${nodeType} node)`, async function () { const request = url2request('https://google.com/ipfs/notacid?argTest#hashTest') - await expectNoRedirect(modifyRequest, request, browser) + await expectNoRedirect(modifyRequest, request) }) it(`should be left untouched if its is a HEAD preload with explicit opt-out in URL hash (${nodeType} node)`, async function () { // HTTP HEAD is a popular way for preloading data at arbitrary gateways, so we have a dedicated test to make sure it works as expected const headRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#x-ipfs-companion-no-redirect', method: 'HEAD' } - await expectNoRedirect(modifyRequest, headRequest, browser) + await expectNoRedirect(modifyRequest, headRequest) }) }) }) @@ -293,13 +293,13 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { state.redirect = false const request = url2request('https://google.com/ipns/ipfs.io?argTest#hashTest') - await expectNoRedirect(modifyRequest, request, browser) + await expectNoRedirect(modifyRequest, request) }) it(`should be left untouched if FQDN is not a real domain nor a valid CID (${nodeType} node)`, async function () { const request = url2request('https://google.com/ipns/notafqdnorcid?argTest#hashTest') dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().resolves(false) - await expectNoRedirect(modifyRequest, request, browser) + await expectNoRedirect(modifyRequest, request) }) }) }) @@ -396,7 +396,7 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it('should be left untouched if localhost Gateway is used', async function () { const request = url2request('http://localhost:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - await expectNoRedirect(modifyRequest, request, browser) + await expectNoRedirect(modifyRequest, request) }) it('should fix 127.0.0.1 Gateway to localhost', async function () { const request = url2request('http://127.0.0.1:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') @@ -436,13 +436,13 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { const request = url2request('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DDIFF' }] - await expectNoRedirect(modifyRequest, request, browser) + await expectNoRedirect(modifyRequest, request) }) it('should be left untouched if [::1] is used', async function () { // https://github.com/ipfs/ipfs-companion/issues/291 const request = url2request('http://[::1]:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - await expectNoRedirect(modifyRequest, request, browser) + await expectNoRedirect(modifyRequest, request) }) it('should be redirected to localhost (subdomain in go-ipfs >0.5) if type=main_frame and 127.0.0.1 (path gw) is used un URL', async function () { state.redirect = true diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts index ead69ae4f..517a53e57 100644 --- a/test/helpers/mv3-test-helper.ts +++ b/test/helpers/mv3-test-helper.ts @@ -39,13 +39,10 @@ export function ensureRequestUntouched (resp): void { } export async function expectNoRedirect (modifyRequest, request, browser): Promise { - if (isManifestV3) { - await modifyRequest.onBeforeRequest(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - await modifyRequest.onHeadersReceived(request) - Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) - } else { - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) - } + await Promise.all([ + modifyRequest.onBeforeRequest(request), + modifyRequest.onHeadersReceived(request) + ].map(async (resp) => { + await ensureRequestUntouched(await resp) + })) } From 94cb1417d7e5f74a0a6b3265a01bea45450f2719 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 10:23:48 -0600 Subject: [PATCH 39/63] fix(test): :recycle: Refactoring more. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/ipfs-request-dnslink.test.js | 46 ++++++++----------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/test/functional/lib/ipfs-request-dnslink.test.js b/test/functional/lib/ipfs-request-dnslink.test.js index 7cc52abb6..388088aab 100644 --- a/test/functional/lib/ipfs-request-dnslink.test.js +++ b/test/functional/lib/ipfs-request-dnslink.test.js @@ -1,5 +1,4 @@ 'use strict' -import { expect } from 'chai' import { after, afterEach, before, beforeEach, describe, it } from 'mocha' import sinon from 'sinon' import browser from 'sinon-chrome' @@ -11,7 +10,7 @@ import { cleanupRules } from '../../../add-on/src/lib/redirect-handler/blockOrOb import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' import isManifestV3 from '../../helpers/is-mv3-testing-enabled.js' -import { ensureCallRedirected } from '../../helpers/mv3-test-helper.js' +import { ensureCallRedirected, ensureRequestUntouched, expectNoRedirect } from '../../helpers/mv3-test-helper.js' const url2request = (string) => { return { url: string, type: 'main_frame' } @@ -71,9 +70,8 @@ describe('modifyRequest processing of DNSLinks', function () { // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') // onBeforeRequest should not change anything - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) // onHeadersReceived should not change anything - expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) + await expectNoRedirect(modifyRequest, request) }) it('should do nothing if dnslink for FQDN is in cache', async function () { // stub existence of a positive DNSLink cache hit @@ -82,9 +80,8 @@ describe('modifyRequest processing of DNSLinks', function () { // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') // onBeforeRequest should not change anything - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) // onHeadersReceived should not change anything - expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) + await expectNoRedirect(modifyRequest, request) }) it('should do nothing if DNS TXT record exists and dnslink is in cache', async function () { // stub existence of a valid DNS record and cache @@ -94,9 +91,8 @@ describe('modifyRequest processing of DNSLinks', function () { // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') // onBeforeRequest should not change anything - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) // onHeadersReceived should not change anything - expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) + await expectNoRedirect(modifyRequest, request) }) it('should do nothing if DNS TXT record exists and x-ipfs-path is disabled', async function () { // enable detection of x-ipfs-path to ensure it is not enough without dnslinkPolicy=detectIpfsPathHeader @@ -107,11 +103,11 @@ describe('modifyRequest processing of DNSLinks', function () { // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') // onBeforeRequest should not change anything - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) // simulate presence of x-ipfs-path header returned by HTTP gateway request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipns/value-from-x-ipfs-path.io' }] // onHeadersReceived should not change anything - expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onHeadersReceived(request)) }) it('should ignore DNS TXT record and use /ipfs/ path from x-ipfs-path if both are present', async function () { // enable detection of x-ipfs-path to ensure it is not enough without dnslinkPolicy=detectIpfsPathHeader @@ -122,7 +118,7 @@ describe('modifyRequest processing of DNSLinks', function () { // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') // onBeforeRequest should not change anything - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) // simulate presence of x-ipfs-path header returned by HTTP gateway request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] // onHeadersReceived should redirect to value from X-Ipfs-Path @@ -144,12 +140,12 @@ describe('modifyRequest processing of DNSLinks', function () { // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') // onBeforeRequest should not change anything - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) // simulate presence of x-ipfs-path header returned by HTTP gateway request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipns/value-from-x-ipfs-path-to-ignore.io' }] // onHeadersReceived should ignore /ipns/ from x-ipfs-path because dnslink is disabled in preferences // and redirect would confuse users - expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onHeadersReceived(request)) }) }) @@ -226,7 +222,7 @@ describe('modifyRequest processing of DNSLinks', function () { // Firefox uses 'originUrl' for origin const xhrRequest = { url: 'http://explore.ipld.io/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } // onBeforeRequest should not change anything, as it will trigger false-positive CORS error - expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onBeforeRequest(xhrRequest)) // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late ensureCallRedirected({ modifiedRequestCallResp: await modifyRequest.onHeadersReceived(xhrRequest), @@ -246,9 +242,8 @@ describe('modifyRequest processing of DNSLinks', function () { // Firefox uses 'originUrl' for origin const xhrRequest = { url: 'https://youtube.com/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } // onBeforeRequest should not change anything - expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) // onHeadersReceived should not change anything - expect(await modifyRequest.onHeadersReceived(xhrRequest)).to.equal(undefined) + await expectNoRedirect(modifyRequest, xhrRequest) }) }) @@ -278,7 +273,7 @@ describe('modifyRequest processing of DNSLinks', function () { // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') request.type = 'sub_frame' // we test a subrequests because main_frame gets early DNSLink preload in onBeforeRequest - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) // simulate presence of x-ipfs-path header returned by HTTP gateway request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] // DNSLink is present, so we ignore hash from X-Ipfs-Path header and redirect to nice /ipns/ address @@ -300,7 +295,7 @@ describe('modifyRequest processing of DNSLinks', function () { // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') request.type = 'sub_frame' // we test a subrequest here because main_frame gets early DNSLink preload in onBeforeRequest - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) // simulate presence of x-ipfs-path header returned by HTTP gateway request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] // Note that DNSLink is missing, so a path from x-ipfs-path is used @@ -322,8 +317,7 @@ describe('modifyRequest processing of DNSLinks', function () { // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') request.type = 'sub_frame' // we test a subrequest here because main_frame gets early DNSLink preload in onBeforeRequest - expect(await modifyRequest.onBeforeRequest(request)).to.equal(undefined) - expect(await modifyRequest.onHeadersReceived(request)).to.equal(undefined) + await expectNoRedirect(modifyRequest, request) }) describe('(XHR CORS scenario)', function () { // Test makes more sense for dnslinkPolicy=enabled, but we keep it here for completeness @@ -334,7 +328,7 @@ describe('modifyRequest processing of DNSLinks', function () { // runtime.isFirefox = false const xhrRequest = { url: 'http://explore.ipld.io/index.html?argTest#hashTest', type: 'xmlhttprequest', initiator: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } - expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onBeforeRequest(xhrRequest)) xhrRequest.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] ensureCallRedirected({ modifiedRequestCallResp: await modifyRequest.onHeadersReceived(xhrRequest), @@ -355,7 +349,7 @@ describe('modifyRequest processing of DNSLinks', function () { runtime.isFirefox = true const xhrRequest = { url: 'http://explore.ipld.io/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } // onBeforeRequest should not change anything, as it will trigger false-positive CORS error - expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onBeforeRequest(xhrRequest)) // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late xhrRequest.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] ensureCallRedirected({ @@ -376,7 +370,7 @@ describe('modifyRequest processing of DNSLinks', function () { runtime.requiresXHRCORSfix = true const xhrRequest = { url: 'http://explore.ipld.io/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } // onBeforeRequest should not change anything, as it will trigger false-positive CORS error - expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onBeforeRequest(xhrRequest)) // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late ensureCallRedirected({ modifiedRequestCallResp: await modifyRequest.onHeadersReceived(xhrRequest), @@ -396,9 +390,8 @@ describe('modifyRequest processing of DNSLinks', function () { runtime.isFirefox = true const xhrRequest = { url: 'https://youtube.com/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } // onBeforeRequest should not change anything - expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) // onHeadersReceived should not change anything - expect(await modifyRequest.onHeadersReceived(xhrRequest)).to.equal(undefined) + await expectNoRedirect(modifyRequest, xhrRequest) }) }) }) @@ -461,9 +454,8 @@ describe('modifyRequest processing of DNSLinks', function () { runtime.isFirefox = true const xhrRequest = { url: 'https://youtube.com/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } // onBeforeRequest should not change anything - expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) // onHeadersReceived should not change anything - expect(await modifyRequest.onHeadersReceived(xhrRequest)).to.equal(undefined) + await expectNoRedirect(modifyRequest, xhrRequest) }) }) }) From e3e73c975890ba1167f99917dd389b31e40024fe Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 10:27:56 -0600 Subject: [PATCH 40/63] fix: replacing checks to undefined Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- test/functional/lib/ipfs-request-gateway-redirect.test.js | 2 +- test/functional/lib/ipfs-request-workarounds.test.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index f16a985a0..b14232a15 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -232,7 +232,7 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { const xhrRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } // onBeforeRequest should not change anything, as it will trigger false-positive CORS error - expect(await modifyRequest.onBeforeRequest(xhrRequest)).to.equal(undefined) + ensureRequestUntouched(await modifyRequest.onBeforeRequest(xhrRequest)) ensureCallRedirected({ modifiedRequestCallResp: await modifyRequest.onHeadersReceived(xhrRequest), diff --git a/test/functional/lib/ipfs-request-workarounds.test.js b/test/functional/lib/ipfs-request-workarounds.test.js index 0263d13a8..acb25d8f8 100644 --- a/test/functional/lib/ipfs-request-workarounds.test.js +++ b/test/functional/lib/ipfs-request-workarounds.test.js @@ -12,7 +12,7 @@ import { cleanupRules } from '../../../add-on/src/lib/redirect-handler/blockOrOb import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' import isManifestV3 from '../../helpers/is-mv3-testing-enabled.js' -import { ensureCallRedirected } from '../../helpers/mv3-test-helper.js' +import { ensureCallRedirected, expectNoRedirect } from '../../helpers/mv3-test-helper.js' import { spoofDnsTxtRecord } from './dnslink.test.js' describe('modifyRequest processing', function () { @@ -355,7 +355,7 @@ describe('modifyRequest processing', function () { }) // https://github.com/ipfs-shipyard/ipfs-companion/issues/962 - describe('redirect of IPFS resource to local gateway in Brave', function () { + describe('redirect of IPFS resource to local gateway in Brave', async function () { it('should be redirected if not a subresource (not impacted by Brave Shields)', async function () { runtime.isFirefox = false runtime.brave = { thisIsFakeBraveRuntime: true } @@ -365,8 +365,7 @@ describe('modifyRequest processing', function () { url: 'https://ipfs.io/ipfs/bafkqae2xmvwgg33nmuqhi3zajfiemuzahiwss', initiator: 'https://some-website.example.com' // Brave (built on Chromium) } - expect(await modifyRequest.onBeforeRequest(request)) - .to.equal(undefined) + await expectNoRedirect(modifyRequest, request) }) it('should be left untouched if subresource (would be blocked by Brave Shields)', async function () { runtime.isFirefox = false From 80e7d51b18ce7e9732b1a07a0f7ea503fa0af7a8 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 10:29:38 -0600 Subject: [PATCH 41/63] fix: renaming expectNoRedirect -> ensureNoRedirect Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/ipfs-request-dnslink.test.js | 16 ++++++------- .../lib/ipfs-request-gateway-redirect.test.js | 24 +++++++++---------- .../lib/ipfs-request-workarounds.test.js | 4 ++-- test/helpers/mv3-test-helper.ts | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/test/functional/lib/ipfs-request-dnslink.test.js b/test/functional/lib/ipfs-request-dnslink.test.js index 388088aab..2d2e01b00 100644 --- a/test/functional/lib/ipfs-request-dnslink.test.js +++ b/test/functional/lib/ipfs-request-dnslink.test.js @@ -10,7 +10,7 @@ import { cleanupRules } from '../../../add-on/src/lib/redirect-handler/blockOrOb import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' import isManifestV3 from '../../helpers/is-mv3-testing-enabled.js' -import { ensureCallRedirected, ensureRequestUntouched, expectNoRedirect } from '../../helpers/mv3-test-helper.js' +import { ensureCallRedirected, ensureNoRedirect, ensureRequestUntouched } from '../../helpers/mv3-test-helper.js' const url2request = (string) => { return { url: string, type: 'main_frame' } @@ -71,7 +71,7 @@ describe('modifyRequest processing of DNSLinks', function () { const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') // onBeforeRequest should not change anything // onHeadersReceived should not change anything - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it('should do nothing if dnslink for FQDN is in cache', async function () { // stub existence of a positive DNSLink cache hit @@ -81,7 +81,7 @@ describe('modifyRequest processing of DNSLinks', function () { const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') // onBeforeRequest should not change anything // onHeadersReceived should not change anything - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it('should do nothing if DNS TXT record exists and dnslink is in cache', async function () { // stub existence of a valid DNS record and cache @@ -92,7 +92,7 @@ describe('modifyRequest processing of DNSLinks', function () { const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') // onBeforeRequest should not change anything // onHeadersReceived should not change anything - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it('should do nothing if DNS TXT record exists and x-ipfs-path is disabled', async function () { // enable detection of x-ipfs-path to ensure it is not enough without dnslinkPolicy=detectIpfsPathHeader @@ -243,7 +243,7 @@ describe('modifyRequest processing of DNSLinks', function () { const xhrRequest = { url: 'https://youtube.com/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } // onBeforeRequest should not change anything // onHeadersReceived should not change anything - await expectNoRedirect(modifyRequest, xhrRequest) + await ensureNoRedirect(modifyRequest, xhrRequest) }) }) @@ -317,7 +317,7 @@ describe('modifyRequest processing of DNSLinks', function () { // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') request.type = 'sub_frame' // we test a subrequest here because main_frame gets early DNSLink preload in onBeforeRequest - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) describe('(XHR CORS scenario)', function () { // Test makes more sense for dnslinkPolicy=enabled, but we keep it here for completeness @@ -391,7 +391,7 @@ describe('modifyRequest processing of DNSLinks', function () { const xhrRequest = { url: 'https://youtube.com/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } // onBeforeRequest should not change anything // onHeadersReceived should not change anything - await expectNoRedirect(modifyRequest, xhrRequest) + await ensureNoRedirect(modifyRequest, xhrRequest) }) }) }) @@ -455,7 +455,7 @@ describe('modifyRequest processing of DNSLinks', function () { const xhrRequest = { url: 'https://youtube.com/index.html?argTest#hashTest', type: 'xmlhttprequest', originUrl: 'https://www.nasa.gov/foo.html', requestId: fakeRequestId() } // onBeforeRequest should not change anything // onHeadersReceived should not change anything - await expectNoRedirect(modifyRequest, xhrRequest) + await ensureNoRedirect(modifyRequest, xhrRequest) }) }) }) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index b14232a15..fecce49c9 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -12,7 +12,7 @@ import { cleanupRules } from '../../../add-on/src/lib/redirect-handler/blockOrOb import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' import isManifestV3, { manifestVersion } from '../../helpers/is-mv3-testing-enabled.js' -import { ensureCallRedirected, ensureRequestUntouched, expectNoRedirect } from '../../helpers/mv3-test-helper.js' +import { ensureCallRedirected, ensureNoRedirect, ensureRequestUntouched } from '../../helpers/mv3-test-helper.js' const url2request = (string) => { return { url: string, type: 'main_frame' } @@ -83,20 +83,20 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { state.redirect = false const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it(`should be left untouched if redirect is enabled but global active flag is OFF (${nodeType} node)`, async function () { state.active = false state.redirect = true const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it(`should be left untouched if URL includes opt-out hint (${nodeType} node)`, async function () { // A safe way for preloading data at arbitrary gateways - it should arrive at original destination const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?x-ipfs-companion-no-redirect#hashTest') - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) expect(redirectOptOutHint).to.equal('x-ipfs-companion-no-redirect') }) it(`should be left untouched if request is for subresource on a page loaded from URL that includes opt-out hint (${nodeType} node)`, async function () { @@ -107,18 +107,18 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { originUrl: 'https://example.com/?x-ipfs-companion-no-redirect#hashTest' } - await expectNoRedirect(modifyRequest, subRequest) + await ensureNoRedirect(modifyRequest, subRequest) }) it(`should be left untouched if CID is invalid (${nodeType} node)`, async function () { const request = url2request('https://google.com/ipfs/notacid?argTest#hashTest') - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it(`should be left untouched if its is a HEAD preload with explicit opt-out in URL hash (${nodeType} node)`, async function () { // HTTP HEAD is a popular way for preloading data at arbitrary gateways, so we have a dedicated test to make sure it works as expected const headRequest = { url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#x-ipfs-companion-no-redirect', method: 'HEAD' } - await expectNoRedirect(modifyRequest, headRequest) + await ensureNoRedirect(modifyRequest, headRequest) }) }) }) @@ -293,13 +293,13 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { state.redirect = false const request = url2request('https://google.com/ipns/ipfs.io?argTest#hashTest') - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it(`should be left untouched if FQDN is not a real domain nor a valid CID (${nodeType} node)`, async function () { const request = url2request('https://google.com/ipns/notafqdnorcid?argTest#hashTest') dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().resolves(false) - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) }) }) @@ -396,7 +396,7 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { it('should be left untouched if localhost Gateway is used', async function () { const request = url2request('http://localhost:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it('should fix 127.0.0.1 Gateway to localhost', async function () { const request = url2request('http://127.0.0.1:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') @@ -436,13 +436,13 @@ describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { const request = url2request('http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DDIFF' }] - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it('should be left untouched if [::1] is used', async function () { // https://github.com/ipfs/ipfs-companion/issues/291 const request = url2request('http://[::1]:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/') - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it('should be redirected to localhost (subdomain in go-ipfs >0.5) if type=main_frame and 127.0.0.1 (path gw) is used un URL', async function () { state.redirect = true diff --git a/test/functional/lib/ipfs-request-workarounds.test.js b/test/functional/lib/ipfs-request-workarounds.test.js index acb25d8f8..92d863249 100644 --- a/test/functional/lib/ipfs-request-workarounds.test.js +++ b/test/functional/lib/ipfs-request-workarounds.test.js @@ -12,7 +12,7 @@ import { cleanupRules } from '../../../add-on/src/lib/redirect-handler/blockOrOb import createRuntimeChecks from '../../../add-on/src/lib/runtime-checks.js' import { initState } from '../../../add-on/src/lib/state.js' import isManifestV3 from '../../helpers/is-mv3-testing-enabled.js' -import { ensureCallRedirected, expectNoRedirect } from '../../helpers/mv3-test-helper.js' +import { ensureCallRedirected, ensureNoRedirect } from '../../helpers/mv3-test-helper.js' import { spoofDnsTxtRecord } from './dnslink.test.js' describe('modifyRequest processing', function () { @@ -365,7 +365,7 @@ describe('modifyRequest processing', function () { url: 'https://ipfs.io/ipfs/bafkqae2xmvwgg33nmuqhi3zajfiemuzahiwss', initiator: 'https://some-website.example.com' // Brave (built on Chromium) } - await expectNoRedirect(modifyRequest, request) + await ensureNoRedirect(modifyRequest, request) }) it('should be left untouched if subresource (would be blocked by Brave Shields)', async function () { runtime.isFirefox = false diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts index 517a53e57..84c7f4894 100644 --- a/test/helpers/mv3-test-helper.ts +++ b/test/helpers/mv3-test-helper.ts @@ -38,7 +38,7 @@ export function ensureRequestUntouched (resp): void { } } -export async function expectNoRedirect (modifyRequest, request, browser): Promise { +export async function ensureNoRedirect (modifyRequest, request, browser): Promise { await Promise.all([ modifyRequest.onBeforeRequest(request), modifyRequest.onHeadersReceived(request) From 7d1e97c27631175a636fca78cfd3fbefe678d918 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 10:34:11 -0600 Subject: [PATCH 42/63] fix(test): Adding missing JSDoc Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- test/helpers/mv3-test-helper.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts index 84c7f4894..eb33f09ae 100644 --- a/test/helpers/mv3-test-helper.ts +++ b/test/helpers/mv3-test-helper.ts @@ -6,6 +6,15 @@ import isManifestV3 from './is-mv3-testing-enabled' export const regexRuleEnding = '((?:[^\\.]|$).*)$' +/** + * Ensure that the request is redirected + * + * @param modifiedRequestCallResp - Response from onBeforeRequest or onHeadersReceived + * @param MV2Expectation - Expected redirect URL for Manifest V2 + * @param MV3Expectation - Expected redirect URL for Manifest V3 + * @param MV3Expectation.origin - Expected origin URL for Manifest V3 + * @param MV3Expectation.destination - Expected destination URL for Manifest V3 + */ export function ensureCallRedirected ({ modifiedRequestCallResp, MV2Expectation, @@ -17,7 +26,7 @@ export function ensureCallRedirected ({ origin: string, destination: string } -}) { +}): void { if (isManifestV3) { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args.addRules[0]).to.deep.equal(generateAddRule( @@ -30,6 +39,11 @@ export function ensureCallRedirected ({ } } +/** + * Ensure that the request is not touched + * + * @param resp - Response from onBeforeRequest or onHeadersReceived + */ export function ensureRequestUntouched (resp): void { if (isManifestV3) { Sinon.assert.notCalled(browser.declarativeNetRequest.updateDynamicRules) @@ -38,7 +52,13 @@ export function ensureRequestUntouched (resp): void { } } -export async function ensureNoRedirect (modifyRequest, request, browser): Promise { +/** + * Ensure that the request is not redirected + * + * @param modifyRequest - Request Modifier + * @param request - Request to be modified + */ +export async function ensureNoRedirect (modifyRequest, request): Promise { await Promise.all([ modifyRequest.onBeforeRequest(request), modifyRequest.onHeadersReceived(request) From 33b806268c33705d90fe180238d5de6b6ef28300 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 18:37:21 -0600 Subject: [PATCH 43/63] fix(test): :shrug: how did this get removed. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../redirect-handler/blockOrObserve.test.ts | 203 ++++++++++++------ 1 file changed, 134 insertions(+), 69 deletions(-) diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.ts index e8a5298e8..6c8edd036 100644 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.ts +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.ts @@ -1,13 +1,13 @@ -import { expect } from 'chai' -import { before, describe, it } from 'mocha' -import sinon from 'sinon' -import browserMock from 'sinon-chrome' +import { expect } from 'chai'; +import { before, describe, it } from 'mocha'; +import sinon from 'sinon'; +import browserMock from 'sinon-chrome'; -import { optionDefaults } from '../../../../add-on/src/lib/options.js' -import { addRuleToDynamicRuleSetGenerator, cleanupRules, isLocalHost, supportsBlock } from '../../../../add-on/src/lib/redirect-handler/blockOrObserve' -import { initState } from '../../../../add-on/src/lib/state.js' -import isManifestV3, { manifestVersion } from '../../../helpers/is-mv3-testing-enabled.js' -import DeclarativeNetRequestMock from './declarativeNetRequest.mock.js' +import { optionDefaults } from '../../../../add-on/src/lib/options.js'; +import { addRuleToDynamicRuleSetGenerator, cleanupRules, isLocalHost } from '../../../../add-on/src/lib/redirect-handler/blockOrObserve'; +import { initState } from '../../../../add-on/src/lib/state.js'; +import isManifestV3 from '../../../helpers/is-mv3-testing-enabled'; +import DeclarativeNetRequestMock from './declarativeNetRequest.mock.js'; const dynamicRulesConditions = (regexFilter) => ({ regexFilter, @@ -31,7 +31,52 @@ const dynamicRulesConditions = (regexFilter) => ({ ] }) -const manifestVeresion = isManifestV3 ? 'MV3' : 'MV2' +const LAST_GROUP_REGEX = '((?:[^\\.]|$).*)$' + +/** + * Ensures that the tab is redirected to the given url on the first request. + * + * @param url + */ +function ensureTabRedirected (url): void { + expect(browserMock.tabs.query.called).to.be.true + expect(browserMock.tabs.update.called).to.be.true + expect(browserMock.tabs.update.lastCall.args).to.deep.equal([40, { url }]) +} + +/** + * Ensures that the declarativeNetRequest API is called with the expected rule. + * @param expectedCondition + * @param regexSubstitution + */ +function ensureDeclrativeNetRequetRuleIsAdded ({ + addRuleLength = 1, + callIndex = 0, + expectedCondition, + regexSubstitution, + removedRulesIds = [], +}: { + addRuleLength?: number + callIndex?: number + expectedCondition: string + regexSubstitution: string + removedRulesIds?: number[] +}): void { + if (callIndex < 0) { + callIndex = browserMock.declarativeNetRequest.updateDynamicRules.getCalls().length + callIndex + } + expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true + const [{ addRules, removeRuleIds }] = browserMock.declarativeNetRequest.updateDynamicRules.getCall(callIndex).args + expect(removeRuleIds).to.deep.equal(removedRulesIds) + if (addRuleLength > 0) { + expect(addRules).to.have.lengthOf(addRuleLength) + const [{ id, priority, action, condition }] = addRules + expect(id).to.be.a('number') + expect(priority).to.equal(1) + expect(action).to.deep.equal({ type: 'redirect', redirect: { regexSubstitution } }) + expect(condition).to.deep.equal(dynamicRulesConditions(expectedCondition)) + } +} describe('lib/redirect-handler/blockOrObserve', () => { before(function () { @@ -59,16 +104,6 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) }) - describe(`supportsBlock on ${manifestVersion}` , () => { - it(`should return ${isManifestV3 ? false : true} for ${manifestVersion}`, function () { - if (isManifestV3) { - expect(supportsBlock()).to.be.false - } else { - expect(supportsBlock()).to.be.true - } - }) - }) - describe('addRuleToDynamicRuleSetGenerator', () => { let addRuleToDynamicRuleSet let state @@ -82,6 +117,9 @@ describe('lib/redirect-handler/blockOrObserve', () => { beforeEach(async () => { sinonSandbox.restore() + browserMock.tabs.query.resetHistory() + browserMock.tabs.reload.resetHistory() + browserMock.tabs.update.resetHistory() browserMock.declarativeNetRequest = sinonSandbox.spy(new DeclarativeNetRequestMock()) // this cleans up the rules from the previous test stored in memory. await cleanupRules(true) @@ -97,6 +135,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { // when redirectUrl is different from originUrl, but both are localhost. await addRuleToDynamicRuleSet({ originUrl: 'http://localhost:9001/foo', redirectUrl: 'http://localhost:9001/bar' }) expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.false + expect (browserMock.tabs.query.called).to.be.false }) it('Should allow pages to be recovered', async () => { @@ -105,7 +144,11 @@ describe('lib/redirect-handler/blockOrObserve', () => { originUrl: 'http://localhost:8080', redirectUrl: 'chrome-extension://some-path/dist/recover/recovery.html' }) - expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true + ensureTabRedirected('chrome-extension://some-path/dist/recover/recovery.html') + ensureDeclrativeNetRequetRuleIsAdded({ + expectedCondition: `^https?\\:\\/\\/localhost\\:8080${LAST_GROUP_REGEX}`, + regexSubstitution: 'chrome-extension://some-path/dist/recover/recovery.html\\1', + }) }) it('Should add redirect rules for local gateway', async () => { @@ -113,15 +156,11 @@ describe('lib/redirect-handler/blockOrObserve', () => { originUrl: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org', redirectUrl: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org' }) - expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true - const [{ addRules, removeRuleIds }] = browserMock.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(removeRuleIds).to.deep.equal([]) - expect(addRules).to.have.lengthOf(1) - const [{ id, priority, action, condition }] = addRules - expect(id).to.be.a('number') - expect(priority).to.equal(1) - expect(action).to.deep.equal({ type: 'redirect', redirect: { "regexSubstitution": "http://localhost:8080\\1" } }) - expect(condition).to.deep.equal(dynamicRulesConditions('^https?\\:\\/\\/ipfs\\.io((?:[^\\.]|$).*)$')) + ensureTabRedirected('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org') + ensureDeclrativeNetRequetRuleIsAdded({ + expectedCondition: `^https?\\:\\/\\/ipfs\\.io${LAST_GROUP_REGEX}`, + regexSubstitution: 'http://localhost:8080\\1' + }) }) it('Should add redirect for local gateway where originUrl is similar to redirectUrl', async () => { @@ -129,19 +168,11 @@ describe('lib/redirect-handler/blockOrObserve', () => { originUrl: 'https://docs.ipfs.tech', redirectUrl: 'http://localhost:8080/ipns/docs.ipfs.tech' }) - expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true - const [{ addRules, removeRuleIds }] = browserMock.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(removeRuleIds).to.deep.equal([]) - expect(addRules).to.have.lengthOf(1) - const [{ id, priority, action, condition }] = addRules - expect(id).to.be.a('number') - expect(priority).to.equal(1) - expect(action).to.deep.equal({ - type: 'redirect', redirect: { - "regexSubstitution": "http://localhost:8080/ipns/docs.ipfs.tech\\1" - } - }) - expect(condition).to.deep.equal(dynamicRulesConditions('^https?\\:\\/\\/docs\\.ipfs\\.tech((?:[^\\.]|$).*)$')) + ensureTabRedirected('http://localhost:8080/ipns/docs.ipfs.tech') + ensureDeclrativeNetRequetRuleIsAdded({ + expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, + regexSubstitution: 'http://localhost:8080/ipns/docs.ipfs.tech\\1' + }) }) it('Should add redirect for local gateway where originUrl is similar to redirectUrl and is not https', async () => { @@ -149,34 +180,68 @@ describe('lib/redirect-handler/blockOrObserve', () => { originUrl: 'http://docs.ipfs.tech', redirectUrl: 'http://localhost:8080/ipns/docs.ipfs.tech' }) - expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true - const [{ addRules, removeRuleIds }] = browserMock.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(removeRuleIds).to.deep.equal([]) - expect(addRules).to.have.lengthOf(1) - const [{ id, priority, action, condition }] = addRules - expect(id).to.be.a('number') - expect(priority).to.equal(1) - expect(action).to.deep.equal({ - type: 'redirect', redirect: { - "regexSubstitution": "http://localhost:8080/ipns/docs.ipfs.tech\\1" - } - }) - expect(condition).to.deep.equal(dynamicRulesConditions('^https?\\:\\/\\/docs\\.ipfs\\.tech((?:[^\\.]|$).*)$')) + ensureTabRedirected('http://localhost:8080/ipns/docs.ipfs.tech') + ensureDeclrativeNetRequetRuleIsAdded({ + expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, + regexSubstitution: 'http://localhost:8080/ipns/docs.ipfs.tech\\1' + }) }) - it('Should refresh the tab when redirect URL is added', async () => { - if (!isManifestV3) { - // TODO - } else { - - browserMock.tabs.query.resolves([{id: 1234}]) - await addRuleToDynamicRuleSet({ - originUrl: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org', - redirectUrl: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org' - }) - sinon.assert.calledWith(browserMock.tabs.query, { url: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org*' }) - sinon.assert.calledWith(browserMock.tabs.update, 1234, { url: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org' }) - } + it('Should remove the old rule when redirect changes for local gateway', async () => { + await addRuleToDynamicRuleSet({ + originUrl: 'http://docs.ipfs.tech', + redirectUrl: 'http://localhost:8080/ipns/docs.ipfs.tech' + }) + ensureTabRedirected('http://localhost:8080/ipns/docs.ipfs.tech') + ensureDeclrativeNetRequetRuleIsAdded({ + expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, + regexSubstitution: 'http://localhost:8080/ipns/docs.ipfs.tech\\1' + }) + const [{ addRules }] = browserMock.declarativeNetRequest.updateDynamicRules.firstCall.args + + await browserMock.declarativeNetRequest.updateDynamicRules.resetHistory() + // assuming the localhost changed or the redirectURL changed. + await addRuleToDynamicRuleSet({ + originUrl: 'http://docs.ipfs.tech', + redirectUrl: 'http://localhost:8081/ipns/docs.ipfs.tech' + }) + ensureTabRedirected('http://localhost:8081/ipns/docs.ipfs.tech') + ensureDeclrativeNetRequetRuleIsAdded({ + expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, + regexSubstitution: 'http://localhost:8081/ipns/docs.ipfs.tech\\1', + removedRulesIds: [addRules[0].id] + }) + }) + + it('Should remove the old rules when companion is no longer in active state', async () => { + // first redirect + const getRuleIdsAddedSoFar = () => browserMock.declarativeNetRequest.updateDynamicRules.getCalls().map(({args}) => args[0]?.addRules.map(rule => rule.id).flat()).flat() + + await addRuleToDynamicRuleSet({ + originUrl: 'http://docs.ipfs.tech', + redirectUrl: 'http://localhost:8080/ipns/docs.ipfs.tech' + }) + + await addRuleToDynamicRuleSet({ + originUrl: 'http://awesome.ipfs.io', + redirectUrl: 'http://localhost:8080/ipns/awesome.ipfs.io' + }) + + state.active = false + await addRuleToDynamicRuleSet({ + originUrl: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org', + redirectUrl: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org' + }) + + ensureTabRedirected('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org') + ensureDeclrativeNetRequetRuleIsAdded({ + addRuleLength: 0, + callIndex: -1, + expectedCondition: `^https?\\:\\/\\/ipfs\\.io${LAST_GROUP_REGEX}`, + regexSubstitution: 'http://localhost:8080\\1', + removedRulesIds: getRuleIdsAddedSoFar() + }) + }) }) }) From ae23f4c18a656213e42116834859c46ffcfa63ba Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 20:40:14 -0600 Subject: [PATCH 44/63] fix(test): :wastebasket: removed. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- test/functional/lib/ipfs-import.test.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/functional/lib/ipfs-import.test.js b/test/functional/lib/ipfs-import.test.js index 4967ed087..6dad1be3c 100644 --- a/test/functional/lib/ipfs-import.test.js +++ b/test/functional/lib/ipfs-import.test.js @@ -30,13 +30,4 @@ describe('ipfs-import.js', function () { expect(formatImportDirectory(path)).to.equal('/ipfs-companion-imports/2017-11-05_120101/') }) }) - // TODO: complete tests - // describe('openFilesAtWebUI', function () { - // }) - // - // describe('openFilesAtGateway', function () { - // }) - // - // describe('importFiles', function () { - // }) }) From b77ab7b3a0b65a7c4a7b4c2a3dd6f6ff008e1f35 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 27 Jul 2023 20:50:49 -0600 Subject: [PATCH 45/63] fix(test): Suggestion --- test/functional/lib/ipfs-request-gateway-redirect.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index fecce49c9..315c037b6 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -24,7 +24,7 @@ const fakeRequestId = () => { const nodeTypes = ['external'] -describe(`[${manifestVersion}] modifyRequest.onBeforeRequest:`, function () { +describe(`[${manifestVersion}] gateway-redirect:`, function () { let state, dnslinkResolver, ipfsPathValidator, modifyRequest, runtime beforeEach(async function () { From 6fe39a3cfdf7ea51ea131151a00d9cb156519d67 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Fri, 28 Jul 2023 15:04:16 -0600 Subject: [PATCH 46/63] fix(test): :adhesive_bandage: Bad Merge Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- add-on/src/lib/ipfs-request.js | 2 +- add-on/src/lib/redirect-handler/blockOrObserve.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/add-on/src/lib/ipfs-request.js b/add-on/src/lib/ipfs-request.js index bb0694534..c2a8bf0de 100644 --- a/add-on/src/lib/ipfs-request.js +++ b/add-on/src/lib/ipfs-request.js @@ -485,7 +485,7 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida * @param {object} input contains originUrl and redirectUrl. * @returns */ -async function handleRedirection ({ originUrl, redirectUrl }) { +async function handleRedirection ({ originUrl, redirectUrl, request }) { if (redirectUrl !== '' && originUrl !== '' && redirectUrl !== originUrl) { resolvedRequestTracker.track(request) if (supportsBlock()) { diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 712ba6a2b..850dca74e 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -37,8 +37,6 @@ interface messageToSelf { // rather it gets replaced dynamically when the module is imported. Which means, we can't // just check for the existence of the property, we need to call the browser instance at that point. export const supportsBlock = (): boolean => !(browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES === 5000) -export const GLOBAL_STATE_CHANGE = 'GLOBAL_STATE_CHANGE' -export const GLOBAL_STATE_OPTION_CHANGE = 'GLOBAL_STATE_OPTION_CHANGE' /** * Notify self about state change. From e56bb6ac0e1146e51643d09a2d27a971656ddca3 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 3 Aug 2023 14:24:43 +0200 Subject: [PATCH 47/63] fix(test): sequential expectNoRedirect --- test/helpers/mv3-test-helper.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts index eb33f09ae..d6579b532 100644 --- a/test/helpers/mv3-test-helper.ts +++ b/test/helpers/mv3-test-helper.ts @@ -53,16 +53,15 @@ export function ensureRequestUntouched (resp): void { } /** - * Ensure that the request is not redirected + * Execute webRequest stages in order and ensure that the request + * is not redirected by any of them * * @param modifyRequest - Request Modifier * @param request - Request to be modified */ export async function ensureNoRedirect (modifyRequest, request): Promise { - await Promise.all([ - modifyRequest.onBeforeRequest(request), - modifyRequest.onHeadersReceived(request) - ].map(async (resp) => { - await ensureRequestUntouched(await resp) - })) + // check webRequest stages sequentially in the same order a browser would + // (each stage may modify state and must be inspected idependently, in order) + await ensureRequestUntouched(await modifyRequest.onBeforeRequest(request)) + await ensureRequestUntouched(await modifyRequest.onHeadersReceived(request)) } From 6bd8c3c0e070814d9099772b381d57b1980f1015 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 3 Aug 2023 22:22:40 -0600 Subject: [PATCH 48/63] Update add-on/src/lib/redirect-handler/blockOrObserve.ts Co-authored-by: Marcin Rataj --- add-on/src/lib/redirect-handler/blockOrObserve.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 850dca74e..9ddaaf588 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -36,7 +36,7 @@ interface messageToSelf { // the way sinon ends up stubbing it, it's not directly available in the global scope on import // rather it gets replaced dynamically when the module is imported. Which means, we can't // just check for the existence of the property, we need to call the browser instance at that point. -export const supportsBlock = (): boolean => !(browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES === 5000) +export const supportsBlock = (): boolean => !(browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES > 0) /** * Notify self about state change. From 7f68ab4ba4e2d49ef672206d971e44195014e2fe Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Fri, 4 Aug 2023 03:22:25 -0600 Subject: [PATCH 49/63] fix(mv3): :wrench: Modifying the default local redirect behaviour. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/redirect-handler/blockOrObserve.ts | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 72779daeb..f254674a8 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -58,17 +58,7 @@ async function sendMessageToSelf (msg: typeof GLOBAL_STATE_CHANGE | typeof GLOBA } const savedRegexFilters: Map = new Map() -const DEFAULT_LOCAL_RULES: redirectHandlerInput[] = [ - { - originUrl: 'http://127.0.0.1', - redirectUrl: 'http://localhost' - }, - { - originUrl: 'http://[::1]', - redirectUrl: 'http://localhost' - } -] - +const DEFAULT_NAMESPACES = ['ipfs', 'ipns'] /** * This function determines if the request is headed to a local IPFS gateway. * @@ -226,16 +216,17 @@ async function reconcileRulesAndRemoveOld (state: CompanionState): Promise } } - // make sure that the default rules are added. - for (const { originUrl, redirectUrl } of DEFAULT_LOCAL_RULES) { - const { port } = new URL(state.gwURLString) - const regexFilter = `^${escapeURLRegex(`${originUrl}:${port}`)}(.*)$` - const regexSubstitution = `${redirectUrl}:${port}\\1` + const { host, port, protocol } = new URL(state.gwURLString) + if (host !== 'localhost') { + DEFAULT_NAMESPACES.forEach((namespace): void => { + const regexFilter = `^${escapeURLRegex(`${host}:${port}`)}/${namespace}/(.*)$` + const regexSubstitution = `${protocol}://localhost:${port}/${namespace}/\\1` - if (!savedRegexFilters.has(regexFilter)) { - // We need to add the new rule. - addRules.push(saveAndGenerateRule(regexFilter, regexSubstitution)) - } + if (!savedRegexFilters.has(regexFilter)) { + // We need to add the new rule. + addRules.push(saveAndGenerateRule(regexFilter, regexSubstitution)) + } + }) } await browser.declarativeNetRequest.updateDynamicRules({ addRules, removeRuleIds }) From 045e66022eea0f7a89d933d8e486e5f98d240196 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Fri, 4 Aug 2023 03:22:25 -0600 Subject: [PATCH 50/63] fix(mv3): :wrench: Modifying the default local redirect behaviour. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/redirect-handler/blockOrObserve.ts | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 9ddaaf588..34e684caf 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -72,17 +72,7 @@ async function sendMessageToSelf (msg: messageToSelfType, value?: any): Promise< } const savedRegexFilters: Map = new Map() -const DEFAULT_LOCAL_RULES: redirectHandlerInput[] = [ - { - originUrl: 'http://127.0.0.1', - redirectUrl: 'http://localhost' - }, - { - originUrl: 'http://[::1]', - redirectUrl: 'http://localhost' - } -] - +const DEFAULT_NAMESPACES = ['ipfs', 'ipns'] /** * This function determines if the request is headed to a local IPFS gateway. * @@ -247,16 +237,17 @@ async function reconcileRulesAndRemoveOld (state: CompanionState): Promise } } - // make sure that the default rules are added. - for (const { originUrl, redirectUrl } of DEFAULT_LOCAL_RULES) { - const { port } = new URL(state.gwURLString) - const regexFilter = `^${escapeURLRegex(`${originUrl}:${port}`)}(.*)$` - const regexSubstitution = `${redirectUrl}:${port}\\1` + const { host, port, protocol } = new URL(state.gwURLString) + if (host !== 'localhost') { + DEFAULT_NAMESPACES.forEach((namespace): void => { + const regexFilter = `^${escapeURLRegex(`${host}:${port}`)}/${namespace}/(.*)$` + const regexSubstitution = `${protocol}://localhost:${port}/${namespace}/\\1` - if (!savedRegexFilters.has(regexFilter)) { - // We need to add the new rule. - addRules.push(saveAndGenerateRule(regexFilter, regexSubstitution)) - } + if (!savedRegexFilters.has(regexFilter)) { + // We need to add the new rule. + addRules.push(saveAndGenerateRule(regexFilter, regexSubstitution)) + } + }) } await browser.declarativeNetRequest.updateDynamicRules({ addRules, removeRuleIds }) From fc085b5eb530789500ef43932cd459fa14fae8df Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 10 Aug 2023 02:05:15 -0600 Subject: [PATCH 51/63] fix(mv3): :bug: Making rules less greedy Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/redirect-handler/blockOrObserve.ts | 101 ++++++++++++------ .../redirect-handler/blockOrObserve.test.ts | 17 ++- test/helpers/mv3-test-helper.ts | 5 +- 3 files changed, 76 insertions(+), 47 deletions(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 34e684caf..6397932fa 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -7,11 +7,15 @@ import { CompanionState } from '../../types/companion.js' const log = debug('ipfs-companion:redirect-handler:blockOrObserve') log.error = debug('ipfs-companion:redirect-handler:blockOrObserve:error') +const DEFAULT_NAMESPACES = new Set(['ipfs', 'ipns']) + export const GLOBAL_STATE_CHANGE = 'GLOBAL_STATE_CHANGE' export const GLOBAL_STATE_OPTION_CHANGE = 'GLOBAL_STATE_OPTION_CHANGE' export const DELETE_RULE_REQUEST = 'DELETE_RULE_REQUEST' export const DELETE_RULE_REQUEST_SUCCESS = 'DELETE_RULE_REQUEST_SUCCESS' -export const RULE_REGEX_ENDING = '((?:[^\\.]|$).*)$' + +// We need to match the rest of the URL, so we can use a wildcard. +export const RULE_REGEX_ENDING = `(\\/(?:${[...DEFAULT_NAMESPACES].join('|')})\\/(?:[^\\.]|$).*)$` interface regexFilterMap { id: number @@ -72,7 +76,17 @@ async function sendMessageToSelf (msg: messageToSelfType, value?: any): Promise< } const savedRegexFilters: Map = new Map() -const DEFAULT_NAMESPACES = ['ipfs', 'ipns'] +const DEFAULT_LOCAL_RULES: redirectHandlerInput[] = [ + { + originUrl: 'http://127.0.0.1', + redirectUrl: 'http://localhost' + }, + { + originUrl: 'http://[::1]', + redirectUrl: 'http://localhost' + } +] + /** * This function determines if the request is headed to a local IPFS gateway. * @@ -98,6 +112,16 @@ function escapeURLRegex (str: string): string { return str.replace(ALLOWED_CHARS_URL_REGEX, '\\$1') } +/** + * Compute the namespace from the URL. + * + * @param url string + */ +function computeNamespaceFromUrl (url: string): string { + const { pathname } = new URL(url) + return (/\/([^\/]+)\//i.exec(pathname)?.[1] ?? '').toLowerCase() +} + /** * Construct a regex filter and substitution for a redirect. * @@ -109,31 +133,39 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) regexSubstitution: string regexFilter: string } { - // We can traverse the URL from the end, and find the first character that is different. - let commonIdx = 1 - while (commonIdx < Math.min(originUrl.length, redirectUrl.length)) { - if (originUrl[originUrl.length - commonIdx] !== redirectUrl[redirectUrl.length - commonIdx]) { - break + let regexSubstitution = redirectUrl; + let regexFilter = originUrl; + const redirectNS = computeNamespaceFromUrl(redirectUrl) + const originNS = computeNamespaceFromUrl(originUrl) + if ( + DEFAULT_NAMESPACES.has(redirectNS) && + DEFAULT_NAMESPACES.has(originNS) && + redirectNS === originNS + ) { + // We can traverse the URL from the end, and find the first character that is different. + let commonIdx = 1 + while (commonIdx < Math.min(originUrl.length, redirectUrl.length)) { + if (originUrl[originUrl.length - commonIdx] !== redirectUrl[redirectUrl.length - commonIdx]) { + break + } + commonIdx += 1 } - commonIdx += 1 - } - // We can now construct the regex filter and substitution. - let regexSubstitution = redirectUrl.slice(0, redirectUrl.length - commonIdx + 1) + '\\1' - // We need to escape the characters that are allowed in the URL, but not in the regex. - const regexFilterFirst = escapeURLRegex(originUrl.slice(0, originUrl.length - commonIdx + 1)) - // We need to match the rest of the URL, so we can use a wildcard. - const RULE_REGEX_ENDING = '((?:[^\\.]|$).*)$' - let regexFilter = `^${regexFilterFirst}${RULE_REGEX_ENDING}`.replace(/https?/ig, 'https?') - - // This method does not parse: - // originUrl: "https://awesome.ipfs.io/" - // redirectUrl: "http://localhost:8081/ipns/awesome.ipfs.io/" - // that ends up with capturing all urls which we do not want. - if (regexFilter === `^https?\\:\\/${RULE_REGEX_ENDING}`) { - const subdomain = new URL(originUrl).hostname - regexFilter = `^https?\\:\\/\\/${escapeURLRegex(subdomain)}${RULE_REGEX_ENDING}` - regexSubstitution = regexSubstitution.replace('\\1', `/${subdomain}\\1`) + // We can now construct the regex filter and substitution. + regexSubstitution = redirectUrl.slice(0, redirectUrl.length - commonIdx + 1) + '\\1' + // We need to escape the characters that are allowed in the URL, but not in the regex. + const regexFilterFirst = escapeURLRegex(originUrl.slice(0, originUrl.length - commonIdx + 1)) + regexFilter = `^${regexFilterFirst}${RULE_REGEX_ENDING}`.replace(/https?/ig, 'https?') + + // This method does not parse: + // originUrl: "https://awesome.ipfs.io/" + // redirectUrl: "http://localhost:8081/ipns/awesome.ipfs.io/" + // that ends up with capturing all urls which we do not want. + if (regexFilter === `^https?\\:\\/${RULE_REGEX_ENDING}`) { + const subdomain = new URL(originUrl).hostname + regexFilter = `^https?\\:\\/\\/${escapeURLRegex(subdomain)}${RULE_REGEX_ENDING}` + regexSubstitution = regexSubstitution.replace('\\1', `/${subdomain}\\1`) + } } return { regexSubstitution, regexFilter } @@ -237,17 +269,16 @@ async function reconcileRulesAndRemoveOld (state: CompanionState): Promise } } - const { host, port, protocol } = new URL(state.gwURLString) - if (host !== 'localhost') { - DEFAULT_NAMESPACES.forEach((namespace): void => { - const regexFilter = `^${escapeURLRegex(`${host}:${port}`)}/${namespace}/(.*)$` - const regexSubstitution = `${protocol}://localhost:${port}/${namespace}/\\1` + const { port } = new URL(state.gwURLString) + // make sure that the default rules are added. + for (const { originUrl, redirectUrl } of DEFAULT_LOCAL_RULES) { + const regexFilter = `^${escapeURLRegex(`${originUrl}:${port}`)}${RULE_REGEX_ENDING}` + const regexSubstitution = `${redirectUrl}:${port}/\\1` - if (!savedRegexFilters.has(regexFilter)) { - // We need to add the new rule. - addRules.push(saveAndGenerateRule(regexFilter, regexSubstitution)) - } - }) + if (!savedRegexFilters.has(regexFilter)) { + // We need to add the new rule. + addRules.push(saveAndGenerateRule(regexFilter, regexSubstitution)) + } } await browser.declarativeNetRequest.updateDynamicRules({ addRules, removeRuleIds }) diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.ts index 6c8edd036..efe7cae01 100644 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.ts +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.ts @@ -8,6 +8,7 @@ import { addRuleToDynamicRuleSetGenerator, cleanupRules, isLocalHost } from '../ import { initState } from '../../../../add-on/src/lib/state.js'; import isManifestV3 from '../../../helpers/is-mv3-testing-enabled'; import DeclarativeNetRequestMock from './declarativeNetRequest.mock.js'; +import { RULE_REGEX_ENDING } from '../../../../add-on/src/lib/redirect-handler/blockOrObserve'; const dynamicRulesConditions = (regexFilter) => ({ regexFilter, @@ -31,8 +32,6 @@ const dynamicRulesConditions = (regexFilter) => ({ ] }) -const LAST_GROUP_REGEX = '((?:[^\\.]|$).*)$' - /** * Ensures that the tab is redirected to the given url on the first request. * @@ -146,7 +145,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) ensureTabRedirected('chrome-extension://some-path/dist/recover/recovery.html') ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/localhost\\:8080${LAST_GROUP_REGEX}`, + expectedCondition: `^https?\\:\\/\\/localhost\\:8080${RULE_REGEX_ENDING}`, regexSubstitution: 'chrome-extension://some-path/dist/recover/recovery.html\\1', }) }) @@ -158,7 +157,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) ensureTabRedirected('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org') ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/ipfs\\.io${LAST_GROUP_REGEX}`, + expectedCondition: `^https?\\:\\/\\/ipfs\\.io${RULE_REGEX_ENDING}`, regexSubstitution: 'http://localhost:8080\\1' }) }) @@ -170,7 +169,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) ensureTabRedirected('http://localhost:8080/ipns/docs.ipfs.tech') ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, + expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${RULE_REGEX_ENDING}`, regexSubstitution: 'http://localhost:8080/ipns/docs.ipfs.tech\\1' }) }) @@ -182,7 +181,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) ensureTabRedirected('http://localhost:8080/ipns/docs.ipfs.tech') ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, + expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${RULE_REGEX_ENDING}`, regexSubstitution: 'http://localhost:8080/ipns/docs.ipfs.tech\\1' }) }) @@ -194,7 +193,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) ensureTabRedirected('http://localhost:8080/ipns/docs.ipfs.tech') ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, + expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${RULE_REGEX_ENDING}`, regexSubstitution: 'http://localhost:8080/ipns/docs.ipfs.tech\\1' }) const [{ addRules }] = browserMock.declarativeNetRequest.updateDynamicRules.firstCall.args @@ -207,7 +206,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) ensureTabRedirected('http://localhost:8081/ipns/docs.ipfs.tech') ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${LAST_GROUP_REGEX}`, + expectedCondition: `^https?\\:\\/\\/docs\\.ipfs\\.tech${RULE_REGEX_ENDING}`, regexSubstitution: 'http://localhost:8081/ipns/docs.ipfs.tech\\1', removedRulesIds: [addRules[0].id] }) @@ -237,7 +236,7 @@ describe('lib/redirect-handler/blockOrObserve', () => { ensureDeclrativeNetRequetRuleIsAdded({ addRuleLength: 0, callIndex: -1, - expectedCondition: `^https?\\:\\/\\/ipfs\\.io${LAST_GROUP_REGEX}`, + expectedCondition: `^https?\\:\\/\\/ipfs\\.io${RULE_REGEX_ENDING}`, regexSubstitution: 'http://localhost:8080\\1', removedRulesIds: getRuleIdsAddedSoFar() }) diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts index d6579b532..7d309ac89 100644 --- a/test/helpers/mv3-test-helper.ts +++ b/test/helpers/mv3-test-helper.ts @@ -3,8 +3,7 @@ import Sinon from 'sinon' import browser from 'sinon-chrome' import { generateAddRule } from '../../add-on/src/lib/redirect-handler/blockOrObserve' import isManifestV3 from './is-mv3-testing-enabled' - -export const regexRuleEnding = '((?:[^\\.]|$).*)$' +import { RULE_REGEX_ENDING } from '../../add-on/src/lib/redirect-handler/blockOrObserve' /** * Ensure that the request is redirected @@ -31,7 +30,7 @@ export function ensureCallRedirected ({ const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args expect(args.addRules[0]).to.deep.equal(generateAddRule( args.addRules[0].id, - MV3Expectation.origin + regexRuleEnding, + MV3Expectation.origin + RULE_REGEX_ENDING, MV3Expectation.destination + '\\1' )) } else { From 007f41f82912ea7397dd0a3a4c5cd0a0c0c65983 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Fri, 11 Aug 2023 03:27:11 -0600 Subject: [PATCH 52/63] fix(mv3): :sparkles: Dynamic Rules for subdomain gateways. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/redirect-handler/blockOrObserve.ts | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 6397932fa..e59e66cea 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -1,6 +1,7 @@ import debug from 'debug' import browser from 'webextension-polyfill' import { CompanionState } from '../../types/companion.js' +import isIPFS from 'is-ipfs' // this won't work in webworker context. Needs to be enabled manually // https://github.com/debug-js/debug/issues/916 @@ -133,15 +134,43 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) regexSubstitution: string regexFilter: string } { - let regexSubstitution = redirectUrl; - let regexFilter = originUrl; + let regexSubstitution = redirectUrl.toLowerCase() + let regexFilter = originUrl.toLowerCase() const redirectNS = computeNamespaceFromUrl(redirectUrl) const originNS = computeNamespaceFromUrl(originUrl) - if ( - DEFAULT_NAMESPACES.has(redirectNS) && - DEFAULT_NAMESPACES.has(originNS) && - redirectNS === originNS - ) { + if (!DEFAULT_NAMESPACES.has(originNS) && DEFAULT_NAMESPACES.has(redirectNS)) { + // A redirect like https://github.com/ipfs/ipfs-companion/issues/1255 + regexFilter = `^${escapeURLRegex(regexFilter)}`.replace(/https?/ig, 'https?') + + const originURL = new URL(originUrl) + const [tld, root, ...subdomain] = originURL.hostname.split('.').reverse() + const staticUrl = [root, tld] + while (subdomain.length > 0) { + const subdomainPart = subdomain.shift() + const commonStaticUrlStart = `^${originURL.protocol}\\:\\/\\/` + const commonStaticUrlEnd = `\\.${escapeURLRegex(staticUrl.join('.'))}\\/${RULE_REGEX_ENDING}` + if (isIPFS.cid(subdomainPart as string)) { + // We didn't find a namespace, but we found a CID + // e.g. https://bafybeib3bzis4mejzsnzsb65od3rnv5ffit7vsllratddjkgfgq4wiamqu.on.fleek.co + regexFilter = `${commonStaticUrlStart}(.*?)${commonStaticUrlEnd}` + regexSubstitution = redirectUrl + .replace(subdomainPart as string, '\\1') // replace CID + .replace(new RegExp(`${originURL.pathname}?$`), '\\2') // replace path + break + } + if (DEFAULT_NAMESPACES.has(subdomainPart as string)) { + // We found a namespace, this is going to match group 2, i.e. namespace. + // e.g https://bafybeib3bzis4mejzsnzsb65od3rnv5ffit7vsllratddjkgfgq4wiamqu.ipfs.dweb.link + regexFilter = `${commonStaticUrlStart}(.*?)\\.(${[...DEFAULT_NAMESPACES].join('|')})${commonStaticUrlEnd}` + regexSubstitution = redirectUrl + .replace(subdomain.reverse().join('.') as string, '\\1') // replace subdomain or CID. + .replace(`/${subdomainPart as string}/`, '/\\2/') // replace namespace dynamically. + .replace(new RegExp(`${originURL.pathname}?$`), '\\3') // replace path + } + // till we find a namespace or CID, we keep adding subdomains to the staticUrl. + staticUrl.unshift(subdomainPart as string) + } + } else { // We can traverse the URL from the end, and find the first character that is different. let commonIdx = 1 while (commonIdx < Math.min(originUrl.length, redirectUrl.length)) { From f18579b0e5c3d10a1c33e5a8647d3e1ed4078ec4 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Fri, 11 Aug 2023 03:37:05 -0600 Subject: [PATCH 53/63] fix(types): Adding ambient types for is-ipfs. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- add-on/src/lib/redirect-handler/blockOrObserve.ts | 4 ++-- add-on/src/types/global.d.ts | 3 +++ webpack.config.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 add-on/src/types/global.d.ts diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index e59e66cea..792864a79 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -120,7 +120,7 @@ function escapeURLRegex (str: string): string { */ function computeNamespaceFromUrl (url: string): string { const { pathname } = new URL(url) - return (/\/([^\/]+)\//i.exec(pathname)?.[1] ?? '').toLowerCase() + return (/\/([^/]+)\//i.exec(pathname)?.[1] ?? '').toLowerCase() } /** @@ -163,7 +163,7 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) // e.g https://bafybeib3bzis4mejzsnzsb65od3rnv5ffit7vsllratddjkgfgq4wiamqu.ipfs.dweb.link regexFilter = `${commonStaticUrlStart}(.*?)\\.(${[...DEFAULT_NAMESPACES].join('|')})${commonStaticUrlEnd}` regexSubstitution = redirectUrl - .replace(subdomain.reverse().join('.') as string, '\\1') // replace subdomain or CID. + .replace(subdomain.reverse().join('.'), '\\1') // replace subdomain or CID. .replace(`/${subdomainPart as string}/`, '/\\2/') // replace namespace dynamically. .replace(new RegExp(`${originURL.pathname}?$`), '\\3') // replace path } diff --git a/add-on/src/types/global.d.ts b/add-on/src/types/global.d.ts new file mode 100644 index 000000000..2bdbca3b5 --- /dev/null +++ b/add-on/src/types/global.d.ts @@ -0,0 +1,3 @@ +declare module 'is-ipfs' { + function cid (value: string): boolean +} diff --git a/webpack.config.js b/webpack.config.js index 37ee165b0..fdc03093e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -191,7 +191,7 @@ const uiConfig = merge(commonConfig, { optionsPage: './add-on/src/options/options.js', recoveryPage: './add-on/src/recovery/recovery.js', welcomePage: './add-on/src/landing-pages/welcome/index.js', - requestPermissionsPage: './add-on/src/landing-pages/permissions/request.js', + requestPermissionsPage: './add-on/src/landing-pages/permissions/request.js' }, optimization: { splitChunks: { From 3e72d365561d664965ccc79fa83d67bc459475c2 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Sat, 12 Aug 2023 00:32:33 -0600 Subject: [PATCH 54/63] fix(test): Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/ipfs-request-dnslink.test.js | 26 ++++++------ .../lib/ipfs-request-gateway-redirect.test.js | 40 +++++++++---------- .../ipfs-request-protocol-handlers.test.js | 36 ++++++++--------- .../lib/ipfs-request-workarounds.test.js | 10 ++--- 4 files changed, 56 insertions(+), 56 deletions(-) diff --git a/test/functional/lib/ipfs-request-dnslink.test.js b/test/functional/lib/ipfs-request-dnslink.test.js index 2d2e01b00..6aca1b2eb 100644 --- a/test/functional/lib/ipfs-request-dnslink.test.js +++ b/test/functional/lib/ipfs-request-dnslink.test.js @@ -127,7 +127,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io\\/index\\.html', - destination: `${activeGateway}/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd` + destination: `${activeGateway}/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd\\1` } }) }) @@ -174,7 +174,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) @@ -191,7 +191,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) @@ -208,7 +208,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) @@ -229,7 +229,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) @@ -282,7 +282,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) @@ -304,7 +304,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io\\/index\\.html', - destination: `${activeGateway}/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd` + destination: `${activeGateway}/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd\\1` } }) }) @@ -335,7 +335,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) @@ -357,7 +357,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) @@ -377,7 +377,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) @@ -408,7 +408,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) @@ -425,7 +425,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) @@ -442,7 +442,7 @@ describe('modifyRequest processing of DNSLinks', function () { MV2Expectation: `${activeGateway}/ipns/explore.ipld.io/index.html?argTest#hashTest`, MV3Expectation: { origin: '^https?\\:\\/\\/explore\\.ipld\\.io', - destination: `${activeGateway}/ipns/explore.ipld.io` + destination: `${activeGateway}/ipns/explore.ipld.io\\1` } }) }) diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index 315c037b6..d368b5754 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -68,7 +68,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://localhost:8080' + destination: 'http://localhost:8080\\1' } }) }) @@ -138,7 +138,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080' + destination: 'http://127.0.0.1:8080\\1' } }) }) @@ -151,7 +151,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080' + destination: 'http://127.0.0.1:8080\\1' } }) }) @@ -164,7 +164,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080' + destination: 'http://127.0.0.1:8080\\1' } }) }) @@ -177,7 +177,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080' + destination: 'http://127.0.0.1:8080\\1' } }) }) @@ -196,7 +196,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080' + destination: 'http://127.0.0.1:8080\\1' } }) }) @@ -209,7 +209,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080' + destination: 'http://127.0.0.1:8080\\1' } }) }) @@ -222,7 +222,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080' + destination: 'http://127.0.0.1:8080\\1' } }) }) @@ -239,7 +239,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080' + destination: 'http://127.0.0.1:8080\\1' } }) }) @@ -264,7 +264,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://localhost:8080' + destination: 'http://localhost:8080\\1' } }) }) @@ -277,7 +277,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://localhost:8080/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://localhost:8080' + destination: 'http://localhost:8080\\1' } }) }) @@ -328,7 +328,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: `http://localhost:8080/ipfs/${cid}/`, MV3Expectation: { origin: `^https?\\:\\/\\/${cid}\\.ipfs\\.dweb\\.link`, - destination: `http://localhost:8080/ipfs/${cid}` + destination: `http://localhost:8080/ipfs/${cid}\\1` } }) }) @@ -341,7 +341,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: `http://localhost:8080/ipfs/${cid}/`, MV3Expectation: { origin: `^https?\\:\\/\\/${cid}\\.ipfs\\.cf\\-ipfs\\.com`, - destination: `http://localhost:8080/ipfs/${cid}` + destination: `http://localhost:8080/ipfs/${cid}\\1` } }) }) @@ -354,7 +354,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy/%3Ffilename=test.jpg?arg=val', MV3Expectation: { origin: '^https?\\:\\/\\/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\.ipfs\\.dweb\\.link', - destination: 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy' + destination: 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\1' } }) }) @@ -367,7 +367,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: `http://localhost:8080/ipns/${peerid}/`, MV3Expectation: { origin: `^https?\\:\\/\\/${peerid}\\.ipns\\.dweb\\.link`, - destination: `http://localhost:8080/ipns/${peerid}` + destination: `http://localhost:8080/ipns/${peerid}\\1` } }) }) @@ -416,7 +416,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/', MV3Expectation: { origin: '^https?\\:\\/\\/0\\.0\\.0\\.0', - destination: 'http://127.0.0.1' + destination: 'http://127.0.0.1\\1' } }) }) @@ -477,7 +477,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'http://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/bar\\.com', - destination: 'http://foo' + destination: 'http://foo\\1' } }) }) @@ -491,7 +491,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'https://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/bar\\.com', - destination: 'https://foo' + destination: 'https://foo\\1' } }) }) @@ -517,7 +517,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar', MV3Expectation: { origin: '^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/', - destination: 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F' + destination: 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1' } }) }) @@ -532,7 +532,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { MV2Expectation: 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2Fbar', MV3Expectation: { origin: '^https?\\:\\/\\/localhost\\:8080\\/ipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\\/foo\\/', - destination: 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F' + destination: 'chrome-extension://testid/dist/recovery/recovery.html#https%3A%2F%2Fipfs.io%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%2Ffoo%2F\\1' } }) }) diff --git a/test/functional/lib/ipfs-request-protocol-handlers.test.js b/test/functional/lib/ipfs-request-protocol-handlers.test.js index 1ba252fd1..84d9596d8 100644 --- a/test/functional/lib/ipfs-request-protocol-handlers.test.js +++ b/test/functional/lib/ipfs-request-protocol-handlers.test.js @@ -72,7 +72,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23', - destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#' + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1' } }) }) @@ -89,7 +89,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipns/ipfs.io?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipns%3A%2F%2Fipfs\\.io%3FargTest%23', - destination: 'https://ipfs.io/ipns/ipfs.io?argTest#' + destination: 'https://ipfs.io/ipns/ipfs.io?argTest#\\1' } }) }) @@ -101,7 +101,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipns/ipfs.io?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=ipfs%3A%2F%2Fipfs\\.io%3FargTest%23', - destination: 'https://ipfs.io/ipns/ipfs.io?argTest#' + destination: 'https://ipfs.io/ipns/ipfs.io?argTest#\\1' } }) }) @@ -113,7 +113,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23', - destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#' + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1' } }) }) @@ -130,7 +130,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipns/ipfs.io?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=dweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23', - destination: 'https://ipfs.io/ipns/ipfs.io?argTest#' + destination: 'https://ipfs.io/ipns/ipfs.io?argTest#\\1' } }) }) @@ -154,7 +154,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23', - destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#' + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1' } }) }) @@ -171,7 +171,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipns/ipfs.io?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bipns%3A%2F%2Fipfs\\.io%3FargTest%23', - destination: 'https://ipfs.io/ipns/ipfs.io?argTest#' + destination: 'https://ipfs.io/ipns/ipfs.io?argTest#\\1' } }) }) @@ -183,7 +183,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipfs\\/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23', - destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#' + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#\\1' } }) }) @@ -200,7 +200,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipns/ipfs.io?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/dweb\\.link\\/ipfs\\/\\?uri\\=web%2Bdweb%3A%2Fipns\\/ipfs\\.io%3FargTest%23', - destination: 'https://ipfs.io/ipns/ipfs.io?argTest#' + destination: 'https://ipfs.io/ipns/ipfs.io?argTest#\\1' } }) }) @@ -235,7 +235,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar', - destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1' } }) }) @@ -252,7 +252,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23', - destination: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#' + destination: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' } }) }) @@ -264,7 +264,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=ipfs%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23', - destination: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#' + destination: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' } }) }) @@ -276,7 +276,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash', MV3Expectation: { origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software', - destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash' + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash\\1' } }) }) @@ -293,7 +293,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash', MV3Expectation: { origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=dweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web', - destination: 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash' + destination: 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash\\1' } }) }) @@ -316,7 +316,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest\\&foo\\=bar', - destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest\\1' } }) }) @@ -333,7 +333,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest', MV3Expectation: { origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bipns%3A%2F%2Fipns\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23', - destination: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#' + destination: 'https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#\\1' } }) }) @@ -345,7 +345,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash', MV3Expectation: { origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=software', - destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash' + destination: 'https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash\\1' } }) }) @@ -362,7 +362,7 @@ describe('modifyRequest.onBeforeRequest:', function () { MV2Expectation: 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash', MV3Expectation: { origin: '^https?\\:\\/\\/duckduckgo\\.com\\/\\?q\\=web%2Bdweb%3A%2Fipns%2Fipfs\\.io%2Findex\\.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash\\&ia\\=web', - destination: 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash' + destination: 'https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash\\1' } }) }) diff --git a/test/functional/lib/ipfs-request-workarounds.test.js b/test/functional/lib/ipfs-request-workarounds.test.js index 92d863249..95d7664b4 100644 --- a/test/functional/lib/ipfs-request-workarounds.test.js +++ b/test/functional/lib/ipfs-request-workarounds.test.js @@ -58,7 +58,7 @@ describe('modifyRequest processing', function () { MV2Expectation: `http://127.0.0.1:8080/ipfs/${cid}`, MV3Expectation: { origin: '^https?\\:\\/\\/ipfs\\.io', - destination: 'http://127.0.0.1:8080' + destination: 'http://127.0.0.1:8080\\1' } }) }) @@ -75,7 +75,7 @@ describe('modifyRequest processing', function () { MV2Expectation: `http://localhost:8080/ipfs/${cid}`, MV3Expectation: { origin: '^https?\\:\\/\\/ipfs\\.io', - destination: 'http://localhost:8080' + destination: 'http://localhost:8080\\1' } }) }) @@ -92,7 +92,7 @@ describe('modifyRequest processing', function () { MV2Expectation: `http://127.0.0.1:8080/ipfs/${cid}`, MV3Expectation: { origin: '^https?\\:\\/\\/ipfs\\.io', - destination: 'http://127.0.0.1:8080' + destination: 'http://127.0.0.1:8080\\1' } }) }) @@ -109,7 +109,7 @@ describe('modifyRequest processing', function () { MV2Expectation: `http://localhost:8080/ipfs/${cid}`, MV3Expectation: { origin: '^https?\\:\\/\\/ipfs\\.io', - destination: 'http://localhost:8080' + destination: 'http://localhost:8080\\1' } }) }) @@ -382,7 +382,7 @@ describe('modifyRequest processing', function () { MV2Expectation: `http://localhost:8080/ipfs/${cid}`, MV3Expectation: { origin: '^https?\\:\\/\\/ipfs\\.io', - destination: 'http://localhost:8080' + destination: 'http://localhost:8080\\1' } }) }) From d36a2829e28391326888cdab267d3e2e6ef8a2d2 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Sat, 12 Aug 2023 01:37:01 -0600 Subject: [PATCH 55/63] fix(test): helper Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- test/helpers/mv3-test-helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts index 7d309ac89..71b1f1563 100644 --- a/test/helpers/mv3-test-helper.ts +++ b/test/helpers/mv3-test-helper.ts @@ -31,7 +31,7 @@ export function ensureCallRedirected ({ expect(args.addRules[0]).to.deep.equal(generateAddRule( args.addRules[0].id, MV3Expectation.origin + RULE_REGEX_ENDING, - MV3Expectation.destination + '\\1' + MV3Expectation.destination )) } else { expect(modifiedRequestCallResp.redirectUrl).to.equal(MV2Expectation) From 6ee2d310e0b5960091f06ee86e03ff0fc2804cda Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Sat, 12 Aug 2023 01:37:34 -0600 Subject: [PATCH 56/63] feat(mv3): less greedy rules Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/redirect-handler/blockOrObserve.ts | 69 ++++++++++++------- .../lib/ipfs-request-gateway-redirect.test.js | 16 ++--- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 792864a79..93181130b 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -16,7 +16,7 @@ export const DELETE_RULE_REQUEST = 'DELETE_RULE_REQUEST' export const DELETE_RULE_REQUEST_SUCCESS = 'DELETE_RULE_REQUEST_SUCCESS' // We need to match the rest of the URL, so we can use a wildcard. -export const RULE_REGEX_ENDING = `(\\/(?:${[...DEFAULT_NAMESPACES].join('|')})\\/(?:[^\\.]|$).*)$` +export const RULE_REGEX_ENDING = `((?:[^\\.]|$).*)$` interface regexFilterMap { id: number @@ -134,13 +134,14 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) regexSubstitution: string regexFilter: string } { - let regexSubstitution = redirectUrl.toLowerCase() - let regexFilter = originUrl.toLowerCase() + let regexSubstitution = redirectUrl + let regexFilter = originUrl const redirectNS = computeNamespaceFromUrl(redirectUrl) const originNS = computeNamespaceFromUrl(originUrl) if (!DEFAULT_NAMESPACES.has(originNS) && DEFAULT_NAMESPACES.has(redirectNS)) { // A redirect like https://github.com/ipfs/ipfs-companion/issues/1255 regexFilter = `^${escapeURLRegex(regexFilter)}`.replace(/https?/ig, 'https?') + const origRegexFilter = regexFilter const originURL = new URL(originUrl) const [tld, root, ...subdomain] = originURL.hostname.split('.').reverse() @@ -156,45 +157,61 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) regexSubstitution = redirectUrl .replace(subdomainPart as string, '\\1') // replace CID .replace(new RegExp(`${originURL.pathname}?$`), '\\2') // replace path + break } if (DEFAULT_NAMESPACES.has(subdomainPart as string)) { // We found a namespace, this is going to match group 2, i.e. namespace. // e.g https://bafybeib3bzis4mejzsnzsb65od3rnv5ffit7vsllratddjkgfgq4wiamqu.ipfs.dweb.link regexFilter = `${commonStaticUrlStart}(.*?)\\.(${[...DEFAULT_NAMESPACES].join('|')})${commonStaticUrlEnd}` + regexSubstitution = redirectUrl .replace(subdomain.reverse().join('.'), '\\1') // replace subdomain or CID. .replace(`/${subdomainPart as string}/`, '/\\2/') // replace namespace dynamically. - .replace(new RegExp(`${originURL.pathname}?$`), '\\3') // replace path + + const pathWithSearch = originURL.pathname + originURL.search + if (pathWithSearch !== '/') { + regexSubstitution = regexSubstitution.replace(pathWithSearch, '/\\3') // replace path + } else { + regexSubstitution += '\\3' + } + + break } // till we find a namespace or CID, we keep adding subdomains to the staticUrl. staticUrl.unshift(subdomainPart as string) } - } else { - // We can traverse the URL from the end, and find the first character that is different. - let commonIdx = 1 - while (commonIdx < Math.min(originUrl.length, redirectUrl.length)) { - if (originUrl[originUrl.length - commonIdx] !== redirectUrl[redirectUrl.length - commonIdx]) { - break - } - commonIdx += 1 + + if (regexFilter !== origRegexFilter) { + return { regexSubstitution, regexFilter } + } else { + regexFilter = originUrl } + } - // We can now construct the regex filter and substitution. - regexSubstitution = redirectUrl.slice(0, redirectUrl.length - commonIdx + 1) + '\\1' - // We need to escape the characters that are allowed in the URL, but not in the regex. - const regexFilterFirst = escapeURLRegex(originUrl.slice(0, originUrl.length - commonIdx + 1)) - regexFilter = `^${regexFilterFirst}${RULE_REGEX_ENDING}`.replace(/https?/ig, 'https?') - - // This method does not parse: - // originUrl: "https://awesome.ipfs.io/" - // redirectUrl: "http://localhost:8081/ipns/awesome.ipfs.io/" - // that ends up with capturing all urls which we do not want. - if (regexFilter === `^https?\\:\\/${RULE_REGEX_ENDING}`) { - const subdomain = new URL(originUrl).hostname - regexFilter = `^https?\\:\\/\\/${escapeURLRegex(subdomain)}${RULE_REGEX_ENDING}` - regexSubstitution = regexSubstitution.replace('\\1', `/${subdomain}\\1`) + // We can traverse the URL from the end, and find the first character that is different. + let commonIdx = 1 + while (commonIdx < Math.min(originUrl.length, redirectUrl.length)) { + if (originUrl[originUrl.length - commonIdx] !== redirectUrl[redirectUrl.length - commonIdx]) { + break } + commonIdx += 1 + } + + // We can now construct the regex filter and substitution. + regexSubstitution = redirectUrl.slice(0, redirectUrl.length - commonIdx + 1) + '\\1' + // We need to escape the characters that are allowed in the URL, but not in the regex. + const regexFilterFirst = escapeURLRegex(originUrl.slice(0, originUrl.length - commonIdx + 1)) + regexFilter = `^${regexFilterFirst}${RULE_REGEX_ENDING}`.replace(/https?/ig, 'https?') + + // This method does not parse: + // originUrl: "https://awesome.ipfs.io/" + // redirectUrl: "http://localhost:8081/ipns/awesome.ipfs.io/" + // that ends up with capturing all urls which we do not want. + if (regexFilter === `^https?\\:\\/${RULE_REGEX_ENDING}`) { + const subdomain = new URL(originUrl).hostname + regexFilter = `^https?\\:\\/\\/${escapeURLRegex(subdomain)}${RULE_REGEX_ENDING}` + regexSubstitution = regexSubstitution.replace('\\1', `/${subdomain}\\1`) } return { regexSubstitution, regexFilter } diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index d368b5754..5d4785aac 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -327,8 +327,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://localhost:8080/ipfs/${cid}/`, MV3Expectation: { - origin: `^https?\\:\\/\\/${cid}\\.ipfs\\.dweb\\.link`, - destination: `http://localhost:8080/ipfs/${cid}\\1` + origin: `^https:\\:\\/\\/(.*?)\\.(ipfs|ipns)\\.dweb\\.link\\/`, + destination: 'http://localhost:8080/\\2/\\1/\\3' } }) }) @@ -340,8 +340,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://localhost:8080/ipfs/${cid}/`, MV3Expectation: { - origin: `^https?\\:\\/\\/${cid}\\.ipfs\\.cf\\-ipfs\\.com`, - destination: `http://localhost:8080/ipfs/${cid}\\1` + origin: `^https:\\:\\/\\/(.*?)\\.(ipfs|ipns)\\.cf\\-ipfs\\.com\\/`, + destination: 'http://localhost:8080/\\2/\\1/\\3' } }) }) @@ -353,8 +353,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy/%3Ffilename=test.jpg?arg=val', MV3Expectation: { - origin: '^https?\\:\\/\\/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\.ipfs\\.dweb\\.link', - destination: 'http://localhost:8080/ipfs/bafybeigfejjsuq5im5c3w3t3krsiytszhfdc4v5myltcg4myv2n2w6jumy\\1' + origin: '^https:\\:\\/\\/(.*?)\\.(ipfs|ipns)\\.dweb\\.link\\/', + destination: 'http://localhost:8080/\\2/\\1/\\3' } }) }) @@ -366,8 +366,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://localhost:8080/ipns/${peerid}/`, MV3Expectation: { - origin: `^https?\\:\\/\\/${peerid}\\.ipns\\.dweb\\.link`, - destination: `http://localhost:8080/ipns/${peerid}\\1` + origin: `^https:\\:\\/\\/(.*?)\\.(ipfs|ipns)\\.dweb\\.link\\/`, + destination: `http://localhost:8080/\\2/\\1/\\3` } }) }) From e592755dde867bacd24bb9010369eb9567ecd508 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Sat, 12 Aug 2023 03:47:59 -0600 Subject: [PATCH 57/63] feat: Adding simpler regex for redirects from similar namespaces. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/redirect-handler/blockOrObserve.ts | 25 ++++++++- .../lib/ipfs-request-gateway-redirect.test.js | 56 +++++++++---------- .../lib/ipfs-request-workarounds.test.js | 20 +++---- .../redirect-handler/blockOrObserve.test.ts | 4 +- 4 files changed, 64 insertions(+), 41 deletions(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 93181130b..02f570355 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -136,6 +136,7 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) } { let regexSubstitution = redirectUrl let regexFilter = originUrl + const originURL = new URL(originUrl) const redirectNS = computeNamespaceFromUrl(redirectUrl) const originNS = computeNamespaceFromUrl(originUrl) if (!DEFAULT_NAMESPACES.has(originNS) && DEFAULT_NAMESPACES.has(redirectNS)) { @@ -143,7 +144,6 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) regexFilter = `^${escapeURLRegex(regexFilter)}`.replace(/https?/ig, 'https?') const origRegexFilter = regexFilter - const originURL = new URL(originUrl) const [tld, root, ...subdomain] = originURL.hostname.split('.').reverse() const staticUrl = [root, tld] while (subdomain.length > 0) { @@ -183,12 +183,35 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) } if (regexFilter !== origRegexFilter) { + // we found a valid regexFilter, so we can return. return { regexSubstitution, regexFilter } } else { + // we didn't find a valid regexFilter, so we can return the default. regexFilter = originUrl } } + // if the namespaces are the same, we can generate simpler regex. + // The only value that needs special handling is the `uri` param. + // TODO: Remove this check, as `uri` param is deprecated. + if ( + DEFAULT_NAMESPACES.has(originNS) && + DEFAULT_NAMESPACES.has(redirectNS) && + originNS === redirectNS && + originURL.searchParams.get('uri') == null + ) { + // A redirect like + // https://ipfs.io/ipfs/QmZMxU -> http://localhost:8080/ipfs/QmZMxU + const [originFirst, originLast] = originUrl.split(`/${originNS}/`) + const defaultNSRegexStr = `(${[...DEFAULT_NAMESPACES].join('|')})` + regexFilter = `^${escapeURLRegex(originFirst)}\\/${defaultNSRegexStr}\\/${RULE_REGEX_ENDING}` + .replace(/https?/ig, 'https?') + regexSubstitution = redirectUrl + .replace(`/${redirectNS}/`, '/\\1/') + .replace(originLast, '\\2') + return { regexSubstitution, regexFilter } + } + // We can traverse the URL from the end, and find the first character that is different. let commonIdx = 1 while (commonIdx < Math.min(originUrl.length, redirectUrl.length)) { diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index 5d4785aac..469ae84e9 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -67,8 +67,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: 'http://localhost:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://localhost:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://localhost:8080/\\1/\\2' } }) }) @@ -137,8 +137,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:8080/\\1/\\2' } }) }) @@ -150,8 +150,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:8080/\\1/\\2' } }) }) @@ -163,8 +163,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:8080/\\1/\\2' } }) }) @@ -176,8 +176,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:8080/\\1/\\2' } }) }) @@ -195,8 +195,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:8080/\\1/\\2' } }) }) @@ -208,8 +208,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:8080/\\1/\\2' } }) }) @@ -221,8 +221,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(xhrRequest), MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:8080/\\1/\\2' } }) }) @@ -238,8 +238,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onHeadersReceived(xhrRequest), MV2Expectation: 'http://127.0.0.1:8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://127.0.0.1:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:8080/\\1/\\2' } }) }) @@ -263,8 +263,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org/index.html?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://localhost:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://localhost:8080/\\1/\\2' } }) }) @@ -276,8 +276,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: 'http://localhost:8080/ipns/QmSWnBwMKZ28tcgMFdihD8XS7p6QzdRSGf71cCybaETSsU/index.html?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/google\\.com', - destination: 'http://localhost:8080\\1' + origin: '^https?\\:\\/\\/google\\.com\\/(ipfs|ipns)\\/', + destination: 'http://localhost:8080/\\1/\\2' } }) }) @@ -415,8 +415,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: 'http://127.0.0.1:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/', MV3Expectation: { - origin: '^https?\\:\\/\\/0\\.0\\.0\\.0', - destination: 'http://127.0.0.1\\1' + origin: '^https?\\:\\/\\/0\\.0\\.0\\.0\\:5001\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:5001/\\1/\\2' } }) }) @@ -476,8 +476,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: 'http://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/bar\\.com', - destination: 'http://foo\\1' + origin: '^https?\\:\\/\\/bar\\.com\\/(ipfs|ipns)\\/', + destination: 'http://foo/\\1/\\2' } }) }) @@ -490,8 +490,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: 'https://foo/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', MV3Expectation: { - origin: '^https?\\:\\/\\/bar\\.com', - destination: 'https://foo\\1' + origin: '^https?\\:\\/\\/bar\\.com\\/(ipfs|ipns)\\/', + destination: 'https://foo/\\1/\\2' } }) }) diff --git a/test/functional/lib/ipfs-request-workarounds.test.js b/test/functional/lib/ipfs-request-workarounds.test.js index 95d7664b4..60edaf12c 100644 --- a/test/functional/lib/ipfs-request-workarounds.test.js +++ b/test/functional/lib/ipfs-request-workarounds.test.js @@ -57,8 +57,8 @@ describe('modifyRequest processing', function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://127.0.0.1:8080/ipfs/${cid}`, MV3Expectation: { - origin: '^https?\\:\\/\\/ipfs\\.io', - destination: 'http://127.0.0.1:8080\\1' + origin: '^https?\\:\\/\\/ipfs\\.io\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:8080/\\1/\\2' } }) }) @@ -74,8 +74,8 @@ describe('modifyRequest processing', function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://localhost:8080/ipfs/${cid}`, MV3Expectation: { - origin: '^https?\\:\\/\\/ipfs\\.io', - destination: 'http://localhost:8080\\1' + origin: '^https?\\:\\/\\/ipfs\\.io\\/(ipfs|ipns)\\/', + destination: 'http://localhost:8080/\\1/\\2' } }) }) @@ -91,8 +91,8 @@ describe('modifyRequest processing', function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://127.0.0.1:8080/ipfs/${cid}`, MV3Expectation: { - origin: '^https?\\:\\/\\/ipfs\\.io', - destination: 'http://127.0.0.1:8080\\1' + origin: '^https?\\:\\/\\/ipfs\\.io\\/(ipfs|ipns)\\/', + destination: 'http://127.0.0.1:8080/\\1/\\2' } }) }) @@ -108,8 +108,8 @@ describe('modifyRequest processing', function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://localhost:8080/ipfs/${cid}`, MV3Expectation: { - origin: '^https?\\:\\/\\/ipfs\\.io', - destination: 'http://localhost:8080\\1' + origin: '^https?\\:\\/\\/ipfs\\.io\\/(ipfs|ipns)\\/', + destination: 'http://localhost:8080/\\1/\\2' } }) }) @@ -381,8 +381,8 @@ describe('modifyRequest processing', function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://localhost:8080/ipfs/${cid}`, MV3Expectation: { - origin: '^https?\\:\\/\\/ipfs\\.io', - destination: 'http://localhost:8080\\1' + origin: '^https?\\:\\/\\/ipfs\\.io\\/(ipfs|ipns)\\/', + destination: 'http://localhost:8080/\\1/\\2' } }) }) diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.ts index efe7cae01..6a4863468 100644 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.ts +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.ts @@ -157,8 +157,8 @@ describe('lib/redirect-handler/blockOrObserve', () => { }) ensureTabRedirected('http://localhost:8080/ipns/en.wikipedia-on-ipfs.org') ensureDeclrativeNetRequetRuleIsAdded({ - expectedCondition: `^https?\\:\\/\\/ipfs\\.io${RULE_REGEX_ENDING}`, - regexSubstitution: 'http://localhost:8080\\1' + expectedCondition: `^https?\\:\\/\\/ipfs\\.io\\/(ipfs|ipns)\\/${RULE_REGEX_ENDING}`, + regexSubstitution: 'http://localhost:8080/\\1/\\2' }) }) From 5c85d841169f589cb4b563358d22bef74dfd84bb Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Sat, 12 Aug 2023 03:50:57 -0600 Subject: [PATCH 58/63] fix(lint): :rotating_light: Warnings Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- add-on/src/lib/redirect-handler/blockOrObserve.ts | 2 +- test/functional/lib/ipfs-request-gateway-redirect.test.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 02f570355..c87320183 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -16,7 +16,7 @@ export const DELETE_RULE_REQUEST = 'DELETE_RULE_REQUEST' export const DELETE_RULE_REQUEST_SUCCESS = 'DELETE_RULE_REQUEST_SUCCESS' // We need to match the rest of the URL, so we can use a wildcard. -export const RULE_REGEX_ENDING = `((?:[^\\.]|$).*)$` +export const RULE_REGEX_ENDING = '((?:[^\\.]|$).*)$' interface regexFilterMap { id: number diff --git a/test/functional/lib/ipfs-request-gateway-redirect.test.js b/test/functional/lib/ipfs-request-gateway-redirect.test.js index 469ae84e9..a2f9582d0 100644 --- a/test/functional/lib/ipfs-request-gateway-redirect.test.js +++ b/test/functional/lib/ipfs-request-gateway-redirect.test.js @@ -327,7 +327,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://localhost:8080/ipfs/${cid}/`, MV3Expectation: { - origin: `^https:\\:\\/\\/(.*?)\\.(ipfs|ipns)\\.dweb\\.link\\/`, + origin: '^https:\\:\\/\\/(.*?)\\.(ipfs|ipns)\\.dweb\\.link\\/', destination: 'http://localhost:8080/\\2/\\1/\\3' } }) @@ -340,7 +340,7 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://localhost:8080/ipfs/${cid}/`, MV3Expectation: { - origin: `^https:\\:\\/\\/(.*?)\\.(ipfs|ipns)\\.cf\\-ipfs\\.com\\/`, + origin: '^https:\\:\\/\\/(.*?)\\.(ipfs|ipns)\\.cf\\-ipfs\\.com\\/', destination: 'http://localhost:8080/\\2/\\1/\\3' } }) @@ -366,8 +366,8 @@ describe(`[${manifestVersion}] gateway-redirect:`, function () { modifiedRequestCallResp: await modifyRequest.onBeforeRequest(request), MV2Expectation: `http://localhost:8080/ipns/${peerid}/`, MV3Expectation: { - origin: `^https:\\:\\/\\/(.*?)\\.(ipfs|ipns)\\.dweb\\.link\\/`, - destination: `http://localhost:8080/\\2/\\1/\\3` + origin: '^https:\\:\\/\\/(.*?)\\.(ipfs|ipns)\\.dweb\\.link\\/', + destination: 'http://localhost:8080/\\2/\\1/\\3' } }) }) From fca5fe2ff01647c4c536a9217b1e556376ff5d6a Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Tue, 15 Aug 2023 03:53:28 -0600 Subject: [PATCH 59/63] feat(mv3): Better Default Rules (#1260) * refactor(mv3): blockOrRequest code Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> * refactor(mv3): Port Logic for Default Rules is more robust. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> * feat(test): Adding tests for default rule logic. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --------- Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/redirect-handler/blockOrObserve.ts | 25 ++++++++----- .../redirect-handler/blockOrObserve.test.ts | 35 ++++++++++++++++++- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index c87320183..dd450a2ac 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -26,6 +26,7 @@ interface regexFilterMap { interface redirectHandlerInput { originUrl: string redirectUrl: string + getPort: (state: CompanionState) => string } type messageToSelfType = typeof GLOBAL_STATE_CHANGE | typeof GLOBAL_STATE_OPTION_CHANGE | typeof DELETE_RULE_REQUEST @@ -34,6 +35,8 @@ interface messageToSelf { value?: string | Record } +const defaultNSRegexStr = `(${[...DEFAULT_NAMESPACES].join('|')})` + // We need to check if the browser supports the declarativeNetRequest API. // TODO: replace with check for `Blocking` in `chrome.webRequest.OnBeforeRequestOptions` // which is currently a bug https://bugs.chromium.org/p/chromium/issues/detail?id=1427952 @@ -80,11 +83,18 @@ const savedRegexFilters: Map = new Map() const DEFAULT_LOCAL_RULES: redirectHandlerInput[] = [ { originUrl: 'http://127.0.0.1', - redirectUrl: 'http://localhost' + redirectUrl: 'http://localhost', + getPort: ({ gwURLString }): string => new URL(gwURLString).port }, { originUrl: 'http://[::1]', - redirectUrl: 'http://localhost' + redirectUrl: 'http://localhost', + getPort: ({ gwURLString }): string => new URL(gwURLString).port + }, + { + originUrl: 'http://localhost', + redirectUrl: 'http://127.0.0.1', + getPort: ({ apiURL }): string => new URL(apiURL).port } ] @@ -163,7 +173,7 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) if (DEFAULT_NAMESPACES.has(subdomainPart as string)) { // We found a namespace, this is going to match group 2, i.e. namespace. // e.g https://bafybeib3bzis4mejzsnzsb65od3rnv5ffit7vsllratddjkgfgq4wiamqu.ipfs.dweb.link - regexFilter = `${commonStaticUrlStart}(.*?)\\.(${[...DEFAULT_NAMESPACES].join('|')})${commonStaticUrlEnd}` + regexFilter = `${commonStaticUrlStart}(.*?)\\.${defaultNSRegexStr}${commonStaticUrlEnd}` regexSubstitution = redirectUrl .replace(subdomain.reverse().join('.'), '\\1') // replace subdomain or CID. @@ -203,7 +213,6 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) // A redirect like // https://ipfs.io/ipfs/QmZMxU -> http://localhost:8080/ipfs/QmZMxU const [originFirst, originLast] = originUrl.split(`/${originNS}/`) - const defaultNSRegexStr = `(${[...DEFAULT_NAMESPACES].join('|')})` regexFilter = `^${escapeURLRegex(originFirst)}\\/${defaultNSRegexStr}\\/${RULE_REGEX_ENDING}` .replace(/https?/ig, 'https?') regexSubstitution = redirectUrl @@ -338,11 +347,11 @@ async function reconcileRulesAndRemoveOld (state: CompanionState): Promise } } - const { port } = new URL(state.gwURLString) // make sure that the default rules are added. - for (const { originUrl, redirectUrl } of DEFAULT_LOCAL_RULES) { - const regexFilter = `^${escapeURLRegex(`${originUrl}:${port}`)}${RULE_REGEX_ENDING}` - const regexSubstitution = `${redirectUrl}:${port}/\\1` + for (const { originUrl, redirectUrl, getPort } of DEFAULT_LOCAL_RULES) { + const port = getPort(state) + const regexFilter = `^${escapeURLRegex(`${originUrl}:${port}`)}\\/${defaultNSRegexStr}\\/${RULE_REGEX_ENDING}` + const regexSubstitution = `${redirectUrl}:${port}/\\1/\\2` if (!savedRegexFilters.has(regexFilter)) { // We need to add the new rule. diff --git a/test/functional/lib/redirect-handler/blockOrObserve.test.ts b/test/functional/lib/redirect-handler/blockOrObserve.test.ts index 6a4863468..455fc5bc2 100644 --- a/test/functional/lib/redirect-handler/blockOrObserve.test.ts +++ b/test/functional/lib/redirect-handler/blockOrObserve.test.ts @@ -49,12 +49,14 @@ function ensureTabRedirected (url): void { * @param regexSubstitution */ function ensureDeclrativeNetRequetRuleIsAdded ({ + addRuleIndex = 0, addRuleLength = 1, callIndex = 0, expectedCondition, regexSubstitution, removedRulesIds = [], }: { + addRuleIndex?: number addRuleLength?: number callIndex?: number expectedCondition: string @@ -69,7 +71,7 @@ function ensureDeclrativeNetRequetRuleIsAdded ({ expect(removeRuleIds).to.deep.equal(removedRulesIds) if (addRuleLength > 0) { expect(addRules).to.have.lengthOf(addRuleLength) - const [{ id, priority, action, condition }] = addRules + const { id, priority, action, condition } = addRules[addRuleIndex] expect(id).to.be.a('number') expect(priority).to.equal(1) expect(action).to.deep.equal({ type: 'redirect', redirect: { regexSubstitution } }) @@ -137,6 +139,37 @@ describe('lib/redirect-handler/blockOrObserve', () => { expect (browserMock.tabs.query.called).to.be.false }) + it('Should add default rules for localhost', async () => { + await addRuleToDynamicRuleSet({ + originUrl: 'https://ipfs.io/ipns/en.wikipedia-on-ipfs.org', + redirectUrl: 'http://localhost:8080/ipns/en.wikipedia-on-ipfs.org' + }) + + ensureDeclrativeNetRequetRuleIsAdded({ + addRuleIndex: 0, + addRuleLength: 3, + callIndex: 1, + expectedCondition: `^http\\:\\/\\/127\\.0\\.0\\.1\\:8080\\/(ipfs|ipns)\\/${RULE_REGEX_ENDING}`, + regexSubstitution: 'http://localhost:8080/\\1/\\2' + }) + + ensureDeclrativeNetRequetRuleIsAdded({ + addRuleIndex: 1, + addRuleLength: 3, + callIndex: 1, + expectedCondition: `^http\\:\\/\\/\\[\\:\\:1\\]\\:8080\\/(ipfs|ipns)\\/${RULE_REGEX_ENDING}`, + regexSubstitution: 'http://localhost:8080/\\1/\\2' + }) + + ensureDeclrativeNetRequetRuleIsAdded({ + addRuleIndex: 2, + addRuleLength: 3, + callIndex: 1, + expectedCondition: `^http\\:\\/\\/localhost\\:5001\\/(ipfs|ipns)\\/${RULE_REGEX_ENDING}`, + regexSubstitution: 'http://127.0.0.1:5001/\\1/\\2' + }) + }) + it('Should allow pages to be recovered', async () => { // when redirecting to recovery page await addRuleToDynamicRuleSet({ From 832679daa9a7e182e83dc25a05fdf8ef894e4e3c Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Tue, 15 Aug 2023 22:10:31 -0600 Subject: [PATCH 60/63] Update add-on/src/lib/redirect-handler/blockOrObserve.ts --- add-on/src/lib/redirect-handler/blockOrObserve.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index dd450a2ac..0efc78524 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -203,7 +203,6 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput) // if the namespaces are the same, we can generate simpler regex. // The only value that needs special handling is the `uri` param. - // TODO: Remove this check, as `uri` param is deprecated. if ( DEFAULT_NAMESPACES.has(originNS) && DEFAULT_NAMESPACES.has(redirectNS) && From 5e22ceaba23526dcaedd21a8587a8e2f2f4490f7 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Wed, 16 Aug 2023 00:08:30 -0600 Subject: [PATCH 61/63] fix(docs): :pencil2: Adding comments Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- add-on/src/lib/redirect-handler/blockOrObserve.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 0efc78524..04c00705e 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -124,12 +124,14 @@ function escapeURLRegex (str: string): string { } /** - * Compute the namespace from the URL. + * Compute the namespace from the URL. This finds the first path segment. + * e.g. http:////path/to/file/or/cid * * @param url string */ function computeNamespaceFromUrl (url: string): string { const { pathname } = new URL(url) + // regex to match the first path segment. return (/\/([^/]+)\//i.exec(pathname)?.[1] ?? '').toLowerCase() } From 99e2d239c045afa1b791e918a6e9c4ba6cecf8a1 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Fri, 18 Aug 2023 00:45:32 -0600 Subject: [PATCH 62/63] feat(mv3): brave: redirection to protocol handlers. Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .../lib/redirect-handler/blockOrObserve.ts | 83 ++++++++++++------- add-on/src/options/page.js | 9 +- test/helpers/mv3-test-helper.ts | 10 +-- 3 files changed, 63 insertions(+), 39 deletions(-) diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 04c00705e..d504cde13 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -1,7 +1,8 @@ import debug from 'debug' +import isIPFS from 'is-ipfs' import browser from 'webextension-polyfill' import { CompanionState } from '../../types/companion.js' -import isIPFS from 'is-ipfs' +import { brave } from '../ipfs-client/brave.js' // this won't work in webworker context. Needs to be enabled manually // https://github.com/debug-js/debug/issues/916 @@ -23,9 +24,19 @@ interface regexFilterMap { regexSubstitution: string } -interface redirectHandlerInput { - originUrl: string +interface redirectPair { + originUrl: string, redirectUrl: string +} + +interface redirectRegexPair { + regexSubstitution: string, + regexFilter: string +} + +interface redirectHandlerInput extends Omit { + priority?: number + getRedirectUrl: (port: string) => string getPort: (state: CompanionState) => string } @@ -83,19 +94,25 @@ const savedRegexFilters: Map = new Map() const DEFAULT_LOCAL_RULES: redirectHandlerInput[] = [ { originUrl: 'http://127.0.0.1', - redirectUrl: 'http://localhost', + getRedirectUrl: (port): string => `http://localhost:${port}/\\1/\\2`, getPort: ({ gwURLString }): string => new URL(gwURLString).port }, { originUrl: 'http://[::1]', - redirectUrl: 'http://localhost', + getRedirectUrl: (port): string => `http://localhost:${port}/\\1/\\2`, getPort: ({ gwURLString }): string => new URL(gwURLString).port }, { originUrl: 'http://localhost', - redirectUrl: 'http://127.0.0.1', + getRedirectUrl: (port): string => `http://localhost:${port}/\\1/\\2`, getPort: ({ apiURL }): string => new URL(apiURL).port - } + }, + ...(brave ? [{ + originUrl: 'http://localhost', + getRedirectUrl: (): string => `\\1://\\2`, + getPort: ({ gwURLString }): string => new URL(gwURLString).port, + priority: 1 + }] : []) as redirectHandlerInput[] ] /** @@ -142,10 +159,7 @@ function computeNamespaceFromUrl (url: string): string { * @param redirectUrl * @returns */ -function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput): { - regexSubstitution: string - regexFilter: string -} { +function constructRegexFilter ({ originUrl, redirectUrl }: redirectPair): redirectRegexPair { let regexSubstitution = redirectUrl let regexFilter = originUrl const originURL = new URL(originUrl) @@ -344,19 +358,19 @@ async function reconcileRulesAndRemoveOld (state: CompanionState): Promise if (rules.length === 0) { // we need to populate old rules. for (const [regexFilter, { regexSubstitution, id }] of savedRegexFilters.entries()) { - addRules.push(generateAddRule(id, regexFilter, regexSubstitution)) + addRules.push(generateAddRule({ id, regexFilter, regexSubstitution })) } } // make sure that the default rules are added. - for (const { originUrl, redirectUrl, getPort } of DEFAULT_LOCAL_RULES) { + for (const { originUrl, getRedirectUrl, getPort, priority } of DEFAULT_LOCAL_RULES) { const port = getPort(state) const regexFilter = `^${escapeURLRegex(`${originUrl}:${port}`)}\\/${defaultNSRegexStr}\\/${RULE_REGEX_ENDING}` - const regexSubstitution = `${redirectUrl}:${port}/\\1/\\2` + const regexSubstitution = getRedirectUrl(port) if (!savedRegexFilters.has(regexFilter)) { // We need to add the new rule. - addRules.push(saveAndGenerateRule(regexFilter, regexSubstitution)) + addRules.push(saveAndGenerateRule({ regexFilter, regexSubstitution, priority })) } } @@ -372,16 +386,20 @@ async function reconcileRulesAndRemoveOld (state: CompanionState): Promise * @param excludedInitiatorDomains - The domains that are excluded from the rule. * @returns */ -function saveAndGenerateRule ( - regexFilter: string, - regexSubstitution: string, - excludedInitiatorDomains: string[] = [] -): browser.DeclarativeNetRequest.Rule { +function saveAndGenerateRule ({ + regexFilter, + regexSubstitution, + excludedInitiatorDomains = [], + priority +}: redirectRegexPair & { + excludedInitiatorDomains?: string[], + priority?: number +}): browser.DeclarativeNetRequest.Rule { // We need to generate a random ID for the rule. const id = Math.floor(Math.random() * 29999) // We need to save the regex filter and ID to check if the rule already exists later. savedRegexFilters.set(regexFilter, { id, regexSubstitution }) - return generateAddRule(id, regexFilter, regexSubstitution, excludedInitiatorDomains) + return generateAddRule({ id, regexFilter, regexSubstitution, excludedInitiatorDomains, priority }) } /** @@ -392,15 +410,20 @@ function saveAndGenerateRule ( * @param excludedInitiatorDomains - The domains that are excluded from the rule. * @returns */ -export function generateAddRule ( +export function generateAddRule ({ + id, + priority = 10, + regexFilter, + regexSubstitution, + excludedInitiatorDomains = [] +}: redirectRegexPair & { id: number, - regexFilter: string, - regexSubstitution: string, - excludedInitiatorDomains: string[] = [] -): browser.DeclarativeNetRequest.Rule { + priority?: number, + excludedInitiatorDomains?: string[] +}): browser.DeclarativeNetRequest.Rule { return { id, - priority: 1, + priority, action: { type: 'redirect', redirect: { regexSubstitution } @@ -436,9 +459,9 @@ export function generateAddRule ( * @returns {Promise} */ export function addRuleToDynamicRuleSetGenerator ( - getState: () => CompanionState): (input: redirectHandlerInput) => Promise { + getState: () => CompanionState): (input: redirectPair) => Promise { // returning a closure to avoid passing `getState` as an argument to `addRuleToDynamicRuleSet`. - return async function ({ originUrl, redirectUrl }: redirectHandlerInput): Promise { + return async function ({ originUrl, redirectUrl }: redirectPair): Promise { // update the rules so that the next request is handled correctly. const state = getState() const redirectIsOrigin = originUrl === redirectUrl @@ -469,7 +492,7 @@ export function addRuleToDynamicRuleSetGenerator ( await browser.declarativeNetRequest.updateDynamicRules( { // We need to add the new rule. - addRules: [saveAndGenerateRule(regexFilter, regexSubstitution)], + addRules: [saveAndGenerateRule({ regexFilter, regexSubstitution })], // We need to remove the old rules. removeRuleIds } diff --git a/add-on/src/options/page.js b/add-on/src/options/page.js index 78b3537d2..ba767bef0 100644 --- a/add-on/src/options/page.js +++ b/add-on/src/options/page.js @@ -115,12 +115,13 @@ export default function optionsPage (state, emit) { ${resetForm({ onOptionsReset })} - ${supportsBlock + ${supportsBlock() ? '' : redirectRuleForm({ - redirectRules: state.redirectRules, - emit - })} + redirectRules: state.redirectRules, + emit + }) + } ` } diff --git a/test/helpers/mv3-test-helper.ts b/test/helpers/mv3-test-helper.ts index 71b1f1563..dd84846e7 100644 --- a/test/helpers/mv3-test-helper.ts +++ b/test/helpers/mv3-test-helper.ts @@ -28,11 +28,11 @@ export function ensureCallRedirected ({ }): void { if (isManifestV3) { const [args] = browser.declarativeNetRequest.updateDynamicRules.firstCall.args - expect(args.addRules[0]).to.deep.equal(generateAddRule( - args.addRules[0].id, - MV3Expectation.origin + RULE_REGEX_ENDING, - MV3Expectation.destination - )) + expect(args.addRules[0]).to.deep.equal(generateAddRule({ + id: args.addRules[0].id, + regexFilter: MV3Expectation.origin + RULE_REGEX_ENDING, + regexSubstitution: MV3Expectation.destination + })) } else { expect(modifiedRequestCallResp.redirectUrl).to.equal(MV2Expectation) } From d6fbcb20ecef1494d9f744e601630bd3d55fd40a Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Fri, 8 Sep 2023 01:37:18 -0600 Subject: [PATCH 63/63] fix(mv3): external node type Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- add-on/src/lib/state.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-on/src/lib/state.js b/add-on/src/lib/state.js index 3f06a7785..860fb689a 100644 --- a/add-on/src/lib/state.js +++ b/add-on/src/lib/state.js @@ -4,7 +4,7 @@ import { isHostname, safeURL } from './options.js' export const offlinePeerCount = -1 -export const POSSIBLE_NODE_TYPES = ['external', 'brave'] +export const POSSIBLE_NODE_TYPES = ['external', 'external:brave'] /** *