Skip to content

Commit

Permalink
FXVPN-12 Allow manipulation of client settings
Browse files Browse the repository at this point in the history
  • Loading branch information
strseb committed Dec 10, 2024
1 parent 926f6a4 commit a115c7e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/background/vpncontroller/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const REQUEST_TYPES = [
"session_start",
"session_stop",
"interventions",
"settings",
];

export class VPNState {
Expand Down Expand Up @@ -214,3 +215,7 @@ export class vpnStatusResponse {
version: "2.25.0",
};
}

export class VPNSettings {
extensionTelemetryEnabled = false;
}
18 changes: 18 additions & 0 deletions src/background/vpncontroller/vpncontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
StateVPNClosed,
StateVPNSignedOut,
StateVPNNeedsUpdate,
VPNSettings,
} from "./states.js";

const log = Logger.logger("TabHandler");
Expand All @@ -47,6 +48,7 @@ export class VPNController extends Component {
postToApp: PropertyType.Function,
isolationKey: PropertyType.Bindable,
featureList: PropertyType.Bindable,
settings: PropertyType.Bindable,
};

get state() {
Expand All @@ -66,6 +68,9 @@ export class VPNController extends Component {
get interventions() {
return this.#mInterventions;
}
get settings() {
return this.#settings.readOnly;
}

initNativeMessaging() {
log("initNativeMessaging");
Expand Down Expand Up @@ -188,6 +193,17 @@ export class VPNController extends Component {
...new FeatureFlags(),
...response.featurelist,
});
break;
case "settings":
const settings = new VPNSettings();
// Copy over all values that we expect to be in VPNSettings
Object.keys(settings).forEach((k) => {
if (response.settings[k]) {
settings[k] = response.settings[k];
}
});
this.#settings.set(settings);
break;
default:
console.log("Unexpected Message type: " + response.t);
}
Expand All @@ -210,6 +226,7 @@ export class VPNController extends Component {
this.postToApp("status");
this.postToApp("servers");
this.postToApp("disabled_apps");
this.postToApp("settings");
});
return;
}
Expand Down Expand Up @@ -247,6 +264,7 @@ export class VPNController extends Component {
#isExcluded = property(false);

#mInterventions = property([]);
#settings = property(new VPNSettings());
}

export function isSplitTunnled(
Expand Down
34 changes: 34 additions & 0 deletions tests/jest/background/vpncontroller/vpncontroller.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
isSplitTunnled,
ServerCity,
ServerCountry,
VPNController,
VPNSettings,
vpnStatusResponse,
} from "../../../../src/background/vpncontroller";

Expand Down Expand Up @@ -178,3 +180,35 @@ describe("fromVPNStatusResponse", () => {
expect(result.state).toBe("NeedsUpdate");
});
});

describe("IPC::Settings", () => {
it("can handle a setting response", async () => {
const target = new VPNController({ registerObserver: () => {} });
// The Value should be the default one.
expect(target.settings.value.extensionTelemetryEnabled).toBe(
new VPNSettings().extensionTelemetryEnabled
);
// The VPN Client may at any point push new data
const message = {
t: "settings",
settings: {
extensionTelemetryEnabled: true,
},
};
await target.handleResponse(message);
expect(target.settings.value.extensionTelemetryEnabled).toBe(
message.settings.extensionTelemetryEnabled
);
});
it("ignores unknown settings", async () => {
const target = new VPNController({ registerObserver: () => {} });
const message = {
t: "settings",
settings: {
thisSettingDoesNotExist: true,
},
};
await target.handleResponse(message);
expect(target.settings.value["thisSettingDoesNotExist"]).toBe(undefined);
});
});

0 comments on commit a115c7e

Please sign in to comment.