336 lines
25 KiB
TypeScript
336 lines
25 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { test } from "node:test"
|
|
import { captureRoutingNetworkNativeParser } from "./routing-network-native-parser.js"
|
|
import { classifyRoutingNetwork, createRoutingNetworkBudget, spendRoutingNetworkBudget, type RoutingNetworkManifest, type RoutingNetworkRound } from "./routing-network-verifier-model.js"
|
|
type RawRow = Record<string, unknown>
|
|
type RawMutation = { routerOsVersion: string; resource: string; payload: RawRow[]; connectionsPayload: RawRow[]; sessionsPayload: RawRow[];
|
|
request: RawRow; pingPayload: RawRow[]; tracePayload: RawRow[] }
|
|
|
|
function fixture(ipv6 = false) {
|
|
const local = ipv6 ? "2001:db8::2" : "192.0.2.2", remote = ipv6 ? "2001:db8::1" : "192.0.2.1"
|
|
const destination = ipv6 ? "2001:db8:10::1" : "203.0.113.1", source = ipv6 ? "2001:db8:20::1" : "198.51.100.1"
|
|
const family = ipv6 ? "ipv6" : "ipv4", afi = ipv6 ? "ipv6" : "ip"
|
|
const manifest: RoutingNetworkManifest = { revision: 1, phase: "forward", identity: { operationId: "00000000-0000-4000-8000-000000000001", profileId: "00000000-0000-4000-8000-000000000002", profileVersion: 1, stepIndex: 0, sourceEpoch: "epoch1", authorityIdentity: "authority1" },
|
|
sourceCreatedAt: 1800000000000, deadline: 1800000120000, observationStartAt: 1800000001000, maximumSampleAgeMs: 30000, serverIds: [1],
|
|
configuration: { serverId: 1, nativeId: "*F1", table: "tenant", bodyIdentity: "body1", dependencyIdentity: "deps1" },
|
|
routes: [{ key: "route1", serverId: 1, family, prefix: ipv6 ? "2001:db8:10::/64" : "203.0.113.0/24", table: "tenant", sessionKey: "peer1", nextHop: remote, interface: "wan1", resolverTable: "main", resolutionChain: [{ address: remote, table: "main", interface: "wan1" }] }],
|
|
bgp: [{ key: "peer1", serverId: 1, family, connectionId: "*C1", instance: "default", localAddress: local, remoteAddress: remote, remoteAsn: 65001 }],
|
|
bfd: [{ key: "bfd1", serverId: 1, applicability: "required", configurationIdentity: "bfd-config", localAddress: local, remoteAddress: remote, interface: "wan1", vrf: "main" }],
|
|
probes: [{ key: "probe1", serverId: 1, family, destination, source, interface: "wan1", probeVrf: "diagnostic", expectedHops: [remote, destination] }],
|
|
logs: [{ key: "logs1", serverId: 1, generation: "boot1", sequenceMode: "contiguous-capture", afterSequence: 0, topics: ["route", "bgp", "bfd", "interface"], relatedKeys: ["route1", "peer1", "bfd1", "probe1"] }],
|
|
}
|
|
// Raw RouterOS REST field names/string values, not model observations.
|
|
const connections = [{ ".id": "*C1", name: "peer", instance: "default", "local.address": local, "remote.address": remote, "remote.as": "65001", afi, disabled: "false", templates: "", vrf: "main", "routing-table": "tenant" }]
|
|
const sessions = [{ ".id": "*B000002", name: "runtime-name-is-not-a-binding", instance: "default", "local.address": local, "remote.address": remote,
|
|
"remote.as": "65001", "local.afi": afi, "remote.afi": afi, established: "true", vrf: "main", "routing-table": "tenant", uptime: "1h" }]
|
|
const base = { serverId: 1, routerOsVersion: "7.20.4 (stable)" }
|
|
const bgp = { ...base, resource: "/routing/bgp/session", payload: sessions, connectionsPayload: connections }
|
|
const route = { ...base, resource: "/routing/route", payload: [{ ".id": "*R1", afi: ipv6 ? "ip6" : "ip4", "dst-address": manifest.routes[0].prefix, "routing-table": "tenant", bgp: "true", dynamic: "true", active: "true", contribution: "active", gateway: remote + "@main", "immediate-gw": remote + "%wan1", "bgp.peer-cache-id": "*B000002", "belongs-to": "untrusted descriptive text" }], sessionsPayload: sessions, connectionsPayload: connections }
|
|
const bfd = { ...base, resource: "/routing/bfd/session", payload: [{ ".id": "*D1", "local-address": local + "%wan1@main", "remote-address": remote + "%wan1@main", state: "Up" }] }
|
|
const probe = { ...base, request: { destination, source, interface: "wan1", probeVrf: "diagnostic", count: 3 as const, maxHops: 16 as const },
|
|
pingPayload: [{ sent: "1", received: "1", "packet-loss": "0", "avg-rtt": "453us", host: destination }, { sent: "2", received: "2", "packet-loss": "0", "avg-rtt": "1ms", host: destination }, { sent: "3", received: "3", "packet-loss": "0", "avg-rtt": "53ms561us", host: destination }],
|
|
tracePayload: [{ address: remote, sent: "1", loss: "0" }, { address: destination, sent: "1", loss: "0" }],
|
|
}
|
|
return { manifest, parser: captureRoutingNetworkNativeParser(manifest), base, bgp, route, bfd, probe }
|
|
}
|
|
|
|
for (const ipv6 of [false, true]) test("raw documented " + (ipv6 ? "IPv6" : "IPv4") + " BGP/BFD/probe observations do not establish route-origin namespace", () => {
|
|
const f = fixture(ipv6)
|
|
for (const result of [f.parser.parseBgp("peer1", f.bgp), f.parser.parseBfd("bfd1", f.bfd), f.parser.parseProbe("probe1", f.probe)]) {
|
|
assert.equal(result.status, "observed", JSON.stringify(result)); assert.equal(result.securityProof, false)
|
|
}
|
|
const route = f.parser.parseRoute("route1", f.route)
|
|
assert.equal(route.status, "unknown"); if (route.status === "unknown") assert.equal(route.reason, "unsupported-route-bgp-origin-namespace")
|
|
const probe = f.parser.parseProbe("probe1", f.probe)
|
|
if (probe.status === "observed") assert.equal(probe.observation.probeVrf, "diagnostic")
|
|
})
|
|
|
|
test("equal cache/session REST IDs collide without proving a shared namespace; aliases never repair it", () => {
|
|
const f = fixture()
|
|
// The old parser accepted this exact collision plus a genuine-looking BGP
|
|
// tuple. Equal strings from distinct native menus are not provenance.
|
|
assert.equal(f.route.payload[0]["bgp.peer-cache-id"], f.bgp.payload[0][".id"])
|
|
for (const mode of ["cache", "session", "both-equal", "both-conflict", "absent"] as const) {
|
|
const raw = structuredClone(f.route) as unknown as RawMutation
|
|
if (mode !== "cache" && mode !== "absent") raw.payload[0]["bgp.session"] = mode === "both-conflict" ? "*OTHER" : "*B000002"
|
|
if (mode === "session" || mode === "absent") delete raw.payload[0]["bgp.peer-cache-id"]
|
|
const result = f.parser.parseRoute("route1", raw)
|
|
assert.equal(result.status, "unknown")
|
|
if (result.status === "unknown") {
|
|
assert.equal(result.reason, "unsupported-route-bgp-origin-namespace")
|
|
assert.deepEqual(result.diagnostic, { peerCacheIdPresent: mode !== "session" && mode !== "absent", sessionFieldPresent: mode !== "cache" && mode !== "absent", routeToSessionBinding: "unproven" })
|
|
assert.equal(Object.hasOwn(result, "observation"), false)
|
|
}
|
|
}
|
|
})
|
|
|
|
for (const mutation of ["missing-peer-id", "conflicting-peer-id", "foreign-peer", "duplicate-route", "wrong-table", "wrong-afi", "hostbits", "missing-active", "contradictory-contribution", "multipath", "missing-resolver", "wrong-resource", "invented-success"] as const) test("route " + mutation + " remains unknown", () => {
|
|
const f = fixture(), raw = structuredClone(f.route) as unknown as RawMutation, row = raw.payload[0]
|
|
if (mutation === "missing-peer-id") delete row["bgp.peer-cache-id"]
|
|
if (mutation === "conflicting-peer-id") row["bgp.session"] = "*OTHER"
|
|
if (mutation === "foreign-peer") row["bgp.peer-cache-id"] = "*FOREIGN"
|
|
if (mutation === "duplicate-route") raw.payload.push({ ...row, ".id": "*R2" })
|
|
if (mutation === "wrong-table") row["routing-table"] = "diagnostic"
|
|
if (mutation === "wrong-afi") row.afi = "ipv6"
|
|
if (mutation === "hostbits") row["dst-address"] = "203.0.113.1/24"
|
|
if (mutation === "missing-active") delete row.active
|
|
if (mutation === "contradictory-contribution") row.contribution = "filtered"
|
|
if (mutation === "multipath") row["immediate-gw"] = "192.0.2.1%wan1,192.0.2.2%wan2"
|
|
if (mutation === "missing-resolver") row.gateway = "192.0.2.1"
|
|
if (mutation === "wrong-resource") raw.resource = "/ip/route"
|
|
if (mutation === "invented-success") raw.payload = [{ ".id": "*R1", "dst-address": f.manifest.routes[0].prefix, "routing-table": "tenant", stagePassed: true, resolved: true, sessionKey: "peer1" }]
|
|
assert.equal(f.parser.parseRoute("route1", raw).status, "unknown")
|
|
})
|
|
|
|
test("recursive route does not copy manifest chain into observed evidence; raw nexthop link namespaces remain unsupported", () => {
|
|
const f = fixture(), raw = structuredClone(f.route)
|
|
raw.payload[0].gateway = "198.18.0.1@main"
|
|
const parsed = f.parser.parseRoute("route1", raw)
|
|
assert.equal(parsed.status, "unknown"); if (parsed.status === "unknown") assert.match(parsed.reason, /recursive/)
|
|
})
|
|
|
|
test("documented link and VPN rows do not obscure the exact recursive IPv4 or IPv6 diagnostic", () => {
|
|
for (const ipv6 of [false, true]) {
|
|
const f = fixture(ipv6), raw = structuredClone(f.route) as unknown as RawMutation
|
|
const [target] = raw.payload
|
|
target.gateway = ipv6 ? "2001:db8:ffff::1@main" : "198.18.0.1@main"
|
|
const table = target["routing-table"]
|
|
raw.payload.unshift(
|
|
{ ".id": "*L1", afi: "link", "dst-address": "ether1", "routing-table": table },
|
|
{ ".id": "*V4", afi: "vpnv4", "dst-address": "203.0.113.0/24&65530:100", "routing-table": table },
|
|
{ ".id": "*V6", afi: "vpnv6", "dst-address": "2001:db8:10::/64&65530:100", "routing-table": table },
|
|
)
|
|
const result = f.parser.parseRoute("route1", raw)
|
|
assert.equal(result.status, "unknown")
|
|
assert.equal(result.reason, "unsupported-recursive-nexthop-link-proof")
|
|
assert.equal(result.securityProof, false)
|
|
raw.payload[0]["dst-address"] = target["dst-address"]
|
|
const collision = f.parser.parseRoute("route1", raw)
|
|
assert.equal(collision.status, "unknown")
|
|
assert.equal(collision.reason, "missing-or-ambiguous-installation-route")
|
|
}
|
|
})
|
|
|
|
for (const ipv6 of [false, true]) test("recursive " + (ipv6 ? "IPv6" : "IPv4") + " cannot infer numeric native joins from matching route/debug IDs or desired chain", () => {
|
|
const f = fixture(ipv6), raw = structuredClone(f.route) as unknown as RawMutation
|
|
const recursive = ipv6 ? "2001:db8:ffff::1" : "198.18.0.1"
|
|
f.manifest.routes[0].resolutionChain.unshift({ address: recursive, table: "main", interface: "wan1" })
|
|
raw.payload[0].gateway = recursive + "@main"
|
|
raw.payload[0]["nexthop-id"] = "1"
|
|
raw.payload[0]["debug.route-ptr"] = "1"
|
|
raw.payload[0]["debug.fwp-ptr"] = "1"
|
|
// A host route with a consistent final endpoint still does not identify
|
|
// which numeric nexthop output link RouterOS actually used.
|
|
raw.payload.push({ ".id": "*1", afi: ipv6 ? "ip6" : "ip4", "dst-address": recursive + (ipv6 ? "/128" : "/32"),
|
|
"routing-table": "main", static: "true", active: "true", contribution: "active", scope: "10", "target-scope": "10",
|
|
gateway: raw.payload[0]["immediate-gw"], "immediate-gw": raw.payload[0]["immediate-gw"], "nexthop-id": "1" })
|
|
const result = captureRoutingNetworkNativeParser(f.manifest).parseRoute("route1", raw)
|
|
assert.equal(result.status, "unknown")
|
|
if (result.status === "unknown") {
|
|
assert.equal(result.reason, "unsupported-recursive-nexthop-link-proof")
|
|
assert.deepEqual(result.diagnostic?.missingEvidence, ["numeric-nexthop-identity", "numeric-route-link-identity", "numeric-interface-index-identity", "complete-recursive-link-catalogue"])
|
|
assert.equal(result.securityProof, false)
|
|
}
|
|
})
|
|
|
|
test("direct final endpoint cannot satisfy a longer desired recursive chain", () => {
|
|
const f = fixture()
|
|
f.manifest.routes[0].resolutionChain.unshift({ address: "198.18.0.1", table: "main", interface: "wan1" })
|
|
const result = captureRoutingNetworkNativeParser(f.manifest).parseRoute("route1", f.route)
|
|
assert.equal(result.status, "unknown")
|
|
if (result.status === "unknown") assert.equal(result.reason, "unsupported-recursive-nexthop-link-proof")
|
|
})
|
|
|
|
test("route ID referencing another observed session and noncanonical duplicate prefix cannot pass attribution", () => {
|
|
const f = fixture(), raw = structuredClone(f.route) as unknown as RawMutation
|
|
raw.sessionsPayload.push({ ...raw.sessionsPayload[0], ".id": "*OTHER", "remote.address": "192.0.2.9" })
|
|
raw.payload[0]["bgp.peer-cache-id"] = "*OTHER"
|
|
assert.equal(f.parser.parseRoute("route1", raw).status, "unknown")
|
|
const malformed = structuredClone(f.route)
|
|
malformed.payload.push({ ...malformed.payload[0], ".id": "*R2", "dst-address": "203.0.113.1/24" })
|
|
assert.equal(f.parser.parseRoute("route1", malformed).status, "unknown")
|
|
})
|
|
|
|
test("a different direct nexthop cannot bypass the missing route-origin binding", () => {
|
|
const f = fixture(), raw = structuredClone(f.route)
|
|
raw.payload[0].gateway = "192.0.2.9@main"; raw.payload[0]["immediate-gw"] = "192.0.2.9%wan9"
|
|
const result = f.parser.parseRoute("route1", raw)
|
|
assert.equal(result.status, "unknown")
|
|
if (result.status === "unknown") assert.equal(result.reason, "unsupported-route-bgp-origin-namespace")
|
|
})
|
|
|
|
for (const mutation of ["duplicate-config", "wrong-config-id", "unresolved-template", "missing-endpoint", "duplicate-session", "wrong-asn", "missing-afi", "wrong-vrf", "disabled-config", "missing-established", "contradictory-state", "name-only"] as const) test("BGP " + mutation + " cannot establish an exact binding", () => {
|
|
const f = fixture(), raw = structuredClone(f.bgp) as unknown as RawMutation, session = raw.payload[0], config = raw.connectionsPayload[0]
|
|
if (mutation === "duplicate-config") raw.connectionsPayload.push({ ...config, ".id": "*C2" })
|
|
if (mutation === "wrong-config-id") config[".id"] = "*C2"
|
|
if (mutation === "unresolved-template") config.templates = "default"
|
|
if (mutation === "missing-endpoint") delete config["local.address"]
|
|
if (mutation === "duplicate-session") raw.payload.push({ ...session, ".id": "*B3" })
|
|
if (mutation === "wrong-asn") session["remote.as"] = "65002"
|
|
if (mutation === "missing-afi") delete session["remote.afi"]
|
|
if (mutation === "wrong-vrf") session.vrf = "diagnostic"
|
|
if (mutation === "disabled-config") config.disabled = "true"
|
|
if (mutation === "missing-established") delete session.established
|
|
if (mutation === "contradictory-state") session.state = "idle"
|
|
if (mutation === "name-only") { session.name = "peer-1"; delete session["remote.address"] }
|
|
assert.equal(f.parser.parseBgp("peer1", raw).status, "unknown")
|
|
})
|
|
|
|
for (const ipv6 of [false, true]) test("BGP runtime context can come from both exact qualified " + (ipv6 ? "IPv6" : "IPv4") + " endpoints", () => {
|
|
const f = fixture(ipv6), raw = structuredClone(f.bgp) as unknown as RawMutation, session = raw.payload[0]
|
|
const local = session["local.address"], remote = session["remote.address"]
|
|
delete session.vrf
|
|
session["local.address"] = `${local}@main`
|
|
session["remote.address"] = `${remote}@main`
|
|
const observation = f.parser.parseBgp("peer1", raw)
|
|
assert.equal(observation.status, "observed", JSON.stringify(observation))
|
|
assert.equal(observation.securityProof, false)
|
|
for (const mutation of [
|
|
{ "remote.address": remote }, { "remote.address": `${remote}@tenant` },
|
|
{ "remote.address": `${remote}@main@main` }, { "routing-table": "main" },
|
|
{ vrf: "tenant" }, { vrf: null },
|
|
]) {
|
|
assert.equal(f.parser.parseBgp("peer1", { ...raw, payload: [{ ...session, ...mutation }] }).status, "unknown")
|
|
}
|
|
assert.equal(f.parser.parseBgp("peer1", { ...raw, payload: [session, { ...session, ".id": "*B3" }] }).status, "unknown")
|
|
})
|
|
|
|
test("native cached non-established BGP cannot invent a model FSM state from an undocumented field", () => {
|
|
const f = fixture(), raw = structuredClone(f.bgp) as unknown as RawMutation
|
|
raw.payload[0].established = "false"
|
|
const parsed = f.parser.parseBgp("peer1", raw); assert.equal(parsed.status, "observed")
|
|
if (parsed.status === "observed") assert.equal(parsed.observation.state, "not-established")
|
|
raw.payload[0].state = "idle"
|
|
assert.equal(f.parser.parseBgp("peer1", raw).status, "unknown")
|
|
})
|
|
|
|
test("cached session health stays observed while route attribution is unknown; explicit inert classifier model remains separate", () => {
|
|
const f = fixture(); f.bgp.payload[0].established = "false"
|
|
const route = f.parser.parseRoute("route1", f.route), bgp = f.parser.parseBgp("peer1", f.bgp), bfd = f.parser.parseBfd("bfd1", f.bfd), probe = f.parser.parseProbe("probe1", f.probe)
|
|
assert.equal(route.status, "unknown")
|
|
assert(bgp.status === "observed" && bfd.status === "observed" && probe.status === "observed")
|
|
// Explicit inert classifier input, NOT an observation returned by the native parser.
|
|
const modelRoute: RoutingNetworkRound["routes"][number] = { ...f.manifest.routes[0], active: true, resolved: true, protocol: "bgp", resolutionChain: f.manifest.routes[0].resolutionChain.map(link => ({ ...link, resolved: true })) }
|
|
const start = f.manifest.sourceCreatedAt, now = start + 10000
|
|
const rounds: RoutingNetworkRound[] = [2000, 3000].map(offset => ({ identity: f.manifest.identity, startedAt: start + offset, observedAt: start + offset + 100,
|
|
configuration: f.manifest.configuration, routes: [modelRoute], bgp: [bgp.observation], bfd: [bfd.observation], probes: [probe.observation],
|
|
// Inert model coverage fixture only; parseLogs never claims this contract.
|
|
logs: f.manifest.logs.map(scope => ({ ...scope, coverageStartAt: f.manifest.observationStartAt, coveredUntil: start + offset + 100, capturedAt: start + offset + 100,
|
|
toSequence: 0, responseRowCount: 0, moreAvailable: false, rotationDetected: false, clockSynchronized: true, rows: [] })) }))
|
|
const budget = spendRoutingNetworkBudget(createRoutingNetworkBudget(start, [f.manifest.deadline], start), "forward", now, { requests: 20, bytes: 40000, rows: 40 }).budget
|
|
const result = classifyRoutingNetwork(f.manifest, rounds, now, budget)
|
|
assert.equal(result.verdict, "failed"); assert.equal(result.securityProof, false)
|
|
rounds[0].logs = []; assert.equal(classifyRoutingNetwork(f.manifest, rounds, now, budget).verdict, "unknown")
|
|
})
|
|
|
|
test("a second session missing its instance cannot be silently excluded from exact mapping", () => {
|
|
const f = fixture(), raw = structuredClone(f.bgp) as unknown as RawMutation
|
|
const row = { ...raw.payload[0], ".id": "*OTHER" }; delete row.instance
|
|
raw.payload.push(row)
|
|
assert.equal(f.parser.parseBgp("peer1", raw).status, "unknown")
|
|
})
|
|
|
|
for (const mutation of ["duplicate", "wrong-interface", "wrong-vrf", "missing-context", "wrong-family", "missing-state", "invented-success"] as const) test("BFD " + mutation + " is unknown", () => {
|
|
const f = fixture(), raw = structuredClone(f.bfd) as unknown as RawMutation
|
|
if (mutation === "duplicate") raw.payload.push({ ...raw.payload[0], ".id": "*D2" })
|
|
if (mutation === "wrong-interface") raw.payload[0].interface = "other"
|
|
if (mutation === "wrong-vrf") raw.payload[0].vrf = "tenant"
|
|
if (mutation === "missing-context") { raw.payload[0]["local-address"] = "192.0.2.2"; raw.payload[0]["remote-address"] = "192.0.2.1" }
|
|
if (mutation === "wrong-family") raw.payload[0]["remote-address"] = "2001:db8::1%wan1@main"
|
|
if (mutation === "missing-state") delete raw.payload[0].state
|
|
if (mutation === "invented-success") raw.payload[0].state = "healthy"
|
|
assert.equal(f.parser.parseBfd("bfd1", raw).status, "unknown")
|
|
})
|
|
|
|
test("BFD canonicalizes actual IPv6 endpoint spelling and never infers not-configured from empty runtime", () => {
|
|
const f = fixture(true), raw = structuredClone(f.bfd)
|
|
raw.payload[0]["remote-address"] = "2001:0db8:0:0:0:0:0:1%wan1@main"
|
|
assert.equal(f.parser.parseBfd("bfd1", raw).status, "observed")
|
|
f.manifest.bfd[0] = { key: "bfd1", serverId: 1, applicability: "not-applicable", reason: "not-configured", configurationIdentity: "absent1" }
|
|
assert.equal(captureRoutingNetworkNativeParser(f.manifest).parseBfd("bfd1", { ...f.bfd, payload: [] }).status, "unknown")
|
|
})
|
|
|
|
test("documented terminal zero receive is observed failure data; partial loss/timeout is not promoted", () => {
|
|
const f = fixture(), raw = { ...f.probe, pingPayload: [{ sent: "3", received: "0", "packet-loss": "100" }], tracePayload: undefined }
|
|
const result = f.parser.parseProbe("probe1", raw); assert.equal(result.status, "observed")
|
|
if (result.status === "observed") { assert.equal(result.observation.received, 0); assert.equal(result.observation.trace.kind, "not-run") }
|
|
assert.equal(f.parser.parseProbe("probe1", { ...raw, pingPayload: [{ sent: "3", received: "1", "packet-loss": "67", "avg-rtt": "1ms" }] }).status, "unknown")
|
|
assert.equal(f.parser.parseProbe("probe1", { ...raw, pingPayload: [{ status: "timeout" }] }).status, "unknown")
|
|
})
|
|
|
|
for (const mutation of ["wrong-vrf", "wrong-source", "wrong-destination", "partial-count", "over-count", "contradictory-loss", "duplicate-summary", "trace-timeout", "missing-hop", "foreign-final", "false-loss", "invented-success"] as const) test("probe " + mutation + " remains unknown", () => {
|
|
const f = fixture(), raw = structuredClone(f.probe) as unknown as RawMutation
|
|
if (mutation === "wrong-vrf") raw.request.probeVrf = "tenant"
|
|
if (mutation === "wrong-source") raw.request.source = "198.51.100.2"
|
|
if (mutation === "wrong-destination") raw.pingPayload[0].host = "203.0.113.2"
|
|
if (mutation === "partial-count") raw.pingPayload.pop()
|
|
if (mutation === "over-count") raw.pingPayload[2].received = "4"
|
|
if (mutation === "contradictory-loss") raw.pingPayload[2]["packet-loss"] = "100"
|
|
if (mutation === "duplicate-summary") raw.pingPayload.push(structuredClone(raw.pingPayload[2]))
|
|
if (mutation === "trace-timeout") raw.tracePayload[0].status = "timeout"
|
|
if (mutation === "missing-hop") raw.tracePayload[0].address = ""
|
|
if (mutation === "foreign-final") raw.tracePayload[1].address = "203.0.113.2"
|
|
if (mutation === "false-loss") raw.tracePayload[0].loss = false
|
|
if (mutation === "invented-success") raw.pingPayload = [{ stagePassed: true, status: "passed" }]
|
|
assert.equal(f.parser.parseProbe("probe1", raw).status, "unknown")
|
|
})
|
|
|
|
test("traceroute final complete section is parsed separately; out-of-order snapshots are unknown", () => {
|
|
const f = fixture(), raw = structuredClone(f.probe) as unknown as RawMutation
|
|
raw.tracePayload = [{ ".section": "0", sent: "1", loss: "100", status: "timeout" }, ...raw.tracePayload.map(row => ({ ...row, ".section": "1" }))]
|
|
assert.equal(f.parser.parseProbe("probe1", raw).status, "observed")
|
|
raw.tracePayload.push({ ".section": "0", sent: "1", loss: "0", address: "203.0.113.1" })
|
|
assert.equal(f.parser.parseProbe("probe1", raw).status, "unknown")
|
|
})
|
|
|
|
test("successful counters with a native terminal timeout status are contradictory and unknown", () => {
|
|
const f = fixture(), raw = structuredClone(f.probe) as unknown as RawMutation
|
|
raw.pingPayload[2].status = "timeout"
|
|
assert.equal(f.parser.parseProbe("probe1", raw).status, "unknown")
|
|
})
|
|
|
|
test("reader probe metadata selectors and derived hop addresses must agree with captured scope", () => {
|
|
const f = fixture(), raw = { ...f.probe, key: "probe1", expectedHopAddresses: [{ serverId: 1, interface: "wan1", address: "192.0.2.1" }, { serverId: 1, interface: "exit1", address: "203.0.113.1" }] }
|
|
assert.equal(f.parser.parseProbe("probe1", raw).status, "observed")
|
|
assert.equal(f.parser.parseProbe("probe1", { ...raw, key: "other" }).status, "unknown")
|
|
raw.expectedHopAddresses[0].serverId = 2; assert.equal(f.parser.parseProbe("probe1", raw).status, "unknown")
|
|
raw.expectedHopAddresses[0].serverId = 1; raw.expectedHopAddresses[0].address = "192.0.2.9"; assert.equal(f.parser.parseProbe("probe1", raw).status, "unknown")
|
|
})
|
|
|
|
test("logs raw shape can be bounded but empty ring and SQL history never establish interval coverage", () => {
|
|
const f = fixture()
|
|
const envelope = { ...f.base, resource: "/log", buffer: "memory" }
|
|
const row = { ".id": "*L1", buffer: "memory", time: "10:00:00", topics: "bgp,info", message: "session up" }
|
|
const rows = (count: number) => Array.from({ length: count }, (_, index) => ({ ...row, ".id": `*${index.toString(16)}` }))
|
|
for (const payload of [[], [row], rows(1000)]) {
|
|
const result = f.parser.parseLogs({ ...envelope, payload })
|
|
assert.equal(result.status, "unknown"); if (result.status === "unknown") assert.equal(result.reason, "authenticated-log-interval-coverage-unsupported")
|
|
}
|
|
const { buffer: _omitted, ...withoutBuffer } = row
|
|
for (const second of [{ ...row, buffer: "other" }, withoutBuffer]) {
|
|
const result = f.parser.parseLogs({ ...envelope, payload: [row, { ...second, ".id": "*L2" }] })
|
|
assert.equal(result.status, "unknown")
|
|
if (result.status === "unknown") assert.equal(result.reason, "native-log-buffer-unconfirmed")
|
|
}
|
|
assert.equal(f.parser.parseLogs({ ...envelope, payload: rows(1001) }).status, "unknown")
|
|
assert.equal(f.parser.parseLogs({ ...envelope, resource: "router_log_entries", payload: [] }).status, "unknown")
|
|
})
|
|
|
|
test("decoded byte/row/depth/id bounds and metadata drift reject malformed catalogues", () => {
|
|
const f = fixture()
|
|
const variants = [null, {}, [null], [{ ...f.bfd.payload[0], opaque: "x".repeat(1048577) }], Array.from({ length: 1001 }, (_, index) => ({ ...f.bfd.payload[0], ".id": "*D" + index })), [{ ...f.bfd.payload[0], ".id": undefined }], [f.bfd.payload[0], f.bfd.payload[0]]]
|
|
for (const payload of variants) assert.equal(f.parser.parseBfd("bfd1", { ...f.bfd, payload }).status, "unknown")
|
|
for (const routerOsVersion of ["6.49.10", "7.19.5", "7.99", "8.0", "7.20beta1", ""]) assert.equal(f.parser.parseBfd("bfd1", { ...f.bfd, routerOsVersion }).status, "unknown")
|
|
assert.equal(f.parser.parseBfd("bfd1", { ...f.bfd, serverId: 2 }).status, "unknown")
|
|
assert.equal(f.parser.parseBgp("unscoped", f.bgp).status, "unknown")
|
|
})
|
|
|
|
test("manifest and returned observations are deeply separated from external input mutation", () => {
|
|
const f = fixture()
|
|
f.manifest.bgp[0].remoteAsn = 65002
|
|
const result = f.parser.parseBgp("peer1", f.bgp); assert.equal(result.status, "observed")
|
|
if (result.status === "observed") result.observation.remoteAsn = 65003
|
|
const again = f.parser.parseBgp("peer1", f.bgp)
|
|
if (again.status === "observed") assert.equal(again.observation.remoteAsn, 65001)
|
|
})
|