fix(wireguard): учитывать неподтверждённую ревизию импорта
This commit is contained in:
1 parent
91ee424b42
commit
8eaf78b686
10 files changed
+84
-11
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { test } from "node:test"
|
||||
import { confirmWireguardImportRevision } from "./wireguard-import-revision.js"
|
||||
import { captureAndAppendRevision } from "./config-revisions.js"
|
||||
|
||||
test("a new or unchanged revision confirms successful persistence", async () => {
|
||||
for (const created of [true, false]) {
|
||||
assert.equal(await confirmWireguardImportRevision(async () => ({ created, revision: { id: "existing-or-created" } })), true)
|
||||
}
|
||||
})
|
||||
|
||||
test("null and missing receipts do not confirm a revision", async () => {
|
||||
for (const receipt of [null, undefined]) assert.equal(await confirmWireguardImportRevision(async () => receipt), false)
|
||||
})
|
||||
|
||||
test("an exception does not confirm persistence", async () => {
|
||||
assert.equal(await confirmWireguardImportRevision(async () => { throw new Error("Persistence unavailable") }), false)
|
||||
})
|
||||
|
||||
test("real snapshot helper swallowing a capture error must fail revision confirmation", async () => {
|
||||
let calls = 0
|
||||
const capture = async () => { calls++; throw new Error("Snapshot unavailable") }
|
||||
const receipt = () => captureAndAppendRevision({ serverId: 1, section: "wireguard", source: "copy", capture })
|
||||
assert.equal(await confirmWireguardImportRevision(receipt), false)
|
||||
assert.equal(calls, 1)
|
||||
})
|
||||
@@ -0,0 +1,8 @@
|
||||
/** A swallowed snapshot/persistence error returns null; it is not an audit receipt. */
|
||||
export async function confirmWireguardImportRevision(save: () => Promise<{ created: boolean; revision: unknown } | null | undefined>): Promise<boolean> {
|
||||
try {
|
||||
return (await save()) != null
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user