Update Harbor client and gateway functionality
This commit is contained in:
@@ -7,7 +7,7 @@ import { createSubscriptionMutationRoute } from '../../dist/server/http/routes/s
|
||||
|
||||
const oldServer = { id: 'shared', label: 'Old', host: 'old.example', port: 443, protocol: 'vless' };
|
||||
const nextServer = { id: 'next', label: 'Next', host: 'next.example', port: 443, protocol: 'vless' };
|
||||
const routeRules = [{ type: 'domain_suffix', value: 'example', enabled: true }];
|
||||
const routeRules = [{ type: 'domain_suffix', value: 'example', enabled: true, outbound: 'direct' }];
|
||||
|
||||
const profile = (id, label, server = oldServer) => ({
|
||||
id,
|
||||
@@ -47,7 +47,7 @@ function defaultState() {
|
||||
function createHarness(overrides = {}) {
|
||||
let state = structuredClone(overrides.state ?? defaultState());
|
||||
let config = Object.hasOwn(overrides, 'config') ? overrides.config : 'old-config';
|
||||
let gatewayAuto = { mode: 'gateway-direct', gatewayId: 'gateway' };
|
||||
let gatewayAuto = structuredClone(overrides.gatewayAuto ?? { mode: 'local-vpn', gatewayId: '' });
|
||||
let running = overrides.running ?? true;
|
||||
let tail = Promise.resolve();
|
||||
let updateCount = 0;
|
||||
@@ -267,6 +267,25 @@ test('active refresh applies a retained server and keeps last-applied snapshot i
|
||||
assert.equal(after.running, true);
|
||||
});
|
||||
|
||||
test('active refresh publishes the route rules used by the rebuilt config', async () => {
|
||||
const nextRules = [{ type: 'domain', value: 'vpn.example', enabled: true, outbound: 'vpn' }];
|
||||
const state = defaultState();
|
||||
state.routeRules = nextRules;
|
||||
state.appliedRouteRules = routeRules;
|
||||
const local = createHarness({ state, fetchSubscription: async () => parsed('personal', [oldServer]) });
|
||||
await local.service.refreshProfile('personal', state.revision);
|
||||
assert.deepEqual(local.snapshot().state.appliedRouteRules, nextRules);
|
||||
assert.deepEqual(JSON.parse(local.snapshot().config).rules, nextRules);
|
||||
|
||||
const bypassed = createHarness({
|
||||
state,
|
||||
gatewayAuto: { mode: 'gateway-direct', gatewayId: 'gateway' },
|
||||
fetchSubscription: async () => parsed('personal', [oldServer]),
|
||||
});
|
||||
await bypassed.service.refreshProfile('personal', state.revision);
|
||||
assert.deepEqual(bypassed.snapshot().state.appliedRouteRules, []);
|
||||
});
|
||||
|
||||
test('inactive delete is state-only; applied delete requires one stop-and-delete transaction', async () => {
|
||||
const inactive = createHarness();
|
||||
await inactive.service.deleteProfile('work', 'delete', 3);
|
||||
@@ -294,7 +313,7 @@ test('deleting a pending desired profile leaves the running applied route untouc
|
||||
const after = harness.snapshot();
|
||||
assert.equal(after.config, 'old-config');
|
||||
assert.equal(after.running, true);
|
||||
assert.deepEqual(after.gatewayAuto, { mode: 'gateway-direct', gatewayId: 'gateway' });
|
||||
assert.deepEqual(after.gatewayAuto, { mode: 'local-vpn', gatewayId: '' });
|
||||
assert.equal(harness.calls.includes('gateway.set'), false);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user