feat: add windows proxy-only app mode
This commit is contained in:
61
test/server/singbox-windows-mode.test.js
Normal file
61
test/server/singbox-windows-mode.test.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
process.env.APP_MODE = "windows";
|
||||
process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "vpn-proxy-windows-test-"));
|
||||
process.env.SING_BOX_CACHE = path.join(process.env.DATA_DIR, "cache.db");
|
||||
process.env.PROXY_PORT = "1080";
|
||||
process.env.PROXY_BIND_IP = "127.0.0.1";
|
||||
|
||||
const { settings } = await import(
|
||||
`../../src/server/config.js?windows-mode=${Date.now()}`
|
||||
);
|
||||
const { buildGatewayConfig } = await import(
|
||||
`../../src/server/singbox.js?windows-mode=${Date.now()}`
|
||||
);
|
||||
|
||||
const subscriptionConfig = {
|
||||
outbounds: [
|
||||
{
|
||||
type: "vless",
|
||||
tag: "win-vpn",
|
||||
server: "vpn.example.test",
|
||||
server_port: 443,
|
||||
uuid: "00000000-0000-4000-8000-000000000000",
|
||||
tls: { enabled: true },
|
||||
},
|
||||
],
|
||||
customRules: [],
|
||||
};
|
||||
|
||||
test("settings accepts APP_MODE=windows", () => {
|
||||
assert.equal(settings.appMode, "windows");
|
||||
assert.equal(settings.proxyPort, 1080);
|
||||
assert.equal(settings.bindIp, "127.0.0.1");
|
||||
});
|
||||
|
||||
test("windows mode exposes only local mixed proxy inbound", () => {
|
||||
const config = buildGatewayConfig(subscriptionConfig, "win-vpn");
|
||||
|
||||
assert.deepEqual(config.inbounds.map((inbound) => inbound.tag), ["mixed-in"]);
|
||||
assert.equal(config.inbounds[0].type, "mixed");
|
||||
assert.equal(config.inbounds[0].listen, "127.0.0.1");
|
||||
assert.equal(config.inbounds[0].listen_port, 1080);
|
||||
});
|
||||
|
||||
test("windows mode routes mixed proxy to selected VPN outbound", () => {
|
||||
const config = buildGatewayConfig(subscriptionConfig, "win-vpn");
|
||||
|
||||
assert.deepEqual(config.route.rule_set, []);
|
||||
assert.deepEqual(config.route.rules, [
|
||||
{ inbound: ["mixed-in"], outbound: "win-vpn" },
|
||||
]);
|
||||
assert.deepEqual(config.outbounds.map((outbound) => outbound.tag), [
|
||||
"win-vpn",
|
||||
"direct",
|
||||
"block",
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user