48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
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 = "client";
|
|
process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "vpn-proxy-test-"));
|
|
process.env.SING_BOX_CACHE = path.join(process.env.DATA_DIR, "cache.db");
|
|
|
|
const { buildGatewayConfig } = await import(
|
|
`../../src/server/singbox.js?client-mode=${Date.now()}`
|
|
);
|
|
|
|
const subscriptionConfig = {
|
|
outbounds: [
|
|
{
|
|
type: "vless",
|
|
tag: "test-vpn",
|
|
server: "vpn.example.test",
|
|
server_port: 443,
|
|
uuid: "00000000-0000-4000-8000-000000000000",
|
|
tls: { enabled: true },
|
|
},
|
|
],
|
|
customRules: [],
|
|
};
|
|
|
|
test("client mode exposes only the local mixed proxy inbound", () => {
|
|
const config = buildGatewayConfig(subscriptionConfig, "test-vpn");
|
|
|
|
assert.deepEqual(
|
|
config.inbounds.map((inbound) => inbound.tag),
|
|
["mixed-in"],
|
|
);
|
|
assert.equal(config.inbounds[0].type, "mixed");
|
|
assert.equal(config.inbounds[0].listen_port, 8080);
|
|
});
|
|
|
|
test("client mode routes mixed proxy fallback to the selected VPN", () => {
|
|
const config = buildGatewayConfig(subscriptionConfig, "test-vpn");
|
|
|
|
assert.deepEqual(config.route.rule_set, []);
|
|
assert.deepEqual(config.route.rules, [
|
|
{ inbound: ["mixed-in"], outbound: "test-vpn" },
|
|
]);
|
|
});
|