Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/review/src/sharing/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomUUID } from "node:crypto";
import { mkdtemp, rm } from "node:fs/promises";

import { afterEach, expect, it } from "vitest";
import { afterEach, expect, it, vi } from "vitest";

import { createShareFixture } from "../../test/fixtures/share/create.js";
import {
Expand Down Expand Up @@ -255,6 +255,25 @@ it.each([409, 503])(
},
);

it("rejects an invalid bundle before contacting the share service", async () => {
const root = await mkdtemp("/tmp/share-client-");
cleanup.push(() => rm(root, { recursive: true, force: true }));
const fixture = await createShareFixture(root);
cleanup.push(async () => {
await fixture.data.close();
fixture.store.close();
});

const bundle = await exportShare(fixture);
bundle.objects.clear();
const network = vi.fn<typeof fetch>();

await expect(
new ShareClient("https://app.dev.fast", undefined, network).create(bundle),
).rejects.toBeInstanceOf(SharePreflightError);
expect(network).not.toHaveBeenCalled();
});

it("bounds concurrent downloads and still rejects corrupt objects", async () => {
const root = await mkdtemp("/tmp/share-download-");
cleanup.push(() => rm(root, { recursive: true, force: true }));
Expand Down
12 changes: 11 additions & 1 deletion packages/review/src/sharing/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,17 @@ export class ShareClient {
requestId: string = randomUUID(),
beforeUpload?: () => Promise<void>,
) {
validateShareBundle(bundle);
try {
validateShareBundle(bundle);
} catch (cause) {
throw new SharePreflightError(
new Error(
"Whiteboard could not prepare this review for sharing. Please report this issue.",
{ cause },
),
);
}

const manifestBytes = Buffer.from(JSON.stringify(bundle.manifest));

const created = createdSchema.parse(
Expand Down
Loading