Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FXVPN-12 - Allow Extension to set Client Telemetry Setting #134

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
Loading