function installSsrFPolicyCapture(policies: unknown[]) {
setFetchGuardPassthrough((policy) => {
policies.push(policy);
});
}
describe("send", () => {
describe("resolveChatGuidForTarget", () => { const resolveHandleTargetGuid = async (
data: Array<Record<string, unknown>>,
service: "imessage" | "sms" | "auto" = "imessage",
) => { // First page returns the provided chats; second page is empty so the // pagination loop exits cleanly. We can't break early on participant or // non-preferred direct matches — a stronger preferred-service direct // match could still appear on a later page — so we always need to mock // at least one trailing empty page.
mockFetch
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ data }),
})
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ data: [] }),
});
it("prefers iMessage over SMS when both chats exist for the same handle", async () => { // Both chats exist; we should never silently downgrade to SMS. const result = await resolveHandleTargetGuid([
{
guid: "SMS;-;+15551234567",
participants: [{ address: "+15551234567" }],
},
{
guid: "iMessage;-;+15551234567",
participants: [{ address: "+15551234567" }],
},
]);
it("returns null when handle only exists in group chat (not DM)", async () => { // This is the critical fix: if a phone number only exists as a participant in a group chat // (no direct DM chat), we should NOT send to that group. Return null instead.
mockFetch
.mockResolvedValueOnce({
ok: true,
json: () =>
Promise.resolve({
data: [
{
guid: "iMessage;+;group-the-council",
participants: [
{ address: "+12622102921" },
{ address: "+15550001111" },
{ address: "+15550002222" },
],
},
],
}),
}) // Empty second page to stop pagination
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ data: [] }),
});
const sendCall = mockFetch.mock.calls[1]; const body = JSON.parse(sendCall[1].body); // Markdown should be stripped: no asterisks, backticks, or hashes
expect(body.message).toBe("Bold and italic with code\nHeader");
});
it("strips markdown when creating a new chat", async () => {
mockNewChatSendResponse("new-msg-stripped");
const result = await sendMessageBlueBubbles("+15550009999", "**Welcome** to the _chat_!", {
serverUrl: "http://localhost:1234",
password: "test",
});
const createCall = mockFetch.mock.calls[1];
expect(createCall[0]).toContain("/api/v1/chat/new"); const body = JSON.parse(createCall[1].body); // Markdown should be stripped
expect(body.message).toBe("Welcome to the chat!");
});
it("creates a new chat when handle target is missing", async () => {
mockNewChatSendResponse("new-msg-guid");
const result = await sendMessageBlueBubbles("+15550009999", "Hello new chat", {
serverUrl: "http://localhost:1234",
password: "test",
});
// macOS 26 Tahoe broke AppleScript Messages.app automation (-1700). When // Private API is available on these hosts, plain text sends should prefer // Private API even without reply/effect features. (#53159 Bug B, #64480)
it("forces Private API for plain text on macOS 26 when available", async () => {
mockBlueBubblesPrivateApiStatusOnce(
privateApiStatusMock,
BLUE_BUBBLES_PRIVATE_API_STATUS.enabled,
);
isMacOS26OrHigherMock.mockReturnValue(true);
mockResolvedHandleTarget();
mockSendResponse({ data: { guid: "msg-macos26" } });
// If macOS 26 host has Private API disabled, there is nothing we can do — // the AppleScript path is broken on that OS. We still tag the send // explicitly as apple-script rather than omitting `method`; BB Server's // behavior on an omitted field is version-dependent and silently drops // on some setups, which is the worse failure mode. (#64480)
it("falls back to apple-script on macOS 26 when Private API is disabled", async () => {
mockBlueBubblesPrivateApiStatusOnce(
privateApiStatusMock,
BLUE_BUBBLES_PRIVATE_API_STATUS.disabled,
);
isMacOS26OrHigherMock.mockReturnValue(true);
mockResolvedHandleTarget();
mockSendResponse({ data: { guid: "msg-macos26-no-pa" } });
expect(result.messageId).toBe("msg-uuid-unknown");
expect(runtimeLog).toHaveBeenCalledTimes(1);
expect(runtimeLog.mock.calls[0]?.[0]).toContain("Private API status unknown");
expect(warnSpy).not.toHaveBeenCalled();
expect(result.messageId).toBe("msg-degraded");
expect(fetchServerInfoMock).toHaveBeenCalledTimes(1); // Should warn about unknown status and send without threading
expect(runtimeLog).toHaveBeenCalledTimes(1);
expect(runtimeLog.mock.calls[0]?.[0]).toContain("Private API status unknown"); const sendCall = mockFetch.mock.calls[1]; const body = JSON.parse(sendCall[1].body);
expect(body.method).toBe("apple-script");
expect(body.selectedMessageGuid).toBeUndefined();
} finally {
clearBlueBubblesRuntime();
}
});
it("throws for effects when refresh succeeds with private_api: false", async () => { // Cache expired, refresh succeeds but Private API is explicitly disabled
privateApiStatusMock.mockReturnValueOnce(null).mockReturnValueOnce(false);
fetchServerInfoMock.mockResolvedValueOnce({ private_api: false });
mockResolvedHandleTarget();
expect(result.messageId).toBe("msg-disabled-after-refresh");
expect(fetchServerInfoMock).toHaveBeenCalledTimes(1); // No warning — status is known (disabled), not unknown
expect(runtimeLog).not.toHaveBeenCalled(); const sendCall = mockFetch.mock.calls[1]; const body = JSON.parse(sendCall[1].body);
expect(body.method).toBe("apple-script");
expect(body.selectedMessageGuid).toBeUndefined();
} finally {
clearBlueBubblesRuntime();
}
});
// Plain-text sends also need the cache populated so `isMacOS26OrHigher` // can read `os_version` from the same `serverInfoCache`. Without a // refresh on cold/expired cache, macOS 26 detection would silently // miss and force-route would fall back to broken AppleScript. // (Greptile/Codex PR #69070)
it("refreshes cache for plain-text sends when status is unknown", async () => { // First call returns null (cache cold/expired). The refresh path // fetches server info; plain-text send still uses AppleScript when // Private API is disabled on the server — but the refresh ran.
privateApiStatusMock.mockReturnValueOnce(null).mockReturnValueOnce(false);
fetchServerInfoMock.mockResolvedValueOnce({ private_api: false });
mockResolvedHandleTarget();
mockSendResponse({ data: { guid: "msg-plain-refreshed" } });
expect(result.messageId).toBe("msg-null-refresh");
expect(fetchServerInfoMock).toHaveBeenCalledTimes(1); // privateApiStatus still null after failed refresh → warning + degradation
expect(runtimeLog).toHaveBeenCalledTimes(1);
expect(runtimeLog.mock.calls[0]?.[0]).toContain("Private API status unknown");
} finally {
clearBlueBubblesRuntime();
}
});
});
describe("send timeout (#67486)", () => { // Capture the `timeoutMs` that the SSRF guard receives on each call. // Index 0 is the `chat/query` preflight; index 1 is the actual // `/api/v1/message/text` POST — that's the one we care about. function installTimeoutCapture(): (number | undefined)[] { const timeouts: (number | undefined)[] = [];
_setFetchGuardForTesting(async (guardParams) => {
timeouts.push(guardParams.timeoutMs); const raw = await globalThis.fetch(guardParams.url, guardParams.init); // Mirrors `createBlueBubblesFetchGuardPassthroughInstaller` so both // `.json()`-only chat-query mocks and `.text()`-only send mocks work.
let body: ArrayBuffer; if ( typeof (raw as { arrayBuffer?: () => Promise<ArrayBuffer> }).arrayBuffer === "function"
) {
body = await (raw as { arrayBuffer: () => Promise<ArrayBuffer> }).arrayBuffer();
} else { const text = typeof (raw as { text?: () => Promise<string> }).text === "function"
? await (raw as { text: () => Promise<string> }).text()
: typeof (raw as { json?: () => Promise<unknown> }).json === "function"
? JSON.stringify(await (raw as { json: () => Promise<unknown> }).json())
: "";
body = new TextEncoder().encode(text).buffer;
} return {
response: new Response(body, {
status: (raw as { status?: number }).status ?? 200,
headers: (raw as { headers?: HeadersInit }).headers,
}),
release: async () => {},
finalUrl: guardParams.url,
};
}); return timeouts;
}
it("defaults the /message/text send to DEFAULT_SEND_TIMEOUT_MS (30s), not 10s", async () => { const timeouts = installTimeoutCapture();
mockResolvedHandleTarget();
mockSendResponse({ data: { guid: "msg-default-timeout" } });
try { const result = await sendMessageBlueBubbles("+15551234567", "Hello", {
serverUrl: "http://localhost:1234",
password: "test",
});
expect(result.messageId).toBe("msg-default-timeout"); // chat/query preflight must stay at the short default; only the send POST rises.
expect(timeouts[0]).toBe(10_000);
expect(timeouts[1]).toBe(30_000);
} finally {
_setFetchGuardForTesting(null);
}
});
it("honors channels.bluebubbles.sendTimeoutMs from config for the send POST", async () => { const timeouts = installTimeoutCapture();
mockResolvedHandleTarget();
mockSendResponse({ data: { guid: "msg-config-timeout" } });
try { const result = await sendMessageBlueBubbles("+15551234567", "Hello", {
cfg: {
channels: {
bluebubbles: {
serverUrl: "http://localhost:1234",
password: "test",
sendTimeoutMs: 45_000,
},
},
},
});
expect(result.messageId).toBe("msg-config-timeout"); // chat/query preflight must stay at the short default; only the send POST rises.
expect(timeouts[0]).toBe(10_000);
expect(timeouts[1]).toBe(45_000);
} finally {
_setFetchGuardForTesting(null);
}
});
it("explicit opts.timeoutMs wins over both config and default", async () => { const timeouts = installTimeoutCapture();
mockResolvedHandleTarget();
mockSendResponse({ data: { guid: "msg-explicit-timeout" } });
try { const result = await sendMessageBlueBubbles("+15551234567", "Hello", {
cfg: {
channels: {
bluebubbles: {
serverUrl: "http://localhost:1234",
password: "test",
sendTimeoutMs: 45_000,
},
},
},
timeoutMs: 90_000,
});
expect(result.messageId).toBe("msg-explicit-timeout"); // Explicit opts.timeoutMs is forwarded to every call site, including // the chat/query preflight — the only override that can push that // preflight above the 10s default.
expect(timeouts[0]).toBe(90_000);
expect(timeouts[1]).toBe(90_000);
} finally {
_setFetchGuardForTesting(null);
}
});
});
});
describe("createChatForHandle", () => {
it("creates a new chat and returns chatGuid from response", async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
text: () =>
Promise.resolve(
JSON.stringify({
data: { guid: "iMessage;-;+15559876543", chatGuid: "iMessage;-;+15559876543" },
}),
),
});
it("throws when Private API is not enabled", async () => {
mockFetch.mockResolvedValueOnce({
ok: false,
status: 403,
text: () => Promise.resolve("Private API not enabled"),
});
await expect(
createChatForHandle({
baseUrl: "http://localhost:1234",
password: "test",
address: "+15559876543",
}),
).rejects.toThrow("Private API must be enabled");
});
it("returns null chatGuid when response has no chat data", async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
text: () => Promise.resolve(JSON.stringify({ data: {} })),
});
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.26Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.