@openclaw/msteams 2026.5.2 → 2026.5.3-beta.2
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/dist/api.js +3 -0
- package/dist/channel-D7hdreTh.js +984 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-BC1ruIfN.js +573 -0
- package/dist/config-schema-B8QezH6t.js +15 -0
- package/dist/contract-api.js +2 -0
- package/dist/graph-users-9uQJepqr.js +1354 -0
- package/dist/index.js +22 -0
- package/dist/oauth-BWJyilR1.js +114 -0
- package/dist/oauth.token-xxpoLWy5.js +115 -0
- package/dist/policy-DTnU2GR7.js +142 -0
- package/dist/probe-D_H8yFps.js +2194 -0
- package/dist/resolve-allowlist-D41JSziq.js +219 -0
- package/dist/runtime-api-DV1iVMn1.js +28 -0
- package/dist/runtime-api.js +2 -0
- package/dist/secret-contract-BuoEXmPS.js +35 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/setup-entry.js +15 -0
- package/dist/setup-plugin-api.js +64 -0
- package/dist/setup-surface-BLkFQYIQ.js +313 -0
- package/dist/src-CFp1QpFd.js +4064 -0
- package/dist/test-api.js +2 -0
- package/package.json +14 -6
- package/api.ts +0 -3
- package/channel-config-api.ts +0 -1
- package/channel-plugin-api.ts +0 -2
- package/config-api.ts +0 -4
- package/contract-api.ts +0 -4
- package/index.ts +0 -20
- package/runtime-api.ts +0 -73
- package/secret-contract-api.ts +0 -5
- package/setup-entry.ts +0 -13
- package/setup-plugin-api.ts +0 -3
- package/src/ai-entity.ts +0 -7
- package/src/approval-auth.ts +0 -44
- package/src/attachments/bot-framework.test.ts +0 -461
- package/src/attachments/bot-framework.ts +0 -362
- package/src/attachments/download.ts +0 -311
- package/src/attachments/graph.test.ts +0 -416
- package/src/attachments/graph.ts +0 -484
- package/src/attachments/html.ts +0 -122
- package/src/attachments/payload.ts +0 -14
- package/src/attachments/remote-media.test.ts +0 -137
- package/src/attachments/remote-media.ts +0 -112
- package/src/attachments/shared.test.ts +0 -530
- package/src/attachments/shared.ts +0 -626
- package/src/attachments/types.ts +0 -47
- package/src/attachments.graph.test.ts +0 -342
- package/src/attachments.helpers.test.ts +0 -246
- package/src/attachments.test-helpers.ts +0 -17
- package/src/attachments.test.ts +0 -687
- package/src/attachments.ts +0 -18
- package/src/block-streaming-config.test.ts +0 -61
- package/src/channel-api.ts +0 -1
- package/src/channel.actions.test.ts +0 -742
- package/src/channel.directory.test.ts +0 -200
- package/src/channel.runtime.ts +0 -56
- package/src/channel.setup.ts +0 -77
- package/src/channel.test.ts +0 -128
- package/src/channel.ts +0 -1136
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -12
- package/src/conversation-store-fs.test.ts +0 -74
- package/src/conversation-store-fs.ts +0 -149
- package/src/conversation-store-helpers.test.ts +0 -202
- package/src/conversation-store-helpers.ts +0 -105
- package/src/conversation-store-memory.ts +0 -51
- package/src/conversation-store.shared.test.ts +0 -225
- package/src/conversation-store.ts +0 -71
- package/src/directory-live.test.ts +0 -156
- package/src/directory-live.ts +0 -111
- package/src/doctor.ts +0 -27
- package/src/errors.test.ts +0 -133
- package/src/errors.ts +0 -246
- package/src/feedback-reflection-prompt.ts +0 -117
- package/src/feedback-reflection-store.ts +0 -114
- package/src/feedback-reflection.test.ts +0 -237
- package/src/feedback-reflection.ts +0 -283
- package/src/file-consent-helpers.test.ts +0 -326
- package/src/file-consent-helpers.ts +0 -126
- package/src/file-consent-invoke.ts +0 -150
- package/src/file-consent.test.ts +0 -363
- package/src/file-consent.ts +0 -287
- package/src/graph-chat.ts +0 -55
- package/src/graph-group-management.test.ts +0 -318
- package/src/graph-group-management.ts +0 -168
- package/src/graph-members.test.ts +0 -89
- package/src/graph-members.ts +0 -48
- package/src/graph-messages.actions.test.ts +0 -243
- package/src/graph-messages.read.test.ts +0 -391
- package/src/graph-messages.search.test.ts +0 -213
- package/src/graph-messages.test-helpers.ts +0 -50
- package/src/graph-messages.ts +0 -534
- package/src/graph-teams.test.ts +0 -215
- package/src/graph-teams.ts +0 -114
- package/src/graph-thread.test.ts +0 -246
- package/src/graph-thread.ts +0 -146
- package/src/graph-upload.test.ts +0 -258
- package/src/graph-upload.ts +0 -531
- package/src/graph-users.ts +0 -29
- package/src/graph.test.ts +0 -516
- package/src/graph.ts +0 -293
- package/src/inbound.test.ts +0 -221
- package/src/inbound.ts +0 -148
- package/src/index.ts +0 -4
- package/src/media-helpers.test.ts +0 -202
- package/src/media-helpers.ts +0 -105
- package/src/mentions.test.ts +0 -244
- package/src/mentions.ts +0 -114
- package/src/messenger.test.ts +0 -865
- package/src/messenger.ts +0 -605
- package/src/monitor-handler/access.ts +0 -125
- package/src/monitor-handler/inbound-media.test.ts +0 -289
- package/src/monitor-handler/inbound-media.ts +0 -180
- package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
- package/src/monitor-handler/message-handler.authz.test.ts +0 -669
- package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
- package/src/monitor-handler/message-handler.test-support.ts +0 -100
- package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -223
- package/src/monitor-handler/message-handler.thread-session.test.ts +0 -77
- package/src/monitor-handler/message-handler.ts +0 -1000
- package/src/monitor-handler/reaction-handler.test.ts +0 -267
- package/src/monitor-handler/reaction-handler.ts +0 -210
- package/src/monitor-handler/thread-session.ts +0 -17
- package/src/monitor-handler.adaptive-card.test.ts +0 -162
- package/src/monitor-handler.feedback-authz.test.ts +0 -314
- package/src/monitor-handler.file-consent.test.ts +0 -423
- package/src/monitor-handler.sso.test.ts +0 -563
- package/src/monitor-handler.test-helpers.ts +0 -180
- package/src/monitor-handler.ts +0 -534
- package/src/monitor-handler.types.ts +0 -27
- package/src/monitor-types.ts +0 -6
- package/src/monitor.lifecycle.test.ts +0 -278
- package/src/monitor.test.ts +0 -119
- package/src/monitor.ts +0 -442
- package/src/oauth.flow.ts +0 -77
- package/src/oauth.shared.ts +0 -37
- package/src/oauth.test.ts +0 -305
- package/src/oauth.token.ts +0 -158
- package/src/oauth.ts +0 -130
- package/src/outbound.test.ts +0 -130
- package/src/outbound.ts +0 -71
- package/src/pending-uploads-fs.test.ts +0 -246
- package/src/pending-uploads-fs.ts +0 -235
- package/src/pending-uploads.test.ts +0 -173
- package/src/pending-uploads.ts +0 -121
- package/src/policy.test.ts +0 -240
- package/src/policy.ts +0 -262
- package/src/polls-store-memory.ts +0 -32
- package/src/polls.test.ts +0 -160
- package/src/polls.ts +0 -323
- package/src/presentation.ts +0 -68
- package/src/probe.test.ts +0 -77
- package/src/probe.ts +0 -132
- package/src/reply-dispatcher.test.ts +0 -437
- package/src/reply-dispatcher.ts +0 -346
- package/src/reply-stream-controller.test.ts +0 -235
- package/src/reply-stream-controller.ts +0 -147
- package/src/resolve-allowlist.test.ts +0 -250
- package/src/resolve-allowlist.ts +0 -309
- package/src/revoked-context.ts +0 -17
- package/src/runtime.ts +0 -9
- package/src/sdk-types.ts +0 -59
- package/src/sdk.test.ts +0 -666
- package/src/sdk.ts +0 -884
- package/src/secret-contract.ts +0 -49
- package/src/secret-input.ts +0 -7
- package/src/send-context.ts +0 -231
- package/src/send.test.ts +0 -493
- package/src/send.ts +0 -637
- package/src/sent-message-cache.test.ts +0 -15
- package/src/sent-message-cache.ts +0 -56
- package/src/session-route.ts +0 -40
- package/src/setup-core.ts +0 -160
- package/src/setup-surface.test.ts +0 -202
- package/src/setup-surface.ts +0 -320
- package/src/sso-token-store.test.ts +0 -72
- package/src/sso-token-store.ts +0 -166
- package/src/sso.ts +0 -300
- package/src/storage.ts +0 -25
- package/src/store-fs.ts +0 -44
- package/src/streaming-message.test.ts +0 -262
- package/src/streaming-message.ts +0 -297
- package/src/test-runtime.ts +0 -16
- package/src/thread-parent-context.test.ts +0 -224
- package/src/thread-parent-context.ts +0 -159
- package/src/token-response.ts +0 -11
- package/src/token.test.ts +0 -259
- package/src/token.ts +0 -195
- package/src/user-agent.test.ts +0 -86
- package/src/user-agent.ts +0 -53
- package/src/webhook-timeouts.ts +0 -27
- package/src/welcome-card.test.ts +0 -81
- package/src/welcome-card.ts +0 -57
- package/test-api.ts +0 -1
- package/tsconfig.json +0 -16
package/src/attachments.test.ts
DELETED
|
@@ -1,687 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type { PluginRuntime, SsrFPolicy } from "../runtime-api.js";
|
|
3
|
-
import { readRemoteMediaResponse } from "./attachments.test-helpers.js";
|
|
4
|
-
import { downloadMSTeamsAttachments } from "./attachments/download.js";
|
|
5
|
-
import { resolveRequestUrl } from "./attachments/shared.js";
|
|
6
|
-
import { setMSTeamsRuntime } from "./runtime.js";
|
|
7
|
-
|
|
8
|
-
const GRAPH_HOST = "graph.microsoft.com";
|
|
9
|
-
const _SHAREPOINT_HOST = "contoso.sharepoint.com";
|
|
10
|
-
const AZUREEDGE_HOST = "azureedge.net";
|
|
11
|
-
const TEST_HOST = "x";
|
|
12
|
-
const createUrlForHost = (host: string, pathSegment: string) => `https://${host}/${pathSegment}`;
|
|
13
|
-
const createTestUrl = (pathSegment: string) => createUrlForHost(TEST_HOST, pathSegment);
|
|
14
|
-
const SAVED_PNG_PATH = "/tmp/saved.png";
|
|
15
|
-
const SAVED_PDF_PATH = "/tmp/saved.pdf";
|
|
16
|
-
const TEST_URL_IMAGE = createTestUrl("img");
|
|
17
|
-
const _TEST_URL_IMAGE_PNG = createTestUrl("img.png");
|
|
18
|
-
const _TEST_URL_IMAGE_1_PNG = createTestUrl("1.png");
|
|
19
|
-
const _TEST_URL_IMAGE_2_JPG = createTestUrl("2.jpg");
|
|
20
|
-
const _TEST_URL_PDF = createTestUrl("x.pdf");
|
|
21
|
-
const _TEST_URL_PDF_1 = createTestUrl("1.pdf");
|
|
22
|
-
const _TEST_URL_PDF_2 = createTestUrl("2.pdf");
|
|
23
|
-
const _TEST_URL_HTML_A = createTestUrl("a.png");
|
|
24
|
-
const _TEST_URL_HTML_B = createTestUrl("b.png");
|
|
25
|
-
const TEST_URL_INLINE_IMAGE = createTestUrl("inline.png");
|
|
26
|
-
const TEST_URL_DOC_PDF = createTestUrl("doc.pdf");
|
|
27
|
-
const TEST_URL_FILE_DOWNLOAD = createTestUrl("dl");
|
|
28
|
-
const TEST_URL_OUTSIDE_ALLOWLIST = "https://evil.test/img";
|
|
29
|
-
const CONTENT_TYPE_IMAGE_PNG = "image/png";
|
|
30
|
-
const CONTENT_TYPE_APPLICATION_PDF = "application/pdf";
|
|
31
|
-
const CONTENT_TYPE_TEXT_HTML = "text/html";
|
|
32
|
-
const CONTENT_TYPE_TEAMS_FILE_DOWNLOAD_INFO = "application/vnd.microsoft.teams.file.download.info";
|
|
33
|
-
const REDIRECT_STATUS_CODES = new Set([301, 302, 303, 307, 308]);
|
|
34
|
-
const MAX_REDIRECT_HOPS = 5;
|
|
35
|
-
type RemoteMediaFetchParams = {
|
|
36
|
-
url: string;
|
|
37
|
-
maxBytes?: number;
|
|
38
|
-
filePathHint?: string;
|
|
39
|
-
ssrfPolicy?: SsrFPolicy;
|
|
40
|
-
fetchImpl?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const detectMimeMock = vi.fn(async () => CONTENT_TYPE_IMAGE_PNG);
|
|
44
|
-
const saveMediaBufferMock = vi.fn(async () => ({
|
|
45
|
-
id: "saved.png",
|
|
46
|
-
path: SAVED_PNG_PATH,
|
|
47
|
-
size: Buffer.byteLength(PNG_BUFFER),
|
|
48
|
-
contentType: CONTENT_TYPE_IMAGE_PNG,
|
|
49
|
-
}));
|
|
50
|
-
function isHostnameAllowedByPattern(hostname: string, pattern: string): boolean {
|
|
51
|
-
if (pattern.startsWith("*.")) {
|
|
52
|
-
const suffix = pattern.slice(2);
|
|
53
|
-
return suffix.length > 0 && hostname !== suffix && hostname.endsWith(`.${suffix}`);
|
|
54
|
-
}
|
|
55
|
-
return hostname === pattern;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function isUrlAllowedBySsrfPolicy(url: string, policy?: SsrFPolicy): boolean {
|
|
59
|
-
if (!policy?.hostnameAllowlist || policy.hostnameAllowlist.length === 0) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
const hostname = new URL(url).hostname.toLowerCase();
|
|
63
|
-
return policy.hostnameAllowlist.some((pattern) =>
|
|
64
|
-
isHostnameAllowedByPattern(hostname, pattern.toLowerCase()),
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function fetchRemoteMediaWithRedirects(
|
|
69
|
-
params: RemoteMediaFetchParams,
|
|
70
|
-
requestInit?: RequestInit,
|
|
71
|
-
) {
|
|
72
|
-
const fetchFn = params.fetchImpl ?? fetch;
|
|
73
|
-
let currentUrl = params.url;
|
|
74
|
-
for (let i = 0; i <= MAX_REDIRECT_HOPS; i += 1) {
|
|
75
|
-
if (!isUrlAllowedBySsrfPolicy(currentUrl, params.ssrfPolicy)) {
|
|
76
|
-
throw new Error(`Blocked hostname (not in allowlist): ${currentUrl}`);
|
|
77
|
-
}
|
|
78
|
-
const res = await fetchFn(currentUrl, { redirect: "manual", ...requestInit });
|
|
79
|
-
if (REDIRECT_STATUS_CODES.has(res.status)) {
|
|
80
|
-
const location = res.headers.get("location");
|
|
81
|
-
if (!location) {
|
|
82
|
-
throw new Error("redirect missing location");
|
|
83
|
-
}
|
|
84
|
-
currentUrl = new URL(location, currentUrl).toString();
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
return readRemoteMediaResponse(res, params);
|
|
88
|
-
}
|
|
89
|
-
throw new Error("too many redirects");
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const fetchRemoteMediaMock = vi.fn(async (params: RemoteMediaFetchParams) => {
|
|
93
|
-
return await fetchRemoteMediaWithRedirects(params);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const runtimeStub = {
|
|
97
|
-
media: {
|
|
98
|
-
detectMime: detectMimeMock,
|
|
99
|
-
},
|
|
100
|
-
channel: {
|
|
101
|
-
media: {
|
|
102
|
-
fetchRemoteMedia: fetchRemoteMediaMock,
|
|
103
|
-
saveMediaBuffer: saveMediaBufferMock,
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
} as unknown as PluginRuntime;
|
|
107
|
-
|
|
108
|
-
type DownloadAttachmentsParams = Parameters<typeof downloadMSTeamsAttachments>[0];
|
|
109
|
-
type DownloadedMedia = Awaited<ReturnType<typeof downloadMSTeamsAttachments>>;
|
|
110
|
-
type DownloadAttachmentsBuildOverrides = Partial<
|
|
111
|
-
Omit<DownloadAttachmentsParams, "attachments" | "maxBytes" | "allowHosts">
|
|
112
|
-
> &
|
|
113
|
-
Pick<DownloadAttachmentsParams, "allowHosts">;
|
|
114
|
-
type DownloadAttachmentsNoFetchOverrides = Partial<
|
|
115
|
-
Omit<DownloadAttachmentsParams, "attachments" | "maxBytes" | "allowHosts" | "fetchFn">
|
|
116
|
-
> &
|
|
117
|
-
Pick<DownloadAttachmentsParams, "allowHosts">;
|
|
118
|
-
type FetchFn = typeof fetch;
|
|
119
|
-
type MSTeamsAttachments = DownloadAttachmentsParams["attachments"];
|
|
120
|
-
type LabeledCase = { label: string };
|
|
121
|
-
type FetchCallExpectation = { expectFetchCalled?: boolean };
|
|
122
|
-
type DownloadedMediaExpectation = { path?: string; placeholder?: string };
|
|
123
|
-
|
|
124
|
-
const DEFAULT_MAX_BYTES = 1024 * 1024;
|
|
125
|
-
const DEFAULT_ALLOW_HOSTS = [TEST_HOST];
|
|
126
|
-
const MEDIA_PLACEHOLDER_IMAGE = "<media:image>";
|
|
127
|
-
const MEDIA_PLACEHOLDER_DOCUMENT = "<media:document>";
|
|
128
|
-
const _formatImagePlaceholder = (count: number) =>
|
|
129
|
-
count > 1 ? `${MEDIA_PLACEHOLDER_IMAGE} (${count} images)` : MEDIA_PLACEHOLDER_IMAGE;
|
|
130
|
-
const formatDocumentPlaceholder = (count: number) =>
|
|
131
|
-
count > 1 ? `${MEDIA_PLACEHOLDER_DOCUMENT} (${count} files)` : MEDIA_PLACEHOLDER_DOCUMENT;
|
|
132
|
-
const IMAGE_ATTACHMENT = { contentType: CONTENT_TYPE_IMAGE_PNG, contentUrl: TEST_URL_IMAGE };
|
|
133
|
-
const PNG_BUFFER = Buffer.from("png");
|
|
134
|
-
const PNG_BASE64 = PNG_BUFFER.toString("base64");
|
|
135
|
-
const PDF_BUFFER = Buffer.from("pdf");
|
|
136
|
-
const createTokenProvider = (
|
|
137
|
-
tokenOrResolver: string | ((scope: string) => string | Promise<string>) = "token",
|
|
138
|
-
) => ({
|
|
139
|
-
getAccessToken: vi.fn(async (scope: string) =>
|
|
140
|
-
typeof tokenOrResolver === "function" ? await tokenOrResolver(scope) : tokenOrResolver,
|
|
141
|
-
),
|
|
142
|
-
});
|
|
143
|
-
const asSingleItemArray = <T>(value: T) => [value];
|
|
144
|
-
const withLabel = <T extends object>(label: string, fields: T): T & LabeledCase => ({
|
|
145
|
-
label,
|
|
146
|
-
...fields,
|
|
147
|
-
});
|
|
148
|
-
const buildAttachment = <T extends Record<string, unknown>>(contentType: string, props: T) => ({
|
|
149
|
-
contentType,
|
|
150
|
-
...props,
|
|
151
|
-
});
|
|
152
|
-
const createHtmlAttachment = (content: string) =>
|
|
153
|
-
buildAttachment(CONTENT_TYPE_TEXT_HTML, { content });
|
|
154
|
-
const buildHtmlImageTag = (src: string) => `<img src="${src}" />`;
|
|
155
|
-
const createHtmlImageAttachments = (sources: string[], prefix = "") =>
|
|
156
|
-
asSingleItemArray(createHtmlAttachment(`${prefix}${sources.map(buildHtmlImageTag).join("")}`));
|
|
157
|
-
const createContentUrlAttachments = (contentType: string, ...contentUrls: string[]) =>
|
|
158
|
-
contentUrls.map((contentUrl) => buildAttachment(contentType, { contentUrl }));
|
|
159
|
-
const createImageAttachments = (...contentUrls: string[]) =>
|
|
160
|
-
createContentUrlAttachments(CONTENT_TYPE_IMAGE_PNG, ...contentUrls);
|
|
161
|
-
const createPdfAttachments = (...contentUrls: string[]) =>
|
|
162
|
-
createContentUrlAttachments(CONTENT_TYPE_APPLICATION_PDF, ...contentUrls);
|
|
163
|
-
const createTeamsFileDownloadInfoAttachments = (
|
|
164
|
-
downloadUrl = TEST_URL_FILE_DOWNLOAD,
|
|
165
|
-
fileType = "png",
|
|
166
|
-
) =>
|
|
167
|
-
asSingleItemArray(
|
|
168
|
-
buildAttachment(CONTENT_TYPE_TEAMS_FILE_DOWNLOAD_INFO, {
|
|
169
|
-
content: { downloadUrl, fileType },
|
|
170
|
-
}),
|
|
171
|
-
);
|
|
172
|
-
const createHostedContentsWithType = (contentType: string, ...ids: string[]) =>
|
|
173
|
-
ids.map((id) => ({ id, contentType, contentBytes: PNG_BASE64 }));
|
|
174
|
-
const _createHostedImageContents = (...ids: string[]) =>
|
|
175
|
-
createHostedContentsWithType(CONTENT_TYPE_IMAGE_PNG, ...ids);
|
|
176
|
-
type BinaryPayload = Uint8Array | string;
|
|
177
|
-
const _createPdfResponse = (payload: BinaryPayload = PDF_BUFFER) => {
|
|
178
|
-
return createBufferResponse(payload, CONTENT_TYPE_APPLICATION_PDF);
|
|
179
|
-
};
|
|
180
|
-
const createBufferResponse = (payload: BinaryPayload, contentType: string, status = 200) => {
|
|
181
|
-
const raw = typeof payload === "string" ? Buffer.from(payload) : payload;
|
|
182
|
-
return new Response(new Uint8Array(raw), {
|
|
183
|
-
status,
|
|
184
|
-
headers: { "content-type": contentType },
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
const createJsonResponse = (payload: unknown, status = 200) =>
|
|
188
|
-
new Response(JSON.stringify(payload), { status });
|
|
189
|
-
const createTextResponse = (body: string, status = 200) => new Response(body, { status });
|
|
190
|
-
const _createGraphCollectionResponse = (value: unknown[]) => createJsonResponse({ value });
|
|
191
|
-
const createNotFoundResponse = () => new Response("not found", { status: 404 });
|
|
192
|
-
const createRedirectResponse = (location: string, status = 302) =>
|
|
193
|
-
new Response(null, { status, headers: { location } });
|
|
194
|
-
const publicResolve = async () => ({ address: "13.107.136.10" });
|
|
195
|
-
|
|
196
|
-
const createOkFetchMock = (contentType: string, payload = "png") =>
|
|
197
|
-
vi.fn(async (_input: RequestInfo | URL, _init?: RequestInit) =>
|
|
198
|
-
createBufferResponse(payload, contentType),
|
|
199
|
-
);
|
|
200
|
-
const asFetchFn = (fetchFn: unknown): FetchFn => fetchFn as FetchFn;
|
|
201
|
-
|
|
202
|
-
const buildDownloadParams = (
|
|
203
|
-
attachments: MSTeamsAttachments,
|
|
204
|
-
overrides: DownloadAttachmentsBuildOverrides = {},
|
|
205
|
-
): DownloadAttachmentsParams => {
|
|
206
|
-
return {
|
|
207
|
-
attachments,
|
|
208
|
-
maxBytes: DEFAULT_MAX_BYTES,
|
|
209
|
-
allowHosts: DEFAULT_ALLOW_HOSTS,
|
|
210
|
-
resolveFn: publicResolve,
|
|
211
|
-
...overrides,
|
|
212
|
-
};
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
const downloadAttachmentsWithFetch = async (
|
|
216
|
-
attachments: MSTeamsAttachments,
|
|
217
|
-
fetchFn: unknown,
|
|
218
|
-
overrides: DownloadAttachmentsNoFetchOverrides = {},
|
|
219
|
-
options: FetchCallExpectation = {},
|
|
220
|
-
) => {
|
|
221
|
-
const media = await downloadMSTeamsAttachments(
|
|
222
|
-
buildDownloadParams(attachments, {
|
|
223
|
-
...overrides,
|
|
224
|
-
fetchFn: asFetchFn(fetchFn),
|
|
225
|
-
}),
|
|
226
|
-
);
|
|
227
|
-
expectMockCallState(fetchFn, options.expectFetchCalled ?? true);
|
|
228
|
-
return media;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const createAuthAwareImageFetchMock = (params: { unauthStatus: number; unauthBody: string }) =>
|
|
232
|
-
vi.fn(async (_url: string, opts?: RequestInit) => {
|
|
233
|
-
const headers = new Headers(opts?.headers);
|
|
234
|
-
const hasAuth = Boolean(headers.get("Authorization"));
|
|
235
|
-
if (!hasAuth) {
|
|
236
|
-
return createTextResponse(params.unauthBody, params.unauthStatus);
|
|
237
|
-
}
|
|
238
|
-
return createBufferResponse(PNG_BUFFER, CONTENT_TYPE_IMAGE_PNG);
|
|
239
|
-
});
|
|
240
|
-
const expectMockCallState = (mockFn: unknown, shouldCall: boolean) => {
|
|
241
|
-
if (shouldCall) {
|
|
242
|
-
expect(mockFn).toHaveBeenCalled();
|
|
243
|
-
} else {
|
|
244
|
-
expect(mockFn).not.toHaveBeenCalled();
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
const expectAttachmentMediaLength = (media: DownloadedMedia, expectedLength: number) => {
|
|
249
|
-
expect(media).toHaveLength(expectedLength);
|
|
250
|
-
};
|
|
251
|
-
const expectSingleMedia = (media: DownloadedMedia, expected: DownloadedMediaExpectation = {}) => {
|
|
252
|
-
expectAttachmentMediaLength(media, 1);
|
|
253
|
-
expectFirstMedia(media, expected);
|
|
254
|
-
};
|
|
255
|
-
const expectMediaBufferSaved = () => {
|
|
256
|
-
expect(saveMediaBufferMock).toHaveBeenCalled();
|
|
257
|
-
};
|
|
258
|
-
const expectFirstMedia = (media: DownloadedMedia, expected: DownloadedMediaExpectation) => {
|
|
259
|
-
const first = media[0];
|
|
260
|
-
if (expected.path !== undefined) {
|
|
261
|
-
expect(first?.path).toBe(expected.path);
|
|
262
|
-
}
|
|
263
|
-
if (expected.placeholder !== undefined) {
|
|
264
|
-
expect(first?.placeholder).toBe(expected.placeholder);
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
type AttachmentDownloadSuccessCase = LabeledCase & {
|
|
268
|
-
attachments: MSTeamsAttachments;
|
|
269
|
-
buildFetchFn?: () => unknown;
|
|
270
|
-
beforeDownload?: () => void;
|
|
271
|
-
assert?: (media: DownloadedMedia) => void;
|
|
272
|
-
};
|
|
273
|
-
type AttachmentAuthRetryScenario = {
|
|
274
|
-
attachmentUrl: string;
|
|
275
|
-
unauthStatus: number;
|
|
276
|
-
unauthBody: string;
|
|
277
|
-
overrides?: Omit<DownloadAttachmentsNoFetchOverrides, "tokenProvider">;
|
|
278
|
-
};
|
|
279
|
-
type AttachmentAuthRetryCase = LabeledCase & {
|
|
280
|
-
scenario: AttachmentAuthRetryScenario;
|
|
281
|
-
expectedMediaLength: number;
|
|
282
|
-
expectTokenFetch: boolean;
|
|
283
|
-
};
|
|
284
|
-
const ATTACHMENT_DOWNLOAD_SUCCESS_CASES: AttachmentDownloadSuccessCase[] = [
|
|
285
|
-
withLabel("downloads and stores image contentUrl attachments", {
|
|
286
|
-
attachments: asSingleItemArray(IMAGE_ATTACHMENT),
|
|
287
|
-
assert: (media) => {
|
|
288
|
-
expectFirstMedia(media, { path: SAVED_PNG_PATH });
|
|
289
|
-
expectMediaBufferSaved();
|
|
290
|
-
},
|
|
291
|
-
}),
|
|
292
|
-
withLabel("supports Teams file.download.info downloadUrl attachments", {
|
|
293
|
-
attachments: createTeamsFileDownloadInfoAttachments(),
|
|
294
|
-
}),
|
|
295
|
-
withLabel("downloads inline image URLs from html attachments", {
|
|
296
|
-
attachments: createHtmlImageAttachments([TEST_URL_INLINE_IMAGE]),
|
|
297
|
-
}),
|
|
298
|
-
withLabel("downloads non-image file attachments (PDF)", {
|
|
299
|
-
attachments: createPdfAttachments(TEST_URL_DOC_PDF),
|
|
300
|
-
buildFetchFn: () => createOkFetchMock(CONTENT_TYPE_APPLICATION_PDF, "pdf"),
|
|
301
|
-
beforeDownload: () => {
|
|
302
|
-
detectMimeMock.mockResolvedValueOnce(CONTENT_TYPE_APPLICATION_PDF);
|
|
303
|
-
saveMediaBufferMock.mockResolvedValueOnce({
|
|
304
|
-
id: "saved.pdf",
|
|
305
|
-
path: SAVED_PDF_PATH,
|
|
306
|
-
size: Buffer.byteLength(PDF_BUFFER),
|
|
307
|
-
contentType: CONTENT_TYPE_APPLICATION_PDF,
|
|
308
|
-
});
|
|
309
|
-
},
|
|
310
|
-
assert: (media) => {
|
|
311
|
-
expectSingleMedia(media, {
|
|
312
|
-
path: SAVED_PDF_PATH,
|
|
313
|
-
placeholder: formatDocumentPlaceholder(1),
|
|
314
|
-
});
|
|
315
|
-
},
|
|
316
|
-
}),
|
|
317
|
-
];
|
|
318
|
-
const ATTACHMENT_AUTH_RETRY_CASES: AttachmentAuthRetryCase[] = [
|
|
319
|
-
withLabel("retries with auth when the first request is unauthorized", {
|
|
320
|
-
scenario: {
|
|
321
|
-
attachmentUrl: IMAGE_ATTACHMENT.contentUrl,
|
|
322
|
-
unauthStatus: 401,
|
|
323
|
-
unauthBody: "unauthorized",
|
|
324
|
-
overrides: { authAllowHosts: [TEST_HOST] },
|
|
325
|
-
},
|
|
326
|
-
expectedMediaLength: 1,
|
|
327
|
-
expectTokenFetch: true,
|
|
328
|
-
}),
|
|
329
|
-
withLabel("skips auth retries when the host is not in auth allowlist", {
|
|
330
|
-
scenario: {
|
|
331
|
-
attachmentUrl: createUrlForHost(AZUREEDGE_HOST, "img"),
|
|
332
|
-
unauthStatus: 403,
|
|
333
|
-
unauthBody: "forbidden",
|
|
334
|
-
overrides: {
|
|
335
|
-
allowHosts: [AZUREEDGE_HOST],
|
|
336
|
-
authAllowHosts: [GRAPH_HOST],
|
|
337
|
-
},
|
|
338
|
-
},
|
|
339
|
-
expectedMediaLength: 0,
|
|
340
|
-
expectTokenFetch: false,
|
|
341
|
-
}),
|
|
342
|
-
];
|
|
343
|
-
const runAttachmentDownloadSuccessCase = async ({
|
|
344
|
-
attachments,
|
|
345
|
-
buildFetchFn,
|
|
346
|
-
beforeDownload,
|
|
347
|
-
assert,
|
|
348
|
-
}: AttachmentDownloadSuccessCase) => {
|
|
349
|
-
const fetchFn = (buildFetchFn ?? (() => createOkFetchMock(CONTENT_TYPE_IMAGE_PNG)))();
|
|
350
|
-
beforeDownload?.();
|
|
351
|
-
const media = await downloadAttachmentsWithFetch(attachments, fetchFn);
|
|
352
|
-
expectSingleMedia(media);
|
|
353
|
-
assert?.(media);
|
|
354
|
-
};
|
|
355
|
-
const runAttachmentAuthRetryCase = async ({
|
|
356
|
-
scenario,
|
|
357
|
-
expectedMediaLength,
|
|
358
|
-
expectTokenFetch,
|
|
359
|
-
}: AttachmentAuthRetryCase) => {
|
|
360
|
-
const tokenProvider = createTokenProvider();
|
|
361
|
-
const fetchMock = createAuthAwareImageFetchMock({
|
|
362
|
-
unauthStatus: scenario.unauthStatus,
|
|
363
|
-
unauthBody: scenario.unauthBody,
|
|
364
|
-
});
|
|
365
|
-
const media = await downloadAttachmentsWithFetch(
|
|
366
|
-
createImageAttachments(scenario.attachmentUrl),
|
|
367
|
-
fetchMock,
|
|
368
|
-
{ tokenProvider, ...scenario.overrides },
|
|
369
|
-
);
|
|
370
|
-
expectAttachmentMediaLength(media, expectedMediaLength);
|
|
371
|
-
expectMockCallState(tokenProvider.getAccessToken, expectTokenFetch);
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
describe("msteams attachments", () => {
|
|
375
|
-
beforeEach(() => {
|
|
376
|
-
detectMimeMock.mockClear();
|
|
377
|
-
saveMediaBufferMock.mockClear();
|
|
378
|
-
fetchRemoteMediaMock.mockClear();
|
|
379
|
-
setMSTeamsRuntime(runtimeStub);
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
describe("downloadMSTeamsAttachments", () => {
|
|
383
|
-
it.each<AttachmentDownloadSuccessCase>(ATTACHMENT_DOWNLOAD_SUCCESS_CASES)(
|
|
384
|
-
"$label",
|
|
385
|
-
runAttachmentDownloadSuccessCase,
|
|
386
|
-
);
|
|
387
|
-
|
|
388
|
-
it("stores inline data:image base64 payloads", async () => {
|
|
389
|
-
const media = await downloadMSTeamsAttachments(
|
|
390
|
-
buildDownloadParams([
|
|
391
|
-
...createHtmlImageAttachments([`data:image/png;base64,${PNG_BASE64}`]),
|
|
392
|
-
]),
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
expectSingleMedia(media);
|
|
396
|
-
expectMediaBufferSaved();
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
it.each<AttachmentAuthRetryCase>(ATTACHMENT_AUTH_RETRY_CASES)(
|
|
400
|
-
"$label",
|
|
401
|
-
runAttachmentAuthRetryCase,
|
|
402
|
-
);
|
|
403
|
-
|
|
404
|
-
it("preserves auth fallback when dispatcher-mode fetch returns a redirect", async () => {
|
|
405
|
-
const redirectedUrl = createTestUrl("redirected.png");
|
|
406
|
-
const tokenProvider = createTokenProvider();
|
|
407
|
-
const fetchMock = vi.fn(async (url: string, opts?: RequestInit) => {
|
|
408
|
-
const hasAuth = Boolean(new Headers(opts?.headers).get("Authorization"));
|
|
409
|
-
if (url === TEST_URL_IMAGE) {
|
|
410
|
-
return hasAuth
|
|
411
|
-
? createRedirectResponse(redirectedUrl)
|
|
412
|
-
: createTextResponse("unauthorized", 401);
|
|
413
|
-
}
|
|
414
|
-
if (url === redirectedUrl) {
|
|
415
|
-
return createBufferResponse(PNG_BUFFER, CONTENT_TYPE_IMAGE_PNG);
|
|
416
|
-
}
|
|
417
|
-
return createNotFoundResponse();
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
fetchRemoteMediaMock.mockImplementationOnce(async (params) => {
|
|
421
|
-
return await fetchRemoteMediaWithRedirects(params, {
|
|
422
|
-
dispatcher: {},
|
|
423
|
-
} as RequestInit);
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
const media = await downloadAttachmentsWithFetch(
|
|
427
|
-
createImageAttachments(TEST_URL_IMAGE),
|
|
428
|
-
fetchMock,
|
|
429
|
-
{ tokenProvider, authAllowHosts: [TEST_HOST] },
|
|
430
|
-
);
|
|
431
|
-
|
|
432
|
-
expectAttachmentMediaLength(media, 1);
|
|
433
|
-
expect(tokenProvider.getAccessToken).toHaveBeenCalledOnce();
|
|
434
|
-
expect(fetchMock.mock.calls.map(([calledUrl]) => calledUrl)).toContain(redirectedUrl);
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
it("continues scope fallback after non-auth failure and succeeds on later scope", async () => {
|
|
438
|
-
let authAttempt = 0;
|
|
439
|
-
const tokenProvider = createTokenProvider((scope) => `token:${scope}`);
|
|
440
|
-
const fetchMock = vi.fn(async (_url: string, opts?: RequestInit) => {
|
|
441
|
-
const auth = new Headers(opts?.headers).get("Authorization");
|
|
442
|
-
if (!auth) {
|
|
443
|
-
return createTextResponse("unauthorized", 401);
|
|
444
|
-
}
|
|
445
|
-
authAttempt += 1;
|
|
446
|
-
if (authAttempt === 1) {
|
|
447
|
-
return createTextResponse("upstream transient", 500);
|
|
448
|
-
}
|
|
449
|
-
return createBufferResponse(PNG_BUFFER, CONTENT_TYPE_IMAGE_PNG);
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
const media = await downloadAttachmentsWithFetch(
|
|
453
|
-
createImageAttachments(TEST_URL_IMAGE),
|
|
454
|
-
fetchMock,
|
|
455
|
-
{ tokenProvider, authAllowHosts: [TEST_HOST] },
|
|
456
|
-
);
|
|
457
|
-
|
|
458
|
-
expectAttachmentMediaLength(media, 1);
|
|
459
|
-
expect(tokenProvider.getAccessToken).toHaveBeenCalledTimes(2);
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
it("does not forward Authorization to redirects outside auth allowlist", async () => {
|
|
463
|
-
const tokenProvider = createTokenProvider("top-secret-token");
|
|
464
|
-
const graphFileUrl = createUrlForHost(GRAPH_HOST, "file");
|
|
465
|
-
const seen: Array<{ url: string; auth: string }> = [];
|
|
466
|
-
const fetchMock = vi.fn(async (url: string, opts?: RequestInit) => {
|
|
467
|
-
const auth = new Headers(opts?.headers).get("Authorization") ?? "";
|
|
468
|
-
seen.push({ url, auth });
|
|
469
|
-
if (url === graphFileUrl && !auth) {
|
|
470
|
-
return new Response("unauthorized", { status: 401 });
|
|
471
|
-
}
|
|
472
|
-
if (url === graphFileUrl && auth) {
|
|
473
|
-
return new Response("", {
|
|
474
|
-
status: 302,
|
|
475
|
-
headers: { location: "https://attacker.azureedge.net/collect" },
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
if (url === "https://attacker.azureedge.net/collect") {
|
|
479
|
-
return new Response(Buffer.from("png"), {
|
|
480
|
-
status: 200,
|
|
481
|
-
headers: { "content-type": CONTENT_TYPE_IMAGE_PNG },
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
return createNotFoundResponse();
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
const media = await downloadMSTeamsAttachments(
|
|
488
|
-
buildDownloadParams([{ contentType: CONTENT_TYPE_IMAGE_PNG, contentUrl: graphFileUrl }], {
|
|
489
|
-
tokenProvider,
|
|
490
|
-
allowHosts: [GRAPH_HOST, AZUREEDGE_HOST],
|
|
491
|
-
authAllowHosts: [GRAPH_HOST],
|
|
492
|
-
fetchFn: asFetchFn(fetchMock),
|
|
493
|
-
}),
|
|
494
|
-
);
|
|
495
|
-
|
|
496
|
-
expectSingleMedia(media);
|
|
497
|
-
const redirected = seen.find(
|
|
498
|
-
(entry) => entry.url === "https://attacker.azureedge.net/collect",
|
|
499
|
-
);
|
|
500
|
-
expect(redirected).toBeDefined();
|
|
501
|
-
expect(redirected?.auth).toBe("");
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
it("skips urls outside the allowlist", async () => {
|
|
505
|
-
const fetchMock = vi.fn();
|
|
506
|
-
const media = await downloadAttachmentsWithFetch(
|
|
507
|
-
createImageAttachments(TEST_URL_OUTSIDE_ALLOWLIST),
|
|
508
|
-
fetchMock,
|
|
509
|
-
{
|
|
510
|
-
allowHosts: [GRAPH_HOST],
|
|
511
|
-
},
|
|
512
|
-
{ expectFetchCalled: false },
|
|
513
|
-
);
|
|
514
|
-
|
|
515
|
-
expectAttachmentMediaLength(media, 0);
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
it("blocks redirects to non-https URLs", async () => {
|
|
519
|
-
const insecureUrl = "http://x/insecure.png";
|
|
520
|
-
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
|
|
521
|
-
const url = resolveRequestUrl(input);
|
|
522
|
-
if (url === TEST_URL_IMAGE) {
|
|
523
|
-
return createRedirectResponse(insecureUrl);
|
|
524
|
-
}
|
|
525
|
-
if (url === insecureUrl) {
|
|
526
|
-
return createBufferResponse("insecure", CONTENT_TYPE_IMAGE_PNG);
|
|
527
|
-
}
|
|
528
|
-
return createNotFoundResponse();
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
const media = await downloadAttachmentsWithFetch(
|
|
532
|
-
createImageAttachments(TEST_URL_IMAGE),
|
|
533
|
-
fetchMock,
|
|
534
|
-
{
|
|
535
|
-
allowHosts: [TEST_HOST],
|
|
536
|
-
},
|
|
537
|
-
);
|
|
538
|
-
|
|
539
|
-
expectAttachmentMediaLength(media, 0);
|
|
540
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
describe("OneDrive/SharePoint shared links", () => {
|
|
544
|
-
const GRAPH_SHARES_URL_PREFIX = `https://${GRAPH_HOST}/v1.0/shares/`;
|
|
545
|
-
const DEFAULT_GRAPH_ALLOW_HOSTS = [GRAPH_HOST];
|
|
546
|
-
const PDF_PAYLOAD = Buffer.from("pdf-bytes");
|
|
547
|
-
|
|
548
|
-
const createGraphSharesFetchMock = () =>
|
|
549
|
-
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
550
|
-
const url = resolveRequestUrl(input);
|
|
551
|
-
const auth = new Headers(init?.headers).get("Authorization");
|
|
552
|
-
if (url.startsWith(GRAPH_SHARES_URL_PREFIX)) {
|
|
553
|
-
if (!auth) {
|
|
554
|
-
return createTextResponse("unauthorized", 401);
|
|
555
|
-
}
|
|
556
|
-
return createBufferResponse(PDF_PAYLOAD, CONTENT_TYPE_APPLICATION_PDF);
|
|
557
|
-
}
|
|
558
|
-
return createNotFoundResponse();
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
it.each([
|
|
562
|
-
{
|
|
563
|
-
label: "SharePoint URL",
|
|
564
|
-
contentUrl: "https://contoso.sharepoint.com/personal/user/Documents/report.pdf",
|
|
565
|
-
},
|
|
566
|
-
{
|
|
567
|
-
label: "OneDrive 1drv.ms URL",
|
|
568
|
-
contentUrl: "https://1drv.ms/b/s!AkxYabcdefg",
|
|
569
|
-
},
|
|
570
|
-
{
|
|
571
|
-
label: "OneDrive onedrive.live.com URL",
|
|
572
|
-
contentUrl: "https://onedrive.live.com/share/file",
|
|
573
|
-
},
|
|
574
|
-
])("routes $label through Graph shares endpoint", async ({ contentUrl }) => {
|
|
575
|
-
const tokenProvider = createTokenProvider();
|
|
576
|
-
const fetchMock = createGraphSharesFetchMock();
|
|
577
|
-
detectMimeMock.mockResolvedValueOnce(CONTENT_TYPE_APPLICATION_PDF);
|
|
578
|
-
saveMediaBufferMock.mockResolvedValueOnce({
|
|
579
|
-
id: "saved.pdf",
|
|
580
|
-
path: SAVED_PDF_PATH,
|
|
581
|
-
size: Buffer.byteLength(PDF_PAYLOAD),
|
|
582
|
-
contentType: CONTENT_TYPE_APPLICATION_PDF,
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
const media = await downloadMSTeamsAttachments(
|
|
586
|
-
buildDownloadParams(
|
|
587
|
-
[
|
|
588
|
-
{
|
|
589
|
-
contentType: "reference",
|
|
590
|
-
contentUrl,
|
|
591
|
-
name: "report.pdf",
|
|
592
|
-
},
|
|
593
|
-
],
|
|
594
|
-
{
|
|
595
|
-
tokenProvider,
|
|
596
|
-
allowHosts: DEFAULT_GRAPH_ALLOW_HOSTS,
|
|
597
|
-
authAllowHosts: DEFAULT_GRAPH_ALLOW_HOSTS,
|
|
598
|
-
fetchFn: asFetchFn(fetchMock),
|
|
599
|
-
},
|
|
600
|
-
),
|
|
601
|
-
);
|
|
602
|
-
|
|
603
|
-
expectAttachmentMediaLength(media, 1);
|
|
604
|
-
expect(media[0]?.path).toBe(SAVED_PDF_PATH);
|
|
605
|
-
// The only host that should be fetched is graph.microsoft.com.
|
|
606
|
-
const calledUrls = (fetchMock.mock.calls as Array<[RequestInfo | URL, RequestInit?]>).map(
|
|
607
|
-
([input]) => resolveRequestUrl(input),
|
|
608
|
-
);
|
|
609
|
-
expect(calledUrls.length).toBeGreaterThan(0);
|
|
610
|
-
for (const url of calledUrls) {
|
|
611
|
-
expect(url.startsWith(GRAPH_SHARES_URL_PREFIX)).toBe(true);
|
|
612
|
-
}
|
|
613
|
-
// Graph scope token was acquired for the shares fetch.
|
|
614
|
-
expect(tokenProvider.getAccessToken).toHaveBeenCalled();
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
it("falls through to direct fetch for non-shared-link URLs", async () => {
|
|
618
|
-
const directUrl = createTestUrl("direct.pdf");
|
|
619
|
-
const fetchMock = createOkFetchMock(CONTENT_TYPE_APPLICATION_PDF, "pdf");
|
|
620
|
-
detectMimeMock.mockResolvedValueOnce(CONTENT_TYPE_APPLICATION_PDF);
|
|
621
|
-
saveMediaBufferMock.mockResolvedValueOnce({
|
|
622
|
-
id: "saved.pdf",
|
|
623
|
-
path: SAVED_PDF_PATH,
|
|
624
|
-
size: Buffer.byteLength(PDF_BUFFER),
|
|
625
|
-
contentType: CONTENT_TYPE_APPLICATION_PDF,
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
const media = await downloadAttachmentsWithFetch(
|
|
629
|
-
createPdfAttachments(directUrl),
|
|
630
|
-
fetchMock,
|
|
631
|
-
);
|
|
632
|
-
|
|
633
|
-
expectAttachmentMediaLength(media, 1);
|
|
634
|
-
const calledUrls = (fetchMock.mock.calls as unknown[]).map((call) => {
|
|
635
|
-
const input = (call as [RequestInfo | URL])[0];
|
|
636
|
-
return resolveRequestUrl(input);
|
|
637
|
-
});
|
|
638
|
-
// Should have hit the original host, NOT graph shares.
|
|
639
|
-
expect(calledUrls.some((url) => url === directUrl)).toBe(true);
|
|
640
|
-
expect(calledUrls.some((url) => url.startsWith(GRAPH_SHARES_URL_PREFIX))).toBe(false);
|
|
641
|
-
});
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
describe("error logging (issue #63396)", () => {
|
|
645
|
-
// Before this fix, fetch failures were swallowed by empty `catch {}`
|
|
646
|
-
// blocks, leaving operators with no signal that SharePoint downloads
|
|
647
|
-
// were silently failing on Node 24+. These tests pin the logger contract
|
|
648
|
-
// so the regression cannot return.
|
|
649
|
-
it("invokes logger.warn when a remote media download fails", async () => {
|
|
650
|
-
const logger = { warn: vi.fn(), error: vi.fn() };
|
|
651
|
-
const fetchMock = vi.fn(async () => createTextResponse("server error", 500));
|
|
652
|
-
|
|
653
|
-
const media = await downloadMSTeamsAttachments(
|
|
654
|
-
buildDownloadParams(createImageAttachments(TEST_URL_IMAGE), {
|
|
655
|
-
fetchFn: asFetchFn(fetchMock),
|
|
656
|
-
logger,
|
|
657
|
-
}),
|
|
658
|
-
);
|
|
659
|
-
|
|
660
|
-
expectAttachmentMediaLength(media, 0);
|
|
661
|
-
expect(logger.warn).toHaveBeenCalledWith(
|
|
662
|
-
"msteams attachment download failed",
|
|
663
|
-
expect.objectContaining({
|
|
664
|
-
error: expect.stringContaining("HTTP 500"),
|
|
665
|
-
host: expect.any(String),
|
|
666
|
-
}),
|
|
667
|
-
);
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
it("does not log when downloads succeed", async () => {
|
|
671
|
-
const logger = { warn: vi.fn(), error: vi.fn() };
|
|
672
|
-
const fetchMock = createOkFetchMock(CONTENT_TYPE_IMAGE_PNG);
|
|
673
|
-
|
|
674
|
-
const media = await downloadMSTeamsAttachments(
|
|
675
|
-
buildDownloadParams(createImageAttachments(TEST_URL_IMAGE), {
|
|
676
|
-
fetchFn: asFetchFn(fetchMock),
|
|
677
|
-
logger,
|
|
678
|
-
}),
|
|
679
|
-
);
|
|
680
|
-
|
|
681
|
-
expectAttachmentMediaLength(media, 1);
|
|
682
|
-
expect(logger.warn).not.toHaveBeenCalled();
|
|
683
|
-
expect(logger.error).not.toHaveBeenCalled();
|
|
684
|
-
});
|
|
685
|
-
});
|
|
686
|
-
});
|
|
687
|
-
});
|
package/src/attachments.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
downloadMSTeamsBotFrameworkAttachments,
|
|
3
|
-
isBotFrameworkPersonalChatId,
|
|
4
|
-
} from "./attachments/bot-framework.js";
|
|
5
|
-
export { downloadMSTeamsAttachments } from "./attachments/download.js";
|
|
6
|
-
export { buildMSTeamsGraphMessageUrls, downloadMSTeamsGraphMedia } from "./attachments/graph.js";
|
|
7
|
-
export {
|
|
8
|
-
buildMSTeamsAttachmentPlaceholder,
|
|
9
|
-
extractMSTeamsHtmlAttachmentIds,
|
|
10
|
-
summarizeMSTeamsHtmlAttachments,
|
|
11
|
-
} from "./attachments/html.js";
|
|
12
|
-
export { buildMSTeamsMediaPayload } from "./attachments/payload.js";
|
|
13
|
-
export type {
|
|
14
|
-
MSTeamsAccessTokenProvider,
|
|
15
|
-
MSTeamsAttachmentLike,
|
|
16
|
-
MSTeamsHtmlAttachmentSummary,
|
|
17
|
-
MSTeamsInboundMedia,
|
|
18
|
-
} from "./attachments/types.js";
|