Simplify proxy routing and configuration
This commit is contained in:
@@ -43,3 +43,23 @@ test("client proxy range defaults to the single configured proxy port", async ()
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("client proxy defaults to 8082 when no port is configured", async () => {
|
||||
await withEnv(
|
||||
{
|
||||
APP_MODE: "client",
|
||||
PROXY_PORT: undefined,
|
||||
CLIENT_PROXY_PORT_START: undefined,
|
||||
CLIENT_PROXY_PORT_END: undefined,
|
||||
},
|
||||
async () => {
|
||||
const { settings } = await import(
|
||||
`../../src/server/config.js?client-default-port=${Date.now()}`
|
||||
);
|
||||
|
||||
assert.equal(settings.proxyPort, 8082);
|
||||
assert.equal(settings.clientProxyPortStart, 8082);
|
||||
assert.equal(settings.clientProxyPortEnd, 8082);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ test("client mode exposes only the local mixed proxy inbound", () => {
|
||||
["mixed-in"],
|
||||
);
|
||||
assert.equal(config.inbounds[0].type, "mixed");
|
||||
assert.equal(config.inbounds[0].listen_port, 8080);
|
||||
assert.equal(config.inbounds[0].listen_port, 8082);
|
||||
});
|
||||
|
||||
test("client mode routes mixed proxy fallback to the selected VPN", () => {
|
||||
@@ -92,7 +92,7 @@ test("client mode ignores saved proxy port outside the published single port", (
|
||||
|
||||
const config = buildGatewayConfig(subscriptionConfig, "test-vpn");
|
||||
|
||||
assert.equal(config.inbounds[0].listen_port, 8080);
|
||||
assert.equal(config.inbounds[0].listen_port, 8082);
|
||||
assert.deepEqual(config.route.rules, [
|
||||
{ inbound: ["mixed-in"], outbound: "test-vpn" },
|
||||
]);
|
||||
|
||||
12
test/server/subscription.test.js
Normal file
12
test/server/subscription.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { parseSubscriptionBody } from '../../src/server/subscription.js';
|
||||
|
||||
test('subscription server tags are trimmed for selection', () => {
|
||||
const { servers } = parseSubscriptionBody(JSON.stringify({
|
||||
outbounds: [{ type: 'vless', tag: 'de-frankfurt ', server: 'de.example', server_port: 443 }],
|
||||
}));
|
||||
|
||||
assert.equal(servers[0].tag, 'de-frankfurt');
|
||||
});
|
||||
46
test/web/client-controls.test.js
Normal file
46
test/web/client-controls.test.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import {
|
||||
connectionAction,
|
||||
formatConnectionDuration,
|
||||
localProxyUrls,
|
||||
subscriptionDomain,
|
||||
} from '../../src/web/utils/clientControls.js';
|
||||
|
||||
test('connection button chooses the only valid client action', () => {
|
||||
assert.deepEqual(connectionAction({ connected: true }), { type: 'stop' });
|
||||
assert.deepEqual(connectionAction({ selectedTag: 'nl-amsterdam' }), {
|
||||
type: 'apply',
|
||||
selectedTag: 'nl-amsterdam',
|
||||
});
|
||||
assert.deepEqual(connectionAction({ configExists: true }), { type: 'restart' });
|
||||
assert.equal(connectionAction({}), null);
|
||||
});
|
||||
|
||||
test('connection duration is derived from the backend start time', () => {
|
||||
const startedAt = '2026-07-10T10:00:00.000Z';
|
||||
const now = Date.parse('2026-07-11T12:03:04.900Z');
|
||||
|
||||
assert.equal(formatConnectionDuration(startedAt, now), '26:03:04');
|
||||
assert.equal(formatConnectionDuration(null, now), '00:00:00');
|
||||
});
|
||||
|
||||
test('saved subscription is reduced to its public domain', () => {
|
||||
assert.equal(subscriptionDomain('sub.example.com/…'), 'sub.example.com');
|
||||
assert.equal(subscriptionDomain(''), '');
|
||||
});
|
||||
|
||||
test('local proxy exposes both supported URLs', () => {
|
||||
assert.deepEqual(localProxyUrls(18080), {
|
||||
socks5: 'socks5://127.0.0.1:18080',
|
||||
http: 'http://127.0.0.1:18080',
|
||||
});
|
||||
});
|
||||
|
||||
test('local proxy defaults to the macOS client port', () => {
|
||||
assert.deepEqual(localProxyUrls(), {
|
||||
socks5: 'socks5://127.0.0.1:8082',
|
||||
http: 'http://127.0.0.1:8082',
|
||||
});
|
||||
});
|
||||
@@ -1,92 +0,0 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { resolveClientRoute } from "../../src/web/utils/clientRoute.js";
|
||||
|
||||
test("shows gateway route as the active Mac connection", () => {
|
||||
const route = resolveClientRoute({
|
||||
state: {
|
||||
singboxRunning: true,
|
||||
proxyPort: 18080,
|
||||
clientSettings: {
|
||||
sharedProxyEnabled: true,
|
||||
sharedProxy: { host: "192.168.50.111", port: 8080, protocol: "socks5" },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(route.mode, "gateway");
|
||||
assert.equal(route.status, "connected");
|
||||
assert.equal(route.title, "Подключено к gateway");
|
||||
assert.equal(route.target, "192.168.50.111:8080");
|
||||
assert.deepEqual(route.path, [
|
||||
"Mac apps",
|
||||
"127.0.0.1:18080",
|
||||
"Gateway 192.168.50.111:8080",
|
||||
"Internet",
|
||||
]);
|
||||
});
|
||||
|
||||
test("shows local VPN route with selected server", () => {
|
||||
const route = resolveClientRoute({
|
||||
state: {
|
||||
singboxRunning: true,
|
||||
proxyPort: 8082,
|
||||
selectedTag: "nl-amsterdam",
|
||||
clientSettings: {},
|
||||
},
|
||||
activeServer: { tag: "nl-amsterdam", country: "NL" },
|
||||
});
|
||||
|
||||
assert.equal(route.mode, "vpn");
|
||||
assert.equal(route.status, "connected");
|
||||
assert.equal(route.title, "Подключено через VPN");
|
||||
assert.equal(route.target, "nl-amsterdam");
|
||||
});
|
||||
|
||||
test("shows direct route when home mode is enabled", () => {
|
||||
const route = resolveClientRoute({
|
||||
state: {
|
||||
singboxRunning: true,
|
||||
proxyPort: 8082,
|
||||
clientSettings: { homeBypassEnabled: true },
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(route.mode, "direct");
|
||||
assert.equal(route.status, "connected");
|
||||
assert.equal(route.title, "Подключено напрямую");
|
||||
assert.equal(route.target, "без VPN");
|
||||
});
|
||||
|
||||
test("shows configured but stopped route clearly", () => {
|
||||
const route = resolveClientRoute({
|
||||
state: {
|
||||
singboxRunning: false,
|
||||
configExists: true,
|
||||
proxyPort: 8082,
|
||||
selectedTag: "nl-amsterdam",
|
||||
clientSettings: {},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(route.mode, "vpn");
|
||||
assert.equal(route.status, "stopped");
|
||||
assert.equal(route.title, "VPN настроен, но остановлен");
|
||||
});
|
||||
|
||||
test("shows missing setup when nothing is configured", () => {
|
||||
const route = resolveClientRoute({
|
||||
state: {
|
||||
singboxRunning: false,
|
||||
configExists: false,
|
||||
proxyPort: 8082,
|
||||
clientSettings: {},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(route.mode, "none");
|
||||
assert.equal(route.status, "empty");
|
||||
assert.equal(route.title, "Не подключено");
|
||||
assert.equal(route.target, "выберите режим");
|
||||
});
|
||||
Reference in New Issue
Block a user