























@@ -67,6 +67,9 @@ type DemoDmAccount = {
6767allowFrom?: string[];
6868};
696970+type DemoDmPolicy = ReturnType<ReturnType<typeof createDemoDmSecurityResolver>>;
71+type ExpectedDemoDmPolicy = Omit<DemoDmPolicy, "normalizeEntry">;
72+7073function createDemoDmSecurityResolver(
7174params: {
7275inheritSharedDefaultsFromDefaultAccount?: boolean;
@@ -82,6 +85,17 @@ function createDemoDmSecurityResolver(
8285});
8386}
848788+function expectDemoDmPolicy(policy: DemoDmPolicy, expected: ExpectedDemoDmPolicy) {
89+const { normalizeEntry, ...rest } = policy;
90+91+expect(rest).toEqual(expected);
92+expect(normalizeEntry).toBeTypeOf("function");
93+if (typeof normalizeEntry !== "function") {
94+throw new Error("expected normalizeEntry to be a function");
95+}
96+expect(normalizeEntry("OWNER")).toBe("owner");
97+}
98+8599describe("mapAllowFromEntries", () => {
86100it.each([
87101{
@@ -444,7 +458,7 @@ describe("createScopedDmSecurityResolver", () => {
444458it("builds account-aware DM policy payloads", () => {
445459const resolveDmPolicy = createDemoDmSecurityResolver();
446460447-expect(
461+expectDemoDmPolicy(
448462resolveDmPolicy({
449463cfg: {
450464channels: {
@@ -462,22 +476,22 @@ describe("createScopedDmSecurityResolver", () => {
462476allowFrom: ["Owner"],
463477},
464478}),
465-).toEqual({
466-policy: "allowlist",
467-allowFrom: ["Owner"],
468-policyPath: "channels.demo.accounts.alt.dmPolicy",
469-allowFromPath: "channels.demo.accounts.alt.",
470-approveHint: formatPairingApproveHint("demo"),
471-normalizeEntry: expect.any(Function),
472-});
479+ {
480+ policy: "allowlist",
481+ allowFrom: ["Owner"],
482+ policyPath: "channels.demo.accounts.alt.dmPolicy",
483+ allowFromPath: "channels.demo.accounts.alt.",
484+ approveHint: formatPairingApproveHint("demo"),
485+},
486+);
473487});
474488475489it("uses accounts.default paths when named accounts inherit shared defaults", () => {
476490const resolveDmPolicy = createDemoDmSecurityResolver({
477491inheritSharedDefaultsFromDefaultAccount: true,
478492});
479493480-expect(
494+expectDemoDmPolicy(
481495resolveDmPolicy({
482496cfg: {
483497channels: {
@@ -499,20 +513,20 @@ describe("createScopedDmSecurityResolver", () => {
499513allowFrom: ["Owner"],
500514},
501515}),
502-).toEqual({
503-policy: "allowlist",
504-allowFrom: ["Owner"],
505-policyPath: "channels.demo.accounts.default.dmPolicy",
506-allowFromPath: "channels.demo.accounts.default.",
507-approveHint: formatPairingApproveHint("demo"),
508-normalizeEntry: expect.any(Function),
509-});
516+ {
517+ policy: "allowlist",
518+ allowFrom: ["Owner"],
519+ policyPath: "channels.demo.accounts.default.dmPolicy",
520+ allowFromPath: "channels.demo.accounts.default.",
521+ approveHint: formatPairingApproveHint("demo"),
522+},
523+);
510524});
511525512526it("ignores accounts.default paths unless the channel opts into shared default-account inheritance", () => {
513527const resolveDmPolicy = createDemoDmSecurityResolver();
514528515-expect(
529+expectDemoDmPolicy(
516530resolveDmPolicy({
517531cfg: {
518532channels: {
@@ -536,14 +550,14 @@ describe("createScopedDmSecurityResolver", () => {
536550allowFrom: ["*"],
537551},
538552}),
539-).toEqual({
540-policy: "pairing",
541-allowFrom: ["*"],
542-policyPath: "channels.demo.dmPolicy",
543-allowFromPath: "channels.demo.",
544-approveHint: formatPairingApproveHint("demo"),
545-normalizeEntry: expect.any(Function),
546-});
553+ {
554+ policy: "pairing",
555+ allowFrom: ["*"],
556+ policyPath: "channels.demo.dmPolicy",
557+ allowFromPath: "channels.demo.",
558+ approveHint: formatPairingApproveHint("demo"),
559+},
560+);
547561});
548562});
549563此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。