tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 38b532434e1eb733fae221bdacfeb3f3e5a07d3e
parent c6641d8197e0e81657e5284160adce2047405069
Author: Andrea Marchesini <amarchesini@mozilla.com>
Date:   Mon, 10 Nov 2025 14:06:18 +0000

Bug 1998795 - IPProtection: implement the ACTIVATING state - part 1 - ProxyManager as an helper class, r=ip-protection-reviewers,sstreich

Differential Revision: https://phabricator.services.mozilla.com/D271666

Diffstat:
Mbrowser/components/ipprotection/IPPAutoStart.sys.mjs | 7++++---
Mbrowser/components/ipprotection/IPPProxyManager.sys.mjs | 73++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
Mbrowser/components/ipprotection/IPProtectionHelpers.sys.mjs | 45++-------------------------------------------
Mbrowser/components/ipprotection/IPProtectionPanel.sys.mjs | 8++++----
Mbrowser/components/ipprotection/IPProtectionService.sys.mjs | 21++++-----------------
Mbrowser/components/ipprotection/docs/Components.rst | 16++++++++--------
Mbrowser/components/ipprotection/tests/browser/browser_IPPProxyManager.js | 22+++++++++-------------
Mbrowser/components/ipprotection/tests/browser/browser_IPProtectionService.js | 6+++---
Mbrowser/components/ipprotection/tests/browser/browser_ipprotection_telemetry.js | 6+++---
Mbrowser/components/ipprotection/tests/browser/browser_ipprotection_toolbar.js | 4++--
Mbrowser/components/ipprotection/tests/browser/head.js | 4++++
Mbrowser/components/ipprotection/tests/xpcshell/test_IPProtectionService.js | 11+++++++----
Mbrowser/components/ipprotection/tests/xpcshell/test_IPProxyManager.js | 46++++++++++++++++++++--------------------------
13 files changed, 120 insertions(+), 149 deletions(-)

diff --git a/browser/components/ipprotection/IPPAutoStart.sys.mjs b/browser/components/ipprotection/IPPAutoStart.sys.mjs @@ -9,6 +9,7 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { IPProtectionServerlist: "resource:///modules/ipprotection/IPProtectionServerlist.sys.mjs", + IPPProxyManager: "resource:///modules/ipprotection/IPPProxyManager.sys.mjs", IPProtectionService: "resource:///modules/ipprotection/IPProtectionService.sys.mjs", IPProtectionStates: @@ -85,7 +86,7 @@ class IPPAutoStartSingleton { case lazy.IPProtectionStates.READY: if (this.#shouldStartWhenReady) { this.#shouldStartWhenReady = false; - lazy.IPProtectionService.start(); + lazy.IPProtectionService.start(/* user action: */ false); } break; @@ -112,7 +113,7 @@ class IPPEarlyStartupFilter { init() { if (this.#autoStartAndAtStartup) { - lazy.IPProtectionService.proxyManager.createChannelFilter(); + lazy.IPPProxyManager.createChannelFilter(); lazy.IPProtectionService.addEventListener( "IPProtectionService:StateChanged", @@ -135,7 +136,7 @@ class IPPEarlyStartupFilter { } #cancelChannelFilter() { - lazy.IPProtectionService.proxyManager.cancelChannelFilter(); + lazy.IPPProxyManager.cancelChannelFilter(); } #handleEvent(_event) { diff --git a/browser/components/ipprotection/IPPProxyManager.sys.mjs b/browser/components/ipprotection/IPPProxyManager.sys.mjs @@ -5,7 +5,6 @@ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { - GuardianClient: "resource:///modules/ipprotection/GuardianClient.sys.mjs", IPPChannelFilter: "resource:///modules/ipprotection/IPPChannelFilter.sys.mjs", IPProtectionUsage: "resource:///modules/ipprotection/IPProtectionUsage.sys.mjs", @@ -13,6 +12,10 @@ ChromeUtils.defineESModuleGetters(lazy, { "resource:///modules/ipprotection/IPPNetworkErrorObserver.sys.mjs", IPProtectionServerlist: "resource:///modules/ipprotection/IPProtectionServerlist.sys.mjs", + IPProtectionService: + "resource:///modules/ipprotection/IPProtectionService.sys.mjs", + IPProtectionStates: + "resource:///modules/ipprotection/IPProtectionService.sys.mjs", }); const LOG_PREF = "browser.ipProtection.log"; @@ -27,8 +30,7 @@ ChromeUtils.defineLazyGetter(lazy, "logConsole", function () { /** * Manages the proxy connection for the IPProtectionService. */ -class IPPProxyManager { - #guardian = null; +class IPPProxyManagerSingleton { #pass = null; /**@type {import("./IPPChannelFilter.sys.mjs").IPPChannelFilter | null} */ #connection = null; @@ -38,15 +40,38 @@ class IPPProxyManager { #rotateProxyPassPromise = null; #activatedAt = false; - get activatedAt() { - return this.#activatedAt; + constructor() { + this.handleProxyErrorEvent = this.#handleProxyErrorEvent.bind(this); + this.handleEvent = this.#handleEvent.bind(this); } - get guardian() { - if (!this.#guardian) { - this.#guardian = new lazy.GuardianClient(); - } - return this.#guardian; + init() { + lazy.IPProtectionService.addEventListener( + "IPProtectionService:StateChanged", + this.handleEvent + ); + } + + initOnStartupCompleted() {} + + uninit() { + lazy.IPProtectionService.removeEventListener( + "IPProtectionService:StateChanged", + this.handleEvent + ); + + this.reset(); + this.#connection = null; + this.usageObserver.stop(); + } + + /** + * Checks if the proxy is active and was activated. + * + * @returns {Date} + */ + get activatedAt() { + return this.active && this.#activatedAt; } get usageObserver() { @@ -79,11 +104,6 @@ class IPPProxyManager { return !!this.#pass?.isValid(); } - constructor(guardian) { - this.#guardian = guardian; - this.handleProxyErrorEvent = this.#handleProxyErrorEvent.bind(this); - } - createChannelFilter() { if (!this.#connection) { this.#connection = lazy.IPPChannelFilter.create(); @@ -170,13 +190,17 @@ class IPPProxyManager { } } - /** - * Cleans up this instance. - */ - destroy() { - this.reset(); - this.#connection = null; - this.usageObserver.stop(); + #handleEvent(_event) { + if ( + lazy.IPProtectionService.state === lazy.IPProtectionStates.UNAVAILABLE || + lazy.IPProtectionService.state === lazy.IPProtectionStates.UNAUTHENTICATED + ) { + if (this.active) { + this.stop(false); + } + + this.reset(); + } } /** @@ -186,7 +210,8 @@ class IPPProxyManager { * @returns {Promise<ProxyPass|Error>} - the proxy pass if it available. */ async #getProxyPass() { - let { status, error, pass } = await this.guardian.fetchProxyPass(); + let { status, error, pass } = + await lazy.IPProtectionService.guardian.fetchProxyPass(); lazy.logConsole.debug("ProxyPass:", { status, valid: pass?.isValid(), @@ -252,4 +277,6 @@ class IPPProxyManager { } } +const IPPProxyManager = new IPPProxyManagerSingleton(); + export { IPPProxyManager }; diff --git a/browser/components/ipprotection/IPProtectionHelpers.sys.mjs b/browser/components/ipprotection/IPProtectionHelpers.sys.mjs @@ -23,6 +23,7 @@ ChromeUtils.defineESModuleGetters(lazy, { "resource:///modules/ipprotection/IPProtectionService.sys.mjs", }); +import { IPPProxyManager } from "resource:///modules/ipprotection/IPPProxyManager.sys.mjs"; import { IPPAutoStartHelpers } from "resource:///modules/ipprotection/IPPAutoStart.sys.mjs"; import { IPPEnrollAndEntitleManager } from "resource:///modules/ipprotection/IPPEnrollAndEntitleManager.sys.mjs"; import { IPPNimbusHelper } from "resource:///modules/ipprotection/IPPNimbusHelper.sys.mjs"; @@ -73,48 +74,6 @@ class UIHelper { } /** - * This simple class resets the account data when needed - */ -class ProxyResetHelper { - constructor() { - this.handleEvent = this.#handleEvent.bind(this); - } - - init() { - lazy.IPProtectionService.addEventListener( - "IPProtectionService:StateChanged", - this.handleEvent - ); - } - - initOnStartupCompleted() {} - - uninit() { - lazy.IPProtectionService.removeEventListener( - "IPProtectionService:StateChanged", - this.handleEvent - ); - } - - #handleEvent(_event) { - if (!lazy.IPProtectionService.proxyManager) { - return; - } - - if ( - lazy.IPProtectionService.state === lazy.IPProtectionStates.UNAVAILABLE || - lazy.IPProtectionService.state === lazy.IPProtectionStates.UNAUTHENTICATED - ) { - if (lazy.IPProtectionService.proxyManager.active) { - lazy.IPProtectionService.proxyManager.stop(false); - } - - lazy.IPProtectionService.proxyManager.reset(); - } - } -} - -/** * This class removes the UI widget if the VPN add-on is installed. */ class VPNAddonHelper { @@ -159,8 +118,8 @@ const IPPHelpers = [ IPPSignInWatcher, IPProtectionServerlist, IPPEnrollAndEntitleManager, + IPPProxyManager, new UIHelper(), - new ProxyResetHelper(), new VPNAddonHelper(), ...IPPAutoStartHelpers, IPPNimbusHelper, diff --git a/browser/components/ipprotection/IPProtectionPanel.sys.mjs b/browser/components/ipprotection/IPProtectionPanel.sys.mjs @@ -9,6 +9,7 @@ ChromeUtils.defineESModuleGetters(lazy, { "moz-src:///browser/components/customizableui/CustomizableUI.sys.mjs", IPPEnrollAndEntitleManager: "resource:///modules/ipprotection/IPPEnrollAndEntitleManager.sys.mjs", + IPPProxyManager: "resource:///modules/ipprotection/IPPProxyManager.sys.mjs", IPProtectionService: "resource:///modules/ipprotection/IPProtectionService.sys.mjs", IPProtectionStates: @@ -110,7 +111,7 @@ export class IPProtectionPanel { constructor(window) { this.handleEvent = this.#handleEvent.bind(this); - let { activatedAt: protectionEnabledSince } = lazy.IPProtectionService; + let { activatedAt: protectionEnabledSince } = lazy.IPPProxyManager; this.state = { isSignedOut: !lazy.IPPSignInWatcher.isSignedIn, @@ -375,10 +376,9 @@ export class IPProtectionPanel { event.type == "IPProtectionService:StateChanged" || event.type === "IPPEnrollAndEntitleManager:StateChanged" ) { - let { state, activatedAt: protectionEnabledSince } = - lazy.IPProtectionService; + let { activatedAt: protectionEnabledSince } = lazy.IPPProxyManager; let hasError = - state === lazy.IPProtectionStates.ERROR && + lazy.IPProtectionService.state === lazy.IPProtectionStates.ERROR && lazy.IPProtectionService.errors.includes(ERRORS.GENERIC); this.setState({ diff --git a/browser/components/ipprotection/IPProtectionService.sys.mjs b/browser/components/ipprotection/IPProtectionService.sys.mjs @@ -78,7 +78,6 @@ class IPProtectionServiceSingleton extends EventTarget { errors = []; guardian = null; - proxyManager = null; #helpers = null; @@ -92,15 +91,6 @@ class IPProtectionServiceSingleton extends EventTarget { return this.#state; } - /** - * Checks if the proxy is active and was activated. - * - * @returns {Date} - */ - get activatedAt() { - return this.proxyManager?.active && this.proxyManager?.activatedAt; - } - constructor() { super(); @@ -137,8 +127,6 @@ class IPProtectionServiceSingleton extends EventTarget { return; } - this.proxyManager = new lazy.IPPProxyManager(this.guardian); - this.#helpers.forEach(helper => helper.init()); this.#updateState(); @@ -159,7 +147,6 @@ class IPProtectionServiceSingleton extends EventTarget { if (this.#state === IPProtectionStates.ACTIVE) { this.stop(false); } - this.proxyManager?.destroy(); this.errors = []; @@ -203,7 +190,7 @@ class IPProtectionServiceSingleton extends EventTarget { let started; try { - started = await this.proxyManager.start(); + started = await lazy.IPPProxyManager.start(); } catch (error) { this.#setErrorState(ERRORS.GENERIC, error); } @@ -232,11 +219,11 @@ class IPProtectionServiceSingleton extends EventTarget { * True if started by user action, false if system action */ async stop(userAction = true) { - if (!this.proxyManager?.active) { + if (!lazy.IPPProxyManager.active) { return; } - const sessionLength = this.proxyManager.stop(); + const sessionLength = lazy.IPPProxyManager.stop(); Glean.ipprotection.toggled.record({ userAction, @@ -301,7 +288,7 @@ class IPProtectionServiceSingleton extends EventTarget { } // The connection is already active. - if (this.proxyManager?.active) { + if (lazy.IPPProxyManager.active) { return IPProtectionStates.ACTIVE; } diff --git a/browser/components/ipprotection/docs/Components.rst b/browser/components/ipprotection/docs/Components.rst @@ -29,27 +29,25 @@ A diagram of all the main components is the following: subgraph Helpers IPPStartupCache["Startup Cache Helper"] IPPSignInWatcher["Sign-in Observer"] + IPProtectionServerlist + IPPEarlyStartupFilter["Early Startup Filter Helper"] + IPPProxyManager UIHelper["UI Helper"] - AccountResetHelper["Account Reset Helper"] VPNAddonHelper["VPN Add-on Helper"] - IPPNimbusHelper["Nimbus Eligibility Helper"] IPPAutoStart["Auto-Start Helper"] - IPPEarlyStartupFilter["Early Startup Filter Helper"] IPPEnrollAndEntitleManager["Enroll & Entitle Manager"] + IPPNimbusHelper["Nimbus Eligibility Helper"] end %% Proxy stack subgraph Proxy - IPPProxyManager IPPChannelFilter IPProtectionUsage IPPNetworkErrorObserver - IPProtectionServerlist GuardianClient end %% Service wiring - IPProtectionService --> IPPProxyManager IPProtectionService --> GuardianClient IPProtectionService --> Helpers @@ -58,11 +56,9 @@ A diagram of all the main components is the following: IPProtection --> IPProtectionService %% Proxy wiring - IPPProxyManager --> GuardianClient IPPProxyManager --> IPPChannelFilter IPPProxyManager --> IPProtectionUsage IPPProxyManager --> IPPNetworkErrorObserver - IPPProxyManager --> IPProtectionServerlist IPPNetworkErrorObserver -- "error events (401)" --> IPPProxyManager @@ -141,6 +137,10 @@ IPPEnrollAndEntitleManager Orchestrates the user enrollment flow with Guardian and updates the service when enrollment status changes. +IPPProxyManager + Manages the proxy lifecycle: requests proxy passes, selects the active server, + and exposes the connection status to the rest of the feature. + How to implement new components ------------------------------- diff --git a/browser/components/ipprotection/tests/browser/browser_IPPProxyManager.js b/browser/components/ipprotection/tests/browser/browser_IPPProxyManager.js @@ -4,9 +4,6 @@ "use strict"; -const { IPPProxyManager } = ChromeUtils.importESModule( - "resource:///modules/ipprotection/IPPProxyManager.sys.mjs" -); const { IPProtectionServerlist } = ChromeUtils.importESModule( "resource:///modules/ipprotection/IPProtectionServerlist.sys.mjs" ); @@ -21,11 +18,9 @@ add_task(async function test_IPPProxyManager_handleProxyErrorEvent() { }); let cleanupAlpha = await setupExperiment({ enabled: true, variant: "alpha" }); - let proxyManager = new IPPProxyManager(IPProtectionService.guardian); - await IPProtectionServerlist.maybeFetchList(); - await proxyManager.start(); + await IPPProxyManager.start(); const cases = [ { @@ -56,7 +51,7 @@ add_task(async function test_IPPProxyManager_handleProxyErrorEvent() { ]; for (const testCase of cases) { - const originalIsolationKey = proxyManager.isolationKey; + const originalIsolationKey = IPPProxyManager.isolationKey; // Create the error event const errorEvent = new CustomEvent("proxy-http-error", { detail: { @@ -68,7 +63,7 @@ add_task(async function test_IPPProxyManager_handleProxyErrorEvent() { console.log(`Testing: ${testCase.name}`); - const result = proxyManager.handleProxyErrorEvent(errorEvent); + const result = IPPProxyManager.handleProxyErrorEvent(errorEvent); if (testCase.shouldRotate) { Assert.ok( @@ -78,7 +73,7 @@ add_task(async function test_IPPProxyManager_handleProxyErrorEvent() { await result; - const newIsolationKey = proxyManager.isolationKey; + const newIsolationKey = IPPProxyManager.isolationKey; Assert.notEqual( originalIsolationKey, newIsolationKey, @@ -91,7 +86,7 @@ add_task(async function test_IPPProxyManager_handleProxyErrorEvent() { `${testCase.name}: Should not return a promise when rotation is not triggered` ); - const unchangedIsolationKey = proxyManager.isolationKey; + const unchangedIsolationKey = IPPProxyManager.isolationKey; Assert.equal( originalIsolationKey, unchangedIsolationKey, @@ -101,8 +96,8 @@ add_task(async function test_IPPProxyManager_handleProxyErrorEvent() { } // Test inactive connection - const isolationKeyBeforeStop = proxyManager.isolationKey; - proxyManager.stop(); + const isolationKeyBeforeStop = IPPProxyManager.isolationKey; + IPPProxyManager.stop(); const inactiveErrorEvent = new CustomEvent("proxy-http-error", { detail: { @@ -112,7 +107,8 @@ add_task(async function test_IPPProxyManager_handleProxyErrorEvent() { }, }); - const inactiveResult = proxyManager.handleProxyErrorEvent(inactiveErrorEvent); + const inactiveResult = + IPPProxyManager.handleProxyErrorEvent(inactiveErrorEvent); Assert.equal( inactiveResult, undefined, diff --git a/browser/components/ipprotection/tests/browser/browser_IPProtectionService.js b/browser/components/ipprotection/tests/browser/browser_IPProtectionService.js @@ -339,7 +339,7 @@ add_task(async function test_IPProtectionService_retry_errors() { IPProtectionService, "IPProtectionService:StateChanged", false, - () => !!IPProtectionService.activatedAt + () => !!IPPProxyManager.activatedAt ); content.connectionToggleEl.click(); @@ -385,7 +385,7 @@ add_task(async function test_IPProtectionService_stop_on_signout() { IPProtectionService, "IPProtectionService:StateChanged", false, - () => !!IPProtectionService.activatedAt + () => !!IPPProxyManager.activatedAt ); content.connectionToggleEl.click(); @@ -401,7 +401,7 @@ add_task(async function test_IPProtectionService_stop_on_signout() { IPProtectionService, "IPProtectionService:StateChanged", false, - () => !IPProtectionService.activatedAt + () => !IPPProxyManager.activatedAt ); setupService({ diff --git a/browser/components/ipprotection/tests/browser/browser_ipprotection_telemetry.js b/browser/components/ipprotection/tests/browser/browser_ipprotection_telemetry.js @@ -63,7 +63,7 @@ add_task(async function user_toggle_on_and_off() { lazy.IPProtectionService, "IPProtectionService:StateChanged", false, - () => !!IPProtectionService.activatedAt + () => !!IPPProxyManager.activatedAt ); // Toggle the VPN on toggle.click(); @@ -79,7 +79,7 @@ add_task(async function user_toggle_on_and_off() { lazy.IPProtectionService, "IPProtectionService:StateChanged", false, - () => !IPProtectionService.activatedAt + () => !IPPProxyManager.activatedAt ); // Toggle the VPN off toggle.click(); @@ -149,7 +149,7 @@ add_task(async function toggle_off_on_shutdown() { lazy.IPProtectionService, "IPProtectionService:StateChanged", false, - () => !!IPProtectionService.activatedAt + () => !!IPPProxyManager.activatedAt ); // Toggle the VPN on toggle.click(); diff --git a/browser/components/ipprotection/tests/browser/browser_ipprotection_toolbar.js b/browser/components/ipprotection/tests/browser/browser_ipprotection_toolbar.js @@ -88,7 +88,7 @@ add_task(async function toolbar_icon_status() { lazy.IPProtectionService, "IPProtectionService:StateChanged", false, - () => !!IPProtectionService.activatedAt + () => !!IPPProxyManager.activatedAt ); // Toggle the VPN on toggle.click(); @@ -135,7 +135,7 @@ add_task(async function toolbar_icon_status_new_window() { lazy.IPProtectionService, "IPProtectionService:StateChanged", false, - () => !!IPProtectionService.activatedAt + () => !!IPPProxyManager.activatedAt ); // Toggle the VPN on content.connectionToggleEl.click(); diff --git a/browser/components/ipprotection/tests/browser/head.js b/browser/components/ipprotection/tests/browser/head.js @@ -13,6 +13,10 @@ const { IPProtectionService, IPProtectionStates } = ChromeUtils.importESModule( "resource:///modules/ipprotection/IPProtectionService.sys.mjs" ); +const { IPPProxyManager } = ChromeUtils.importESModule( + "resource:///modules/ipprotection/IPPProxyManager.sys.mjs" +); + const { IPPSignInWatcher } = ChromeUtils.importESModule( "resource:///modules/ipprotection/IPPSignInWatcher.sys.mjs" ); diff --git a/browser/components/ipprotection/tests/xpcshell/test_IPProtectionService.js b/browser/components/ipprotection/tests/xpcshell/test_IPProtectionService.js @@ -9,6 +9,9 @@ const { AddonTestUtils } = ChromeUtils.importESModule( const { ExtensionTestUtils } = ChromeUtils.importESModule( "resource://testing-common/ExtensionXPCShellUtils.sys.mjs" ); +const { IPPProxyManager } = ChromeUtils.importESModule( + "resource:///modules/ipprotection/IPPProxyManager.sys.mjs" +); const { IPProtectionService, IPProtectionStates } = ChromeUtils.importESModule( "resource:///modules/ipprotection/IPProtectionService.sys.mjs" ); @@ -88,7 +91,7 @@ add_task(async function test_IPProtectionService_start() { ); Assert.ok( - !IPProtectionService.activatedAt, + !IPPProxyManager.activatedAt, "IP Protection service should not be active initially" ); @@ -108,11 +111,11 @@ add_task(async function test_IPProtectionService_start() { "IP Protection service should be active after starting" ); Assert.ok( - IPProtectionService.activatedAt, + !!IPPProxyManager.activatedAt, "IP Protection service should have an activation timestamp" ); Assert.ok( - IPProtectionService.proxyManager.active, + IPPProxyManager.active, "IP Protection service should have an active connection" ); @@ -152,7 +155,7 @@ add_task(async function test_IPProtectionService_stop() { "IP Protection service should not be active after stopping" ); Assert.ok( - !IPProtectionService.activatedAt, + !IPPProxyManager.activatedAt, "IP Protection service should not have an activation timestamp after stopping" ); Assert.ok( diff --git a/browser/components/ipprotection/tests/xpcshell/test_IPProxyManager.js b/browser/components/ipprotection/tests/xpcshell/test_IPProxyManager.js @@ -7,12 +7,12 @@ const { IPPProxyManager } = ChromeUtils.importESModule( "resource:///modules/ipprotection/IPPProxyManager.sys.mjs" ); +const { IPProtectionService } = ChromeUtils.importESModule( + "resource:///modules/ipprotection/IPProtectionService.sys.mjs" +); const { IPProtectionServerlist } = ChromeUtils.importESModule( "resource:///modules/ipprotection/IPProtectionServerlist.sys.mjs" ); -const { GuardianClient } = ChromeUtils.importESModule( - "resource:///modules/ipprotection/GuardianClient.sys.mjs" -); add_setup(async function () { await putServerInRemoteSettings(); @@ -24,8 +24,7 @@ add_setup(async function () { */ add_task(async function test_IPPProxyManager_start_stop_reset() { let sandbox = sinon.createSandbox(); - let guardian = new GuardianClient(); - sandbox.stub(guardian, "fetchProxyPass").returns({ + sandbox.stub(IPProtectionService.guardian, "fetchProxyPass").returns({ status: 200, error: undefined, pass: { @@ -36,28 +35,26 @@ add_task(async function test_IPPProxyManager_start_stop_reset() { await IPProtectionServerlist.maybeFetchList(); - let proxyManager = new IPPProxyManager(guardian); + await IPPProxyManager.start(); - await proxyManager.start(); - - Assert.ok(proxyManager.active, "Should be active after starting"); + Assert.ok(IPPProxyManager.active, "Should be active after starting"); Assert.ok( - proxyManager.isolationKey, + IPPProxyManager.isolationKey, "Should have an isolationKey after starting" ); Assert.ok( - proxyManager.hasValidProxyPass, + IPPProxyManager.hasValidProxyPass, "Should have a valid proxy pass after starting" ); - await proxyManager.stop(); + await IPPProxyManager.stop(); - Assert.ok(!proxyManager.active, "Should not be active after starting"); + Assert.ok(!IPPProxyManager.active, "Should not be active after starting"); Assert.ok( - !proxyManager.isolationKey, + !IPPProxyManager.isolationKey, "Should not have an isolationKey after stopping" ); @@ -70,8 +67,7 @@ add_task(async function test_IPPProxyManager_start_stop_reset() { */ add_task(async function test_IPPProxyManager_reset() { let sandbox = sinon.createSandbox(); - let guardian = new GuardianClient(); - sandbox.stub(guardian, "fetchProxyPass").returns({ + sandbox.stub(IPProtectionService.guardian, "fetchProxyPass").returns({ status: 200, error: undefined, pass: { @@ -80,33 +76,31 @@ add_task(async function test_IPPProxyManager_reset() { }, }); - let proxyManager = new IPPProxyManager(guardian); - - await proxyManager.start(); + await IPPProxyManager.start(); - Assert.ok(proxyManager.active, "Should be active after starting"); + Assert.ok(IPPProxyManager.active, "Should be active after starting"); Assert.ok( - proxyManager.isolationKey, + IPPProxyManager.isolationKey, "Should have an isolationKey after starting" ); Assert.ok( - proxyManager.hasValidProxyPass, + IPPProxyManager.hasValidProxyPass, "Should have a valid proxy pass after starting" ); - await proxyManager.reset(); + await IPPProxyManager.reset(); - Assert.ok(!proxyManager.active, "Should not be active after starting"); + Assert.ok(!IPPProxyManager.active, "Should not be active after starting"); Assert.ok( - !proxyManager.isolationKey, + !IPPProxyManager.isolationKey, "Should not have an isolationKey after stopping" ); Assert.ok( - !proxyManager.hasValidProxyPass, + !IPPProxyManager.hasValidProxyPass, "Should not have a proxy pass after stopping" );