@kodelyth/zalouser 2026.5.42 → 2026.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/klaw.plugin.json +286 -3
- package/package.json +17 -4
- package/api.ts +0 -9
- package/channel-plugin-api.ts +0 -3
- package/contract-api.ts +0 -2
- package/doctor-contract-api.ts +0 -1
- package/index.ts +0 -34
- package/runtime-api.ts +0 -62
- package/secret-contract-api.ts +0 -4
- package/setup-entry.ts +0 -9
- package/setup-plugin-api.ts +0 -2
- package/src/accounts.runtime.ts +0 -1
- package/src/accounts.test-mocks.ts +0 -14
- package/src/accounts.test.ts +0 -298
- package/src/accounts.ts +0 -136
- package/src/channel-api.ts +0 -16
- package/src/channel.adapters.ts +0 -432
- package/src/channel.directory.test.ts +0 -59
- package/src/channel.runtime.ts +0 -12
- package/src/channel.sendpayload.test.ts +0 -311
- package/src/channel.setup.test.ts +0 -30
- package/src/channel.setup.ts +0 -12
- package/src/channel.test.ts +0 -424
- package/src/channel.ts +0 -221
- package/src/config-schema.ts +0 -33
- package/src/directory.ts +0 -54
- package/src/doctor-contract.ts +0 -156
- package/src/doctor.test.ts +0 -87
- package/src/doctor.ts +0 -37
- package/src/group-policy.test.ts +0 -61
- package/src/group-policy.ts +0 -83
- package/src/message-sid.test.ts +0 -66
- package/src/message-sid.ts +0 -80
- package/src/monitor.account-scope.test.ts +0 -122
- package/src/monitor.group-gating.test.ts +0 -967
- package/src/monitor.send-mocks.ts +0 -20
- package/src/monitor.ts +0 -1057
- package/src/probe.test.ts +0 -60
- package/src/probe.ts +0 -35
- package/src/qr-temp-file.ts +0 -19
- package/src/reaction.test.ts +0 -19
- package/src/reaction.ts +0 -32
- package/src/runtime.ts +0 -9
- package/src/security-audit.test.ts +0 -83
- package/src/security-audit.ts +0 -71
- package/src/send-receipt.ts +0 -31
- package/src/send.test.ts +0 -424
- package/src/send.ts +0 -280
- package/src/session-route.ts +0 -121
- package/src/setup-core.ts +0 -36
- package/src/setup-surface.test.ts +0 -367
- package/src/setup-surface.ts +0 -481
- package/src/setup-test-helpers.ts +0 -42
- package/src/shared.ts +0 -92
- package/src/status-issues.test.ts +0 -31
- package/src/status-issues.ts +0 -55
- package/src/test-helpers.ts +0 -26
- package/src/text-styles.test.ts +0 -203
- package/src/text-styles.ts +0 -540
- package/src/tool.test.ts +0 -212
- package/src/tool.ts +0 -200
- package/src/types.ts +0 -127
- package/src/zalo-js.credentials.test.ts +0 -465
- package/src/zalo-js.test-mocks.ts +0 -89
- package/src/zalo-js.ts +0 -1889
- package/src/zca-client.test.ts +0 -27
- package/src/zca-client.ts +0 -259
- package/src/zca-constants.ts +0 -55
- package/src/zca-js-exports.d.ts +0 -22
- package/test-api.ts +0 -21
- package/tsconfig.json +0 -16
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type { KlawConfig, PluginRuntime } from "../runtime-api.js";
|
|
3
|
-
import "./monitor.send-mocks.js";
|
|
4
|
-
import { testing } from "./monitor.js";
|
|
5
|
-
import "./zalo-js.test-mocks.js";
|
|
6
|
-
import { sendMessageZalouserMock } from "./monitor.send-mocks.js";
|
|
7
|
-
import { setZalouserRuntime } from "./runtime.js";
|
|
8
|
-
import { createZalouserRuntimeEnv } from "./test-helpers.js";
|
|
9
|
-
import type { ResolvedZalouserAccount, ZaloInboundMessage } from "./types.js";
|
|
10
|
-
|
|
11
|
-
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
|
12
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
13
|
-
throw new Error(`expected ${label} to be a record`);
|
|
14
|
-
}
|
|
15
|
-
return value as Record<string, unknown>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
describe("zalouser monitor pairing account scoping", () => {
|
|
19
|
-
it("scopes DM pairing-store reads and pairing requests to accountId", async () => {
|
|
20
|
-
const readAllowFromStore = vi.fn(
|
|
21
|
-
async (
|
|
22
|
-
channelOrParams:
|
|
23
|
-
| string
|
|
24
|
-
| {
|
|
25
|
-
channel?: string;
|
|
26
|
-
accountId?: string;
|
|
27
|
-
},
|
|
28
|
-
_env?: NodeJS.ProcessEnv,
|
|
29
|
-
accountId?: string,
|
|
30
|
-
) => {
|
|
31
|
-
const scopedAccountId =
|
|
32
|
-
typeof channelOrParams === "object" && channelOrParams !== null
|
|
33
|
-
? channelOrParams.accountId
|
|
34
|
-
: accountId;
|
|
35
|
-
return scopedAccountId === "beta" ? [] : ["attacker"];
|
|
36
|
-
},
|
|
37
|
-
);
|
|
38
|
-
const upsertPairingRequest = vi.fn(
|
|
39
|
-
async (_params: { channel: string; id: string; accountId?: string }) => ({
|
|
40
|
-
code: "PAIRME88",
|
|
41
|
-
created: true,
|
|
42
|
-
}),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
setZalouserRuntime({
|
|
46
|
-
logging: {
|
|
47
|
-
shouldLogVerbose: () => false,
|
|
48
|
-
},
|
|
49
|
-
channel: {
|
|
50
|
-
pairing: {
|
|
51
|
-
readAllowFromStore,
|
|
52
|
-
upsertPairingRequest,
|
|
53
|
-
buildPairingReply: vi.fn(() => "pairing reply"),
|
|
54
|
-
},
|
|
55
|
-
commands: {
|
|
56
|
-
shouldComputeCommandAuthorized: vi.fn(() => false),
|
|
57
|
-
resolveCommandAuthorizedFromAuthorizers: vi.fn(() => false),
|
|
58
|
-
isControlCommandMessage: vi.fn(() => false),
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
} as unknown as PluginRuntime);
|
|
62
|
-
|
|
63
|
-
const account: ResolvedZalouserAccount = {
|
|
64
|
-
accountId: "beta",
|
|
65
|
-
enabled: true,
|
|
66
|
-
profile: "beta",
|
|
67
|
-
authenticated: true,
|
|
68
|
-
config: {
|
|
69
|
-
dmPolicy: "pairing",
|
|
70
|
-
allowFrom: [],
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const config: KlawConfig = {
|
|
75
|
-
channels: {
|
|
76
|
-
zalouser: {
|
|
77
|
-
accounts: {
|
|
78
|
-
alpha: { dmPolicy: "pairing", allowFrom: [] },
|
|
79
|
-
beta: { dmPolicy: "pairing", allowFrom: [] },
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const message: ZaloInboundMessage = {
|
|
86
|
-
threadId: "chat-1",
|
|
87
|
-
isGroup: false,
|
|
88
|
-
senderId: "attacker",
|
|
89
|
-
senderName: "Attacker",
|
|
90
|
-
groupName: undefined,
|
|
91
|
-
timestampMs: Date.now(),
|
|
92
|
-
msgId: "msg-1",
|
|
93
|
-
content: "hello",
|
|
94
|
-
raw: { source: "test" },
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
await testing.processMessage({
|
|
98
|
-
message,
|
|
99
|
-
account,
|
|
100
|
-
config,
|
|
101
|
-
runtime: createZalouserRuntimeEnv(),
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
expect(readAllowFromStore).toHaveBeenCalledOnce();
|
|
105
|
-
const allowStoreParams = requireRecord(
|
|
106
|
-
readAllowFromStore.mock.calls[0]?.[0],
|
|
107
|
-
"allow store params",
|
|
108
|
-
);
|
|
109
|
-
expect(allowStoreParams.channel).toBe("zalouser");
|
|
110
|
-
expect(allowStoreParams.accountId).toBe("beta");
|
|
111
|
-
|
|
112
|
-
expect(upsertPairingRequest).toHaveBeenCalledOnce();
|
|
113
|
-
const pairingRequest = requireRecord(
|
|
114
|
-
upsertPairingRequest.mock.calls[0]?.[0],
|
|
115
|
-
"pairing request params",
|
|
116
|
-
);
|
|
117
|
-
expect(pairingRequest.channel).toBe("zalouser");
|
|
118
|
-
expect(pairingRequest.id).toBe("attacker");
|
|
119
|
-
expect(pairingRequest.accountId).toBe("beta");
|
|
120
|
-
expect(sendMessageZalouserMock).toHaveBeenCalled();
|
|
121
|
-
});
|
|
122
|
-
});
|