Files
harbor-net/test/server/gateway-routing.test.js
Dmitriy Petrov 41922ad30b
All checks were successful
Build and Deploy Gateway / build-and-push (push) Successful in 14s
Build and Deploy Gateway / deploy (push) Successful in 1s
Add direct gateway forwarding when VPN is off
2026-07-11 11:37:08 +03:00

29 lines
1.0 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { setGatewayInterception } from '../../src/server/gatewayRouting.js';
test('gateway switches only the TProxy PREROUTING jump', () => {
const calls = [];
const missing = (command, args) => {
calls.push([command, args]);
return { status: args.includes('-C') ? 1 : 0, stderr: '' };
};
setGatewayInterception(true, 'VPN_PROXY_TPROXY', missing);
assert.deepEqual(calls.map(([, args]) => args), [
['-w', '-t', 'mangle', '-C', 'PREROUTING', '-j', 'VPN_PROXY_TPROXY'],
['-w', '-t', 'mangle', '-I', 'PREROUTING', '1', '-j', 'VPN_PROXY_TPROXY'],
]);
calls.length = 0;
const existing = (command, args) => {
calls.push([command, args]);
return { status: 0, stderr: '' };
};
setGatewayInterception(false, 'VPN_PROXY_TPROXY', existing);
assert.deepEqual(calls.map(([, args]) => args), [
['-w', '-t', 'mangle', '-C', 'PREROUTING', '-j', 'VPN_PROXY_TPROXY'],
['-w', '-t', 'mangle', '-D', 'PREROUTING', '-j', 'VPN_PROXY_TPROXY'],
]);
});