CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s
Squash the tree into one commit, drop docs/architecture.html, reset the version line to 0.3.0, consolidate the changelog, enable Renovate automerge for non-major updates and add AGENTS.md.
49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
const test = require("node:test");
|
|
const assert = require("node:assert");
|
|
const net = require("node:net");
|
|
const { SIGNATURE } = require("./proxy-protocol");
|
|
const { proxyFront } = require("./proxy-front");
|
|
|
|
const header = ip => {
|
|
const address = Buffer.from(ip.split(".").map(Number));
|
|
const body = Buffer.concat([address, address, Buffer.alloc(4)]);
|
|
const buffer = Buffer.alloc(16 + body.length);
|
|
SIGNATURE.copy(buffer, 0);
|
|
buffer[12] = 0x21;
|
|
buffer[13] = 0x11;
|
|
buffer.writeUInt16BE(body.length, 14);
|
|
body.copy(buffer, 16);
|
|
return buffer;
|
|
};
|
|
|
|
const withFront = async (payload, assertOnTunnel) => new Promise((resolve, reject) => {
|
|
const front = proxyFront({}, tunnel => {
|
|
try {
|
|
assertOnTunnel(tunnel);
|
|
tunnel.destroy();
|
|
front.close(() => resolve());
|
|
} catch (error) {
|
|
front.close(() => reject(error));
|
|
}
|
|
});
|
|
|
|
front.listen(0, "127.0.0.1", () => {
|
|
const socket = net.connect(front.address().port, "127.0.0.1");
|
|
socket.on("connect", () => socket.write(payload));
|
|
socket.on("error", () => {});
|
|
});
|
|
setTimeout(() => reject(new Error("the front did not hand over a connection")), 3000).unref();
|
|
});
|
|
|
|
test("hands the source address of a proxied connection to the TLS socket", async () => {
|
|
await withFront(header("203.0.113.7"), tunnel => {
|
|
assert.strictEqual(tunnel.frislitIp, "203.0.113.7");
|
|
});
|
|
});
|
|
|
|
test("passes a direct connection through untouched", async () => {
|
|
await withFront(Buffer.from([0x16, 0x03, 0x01, 0x00, 0x2a]), tunnel => {
|
|
assert.strictEqual(tunnel.frislitIp, undefined);
|
|
});
|
|
});
|