fix: harden mac nordvpn status inference
This commit is contained in:
@@ -417,6 +417,39 @@ function normalizeSuccessfulConnectState(state, connectResult, verified) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeStatusState(state) {
|
||||||
|
if (
|
||||||
|
!state ||
|
||||||
|
state.platform !== "darwin" ||
|
||||||
|
state.controlMode !== "wireguard" ||
|
||||||
|
state.connected ||
|
||||||
|
!state.wireguard ||
|
||||||
|
state.wireguard.active ||
|
||||||
|
!state.wireguard.endpoint ||
|
||||||
|
!state.wireguard.lastConnection ||
|
||||||
|
!state.publicIp ||
|
||||||
|
!state.publicIp.ok
|
||||||
|
) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
const target =
|
||||||
|
state.wireguard.lastConnection.resolvedTarget ||
|
||||||
|
state.wireguard.lastConnection.requestedTarget;
|
||||||
|
if (!target || !locationMatches(state.publicIp, target)) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
connected: true,
|
||||||
|
wireguard: {
|
||||||
|
...state.wireguard,
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function fetchJson(url, headers = {}) {
|
function fetchJson(url, headers = {}) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const targetUrl = new URL(url);
|
const targetUrl = new URL(url);
|
||||||
@@ -1293,7 +1326,7 @@ async function main() {
|
|||||||
try {
|
try {
|
||||||
if (action === "status") {
|
if (action === "status") {
|
||||||
const ipInfo = await getPublicIpInfo();
|
const ipInfo = await getPublicIpInfo();
|
||||||
emitJson(buildStateSummary(installProbe, ipInfo));
|
emitJson(normalizeStatusState(buildStateSummary(installProbe, ipInfo)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action === "install") {
|
if (action === "install") {
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ module.exports = {
|
|||||||
typeof isMacTailscaleActive === "function" ? isMacTailscaleActive : undefined,
|
typeof isMacTailscaleActive === "function" ? isMacTailscaleActive : undefined,
|
||||||
normalizeSuccessfulConnectState:
|
normalizeSuccessfulConnectState:
|
||||||
typeof normalizeSuccessfulConnectState === "function" ? normalizeSuccessfulConnectState : undefined,
|
typeof normalizeSuccessfulConnectState === "function" ? normalizeSuccessfulConnectState : undefined,
|
||||||
|
normalizeStatusState:
|
||||||
|
typeof normalizeStatusState === "function" ? normalizeStatusState : undefined,
|
||||||
sanitizeOutputPayload:
|
sanitizeOutputPayload:
|
||||||
typeof sanitizeOutputPayload === "function" ? sanitizeOutputPayload : undefined,
|
typeof sanitizeOutputPayload === "function" ? sanitizeOutputPayload : undefined,
|
||||||
shouldAttemptMacWireguardDisconnect:
|
shouldAttemptMacWireguardDisconnect:
|
||||||
@@ -204,6 +206,33 @@ test("normalizeSuccessfulConnectState marks the connect snapshot active after ve
|
|||||||
assert.equal(state.wireguard.endpoint, "de1227.nordvpn.com:51820");
|
assert.equal(state.wireguard.endpoint, "de1227.nordvpn.com:51820");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("normalizeStatusState marks macOS wireguard connected when public IP matches the last successful target", () => {
|
||||||
|
const { normalizeStatusState } = loadInternals();
|
||||||
|
assert.equal(typeof normalizeStatusState, "function");
|
||||||
|
|
||||||
|
const state = normalizeStatusState({
|
||||||
|
platform: "darwin",
|
||||||
|
controlMode: "wireguard",
|
||||||
|
connected: false,
|
||||||
|
wireguard: {
|
||||||
|
active: false,
|
||||||
|
endpoint: "tr73.nordvpn.com:51820",
|
||||||
|
lastConnection: {
|
||||||
|
requestedTarget: { country: "Turkey", city: "" },
|
||||||
|
resolvedTarget: { country: "Turkey", city: "Istanbul" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
publicIp: {
|
||||||
|
ok: true,
|
||||||
|
country: "Turkey",
|
||||||
|
city: "Istanbul",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(state.connected, true);
|
||||||
|
assert.equal(state.wireguard.active, true);
|
||||||
|
});
|
||||||
|
|
||||||
test("sanitizeOutputPayload redacts local path metadata from normal JSON output", () => {
|
test("sanitizeOutputPayload redacts local path metadata from normal JSON output", () => {
|
||||||
const { sanitizeOutputPayload } = loadInternals();
|
const { sanitizeOutputPayload } = loadInternals();
|
||||||
assert.equal(typeof sanitizeOutputPayload, "function");
|
assert.equal(typeof sanitizeOutputPayload, "function");
|
||||||
|
|||||||
Reference in New Issue
Block a user