[HLCC-ICE-000001][ZY-CONTRIB-20260723-001] feat: 以来光者贡献链启用冰朔第五域个人子频道
This commit is contained in:
commit
5615453e4e
660 changed files with 122355 additions and 0 deletions
37
server-tools/lake-lamp-authz/map-gate.test.js
Normal file
37
server-tools/lake-lamp-authz/map-gate.test.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"use strict";
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const { MapGate } = require("./map-gate");
|
||||
|
||||
test("non-map actions stay locked until the exact current map is acknowledged", () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "map-gate-"));
|
||||
try {
|
||||
const maps = path.join(dir, "maps"); fs.mkdirSync(maps);
|
||||
fs.writeFileSync(path.join(maps, "JD-FD-PRIMARY.json"), JSON.stringify({ node_id: "JD-FD-PRIMARY", modules: [{ code: "JD-GTW-01" }] }));
|
||||
const gate = new MapGate({ mapsDir: maps, stateFile: path.join(dir, "state.json") });
|
||||
const map = gate.read("JD-FD-PRIMARY");
|
||||
assert.equal(gate.verify("session-token", "JD-FD-PRIMARY", map.hash).reason, "map_not_acknowledged");
|
||||
assert.equal(gate.ack("session-token", "JD-FD-PRIMARY", map.hash, 100, 3600).ok, true);
|
||||
assert.equal(gate.verify("session-token", "JD-FD-PRIMARY", map.hash, 101).ok, true);
|
||||
assert.equal(gate.verify("session-token", "OTHER", map.hash, 101).reason, "map_target_mismatch");
|
||||
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
test("changing the server map invalidates an old acknowledgement", () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "map-gate-"));
|
||||
try {
|
||||
const maps = path.join(dir, "maps"); fs.mkdirSync(maps);
|
||||
const file = path.join(maps, "JD-FD-PRIMARY.json");
|
||||
fs.writeFileSync(file, JSON.stringify({ node_id: "JD-FD-PRIMARY", modules: ["A"] }));
|
||||
const gate = new MapGate({ mapsDir: maps });
|
||||
const oldMap = gate.read("JD-FD-PRIMARY");
|
||||
gate.ack("session-token", "JD-FD-PRIMARY", oldMap.hash, 100, 3600);
|
||||
fs.writeFileSync(file, JSON.stringify({ node_id: "JD-FD-PRIMARY", modules: ["A", "B"] }));
|
||||
const newMap = gate.read("JD-FD-PRIMARY");
|
||||
assert.notEqual(oldMap.hash, newMap.hash);
|
||||
assert.equal(gate.verify("session-token", "JD-FD-PRIMARY", newMap.hash, 101).reason, "map_changed");
|
||||
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
||||
});
|
||||
Loading…
Reference in a new issue