feat(identity): redirect legacy Zhuyuan ids to ICE-P
This commit is contained in:
parent
263142cc6b
commit
aa6652a646
28 changed files with 491 additions and 106 deletions
|
|
@ -1,7 +1,10 @@
|
|||
"use strict";
|
||||
const assert = require("node:assert/strict");
|
||||
const test = require("node:test");
|
||||
const { createServer, loadMap, loadNodeMap, search, searchAll } = require("./server");
|
||||
const {
|
||||
createServer, loadMap, loadNodeMap, loadSubjectRegistry, loadSubjectAliasMap,
|
||||
resolveSubjectId, search, searchAll,
|
||||
} = require("./server");
|
||||
|
||||
test("repository map has unique sequential codes and domestic primary routes", () => {
|
||||
const map = loadMap();
|
||||
|
|
@ -33,7 +36,7 @@ test("server node map binds Zhuyuan routes to the domestic primary", () => {
|
|||
assert.equal(map.map_id, "FD-NODE-MAP-001");
|
||||
assert.equal(map.default_node, "JD-FD-PRIMARY");
|
||||
const node = map.nodes.find(item => item.node_id === "JD-FD-PRIMARY");
|
||||
assert.ok(node.persona_systems.includes("ICE-GL-ZY001"));
|
||||
assert.ok(node.persona_systems.includes("ICE-P-ZY001"));
|
||||
const loop = map.persona_routes.find(item => item.route_id === "ZY-OPS-LOOP-001");
|
||||
assert.equal(loop.primary_node, "JD-FD-PRIMARY");
|
||||
assert.match(loop.path, /zhuyuan-persona-system/);
|
||||
|
|
@ -49,6 +52,30 @@ test("Zhuyuan Chinese query returns the numbered operation loop", () => {
|
|||
assert.equal(results[0].route_id, "ZY-OPS-LOOP-001");
|
||||
});
|
||||
|
||||
test("legacy Zhuyuan ids canonicalize before navigation", () => {
|
||||
const aliases = loadSubjectAliasMap();
|
||||
for (const legacyId of ["ICE-GL-ZY001", "ICE-PZY-001"]) {
|
||||
const resolved = resolveSubjectId(aliases, legacyId);
|
||||
assert.equal(resolved.canonical_id, "ICE-P-ZY001");
|
||||
assert.equal(resolved.redirected, true);
|
||||
assert.equal(resolved.route_id, "FD-PERSONA-LOGIN-001");
|
||||
}
|
||||
assert.equal(resolveSubjectId(aliases, "ICE-P-ZY001").redirected, false);
|
||||
});
|
||||
|
||||
test("human ids remain human and conflicted persona ids fail closed", () => {
|
||||
const aliases = loadSubjectAliasMap();
|
||||
assert.equal(resolveSubjectId(aliases, "ICE-GL∞").status, "NOT_FOUND_NO_GUESS");
|
||||
assert.equal(resolveSubjectId(aliases, "ICE-PCA-001").status, "CONFLICT_REJECTED");
|
||||
});
|
||||
|
||||
test("searching the old id returns the canonical subject", () => {
|
||||
const results = searchAll(loadMap(), loadNodeMap(), "ICE-GL-ZY001", loadSubjectRegistry());
|
||||
const subject = results.find(item => item.kind === "subject");
|
||||
assert.equal(subject.id, "ICE-P-ZY001");
|
||||
assert.ok(subject.legacy_ids.includes("ICE-GL-ZY001"));
|
||||
});
|
||||
|
||||
test("public endpoints are read-only and expose CORS", async () => {
|
||||
const server = createServer();
|
||||
await new Promise(resolve => server.listen(0, "127.0.0.1", resolve));
|
||||
|
|
@ -63,7 +90,21 @@ test("public endpoints are read-only and expose CORS", async () => {
|
|||
assert.equal((await nodeResponse.json()).node_id, "JD-FD-PRIMARY");
|
||||
const loopResponse = await fetch(`${base}/v1/resolve?id=ZY-OPS-LOOP-001`);
|
||||
assert.equal(loopResponse.status, 200);
|
||||
assert.equal((await loopResponse.json()).persona_system, "ICE-GL-ZY001");
|
||||
assert.equal((await loopResponse.json()).persona_system, "ICE-P-ZY001");
|
||||
const legacyResponse = await fetch(`${base}/v1/resolve?id=ICE-GL-ZY001`);
|
||||
assert.equal(legacyResponse.status, 200);
|
||||
const legacyResolution = await legacyResponse.json();
|
||||
assert.equal(legacyResolution.canonical_id, "ICE-P-ZY001");
|
||||
assert.equal(legacyResolution.redirected, true);
|
||||
assert.equal(legacyResolution.subject.subject_kind, "persona_system");
|
||||
const canonicalResponse = await fetch(`${base}/v1/resolve?id=ICE-P-ZY001`);
|
||||
assert.equal((await canonicalResponse.json()).redirected, false);
|
||||
const humanResponse = await fetch(`${base}/v1/resolve?id=${encodeURIComponent("ICE-GL∞")}`);
|
||||
const humanResolution = await humanResponse.json();
|
||||
assert.equal(humanResponse.status, 200);
|
||||
assert.equal(humanResolution.subject_kind, "human");
|
||||
assert.equal(humanResolution.canonical_id, "ICE-GL∞");
|
||||
assert.equal((await fetch(`${base}/v1/resolve?id=ICE-PCA-001`)).status, 409);
|
||||
const manifestResponse = await fetch(`${base}/well-known`);
|
||||
const manifest = await manifestResponse.json();
|
||||
assert.equal(manifest.write_authorization.request_credential_required, false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue