Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2import {
3 PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
4 PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
5} from "@t3tools/contracts";
6import type { ResolvedSharePayload, SharePayload } from "expo-sharing";
7
8import {
9 buildIncomingShareDraft,
10 hasIncomingShareContent,
11 isOwnedShareFileUri,
12 isShareFileUriUnderOwnedRoots,
13 selectIncomingShareAttachments,
14 selectIncomingShareAttachmentsForServer,
15} from "./incoming-share-model";
16
17const nativeImage = vi.hoisted(() => ({
18 resize: vi.fn(),
19}));
20
21vi.mock("expo-image-manipulator", () => ({
22 SaveFormat: { PNG: "png", JPEG: "jpeg" },
23 ImageManipulator: {
24 manipulate: (source: string | { width: number; height: number }) => {
25 let size = typeof source === "string" ? { width: 3000, height: 1500 } : source;
26 const context = {
27 resize: (next: { width: number; height: number }) => {
28 nativeImage.resize(next);
29 size = next;
30 return context;
31 },
32 renderAsync: async () => ({
33 ...size,
34 release: () => {},
35 saveAsync: async () => ({ uri: "file:///cache/resized.png", base64: "YWJj" }),
36 }),
37 };
38 return context;
39 },
40 },
41}));
42
43describe("incoming native shares", () => {
44 it("converts shared text, URLs, and images into a durable composer draft", async () => {
45 const image: SharePayload = {
46 shareType: "image",
47 value: "file:///shared/Screenshot.png",
48 mimeType: "image/png",
49 };
50 const payloads: SharePayload[] = [
51 { shareType: "text", value: "Please explain this error" },
52 { shareType: "url", value: "https://example.com/issue/1" },
53 { shareType: "text", value: "Please explain this error" },
54 image,
55 ];
56 const resolvedImage: ResolvedSharePayload = {
57 ...image,
58 contentUri: image.value,
59 contentType: "image",
60 contentMimeType: "image/png",
61 contentSize: 3,
62 originalName: "Screenshot.png",
63 };
64 const removeOwnedFile = vi.fn(() => Promise.resolve());
65 const readBase64 = vi.fn(async () => "YWJj");
66 const persistedUri = "file:///documents/t3-composer-attachments/Screenshot.png";
67 const persistFile = vi.fn(async () => persistedUri);
68
69 const result = await buildIncomingShareDraft({
70 id: "share-1",
71 createdAt: "2026-07-15T10:00:00.000Z",
72 payloads,
73 resolvedPayloads: [resolvedImage],
74 fileReader: {
75 readBase64,
76 persistFile,
77 readSize: async (uri) => (uri === persistedUri ? 3 : null),
78 removeOwnedFile,
79 },
80 });
81
82 expect(result).toEqual({
83 schemaVersion: 1,
84 id: "share-1",
85 createdAt: "2026-07-15T10:00:00.000Z",
86 text: "Please explain this error\n\nhttps://example.com/issue/1",
87 attachments: [
88 {
89 id: "share-1-image-3",
90 type: "image",
91 name: "Screenshot.png",
92 mimeType: "image/png",
93 sizeBytes: 3,
94 fileUri: persistedUri,
95 previewUri: persistedUri,
96 },
97 ],
98 warnings: [],
99 });
100 expect(removeOwnedFile).toHaveBeenCalledWith(image.value);
101 expect(removeOwnedFile).not.toHaveBeenCalledWith(persistedUri);
102 expect(hasIncomingShareContent(result)).toBe(true);
103 });
104
105 it("persists the resized PNG for a shared image over 2000px", async () => {
106 const header = Buffer.alloc(24);
107 header.set([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
108 header.set([0x49, 0x48, 0x44, 0x52], 12);
109 header.writeUInt32BE(3000, 16);
110 header.writeUInt32BE(1500, 20);
111 const persistedUri = "file:///documents/t3-composer-attachments/screenshot.png";
112 const persistFile = vi.fn(async () => persistedUri);
113 const removeOwnedFile = vi.fn(async (_uri: string) => undefined);
114
115 const draft = await buildIncomingShareDraft({
116 id: "share-resize",
117 createdAt: "2026-07-15T10:00:00.000Z",
118 payloads: [
119 { shareType: "image", value: "content://shared/screenshot", mimeType: "image/png" },
120 ],
121 resolvedPayloads: [],
122 fileReader: {
123 readBase64: async () => header.toString("base64"),
124 persistFile,
125 readSize: async () => 3,
126 removeOwnedFile,
127 },
128 });
129
130 expect(nativeImage.resize).toHaveBeenCalledWith({ width: 2000, height: 1000 });
131 expect(persistFile).toHaveBeenCalledWith("file:///cache/resized.png", "screenshot");
132 expect(draft.attachments).toEqual([
133 {
134 id: "share-resize-image-0",
135 type: "image",
136 name: "screenshot",
137 mimeType: "image/png",
138 sizeBytes: 3,
139 fileUri: persistedUri,
140 previewUri: persistedUri,
141 },
142 ]);
143 expect(draft.warnings).toEqual([]);
144 expect(removeOwnedFile).not.toHaveBeenCalledWith(persistedUri);
145 });
146
147 it("releases a shared image when its stored size cannot be measured", async () => {
148 const image: SharePayload = {
149 shareType: "image",
150 value: "file:///shared/photo.png",
151 mimeType: "image/png",
152 };
153 const persistedUri = "file:///documents/t3-composer-attachments/photo.png";
154 const removeOwnedFile = vi.fn(async (_uri: string) => undefined);
155 const result = await buildIncomingShareDraft({
156 id: "share-unmeasured",
157 createdAt: "2026-07-15T10:00:00.000Z",
158 payloads: [image],
159 resolvedPayloads: [
160 {
161 ...image,
162 contentUri: image.value,
163 contentType: "image",
164 contentMimeType: "image/png",
165 contentSize: 3,
166 originalName: "photo.png",
167 },
168 ],
169 fileReader: {
170 readBase64: async () => "unused",
171 persistFile: async () => persistedUri,
172 readSize: async () => null,
173 removeOwnedFile,
174 },
175 });
176
177 expect(result.attachments).toEqual([]);
178 expect(result.warnings).toEqual(["'photo.png' is empty or could not be read."]);
179 expect(removeOwnedFile).toHaveBeenCalledWith(persistedUri);
180 expect(removeOwnedFile).toHaveBeenCalledWith(image.value);
181 });
182
183 it("skips oversized images and releases the temporary native file", async () => {
184 const image: SharePayload = {
185 shareType: "image",
186 value: "file:///shared/huge.png",
187 mimeType: "image/png",
188 };
189 const readBase64 = vi.fn(async () => "unused");
190 const removeOwnedFile = vi.fn(() => Promise.resolve());
191
192 const result = await buildIncomingShareDraft({
193 id: "share-2",
194 createdAt: "2026-07-15T10:00:00.000Z",
195 payloads: [image],
196 resolvedPayloads: [
197 {
198 ...image,
199 contentUri: image.value,
200 contentType: "image",
201 contentMimeType: "image/png",
202 contentSize: PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1,
203 originalName: "huge.png",
204 },
205 ],
206 fileReader: { readBase64, removeOwnedFile },
207 });
208
209 expect(result.attachments).toEqual([]);
210 expect(result.warnings).toEqual(["'huge.png' exceeds the 10 MB attachment limit."]);
211 expect(readBase64).not.toHaveBeenCalled();
212 expect(removeOwnedFile).toHaveBeenCalledWith(image.value);
213 expect(hasIncomingShareContent(result)).toBe(false);
214 });
215
216 it("keeps a shared PDF on disk without converting its contents to base64", async () => {
217 const file: SharePayload = {
218 shareType: "file",
219 value: "file:///shared/report.pdf",
220 mimeType: "application/pdf",
221 };
222 const readBase64 = vi.fn(async () => "unused");
223 const persistFile = vi.fn(async () => "file:///documents/report.pdf");
224 const removeOwnedFile = vi.fn(async (_uri: string) => undefined);
225
226 const result = await buildIncomingShareDraft({
227 id: "share-report",
228 createdAt: "2026-07-15T10:00:00.000Z",
229 payloads: [file],
230 resolvedPayloads: [
231 {
232 ...file,
233 contentUri: file.value,
234 contentType: "file",
235 contentMimeType: "application/pdf",
236 contentSize: 42,
237 originalName: "report.pdf",
238 },
239 ],
240 fileReader: { readBase64, persistFile, removeOwnedFile },
241 });
242
243 expect(result.attachments).toEqual([
244 {
245 id: "share-report-file-0",
246 type: "file",
247 name: "report.pdf",
248 mimeType: "application/pdf",
249 sizeBytes: 42,
250 fileUri: "file:///documents/report.pdf",
251 },
252 ]);
253 expect(readBase64).not.toHaveBeenCalled();
254 expect(persistFile).toHaveBeenCalledWith(file.value, "report.pdf");
255 expect(removeOwnedFile).toHaveBeenCalledWith(file.value);
256 });
257
258 it.each([
259 { value: "file:///shared/clip.MOV", mimeType: "video/quicktime", originalName: "clip.MOV" },
260 { value: "content://media/videos/12", mimeType: "video/mp4", originalName: "clip.mp4" },
261 ])("imports a shared video from $value without reading it as an image", async (video) => {
262 const sizeBytes = 20 * 1024 * 1024;
263 const fileUri = `file:///documents/${video.originalName}`;
264 const readBase64 = vi.fn(async () => "unused");
265 const persistFile = vi.fn(async () => fileUri);
266 const removeOwnedFile = vi.fn(async () => undefined);
267
268 const result = await buildIncomingShareDraft({
269 id: "share-video",
270 createdAt: "2026-08-30T10:00:00.000Z",
271 payloads: [{ ...video, shareType: "video" }],
272 resolvedPayloads: [],
273 fileReader: { readBase64, persistFile, readSize: async () => sizeBytes, removeOwnedFile },
274 });
275
276 expect(result.warnings).toEqual([]);
277 expect(result.attachments).toEqual([
278 {
279 id: "share-video-file-0",
280 type: "file",
281 name: video.originalName,
282 mimeType: video.mimeType,
283 sizeBytes,
284 fileUri,
285 },
286 ]);
287 expect(readBase64).not.toHaveBeenCalled();
288 expect(removeOwnedFile).toHaveBeenCalledWith(video.value);
289 expect(
290 selectIncomingShareAttachments({
291 attachments: result.attachments,
292 maxFileAttachmentBytes: 50 * 1024 * 1024,
293 }),
294 ).toEqual({ attachments: result.attachments, warnings: [] });
295 expect(
296 selectIncomingShareAttachments({
297 attachments: result.attachments,
298 maxFileAttachmentBytes: 10 * 1024 * 1024,
299 }),
300 ).toEqual({
301 attachments: [],
302 warnings: [`'${video.originalName}' exceeds the 10 MB attachment limit.`],
303 });
304 });
305
306 it("reports an unreadable shared file without calling it oversized", async () => {
307 const file: SharePayload = {
308 shareType: "file",
309 value: "file:///shared/empty.txt",
310 mimeType: "text/plain",
311 };
312
313 const result = await buildIncomingShareDraft({
314 id: "share-empty",
315 createdAt: "2026-07-15T10:00:00.000Z",
316 payloads: [file],
317 resolvedPayloads: [],
318 fileReader: {
319 readBase64: async () => "unused",
320 readSize: async () => 0,
321 removeOwnedFile: async () => undefined,
322 },
323 });
324
325 expect(result.attachments).toEqual([]);
326 expect(result.warnings).toEqual(["'empty.txt' is empty or could not be read."]);
327 });
328
329 it("reads an Android content URI's size after copying it into app-owned storage", async () => {
330 const file: SharePayload = {
331 shareType: "file",
332 value: "content://shared/report",
333 mimeType: "application/pdf",
334 };
335 const persistFile = vi.fn(async () => "file:///documents/report.pdf");
336 const readSize = vi.fn(async (uri: string) => (uri.startsWith("content:") ? null : 42));
337
338 const result = await buildIncomingShareDraft({
339 id: "share-android-report",
340 createdAt: "2026-07-15T10:00:00.000Z",
341 payloads: [file],
342 resolvedPayloads: [],
343 fileReader: {
344 readBase64: async () => "unused",
345 persistFile,
346 readSize,
347 removeOwnedFile: async () => undefined,
348 },
349 });
350
351 expect(result.attachments).toEqual([
352 {
353 id: "share-android-report-file-0",
354 type: "file",
355 name: "report",
356 mimeType: "application/pdf",
357 sizeBytes: 42,
358 fileUri: "file:///documents/report.pdf",
359 },
360 ]);
361 expect(readSize.mock.calls).toEqual([
362 ["content://shared/report"],
363 ["file:///documents/report.pdf"],
364 ]);
365 });
366
367 it("rejects a shared file whose persisted copy measures empty and releases the copy", async () => {
368 const file: SharePayload = {
369 shareType: "file",
370 value: "content://shared/report",
371 mimeType: "application/pdf",
372 };
373 const persistedUri = "file:///documents/report.pdf";
374 const removeOwnedFile = vi.fn(async (_uri: string) => undefined);
375
376 const result = await buildIncomingShareDraft({
377 id: "share-empty-copy",
378 createdAt: "2026-07-15T10:00:00.000Z",
379 payloads: [file],
380 resolvedPayloads: [],
381 fileReader: {
382 readBase64: async () => "unused",
383 persistFile: async () => persistedUri,
384 readSize: async (uri) => (uri.startsWith("content:") ? 42 : 0),
385 removeOwnedFile,
386 },
387 });
388
389 expect(result.attachments).toEqual([]);
390 expect(result.warnings).toEqual(["'report' is empty or could not be read."]);
391 expect(removeOwnedFile.mock.calls.map(([uri]) => uri)).toContain(persistedUri);
392 });
393
394 it("keeps a no-copy file source that the returned attachment still owns", async () => {
395 const sourceUri = "file:///documents/report.pdf";
396 const removeOwnedFile = vi.fn(async () => undefined);
397
398 const result = await buildIncomingShareDraft({
399 id: "share-no-copy",
400 createdAt: "2026-07-15T10:00:00.000Z",
401 payloads: [{ shareType: "file", value: sourceUri, mimeType: "application/pdf" }],
402 resolvedPayloads: [],
403 fileReader: {
404 readBase64: async () => "unused",
405 readSize: async () => 42,
406 removeOwnedFile,
407 },
408 });
409
410 expect(result.attachments[0]).toMatchObject({ type: "file", fileUri: sourceUri });
411 expect(removeOwnedFile).not.toHaveBeenCalled();
412 });
413
414 it("keeps a persisted copy and releases distinct temporary source URIs", async () => {
415 const payloadUri = "content://shared/report";
416 const resolvedUri = "file:///cache/report.pdf";
417 const persistedUri = "file:///documents/report.pdf";
418 const removeOwnedFile = vi.fn(async (_uri: string) => undefined);
419
420 const result = await buildIncomingShareDraft({
421 id: "share-copy",
422 createdAt: "2026-07-15T10:00:00.000Z",
423 payloads: [{ shareType: "file", value: payloadUri, mimeType: "application/pdf" }],
424 resolvedPayloads: [
425 {
426 shareType: "file",
427 value: payloadUri,
428 mimeType: "application/pdf",
429 contentUri: resolvedUri,
430 contentType: "file",
431 contentMimeType: "application/pdf",
432 contentSize: 42,
433 originalName: "report.pdf",
434 },
435 ],
436 fileReader: {
437 readBase64: async () => "unused",
438 readSize: async () => 42,
439 persistFile: async () => persistedUri,
440 removeOwnedFile,
441 },
442 });
443
444 expect(result.attachments[0]).toMatchObject({ type: "file", fileUri: persistedUri });
445 expect(removeOwnedFile.mock.calls.map(([uri]) => uri)).toEqual([resolvedUri, payloadUri]);
446 });
447
448 it("uses current server support and limits when selecting a reserved share", () => {
449 const file = {
450 id: "file-1",
451 type: "file" as const,
452 name: "report.pdf",
453 mimeType: "application/pdf",
454 sizeBytes: 6 * 1024 * 1024,
455 fileUri: "file:///documents/report.pdf",
456 };
457
458 expect(
459 selectIncomingShareAttachmentsForServer({ attachments: [file], serverConfig: null }),
460 ).toEqual({ status: "pending" });
461 expect(
462 selectIncomingShareAttachmentsForServer({
463 attachments: [file],
464 serverConfig: { environment: { capabilities: {} } },
465 }),
466 ).toMatchObject({ status: "ready", attachments: [] });
467 expect(
468 selectIncomingShareAttachmentsForServer({
469 attachments: [file],
470 serverConfig: {
471 environment: {
472 capabilities: {
473 fileAttachments: { maxUploadBytes: 5 * 1024 * 1024 },
474 },
475 },
476 },
477 }),
478 ).toMatchObject({ status: "ready", attachments: [] });
479 expect(
480 selectIncomingShareAttachmentsForServer({
481 attachments: [file],
482 serverConfig: {
483 environment: {
484 capabilities: {
485 fileAttachments: { maxUploadBytes: 10 * 1024 * 1024 },
486 },
487 },
488 },
489 }),
490 ).toMatchObject({ status: "ready", attachments: [file] });
491 });
492
493 it("releases every temporary file when a share exceeds the attachment limit", async () => {
494 const payloads = Array.from({ length: PROVIDER_SEND_TURN_MAX_ATTACHMENTS + 1 }, (_, index) => ({
495 shareType: "image" as const,
496 value: `file:///shared/${index}.png`,
497 mimeType: "image/png",
498 }));
499 const removeOwnedFile = vi.fn(() => Promise.resolve());
500 const readBase64 = vi.fn(async () => "YWJj");
501
502 const result = await buildIncomingShareDraft({
503 id: "share-3",
504 createdAt: "2026-07-15T10:00:00.000Z",
505 payloads,
506 resolvedPayloads: [],
507 fileReader: { readBase64, removeOwnedFile },
508 });
509
510 expect(result.attachments).toHaveLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS);
511 expect(result.warnings).toEqual([
512 `Only the first ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} shared images were attached.`,
513 ]);
514 expect(readBase64).toHaveBeenCalledTimes(PROVIDER_SEND_TURN_MAX_ATTACHMENTS);
515 expect(removeOwnedFile).toHaveBeenCalledTimes(payloads.length);
516 });
517
518 it("maps duplicate image payloads to distinct resolved files", async () => {
519 const duplicate: SharePayload = {
520 shareType: "image",
521 value: "content://shared/screenshot",
522 mimeType: "image/png",
523 };
524 const resolvedPayloads: ResolvedSharePayload[] = [
525 {
526 ...duplicate,
527 contentUri: "file:///cache/first.png",
528 contentType: "image",
529 contentMimeType: "image/png",
530 contentSize: 3,
531 originalName: "first.png",
532 },
533 {
534 ...duplicate,
535 contentUri: "file:///cache/second.png",
536 contentType: "image",
537 contentMimeType: "image/png",
538 contentSize: 3,
539 originalName: "second.png",
540 },
541 ];
542 const readBase64 = vi.fn(async (uri: string) =>
543 uri.includes("first") ? "Zmlyc3Q=" : "c2Vjb25k",
544 );
545 const removeOwnedFile = vi.fn(async () => undefined);
546
547 const result = await buildIncomingShareDraft({
548 id: "share-duplicates",
549 createdAt: "2026-07-16T08:00:00.000Z",
550 payloads: [duplicate, duplicate],
551 resolvedPayloads,
552 fileReader: { readBase64, removeOwnedFile },
553 });
554
555 expect(readBase64.mock.calls.map(([uri]) => uri)).toEqual([
556 "file:///cache/first.png",
557 "file:///cache/second.png",
558 ]);
559 expect(result.attachments.map((attachment) => attachment.name)).toEqual([
560 "first.png",
561 "second.png",
562 ]);
563 expect(removeOwnedFile).toHaveBeenCalledWith("file:///cache/first.png");
564 expect(removeOwnedFile).toHaveBeenCalledWith("file:///cache/second.png");
565 });
566
567 it("keeps imported content when temporary-file cleanup fails", async () => {
568 const image: SharePayload = {
569 shareType: "image",
570 value: "file:///shared/screenshot.png",
571 mimeType: "image/png",
572 };
573
574 const result = await buildIncomingShareDraft({
575 id: "share-cleanup-failure",
576 createdAt: "2026-07-16T08:00:00.000Z",
577 payloads: [image],
578 resolvedPayloads: [],
579 fileReader: {
580 readBase64: async () => "YWJj",
581 removeOwnedFile: async () => {
582 throw new Error("file is busy");
583 },
584 },
585 });
586
587 expect(result.attachments).toHaveLength(1);
588 expect(result.warnings).toEqual([]);
589 });
590
591 it("releases a persisted copy when a later step fails to read it", async () => {
592 const file: SharePayload = {
593 shareType: "file",
594 value: "content://shared/report",
595 mimeType: "application/pdf",
596 };
597 const persistedUri = "file:///documents/t3-composer-attachments/report.pdf";
598 const removeOwnedFile = vi.fn(async (_uri: string) => undefined);
599
600 const result = await buildIncomingShareDraft({
601 id: "share-persist-leak",
602 createdAt: "2026-07-16T08:00:00.000Z",
603 payloads: [file],
604 resolvedPayloads: [],
605 fileReader: {
606 readBase64: async () => "unused",
607 persistFile: async () => persistedUri,
608 readSize: async (uri) => {
609 if (uri === persistedUri) {
610 throw new Error("read failed");
611 }
612 return null;
613 },
614 removeOwnedFile,
615 },
616 });
617
618 expect(result.attachments).toEqual([]);
619 expect(result.warnings).toEqual(["read failed"]);
620 expect(removeOwnedFile.mock.calls.map(([uri]) => uri)).toContain(persistedUri);
621 });
622});
623
624describe("share cleanup ownership", () => {
625 const ownedRoots = [
626 "file:///var/mobile/Containers/Data/Application/APP/Documents/",
627 "file:///var/mobile/Containers/Shared/AppGroup/GROUP",
628 ];
629
630 it("treats /private/var and /var as the same iOS location", () => {
631 expect(
632 isShareFileUriUnderOwnedRoots(
633 "file:///private/var/mobile/Containers/Shared/AppGroup/GROUP/shared.pdf",
634 ownedRoots,
635 ),
636 ).toBe(true);
637 expect(
638 isShareFileUriUnderOwnedRoots(
639 "file:///var/mobile/Containers/Data/Application/APP/Documents/t3-composer-attachments/a.pdf",
640 ["file:///private/var/mobile/Containers/Data/Application/APP/Documents/"],
641 ),
642 ).toBe(true);
643 });
644
645 it("refuses to delete a sender-owned open-in-place document", () => {
646 expect(
647 isShareFileUriUnderOwnedRoots(
648 "file:///private/var/mobile/Containers/Shared/FileProvider/OTHER/File%20Provider%20Storage/taxes.pdf",
649 ownedRoots,
650 ),
651 ).toBe(false);
652 });
653
654 it("refuses traversal segments that escape an owned root", () => {
655 expect(
656 isShareFileUriUnderOwnedRoots(
657 "file:///var/mobile/Containers/Shared/AppGroup/GROUP/..%2F..%2FsenderDoc.pdf",
658 ownedRoots,
659 ),
660 ).toBe(false);
661 expect(
662 isShareFileUriUnderOwnedRoots(
663 "file:///var/mobile/Containers/Shared/AppGroup/GROUP/../senderDoc.pdf",
664 ownedRoots,
665 ),
666 ).toBe(false);
667 expect(
668 isShareFileUriUnderOwnedRoots(
669 "file:///var/mobile/Containers/Shared/AppGroup/GROUP/%2e%2e/senderDoc.pdf",
670 ownedRoots,
671 ),
672 ).toBe(false);
673 });
674
675 it("deletes only the resolver's share copies on Android", () => {
676 const data = "file:///data/user/0/codes.t3.app";
677 const owned = (uri: string, platform = "android") =>
678 isOwnedShareFileUri(uri, {
679 platform,
680 cacheUri: `${data}/cache/`,
681 otherRootUris: [`${data}/files/`],
682 });
683 const copy = `${data}/cache/expo-sharing/0b0e3f0c-6c1d-4b53-9d0a-2f6f1c3a9e11`;
684 expect(owned(`file:${copy.slice("file://".length)}/report.pdf`)).toBe(true);
685 expect(
686 owned(
687 "file:///data/data/codes.t3.app/cache/expo-sharing/0b0e3f0c-6c1d-4b53-9d0a-2f6f1c3a9e11/a.png",
688 ),
689 ).toBe(true);
690 for (const uri of [
691 `${data}/files/t3-composer-attachments/id-report.pdf`,
692 `${data}/files/SQLite/state.db`,
693 `${data}/cache/http-cache/journal`,
694 `${data}/cache/expo-sharing/notes/notes.txt`,
695 `${copy}/..%2F..%2Ffiles%2FSQLite%2Fstate.db`,
696 copy,
697 ]) {
698 expect(owned(uri)).toBe(false);
699 }
700 expect(owned(`${data}/files/SQLite/state.db`, "ios")).toBe(true);
701 });
702
703 it("refuses non-file URIs and the owned root itself", () => {
704 expect(isShareFileUriUnderOwnedRoots("content://shared/report", ownedRoots)).toBe(false);
705 expect(
706 isShareFileUriUnderOwnedRoots(
707 "file:///var/mobile/Containers/Shared/AppGroup/GROUP",
708 ownedRoots,
709 ),
710 ).toBe(false);
711 });
712});