mirror of
https://github.com/sinanyuntu/trade-message-center.git
synced 2026-09-17 13:22:11 +08:00
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
// 验证纪要读取授权协议的严格解码边界
|
|
|
|
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
decodeOneTalkSummaryReadAuthorization,
|
|
ONETALK_SUMMARY_READ_PURPOSE,
|
|
} from "../src/index.ts";
|
|
|
|
const authorization = {
|
|
purpose: ONETALK_SUMMARY_READ_PURPOSE,
|
|
scope: {
|
|
workspaceId: "803937a7-f7d3-497d-a5ec-b99d0314669e",
|
|
channelAccountId: "account-1",
|
|
conversationId: "conversation-1",
|
|
},
|
|
permissions: ["read"],
|
|
};
|
|
|
|
test("decodes only the exact summary read grant shape", () => {
|
|
assert.deepEqual(decodeOneTalkSummaryReadAuthorization(authorization), {
|
|
ok: true,
|
|
authorization,
|
|
});
|
|
for (const value of [
|
|
{ ...authorization, permissions: ["read", "send"] },
|
|
{ ...authorization, scope: { ...authorization.scope, mindUserId: "invented" } },
|
|
{ ...authorization, purpose: "other" },
|
|
{ ...authorization, unexpected: true },
|
|
]) {
|
|
assert.deepEqual(decodeOneTalkSummaryReadAuthorization(value), { ok: false });
|
|
}
|
|
});
|
|
|
|
test("decodes only registered summary authorization rejections", () => {
|
|
assert.deepEqual(decodeOneTalkSummaryReadAuthorization({ code: "scope_forbidden" }), {
|
|
ok: false,
|
|
rejection: { code: "scope_forbidden" },
|
|
});
|
|
assert.deepEqual(decodeOneTalkSummaryReadAuthorization({ code: "unknown" }), { ok: false });
|
|
});
|