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

Add split-tunnel message #195

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions src/assets/img/message-split-tunnel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/background/vpncontroller/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,6 @@ export class BridgeResponse {
status;
/** @type {string|undefined} */
error;
/** @type {string|undefined} */
exe;
}
48 changes: 25 additions & 23 deletions src/background/vpncontroller/vpncontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Utils } from "../../shared/utils.js";
import {
IBindable,
WritableProperty,
propertySum,
property,
} from "../../shared/property.js";
import { PropertyType } from "../../shared/ipc.js";
Expand Down Expand Up @@ -58,9 +59,6 @@ export class VPNController extends Component {
get servers() {
return this.#mServers;
}
get isExcluded() {
return this.#isExcluded;
}
/** @type {IBindable<FeatureFlags>} */
get featureList() {
return this.#mFeaturelist;
Expand Down Expand Up @@ -134,6 +132,11 @@ export class VPNController extends Component {
});

this.initNativeMessaging();

// Whenever the applist changes, make sure we check if that is us.
this.#mSplitTunnledApps.subscribe(() => {
this.postToApp("proc_info");
});
}
/**
* Sends a message to the client
Expand Down Expand Up @@ -178,7 +181,7 @@ export class VPNController extends Component {
this.#mServers.set(response.servers.countries);
break;
case "disabled_apps":
this.#isExcluded.set(isSplitTunnled(response));
this.#mSplitTunnledApps.set(response["disabled_apps"]);
break;
case "status":
const newStatus = fromVPNStatusResponse(response, this.#mServers.value);
Expand Down Expand Up @@ -225,6 +228,10 @@ export class VPNController extends Component {
async handleBridgeResponse(response, state) {
const currentState = state.value;
// We can only get 2 types of messages right now: client-down/up
if (response.exe) {
this.#mParentProcess.set(response.exe);
}

if (
(response.status && response.status === "vpn-client-down") ||
(response.error && response.error === "vpn-client-down")
Expand Down Expand Up @@ -281,31 +288,26 @@ export class VPNController extends Component {

#mFeaturelist = property(new FeatureFlags());

#isExcluded = property(false);

#mSplitTunnledApps = property([]);
#mParentProcess = property("");
#mInterventions = property([]);
#settings = property(new VPNSettings());

isExcluded = propertySum(
isSplitTunnled,
this.#mParentProcess,
this.#mSplitTunnledApps
);
}

export function isSplitTunnled(
response = {
t: "disabled_apps",
disabled_apps: [""],
export function isSplitTunnled(parent = "", apps = [""]) {
if (parent == "") {
return false;
}
) {
if (response.t != "disabled_apps") {
throw new Error("passed an invalid response");
if (apps.length == 0) {
return false;
}
// Todo: THIS IS STILL HACKY
const search_terms = ["firefox.exe", "firefox"];
let apps = response.disabled_apps;
apps ??= [];
const isFirefoxExcluded = apps.some((path) => {
return search_terms.some((searchPath) => {
return path.endsWith(searchPath);
});
});
return isFirefoxExcluded;
return apps.some((app) => app === parent.replaceAll("\\", "/"));
}

const MOZILLA_VPN_SERVERS_KEY = "mozillaVpnServers";
Expand Down
7 changes: 7 additions & 0 deletions src/components/prefab-screens.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,10 @@ defineMessageScreen({
secondaryAction: tr("getHelp"),
onSecondaryAction: () => closeAfter(() => open(getHelpUrl)),
});

defineMessageScreen({
tag: "split-tunnel-message-screen",
img: "message-split-tunnel.svg",
heading: tr("messageSplitTunnelHeader"),
bodyText: tr("messageSplitTunnelBody"),
});
3 changes: 3 additions & 0 deletions src/ui/browserAction/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<onboarding-screen-2 slot="onboarding-2"></onboarding-screen-2>
<onboarding-screen-3 slot="onboarding-3"></onboarding-screen-3>
<onboarding-screen-4 slot="onboarding-4"></onboarding-screen-4>
<split-tunnel-message-screen
slot="MessageSplitTunnel"
></split-tunnel-message-screen>
<!-- TODO: Split Tunnel Message, Update Message -->
<popup-browseraction slot="default"> </popup-browseraction>
</popup-condview>
Expand Down
20 changes: 16 additions & 4 deletions src/ui/browserAction/popupConditional.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export class PopUpConditionalView extends ConditionalView {
const supportedPlatform = Utils.isSupportedOs(deviceOs.os);

propertySum(
(state, features, currentPage) => {
(state, features, currentPage, isExcluded) => {
this.slotName = PopUpConditionalView.toSlotname(
state,
features,
supportedPlatform,
currentPage
currentPage,
isExcluded
);
if (this.slotName == !"default") {
requestIdleCallback(() => {
Expand All @@ -34,7 +35,8 @@ export class PopUpConditionalView extends ConditionalView {
},
vpnController.state,
vpnController.featureList,
onboardingController.currentOnboardingPage
onboardingController.currentOnboardingPage,
vpnController.isExcluded
);

// Messages may dispatch an event requesting to send a Command to the VPN
Expand All @@ -57,9 +59,16 @@ export class PopUpConditionalView extends ConditionalView {
* @param {FeatureFlags} features
* @param {Boolean} supportedPlatform
* @param {Number} currentOnboardingPage
* @param {Boolean} isExcluded
* @returns {String}
*/
static toSlotname(state, features, supportedPlatform, currentOnboardingPage) {
static toSlotname(
state,
features,
supportedPlatform,
currentOnboardingPage,
isExcluded
) {
if (!supportedPlatform && !features.webExtension) {
return "MessageOSNotSupported";
}
Expand Down Expand Up @@ -87,6 +96,9 @@ export class PopUpConditionalView extends ConditionalView {
) {
return `onboarding-${currentOnboardingPage}`;
}
if (isExcluded) {
return "MessageSplitTunnel";
}

return "default";
}
Expand Down
40 changes: 9 additions & 31 deletions tests/jest/background/vpncontroller/vpncontroller.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,25 @@ import { property } from "../../../../src/shared/property";

describe("isSplitTunneled", () => {
const cases = [
{ res: true, path: "/soo/bar/Firefox Nightly/firefox.exe" },
{ res: true, path: "/soo/bar/Firefox Developer Edition/firefox.exe" },
{ res: true, path: "/soo/bar/Firefox/firefox.exe" },
{ res: true, path: "/soo/bar/Firefox Nightly/firefox" },
{ res: true, path: "/soo/bar/Firefox Developer Edition/firefox" },
{ res: true, path: "/soo/bar/Firefox/firefox" },
{ res: false, path: "/soo/bar/Waterfox/Waterfox" },
{ res: true, path: "/foo/bar/firefox.exe", parent: "/foo/bar/firefox.exe" },
{
res: true,
path: "/foo/bar/firefox.exe",
parent: "\\foo\\bar\\firefox.exe",
},
{ res: false, path: "/foo/bar/fox.exe", parent: "\\foo\\bar\\firefox.exe" },
];
cases.forEach((c) => {
it(`Should handle ${c.path}`, () => {
expect(
isSplitTunnled({
t: "disabled_apps",
disabled_apps: [c.path],
})
).toBe(c.res);
expect(isSplitTunnled(c.parent, [c.path])).toBe(c.res);
});
});
it(`No apps split tunneled`, () => {
expect(
isSplitTunnled({
t: "disabled_apps",
disabled_apps: [],
})
).toBe(false);
expect(isSplitTunnled("", [])).toBe(false);
});
it(`Has default args`, () => {
expect(isSplitTunnled()).toBe(false);
});
it(`Throws with wrong args`, () => {
try {
isSplitTunnled({
t: "malformed_apps",
disabled_apps: [],
});
// Unreachable Hopefully
expect(null).toBe(true);
} catch (error) {
expect(error.toString()).toContain("passed an invalid response");
}
});
});

describe("fromVPNStatusResponse", () => {
Expand Down