@openclaw/tlon 2026.5.2-beta.2 → 2026.5.3-beta.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.
Files changed (75) hide show
  1. package/dist/api.js +4 -0
  2. package/dist/channel-B4LtNGeZ.js +221 -0
  3. package/dist/channel-plugin-api.js +2 -0
  4. package/dist/channel.runtime-v-_0sHkJ.js +3584 -0
  5. package/dist/doctor-contract-W99wMbar.js +7 -0
  6. package/dist/doctor-contract-api.js +2 -0
  7. package/dist/index.js +18 -0
  8. package/dist/runtime-5FiW9E50.js +8 -0
  9. package/dist/runtime-api-C0hr1Rtn.js +4 -0
  10. package/dist/runtime-api.js +2 -0
  11. package/dist/setup-api.js +3 -0
  12. package/dist/setup-core-BUkZJ-MU.js +386 -0
  13. package/dist/setup-entry.js +11 -0
  14. package/dist/setup-surface-FxNMaluC.js +72 -0
  15. package/dist/test-api.js +2 -0
  16. package/package.json +15 -6
  17. package/api.ts +0 -16
  18. package/channel-plugin-api.ts +0 -1
  19. package/doctor-contract-api.ts +0 -1
  20. package/index.ts +0 -183
  21. package/runtime-api.ts +0 -17
  22. package/setup-api.ts +0 -2
  23. package/setup-entry.ts +0 -9
  24. package/src/account-fields.ts +0 -31
  25. package/src/channel.runtime.ts +0 -248
  26. package/src/channel.ts +0 -173
  27. package/src/config-schema.ts +0 -53
  28. package/src/core.test.ts +0 -278
  29. package/src/doctor-contract.ts +0 -9
  30. package/src/doctor.test.ts +0 -40
  31. package/src/doctor.ts +0 -10
  32. package/src/logger-runtime.ts +0 -1
  33. package/src/monitor/approval-runtime.ts +0 -363
  34. package/src/monitor/approval.test.ts +0 -33
  35. package/src/monitor/approval.ts +0 -286
  36. package/src/monitor/authorization.ts +0 -30
  37. package/src/monitor/cites.ts +0 -54
  38. package/src/monitor/discovery.ts +0 -68
  39. package/src/monitor/history.ts +0 -226
  40. package/src/monitor/index.ts +0 -1524
  41. package/src/monitor/media.test.ts +0 -91
  42. package/src/monitor/media.ts +0 -172
  43. package/src/monitor/processed-messages.test.ts +0 -58
  44. package/src/monitor/processed-messages.ts +0 -89
  45. package/src/monitor/settings-helpers.test.ts +0 -113
  46. package/src/monitor/settings-helpers.ts +0 -158
  47. package/src/monitor/utils.ts +0 -372
  48. package/src/runtime.ts +0 -9
  49. package/src/security.test.ts +0 -622
  50. package/src/session-route.ts +0 -40
  51. package/src/settings.ts +0 -391
  52. package/src/setup-core.ts +0 -228
  53. package/src/setup-surface.ts +0 -103
  54. package/src/targets.ts +0 -102
  55. package/src/tlon-api.test.ts +0 -589
  56. package/src/tlon-api.ts +0 -402
  57. package/src/types.ts +0 -160
  58. package/src/urbit/auth.ssrf.test.ts +0 -45
  59. package/src/urbit/auth.ts +0 -48
  60. package/src/urbit/base-url.test.ts +0 -48
  61. package/src/urbit/base-url.ts +0 -61
  62. package/src/urbit/channel-ops.ts +0 -145
  63. package/src/urbit/context.ts +0 -50
  64. package/src/urbit/errors.ts +0 -51
  65. package/src/urbit/fetch.ts +0 -42
  66. package/src/urbit/foreigns.ts +0 -49
  67. package/src/urbit/send.test.ts +0 -38
  68. package/src/urbit/send.ts +0 -176
  69. package/src/urbit/sse-client.test.ts +0 -203
  70. package/src/urbit/sse-client.ts +0 -484
  71. package/src/urbit/story.ts +0 -332
  72. package/src/urbit/upload.test.ts +0 -154
  73. package/src/urbit/upload.ts +0 -60
  74. package/test-api.ts +0 -1
  75. package/tsconfig.json +0 -16
@@ -1,589 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
- import { authenticate } from "./urbit/auth.js";
3
- import { scryUrbitPath } from "./urbit/channel-ops.js";
4
-
5
- const { mockFetchGuard, mockRelease, mockGetSignedUrl } = vi.hoisted(() => ({
6
- mockFetchGuard: vi.fn(),
7
- mockRelease: vi.fn(async () => {}),
8
- mockGetSignedUrl: vi.fn(),
9
- }));
10
-
11
- vi.mock("openclaw/plugin-sdk/ssrf-runtime", async () => {
12
- const original = (await vi.importActual("openclaw/plugin-sdk/ssrf-runtime")) as Record<
13
- string,
14
- unknown
15
- >;
16
- return {
17
- ...original,
18
- fetchWithSsrFGuard: mockFetchGuard,
19
- };
20
- });
21
-
22
- vi.mock("@aws-sdk/s3-request-presigner", () => ({
23
- getSignedUrl: mockGetSignedUrl,
24
- }));
25
-
26
- vi.mock("./urbit/auth.js", () => ({
27
- authenticate: vi.fn(),
28
- }));
29
-
30
- vi.mock("./urbit/channel-ops.js", () => ({
31
- scryUrbitPath: vi.fn(),
32
- }));
33
-
34
- import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
35
- import { configureClient, uploadFile } from "./tlon-api.js";
36
-
37
- const mockAuthenticate = vi.mocked(authenticate);
38
- const mockScryUrbitPath = vi.mocked(scryUrbitPath);
39
- const mockGuardedFetch = vi.mocked(fetchWithSsrFGuard);
40
-
41
- function createMemexResponse(
42
- uploadUrl: string,
43
- filePath = "https://memex.tlon.network/files/uploaded.png",
44
- ): Response {
45
- return new Response(
46
- JSON.stringify({
47
- url: uploadUrl,
48
- filePath,
49
- }),
50
- {
51
- status: 200,
52
- headers: { "content-type": "application/json" },
53
- },
54
- );
55
- }
56
-
57
- function createGuardedResult(response: Response, finalUrl: string) {
58
- return {
59
- response,
60
- finalUrl,
61
- release: mockRelease,
62
- };
63
- }
64
-
65
- describe("uploadFile memex upload hardening", () => {
66
- beforeEach(() => {
67
- vi.clearAllMocks();
68
- vi.stubGlobal("fetch", vi.fn());
69
- mockAuthenticate.mockResolvedValue("urbauth-~zod=fake-cookie");
70
- configureClient({
71
- shipUrl: "https://groups.tlon.network",
72
- shipName: "~zod",
73
- verbose: false,
74
- getCode: async () => "123456",
75
- });
76
- mockScryUrbitPath.mockImplementation(async (_deps, params) => {
77
- if (params.path === "/storage/configuration.json") {
78
- return {
79
- currentBucket: "uploads",
80
- buckets: ["uploads"],
81
- publicUrlBase: "https://files.tlon.network/",
82
- presignedUrl: "https://files.tlon.network/presigned",
83
- region: "us-east-1",
84
- service: "presigned-url",
85
- };
86
- }
87
- if (params.path === "/storage/credentials.json") {
88
- return { "storage-update": {} };
89
- }
90
- if (params.path === "/genuine/secret.json") {
91
- return { secret: "genuine-secret" };
92
- }
93
- throw new Error(`Unexpected scry path: ${params.path}`);
94
- });
95
- });
96
-
97
- afterEach(() => {
98
- vi.unstubAllGlobals();
99
- vi.restoreAllMocks();
100
- });
101
-
102
- it("routes the memex upload URL through the SSRF guard", async () => {
103
- mockGuardedFetch
104
- .mockResolvedValueOnce(
105
- createGuardedResult(
106
- createMemexResponse("https://uploads.tlon.network/put"),
107
- "https://memex.tlon.network/v1/zod/upload",
108
- ),
109
- )
110
- .mockResolvedValueOnce(
111
- createGuardedResult(
112
- new Response(null, { status: 200 }),
113
- "https://uploads.tlon.network/put",
114
- ),
115
- );
116
-
117
- const result = await uploadFile({
118
- blob: new Blob(["image-bytes"], { type: "image/png" }),
119
- fileName: "avatar.png",
120
- contentType: "image/png",
121
- });
122
-
123
- expect(result).toEqual({ url: "https://memex.tlon.network/files/uploaded.png" });
124
- expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();
125
- expect(mockGuardedFetch).toHaveBeenCalledTimes(2);
126
- expect(mockGuardedFetch).toHaveBeenNthCalledWith(
127
- 1,
128
- expect.objectContaining({
129
- url: "https://memex.tlon.network/v1/zod/upload",
130
- init: expect.objectContaining({
131
- method: "PUT",
132
- headers: { "Content-Type": "application/json" },
133
- body: expect.any(String),
134
- }),
135
- auditContext: "tlon-memex-upload-url",
136
- capture: false,
137
- maxRedirects: 0,
138
- }),
139
- );
140
- expect(mockGuardedFetch).toHaveBeenNthCalledWith(2, {
141
- url: "https://uploads.tlon.network/put",
142
- init: expect.objectContaining({
143
- method: "PUT",
144
- body: expect.any(Blob),
145
- headers: expect.objectContaining({
146
- "Cache-Control": "public, max-age=3600",
147
- "Content-Type": "image/png",
148
- }),
149
- }),
150
- auditContext: "tlon-memex-upload",
151
- capture: false,
152
- maxRedirects: 0,
153
- });
154
- const firstCall = mockGuardedFetch.mock.calls[0]?.[0];
155
- const firstBodyRaw = firstCall?.init?.body;
156
- expect(typeof firstBodyRaw).toBe("string");
157
- const firstBody = JSON.parse(firstBodyRaw as string) as Record<string, unknown>;
158
- expect(firstBody).toMatchObject({
159
- token: "genuine-secret",
160
- contentLength: 11,
161
- contentType: "image/png",
162
- });
163
- expect(typeof firstBody.fileName).toBe("string");
164
- expect(mockRelease).toHaveBeenCalledTimes(2);
165
- });
166
-
167
- it("surfaces guarded upload failures for hosted Memex targets", async () => {
168
- mockGuardedFetch
169
- .mockResolvedValueOnce(
170
- createGuardedResult(
171
- createMemexResponse("https://uploads.tlon.network/put"),
172
- "https://memex.tlon.network/v1/zod/upload",
173
- ),
174
- )
175
- .mockRejectedValueOnce(new Error("Blocked upload target"));
176
-
177
- await expect(
178
- uploadFile({
179
- blob: new Blob(["image-bytes"], { type: "image/png" }),
180
- fileName: "avatar.png",
181
- contentType: "image/png",
182
- }),
183
- ).rejects.toThrow("Blocked upload target");
184
-
185
- expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();
186
- expect(mockGuardedFetch).toHaveBeenCalledWith(
187
- expect.objectContaining({
188
- url: "https://uploads.tlon.network/put",
189
- auditContext: "tlon-memex-upload",
190
- capture: false,
191
- maxRedirects: 0,
192
- }),
193
- );
194
- expect(mockRelease).toHaveBeenCalledTimes(1);
195
- });
196
-
197
- it("rejects Memex upload targets outside the hosted Tlon domain allowlist", async () => {
198
- mockGuardedFetch.mockResolvedValueOnce(
199
- createGuardedResult(
200
- createMemexResponse("https://eviltlon.network/upload"),
201
- "https://memex.tlon.network/v1/zod/upload",
202
- ),
203
- );
204
-
205
- await expect(
206
- uploadFile({
207
- blob: new Blob(["image-bytes"], { type: "image/png" }),
208
- fileName: "avatar.png",
209
- contentType: "image/png",
210
- }),
211
- ).rejects.toThrow("Memex upload URL must target a trusted hosted Tlon domain");
212
-
213
- expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();
214
- expect(mockGuardedFetch).toHaveBeenCalledTimes(1);
215
- expect(mockRelease).toHaveBeenCalledTimes(1);
216
- });
217
-
218
- it("rejects Memex hosted result URLs outside the hosted Tlon domain allowlist", async () => {
219
- mockGuardedFetch
220
- .mockResolvedValueOnce(
221
- createGuardedResult(
222
- createMemexResponse(
223
- "https://uploads.tlon.network/put",
224
- "https://evil.example/files/uploaded.png",
225
- ),
226
- "https://memex.tlon.network/v1/zod/upload",
227
- ),
228
- )
229
- .mockResolvedValueOnce(
230
- createGuardedResult(
231
- new Response(null, { status: 200 }),
232
- "https://uploads.tlon.network/put",
233
- ),
234
- );
235
-
236
- await expect(
237
- uploadFile({
238
- blob: new Blob(["image-bytes"], { type: "image/png" }),
239
- fileName: "avatar.png",
240
- contentType: "image/png",
241
- }),
242
- ).rejects.toThrow("Memex hosted URL must target a trusted hosted Tlon domain");
243
-
244
- expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();
245
- expect(mockGuardedFetch).toHaveBeenCalledTimes(2);
246
- expect(mockRelease).toHaveBeenCalledTimes(2);
247
- });
248
-
249
- it("rejects Memex upload targets with a non-standard port", async () => {
250
- mockGuardedFetch.mockResolvedValueOnce(
251
- createGuardedResult(
252
- createMemexResponse("https://uploads.tlon.network:8443/put"),
253
- "https://memex.tlon.network/v1/zod/upload",
254
- ),
255
- );
256
-
257
- await expect(
258
- uploadFile({
259
- blob: new Blob(["image-bytes"], { type: "image/png" }),
260
- fileName: "avatar.png",
261
- contentType: "image/png",
262
- }),
263
- ).rejects.toThrow("Memex upload URL must not specify a non-standard port");
264
-
265
- expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();
266
- expect(mockGuardedFetch).toHaveBeenCalledTimes(1);
267
- expect(mockRelease).toHaveBeenCalledTimes(1);
268
- });
269
-
270
- it("disables redirects for Memex upload targets", async () => {
271
- mockGuardedFetch
272
- .mockResolvedValueOnce(
273
- createGuardedResult(
274
- createMemexResponse("https://uploads.tlon.network/put"),
275
- "https://memex.tlon.network/v1/zod/upload",
276
- ),
277
- )
278
- .mockRejectedValueOnce(new Error("Too many redirects (limit: 0)"));
279
-
280
- await expect(
281
- uploadFile({
282
- blob: new Blob(["image-bytes"], { type: "image/png" }),
283
- fileName: "avatar.png",
284
- contentType: "image/png",
285
- }),
286
- ).rejects.toThrow("Too many redirects (limit: 0)");
287
-
288
- expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();
289
- expect(mockGuardedFetch).toHaveBeenCalledWith(
290
- expect.objectContaining({
291
- url: "https://uploads.tlon.network/put",
292
- auditContext: "tlon-memex-upload",
293
- capture: false,
294
- maxRedirects: 0,
295
- }),
296
- );
297
- expect(mockRelease).toHaveBeenCalledTimes(1);
298
- });
299
-
300
- it("routes scheme-less hosted ship URLs through the Memex upload path", async () => {
301
- configureClient({
302
- shipUrl: "foo.tlon.network",
303
- shipName: "~zod",
304
- verbose: false,
305
- getCode: async () => "123456",
306
- });
307
- mockGuardedFetch
308
- .mockResolvedValueOnce(
309
- createGuardedResult(
310
- createMemexResponse("https://uploads.tlon.network/put"),
311
- "https://memex.tlon.network/v1/zod/upload",
312
- ),
313
- )
314
- .mockResolvedValueOnce(
315
- createGuardedResult(
316
- new Response(null, { status: 200 }),
317
- "https://uploads.tlon.network/put",
318
- ),
319
- );
320
-
321
- const result = await uploadFile({
322
- blob: new Blob(["image-bytes"], { type: "image/png" }),
323
- fileName: "avatar.png",
324
- contentType: "image/png",
325
- });
326
-
327
- expect(result).toEqual({ url: "https://memex.tlon.network/files/uploaded.png" });
328
- expect(mockGuardedFetch).toHaveBeenCalledTimes(2);
329
- expect(mockRelease).toHaveBeenCalledTimes(2);
330
- });
331
-
332
- it("rejects truly unparseable ship URLs as not hosted", async () => {
333
- configureClient({
334
- shipUrl: " ",
335
- shipName: "~zod",
336
- verbose: false,
337
- getCode: async () => "123456",
338
- });
339
- mockScryUrbitPath.mockImplementation(async (_deps, params) => {
340
- if (params.path === "/storage/configuration.json") {
341
- return {
342
- currentBucket: "uploads",
343
- buckets: ["uploads"],
344
- publicUrlBase: "https://files.tlon.network/",
345
- presignedUrl: "https://files.tlon.network/presigned",
346
- region: "us-east-1",
347
- service: "presigned-url",
348
- };
349
- }
350
- if (params.path === "/storage/credentials.json") {
351
- return { "storage-update": {} };
352
- }
353
- throw new Error(`Unexpected scry path: ${params.path}`);
354
- });
355
-
356
- await expect(
357
- uploadFile({
358
- blob: new Blob(["image-bytes"], { type: "image/png" }),
359
- fileName: "avatar.png",
360
- contentType: "image/png",
361
- }),
362
- ).rejects.toThrow("No storage credentials configured");
363
- expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();
364
- expect(mockGuardedFetch).not.toHaveBeenCalled();
365
- expect(mockRelease).not.toHaveBeenCalled();
366
- });
367
-
368
- it("accepts hosted Memex upload URLs with an explicit :443 port", async () => {
369
- mockGuardedFetch
370
- .mockResolvedValueOnce(
371
- createGuardedResult(
372
- createMemexResponse("https://uploads.tlon.network:443/put"),
373
- "https://memex.tlon.network/v1/zod/upload",
374
- ),
375
- )
376
- .mockResolvedValueOnce(
377
- createGuardedResult(
378
- new Response(null, { status: 200 }),
379
- "https://uploads.tlon.network:443/put",
380
- ),
381
- );
382
-
383
- const result = await uploadFile({
384
- blob: new Blob(["image-bytes"], { type: "image/png" }),
385
- fileName: "avatar.png",
386
- contentType: "image/png",
387
- });
388
-
389
- expect(result).toEqual({ url: "https://memex.tlon.network/files/uploaded.png" });
390
- expect(mockGuardedFetch).toHaveBeenCalledTimes(2);
391
- expect(mockRelease).toHaveBeenCalledTimes(2);
392
- });
393
-
394
- it("disables redirects for the Memex upload URL lookup", async () => {
395
- mockGuardedFetch.mockRejectedValueOnce(new Error("Too many redirects (limit: 0)"));
396
-
397
- await expect(
398
- uploadFile({
399
- blob: new Blob(["image-bytes"], { type: "image/png" }),
400
- fileName: "avatar.png",
401
- contentType: "image/png",
402
- }),
403
- ).rejects.toThrow("Too many redirects (limit: 0)");
404
-
405
- expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();
406
- expect(mockGuardedFetch).toHaveBeenCalledTimes(1);
407
- expect(mockGuardedFetch).toHaveBeenCalledWith(
408
- expect.objectContaining({
409
- url: "https://memex.tlon.network/v1/zod/upload",
410
- auditContext: "tlon-memex-upload-url",
411
- capture: false,
412
- maxRedirects: 0,
413
- }),
414
- );
415
- expect(mockRelease).not.toHaveBeenCalled();
416
- });
417
- });
418
-
419
- describe("uploadFile custom S3 upload hardening", () => {
420
- beforeEach(() => {
421
- vi.clearAllMocks();
422
- vi.stubGlobal("fetch", vi.fn());
423
- mockAuthenticate.mockResolvedValue("urbauth-~zod=fake-cookie");
424
- configureClient({
425
- shipUrl: "https://ship.example.com",
426
- shipName: "~zod",
427
- verbose: false,
428
- getCode: async () => "123456",
429
- });
430
- mockScryUrbitPath.mockImplementation(async (_deps, params) => {
431
- if (params.path === "/storage/configuration.json") {
432
- return {
433
- currentBucket: "uploads",
434
- buckets: ["uploads"],
435
- publicUrlBase: "https://files.example.com/",
436
- presignedUrl: "",
437
- region: "us-east-1",
438
- service: "custom",
439
- };
440
- }
441
- if (params.path === "/storage/credentials.json") {
442
- return {
443
- "storage-update": {
444
- credentials: {
445
- endpoint: "https://s3.example.com",
446
- accessKeyId: "AKIAFAKE",
447
- secretAccessKey: "fake-secret",
448
- },
449
- },
450
- };
451
- }
452
- throw new Error(`Unexpected scry path: ${params.path}`);
453
- });
454
- });
455
-
456
- afterEach(() => {
457
- vi.unstubAllGlobals();
458
- vi.restoreAllMocks();
459
- });
460
-
461
- it("routes the custom S3 signed URL through the SSRF guard", async () => {
462
- mockGetSignedUrl.mockResolvedValueOnce("https://s3.example.com/uploads/file?sig=abc");
463
- mockGuardedFetch.mockResolvedValueOnce(
464
- createGuardedResult(
465
- new Response(null, { status: 200 }),
466
- "https://s3.example.com/uploads/file?sig=abc",
467
- ),
468
- );
469
-
470
- const result = await uploadFile({
471
- blob: new Blob(["image-bytes"], { type: "image/png" }),
472
- fileName: "avatar.png",
473
- contentType: "image/png",
474
- });
475
-
476
- expect(result.url.startsWith("https://files.example.com/")).toBe(true);
477
- expect(mockGuardedFetch).toHaveBeenCalledTimes(1);
478
- expect(mockGuardedFetch).toHaveBeenCalledWith(
479
- expect.objectContaining({
480
- url: "https://s3.example.com/uploads/file?sig=abc",
481
- auditContext: "tlon-custom-s3-upload",
482
- capture: false,
483
- maxRedirects: 0,
484
- }),
485
- );
486
- expect(mockRelease).toHaveBeenCalledTimes(1);
487
- expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();
488
- });
489
-
490
- it("surfaces guarded upload failures for custom S3 targets without calling release", async () => {
491
- mockGetSignedUrl.mockResolvedValueOnce("https://169.254.169.254/uploads/file?sig=abc");
492
- mockGuardedFetch.mockRejectedValueOnce(new Error("Blocked private network target"));
493
-
494
- await expect(
495
- uploadFile({
496
- blob: new Blob(["image-bytes"], { type: "image/png" }),
497
- fileName: "avatar.png",
498
- contentType: "image/png",
499
- }),
500
- ).rejects.toThrow("Blocked private network target");
501
-
502
- expect(mockGuardedFetch).toHaveBeenCalledTimes(1);
503
- expect(mockRelease).not.toHaveBeenCalled();
504
- expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();
505
- });
506
-
507
- it("passes the private-network opt-in to guarded custom S3 uploads", async () => {
508
- configureClient({
509
- shipUrl: "https://ship.example.com",
510
- shipName: "~zod",
511
- verbose: false,
512
- getCode: async () => "123456",
513
- dangerouslyAllowPrivateNetwork: true,
514
- });
515
- mockGetSignedUrl.mockResolvedValueOnce("https://10.0.0.15/uploads/file?sig=abc");
516
- mockGuardedFetch.mockResolvedValueOnce(
517
- createGuardedResult(
518
- new Response(null, { status: 200 }),
519
- "https://10.0.0.15/uploads/file?sig=abc",
520
- ),
521
- );
522
-
523
- await expect(
524
- uploadFile({
525
- blob: new Blob(["image-bytes"], { type: "image/png" }),
526
- fileName: "avatar.png",
527
- contentType: "image/png",
528
- }),
529
- ).resolves.toEqual({
530
- url: expect.stringMatching(/^https:\/\/files\.example\.com\//),
531
- });
532
-
533
- expect(mockGuardedFetch).toHaveBeenCalledWith(
534
- expect.objectContaining({
535
- url: "https://10.0.0.15/uploads/file?sig=abc",
536
- auditContext: "tlon-custom-s3-upload",
537
- capture: false,
538
- maxRedirects: 0,
539
- policy: { allowPrivateNetwork: true },
540
- }),
541
- );
542
- expect(mockRelease).toHaveBeenCalledTimes(1);
543
- });
544
-
545
- it("rejects custom S3 result URLs that are not http(s)", async () => {
546
- mockScryUrbitPath.mockImplementation(async (_deps, params) => {
547
- if (params.path === "/storage/configuration.json") {
548
- return {
549
- currentBucket: "uploads",
550
- buckets: ["uploads"],
551
- publicUrlBase: "ftp://files.example.com/",
552
- presignedUrl: "",
553
- region: "us-east-1",
554
- service: "custom",
555
- };
556
- }
557
- if (params.path === "/storage/credentials.json") {
558
- return {
559
- "storage-update": {
560
- credentials: {
561
- endpoint: "https://s3.example.com",
562
- accessKeyId: "AKIAFAKE",
563
- secretAccessKey: "fake-secret",
564
- },
565
- },
566
- };
567
- }
568
- throw new Error(`Unexpected scry path: ${params.path}`);
569
- });
570
- mockGetSignedUrl.mockResolvedValueOnce("https://s3.example.com/uploads/file?sig=abc");
571
- mockGuardedFetch.mockResolvedValueOnce(
572
- createGuardedResult(
573
- new Response(null, { status: 200 }),
574
- "https://s3.example.com/uploads/file?sig=abc",
575
- ),
576
- );
577
-
578
- await expect(
579
- uploadFile({
580
- blob: new Blob(["image-bytes"], { type: "image/png" }),
581
- fileName: "avatar.png",
582
- contentType: "image/png",
583
- }),
584
- ).rejects.toThrow("Upload result URL must use http or https");
585
-
586
- expect(mockGuardedFetch).toHaveBeenCalledTimes(1);
587
- expect(mockRelease).toHaveBeenCalledTimes(1);
588
- });
589
- });