Docker images / prepare-release (push) Successful in 11s
Docker images / backend-test (push) Successful in 10m41s
Docker images / frontend-image (push) Successful in 2m13s
Docker images / updater-image (push) Successful in 1m17s
Docker images / netflow-agent-image (push) Successful in 33s
Docker images / backend-image (push) Successful in 1m58s
Docker images / publish-release (push) Successful in 11s
Docker images / notify-webhook (push) Successful in 2s
107 lines
7.7 KiB
TypeScript
107 lines
7.7 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { createServer } from "node:http"
|
|
import { pool } from "../../db/index.js"
|
|
import type { AuthUser } from "../../lib/permissions.js"
|
|
import { mcpConnectionCreateSchema } from "@mmapp/contracts/mcp"
|
|
import { createMcpConnection, setConnectionStatus, authenticateMcpToken } from "./store.js"
|
|
import { invokeMcpTool } from "./runtime.js"
|
|
|
|
/** Runs only inside the disposable SQL/HTTP acceptance database. */
|
|
export async function acceptOspfRouteProofMcp(actor: AuthUser) {
|
|
const selection = { serverId: 104, prefix: "198.19.1.2/32", table: "local-vrf", interface: "owned-gre" }
|
|
const base: Record<string, unknown> = { ".id": "*a", "dst-address": selection.prefix, "routing-table": selection.table, "immediate-gw": "198.18.1.2%owned-gre@local-vrf", opaque: "NEVER_RIB_PRIVATE" }
|
|
let rows = [base], reads = 0, nativeError = false
|
|
const tablePath = "/rest/routing/table?.proplist=.id,name,disabled,invalid"
|
|
let tables = [{ ".id": "*t", name: selection.table }]
|
|
let beforeReply: (() => Promise<unknown>) | undefined, afterMetric: (() => Promise<unknown>) | undefined
|
|
const router = createServer(async (req, res) => {
|
|
res.setHeader("content-type", "application/json")
|
|
if (req.method === "GET" && req.url === tablePath) { reads++; res.end(JSON.stringify(tables)); return }
|
|
const url = new URL(req.url ?? "/", "http://fixture.invalid")
|
|
if (!["/rest/routing/route", "/rest/routing/route/get"].includes(url.pathname)) { res.statusCode = 404; res.end("{}"); return }
|
|
reads++
|
|
if (beforeReply) { const hook = beforeReply; beforeReply = undefined; await hook() }
|
|
if (nativeError) { res.statusCode = 400; res.end('{"message":"NEVER_ROUTE_PROVIDER_TOKEN"}'); return }
|
|
if (req.method === "GET") {
|
|
if (url.searchParams.get("dst-address") !== selection.prefix || url.searchParams.get("routing-table") !== selection.table) { res.statusCode = 400; res.end("{}"); return }
|
|
res.end(JSON.stringify(rows)); return
|
|
}
|
|
let body = ""; for await (const chunk of req) body += chunk
|
|
const key = JSON.parse(body)["value-name"]
|
|
if (key === "ospf.metric" && afterMetric) { const hook = afterMetric; afterMetric = undefined; await hook() }
|
|
res.end(JSON.stringify({ ret: ({ ospf: "true", active: "true", "ospf.metric": "0" } as Record<string, string>)[key] }))
|
|
})
|
|
await new Promise<void>(resolve => router.listen(0, "127.0.0.1", resolve))
|
|
let connectionId: string | undefined
|
|
try {
|
|
await pool.query("INSERT INTO servers(id,name,host,port,use_ssl,password) VALUES(104,'ospf-route-proof','127.0.0.1',$1,false,'NEVER_RIB_ENDPOINT_PASSWORD')", [(router.address() as { port: number }).port])
|
|
const access = await createMcpConnection(mcpConnectionCreateSchema.parse({ name: "OSPF RIB proof", mode: "observer", expiresAt: new Date(Date.now() + 1800000).toISOString(), permissions: ["mm:network:read"], scope: { serverIds: [104], operationIds: ["routing.ospf.route.proof.read"], allowGlobal: false }, limits: { callsPerMinute: 120 } }), actor)
|
|
connectionId = access.connection.id
|
|
const principal = await authenticateMcpToken(access.token)
|
|
const read = (args = selection, signal?: AbortSignal) => invokeMcpTool(principal, "mm_ospf_route_proof_get", args, signal)
|
|
const result = await read() as { route: { metric: number }; forwardingVerified: boolean; independentPathsVerified: boolean }
|
|
assert.equal(result.route.metric, 0); assert.equal(result.forwardingVerified, false); assert.equal(result.independentPathsVerified, false)
|
|
assert.ok(!JSON.stringify(result).includes("NEVER_")); assert.equal(reads, 4)
|
|
rows = [base, { ...base, ".id": "*b", contribution: "best-candidate" }]
|
|
assert.equal((await read() as typeof result).route.metric, 0)
|
|
assert.equal(reads, 8, "Known inactive alternative needs no property reads")
|
|
const beforeHidden = reads
|
|
await assert.rejects(read({ ...selection, serverId: 1 }))
|
|
await assert.rejects(read({ ...selection, prefix: "not-a-prefix" }))
|
|
await pool.query("UPDATE servers SET enabled=false WHERE id=104")
|
|
await assert.rejects(read(), (error: { code?: string }) => error.code === "DEVICE_UNAVAILABLE")
|
|
await pool.query("UPDATE servers SET enabled=true WHERE id=104")
|
|
assert.equal(reads, beforeHidden)
|
|
rows = [base, { ...base, ".id": "*b" }]
|
|
await assert.rejects(read(), (error: { code?: string }) => error.code === "STATE_UNAVAILABLE")
|
|
rows = [{ ...base, "immediate-gw": "198.18.1.2%wrong-gre" }]
|
|
await assert.rejects(read(), (error: { code?: string }) => error.code === "STATE_UNAVAILABLE")
|
|
rows = [base]; nativeError = true
|
|
await assert.rejects(read(), (error: Error & { code?: string }) => error.code === "STATE_UNAVAILABLE" && !error.message.includes("NEVER_"))
|
|
nativeError = false
|
|
let beforeRace = reads
|
|
beforeReply = async () => {
|
|
await pool.query("UPDATE servers SET verify_ssl=NOT verify_ssl WHERE id=104")
|
|
await pool.query("UPDATE servers SET verify_ssl=NOT verify_ssl WHERE id=104")
|
|
}
|
|
await assert.rejects(read(), (error: { code?: string }) => error.code === "STATE_CONFLICT")
|
|
assert.equal(reads, beforeRace + 1, "Endpoint ABA stops before all missing-field getters")
|
|
beforeRace = reads
|
|
beforeReply = () => setConnectionStatus(access.connection.id, "paused", actor)
|
|
await assert.rejects(read()); assert.equal(reads, beforeRace + 1)
|
|
await setConnectionStatus(access.connection.id, "active", actor)
|
|
beforeRace = reads
|
|
const cancel = new AbortController()
|
|
beforeReply = async () => cancel.abort()
|
|
await assert.rejects(read(selection, cancel.signal), (error: { code?: string }) => error.code === "READ_CANCELLED")
|
|
assert.equal(reads, beforeRace + 1)
|
|
afterMetric = () => setConnectionStatus(access.connection.id, "paused", actor)
|
|
await assert.rejects(read(), "Pause after the last getter must stop publication")
|
|
await setConnectionStatus(access.connection.id, "active", actor)
|
|
const absent = () => invokeMcpTool(principal, "mm_ospf_route_proof_get", { ...selection, expectAbsent: true })
|
|
rows = [{ ...base, "routing-table": "foreign-vrf" },
|
|
{ ".id": "*b", "dst-address": "eth1", afi: "link" },
|
|
{ ".id": "*c", "dst-address": "fe80::%owned-gre/64", "routing-table": selection.table, afi: "ipv6" }]
|
|
const absentResult = await absent() as { route: null; absenceVerified: boolean; prefix: string; table: string }
|
|
assert.equal(absentResult.route, null); assert.equal(absentResult.absenceVerified, true)
|
|
assert.equal(absentResult.prefix, selection.prefix); assert.equal(absentResult.table, selection.table)
|
|
for (const row of [{ ...base, contribution: "best-candidate" }, { ...base, "routing-table": undefined }, { ...base, "dst-address": undefined }]) {
|
|
rows = [row]
|
|
await assert.rejects(absent(), { code: "STATE_UNAVAILABLE" })
|
|
}
|
|
rows = []; nativeError = true
|
|
await assert.rejects(absent(), { code: "STATE_UNAVAILABLE" })
|
|
nativeError = false; tables = []
|
|
await assert.rejects(absent(), { code: "STATE_UNAVAILABLE" })
|
|
assert.equal((await pool.query("SELECT count(*)::int AS n FROM mcp_plans WHERE connection_id=$1", [connectionId])).rows[0].n, 0)
|
|
const recorded = JSON.stringify((await pool.query("SELECT result FROM mcp_requests WHERE connection_id=$1", [connectionId])).rows)
|
|
assert.ok(!recorded.includes("NEVER_"))
|
|
console.log("✓ OSPF RIB MCP proof: active learned route, confirmed table-wide absence, rejection of hidden/ambiguous/failed RIB, source fences and no observer plans")
|
|
} finally {
|
|
if (connectionId) await pool.query("DELETE FROM mcp_connections WHERE id=$1", [connectionId])
|
|
await pool.query("DELETE FROM servers WHERE id=104")
|
|
router.closeAllConnections()
|
|
await new Promise<void>((resolve, reject) => router.close(error => error ? reject(error) : resolve()))
|
|
}
|
|
}
|