41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import test from "node:test";
|
|
|
|
const migrationUrl = new URL(
|
|
"../migrations/007_device_lifecycle_commands.sql",
|
|
import.meta.url,
|
|
);
|
|
const repositoryUrl = new URL("../src/postgres-repository.mjs", import.meta.url);
|
|
|
|
test("lifecycle command migration extends the durable receipt allowlist", async () => {
|
|
const sql = await readFile(migrationUrl, "utf8");
|
|
|
|
for (const kind of [
|
|
"device.claim",
|
|
"device.transfer",
|
|
"discovery.reject",
|
|
"discovery.expire",
|
|
]) {
|
|
assert.match(sql, new RegExp(`'${kind.replace(".", "\\.")}'`));
|
|
}
|
|
});
|
|
|
|
test("lifecycle command migration contains no runtime entity or secret", async () => {
|
|
const sql = await readFile(migrationUrl, "utf8");
|
|
|
|
assert.doesNotMatch(sql, /insert\s+into/i);
|
|
assert.doesNotMatch(sql, /dcctouch|arusnavi|\bb2\b|imei|gelios/i);
|
|
assert.doesNotMatch(sql, /password|secret|credential|private_key/i);
|
|
});
|
|
|
|
test("repository applies lifecycle commands after ownership schema", async () => {
|
|
const source = await readFile(repositoryUrl, "utf8");
|
|
const lifecycleIndex = source.indexOf("006_device_lifecycle_ownership.sql");
|
|
const commandsIndex = source.indexOf("007_device_lifecycle_commands.sql");
|
|
|
|
assert.notEqual(lifecycleIndex, -1);
|
|
assert.notEqual(commandsIndex, -1);
|
|
assert.ok(lifecycleIndex < commandsIndex);
|
|
});
|