* refactor: move WhatsApp channel from src/web/ to extensions/whatsapp/ Move all WhatsApp implementation code (77 source/test files + 9 channel plugin files) from src/web/ and src/channels/plugins/*/whatsapp* to extensions/whatsapp/src/. - Leave thin re-export shims at all original locations so cross-cutting imports continue to resolve - Update plugin-sdk/whatsapp.ts to only re-export generic framework utilities; channel-specific functions imported locally by the extension - Update vi.mock paths in 15 cross-cutting test files - Rename outbound.ts -> send.ts to match extension naming conventions and avoid false positive in cfg-threading guard test - Widen tsconfig.plugin-sdk.dts.json rootDir to support shim->extension cross-directory references Part of the core-channels-to-extensions migration (PR 6/10). * style: format WhatsApp extension files * fix: correct stale import paths in WhatsApp extension tests Fix vi.importActual, test mock, and hardcoded source paths that weren't updated during the file move: - media.test.ts: vi.importActual path - onboarding.test.ts: vi.importActual path - test-helpers.ts: test/mocks/baileys.js path - monitor-inbox.test-harness.ts: incomplete media/store mock - login.test.ts: hardcoded source file path - message-action-runner.media.test.ts: vi.mock/importActual path
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { resolveWhatsAppAuthDir } from "./accounts.js";
|
|
|
|
describe("resolveWhatsAppAuthDir", () => {
|
|
const stubCfg = { channels: { whatsapp: { accounts: {} } } } as Parameters<
|
|
typeof resolveWhatsAppAuthDir
|
|
>[0]["cfg"];
|
|
|
|
it("sanitizes path traversal sequences in accountId", () => {
|
|
const { authDir } = resolveWhatsAppAuthDir({
|
|
cfg: stubCfg,
|
|
accountId: "../../../etc/passwd",
|
|
});
|
|
// Sanitized accountId must not escape the whatsapp auth directory.
|
|
expect(authDir).not.toContain("..");
|
|
expect(path.basename(authDir)).not.toContain("/");
|
|
});
|
|
|
|
it("sanitizes special characters in accountId", () => {
|
|
const { authDir } = resolveWhatsAppAuthDir({
|
|
cfg: stubCfg,
|
|
accountId: "foo/bar\\baz",
|
|
});
|
|
// Sprawdzaj sanityzacje na segmencie accountId, nie na calej sciezce
|
|
// (Windows uzywa backslash jako separator katalogow).
|
|
const segment = path.basename(authDir);
|
|
expect(segment).not.toContain("/");
|
|
expect(segment).not.toContain("\\");
|
|
});
|
|
|
|
it("returns default directory for empty accountId", () => {
|
|
const { authDir } = resolveWhatsAppAuthDir({
|
|
cfg: stubCfg,
|
|
accountId: "",
|
|
});
|
|
expect(authDir).toMatch(/whatsapp[/\\]default$/);
|
|
});
|
|
|
|
it("preserves valid accountId unchanged", () => {
|
|
const { authDir } = resolveWhatsAppAuthDir({
|
|
cfg: stubCfg,
|
|
accountId: "my-account-1",
|
|
});
|
|
expect(authDir).toMatch(/whatsapp[/\\]my-account-1$/);
|
|
});
|
|
});
|