Files
MikrotikManager/backend/src/modules/mcp/ipsec-peer-delete-actions.test.ts
T

12 lines
1.7 KiB
TypeScript

import assert from "node:assert/strict"
import { hasVerifiedIpsecPeerDeletion } from "./ipsec-peer-delete-actions.js"
import { redact } from "./security.js"
const input = { principal: { connectionId: "connection" }, receiptId: "receipt", peerId: "*a1", force: true, expectedAfterProof: "a".repeat(64), expectedProof: "b".repeat(64) }
const result = { receiptId: input.receiptId, peerId: input.peerId, force: true, verified: true, historyRecorded: true, revisionRecorded: true, commandCount: 1, completedCommands: 1, afterProof: input.expectedAfterProof }
const row = { connection_id: "connection", state: "verified", intended_state: redact({ kind: "service", service: "network.ipsec.peers.delete", input }), result }
assert.equal(hasVerifiedIpsecPeerDeletion(row, input, input.expectedAfterProof), true)
for (const patch of [{ state: "unknown" }, { state: "intent" }, { connection_id: "other" }, { intended_state: { ...row.intended_state, input: { ...input, force: false } } }]) assert.equal(hasVerifiedIpsecPeerDeletion({ ...row, ...patch }, input, input.expectedAfterProof), false)
for (const patch of [{ receiptId: "other" }, { peerId: "*a2" }, { force: false }, { historyRecorded: false }, { revisionRecorded: false }, { commandCount: 2 }, { completedCommands: 0 }, { afterProof: "c".repeat(64) }, { verified: false }]) assert.equal(hasVerifiedIpsecPeerDeletion({ ...row, result: { ...result, ...patch } }, input, input.expectedAfterProof), false)
assert.equal(hasVerifiedIpsecPeerDeletion(row, input, input.expectedProof), false)
console.log("✓ IPsec reconciliation requires exact VERIFIED generic step, same connection/intended state/receipt/native ID/one acknowledged command/history proof")