Docker images / prepare-release (push) Successful in 12s
Docker images / backend-test (push) Successful in 11m40s
Docker images / frontend-image (push) Successful in 3m56s
Docker images / updater-image (push) Successful in 2m38s
Docker images / netflow-agent-image (push) Successful in 33s
Docker images / backend-image (push) Successful in 5m2s
Docker images / publish-release (push) Successful in 11s
Docker images / notify-webhook (push) Successful in 2s
56 lines
3.8 KiB
TypeScript
56 lines
3.8 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { test } from "node:test"
|
|
import type { IxBondCandidate, IxBondEdit, IxSavedBond } from "@mmapp/contracts/internet-exchange"
|
|
import { ixSegmentConfigurationSchema } from "@mmapp/contracts/internet-exchange"
|
|
import { bondCandidates, resolveBondMembers } from "./internet-exchange-bonds.js"
|
|
|
|
const owner = "a213a2c7-53cd-4325-8e43-e2d953cd761b"
|
|
const other = "5c1364bd-6147-46ea-b726-273a7e933302"
|
|
const client = "5a7fa65a-f94f-475a-96cd-a2ece0ed77ce"
|
|
const primary: IxBondCandidate = { segmentId: owner, appliedRevision: 3, serverId: 5, segmentName: "eu",
|
|
interfaceName: "wg-vps", name: "alpha", kind: "wireguard", probe: "10.255.0.1", address: "10.255.0.2", endpoint: "192.0.2.1", destinations: ["0.0.0.0/0"] }
|
|
const backup: IxBondCandidate = { ...primary, segmentId: other, segmentName: "asia", clientId: client,
|
|
serverId: 6, kind: "gre-ipsec", interfaceName: "gre-vps", probe: "10.255.0.5", address: "10.255.0.6" }
|
|
const edit: IxBondEdit = { name: "vps", mode: "weighted", directCidrs: [], revision: 0,
|
|
members: [primary, backup].map(({ segmentId, appliedRevision, serverId, interfaceName }, i) =>
|
|
({ segmentId, appliedRevision, serverId, interfaceName, weight: i ? 1 : 3 })) }
|
|
|
|
test("cross-segment members retain order, declared VPS identity and revision", () => {
|
|
const { members, clientId } = resolveBondMembers(edit, [backup, primary], [], owner)
|
|
assert.deepEqual(members, [primary, backup])
|
|
assert.equal(clientId, client)
|
|
const saved: IxSavedBond = { ...edit, id: other, ownerSegmentId: owner, revision: 1, clientId }
|
|
assert.throws(() => resolveBondMembers(edit, [primary, backup], [saved], owner), /уже входит/)
|
|
assert.equal(resolveBondMembers(saved, [primary, backup], [saved], owner, saved).clientId, client)
|
|
})
|
|
|
|
test("reject stale, revoked, foreign-client and conflicting routing paths", () => {
|
|
const invalid: Array<[IxBondCandidate, RegExp]> = [
|
|
[{ ...backup, appliedRevision: 4 }, /изменилось/],
|
|
[{ ...backup, destinations: ["198.51.100.0/24"] }, /назначения/],
|
|
[{ ...backup, address: primary.probe }, /внутренние адреса/],
|
|
]
|
|
for (const [candidate, reason] of invalid) {
|
|
assert.throws(() => resolveBondMembers(edit, [primary, candidate], [], owner), reason)
|
|
}
|
|
assert.throws(() => resolveBondMembers(edit, [primary], [], owner), /недоступно/)
|
|
assert.throws(() => resolveBondMembers(edit, [{ ...primary, clientId: owner }, backup], [], owner), /разными VPS/)
|
|
assert.throws(() => resolveBondMembers(edit, [primary, backup], [], client), /текущего сегмента/)
|
|
})
|
|
|
|
test("existing static WireGuard exports keep their applied prefixes; external GRE and BGP remain independent", () => {
|
|
const config = ixSegmentConfigurationSchema.parse({ name: "legacy", sites: [{ serverId: 5, autonomousSystem: 64512,
|
|
routerId: "192.0.2.1", interfaces: [
|
|
{ kind: "wireguard", name: "wg-static", provisionWireguard: { listenPort: 31820, hubEndpoint: primary.endpoint,
|
|
localAddress: primary.probe + "/30", peerAddress: primary.address, peerPublicKey: Buffer.alloc(32, 3).toString("base64") } },
|
|
{ kind: "gre-ipsec", name: "gre-manual", localEndpoint: primary.endpoint, endpoint: "198.51.100.8", prefixes: ["10.7.0.0/24"] },
|
|
] }] })
|
|
const [candidate] = bondCandidates(owner, 7, config)
|
|
assert.deepEqual(bondCandidates(owner, 7, config).map(c => c.interfaceName), ["wg-static"])
|
|
assert.deepEqual(candidate.destinations, ["10.7.0.0/24"])
|
|
assert.equal(candidate.clientId, undefined)
|
|
config.sites[0].neighbors.push({ id: "bgp", binding: "wg-static", type: "member", remoteAs: 64513,
|
|
address: primary.address, localAddress: primary.probe, prefixes: [], exportPrefixes: [], rules: [], limit: 10 })
|
|
assert.deepEqual(bondCandidates(owner, 7, config), [])
|
|
})
|