@powerhousedao/switchboard 6.2.3-dev.7 → 6.2.3-dev.70
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/.tsbuild/test/attachments/byte-grants.test.d.ts +2 -0
- package/.tsbuild/test/attachments/byte-grants.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts +2 -0
- package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/url-signer.test.d.ts +2 -0
- package/.tsbuild/test/attachments/url-signer.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/boot-create-signature-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
- package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts +2 -0
- package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-without-renown.test.d.ts +2 -0
- package/.tsbuild/test/boot-without-renown.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-without-require-signatures.test.d.ts +2 -0
- package/.tsbuild/test/boot-without-require-signatures.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-worker-trust-policy.test.d.ts +2 -0
- package/.tsbuild/test/boot-worker-trust-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
- package/.tsbuild/test/builder-defaults.test.d.ts +2 -0
- package/.tsbuild/test/builder-defaults.test.d.ts.map +1 -0
- package/.tsbuild/test/create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/create-signature-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
- package/.tsbuild/test/fatal-shutdown.test.d.ts +2 -0
- package/.tsbuild/test/fatal-shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/inspection-flag.test.d.ts +2 -0
- package/.tsbuild/test/inspection-flag.test.d.ts.map +1 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
- package/.tsbuild/test/mcp-flag.test.d.ts +2 -0
- package/.tsbuild/test/mcp-flag.test.d.ts.map +1 -0
- package/.tsbuild/test/observability-signals.test.d.ts +2 -0
- package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
- package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-trust-policy.test.d.ts +2 -0
- package/.tsbuild/test/renown-trust-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/snapshot-writer.d.ts +18 -0
- package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
- package/.tsbuild/test/unsupported-stored-documents.test.d.ts +2 -0
- package/.tsbuild/test/unsupported-stored-documents.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/harness.d.ts +56 -0
- package/.tsbuild/test/workflow/harness.d.ts.map +1 -0
- package/.tsbuild/test/workflow/oauth.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/resolvers.test.d.ts +2 -0
- package/.tsbuild/test/workflow/resolvers.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-signed.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-signed.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-read-gate.test.d.ts +2 -0
- package/.tsbuild/test/workflow-read-gate.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow-runtime.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/.tsbuild/tsdown.config.d.ts.map +1 -1
- package/.tsbuild/vitest.config.d.ts.map +1 -1
- package/Auth.md +144 -2
- package/CHANGELOG.md +842 -0
- package/README.md +47 -10
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +50 -50
- package/dist/index.mjs.map +1 -1
- package/dist/install-packages.d.mts +2 -1
- package/dist/install-packages.mjs +2 -2
- package/dist/install-packages.mjs.map +1 -1
- package/dist/mcp-cNWW82NH.mjs +27 -0
- package/dist/mcp-cNWW82NH.mjs.map +1 -0
- package/dist/migrate.d.mts +2 -1
- package/dist/migrate.mjs +4 -3
- package/dist/migrate.mjs.map +1 -1
- package/dist/plugin-host-CGO4XZzK.d.mts +38 -0
- package/dist/plugin-host-CGO4XZzK.d.mts.map +1 -0
- package/dist/plugins/attachments.d.mts +23 -0
- package/dist/plugins/attachments.d.mts.map +1 -0
- package/dist/plugins/attachments.mjs +4 -0
- package/dist/plugins/mcp.d.mts +21 -0
- package/dist/plugins/mcp.d.mts.map +1 -0
- package/dist/plugins/mcp.mjs +4 -0
- package/dist/plugins/privacy.d.mts +12 -0
- package/dist/plugins/privacy.d.mts.map +1 -0
- package/dist/plugins/privacy.mjs +4 -0
- package/dist/plugins/workflows.d.mts +36 -0
- package/dist/plugins/workflows.d.mts.map +1 -0
- package/dist/plugins/workflows.mjs +4 -0
- package/dist/privacy-C8KVimKF.mjs +113 -0
- package/dist/privacy-C8KVimKF.mjs.map +1 -0
- package/dist/{server-CiKkVE6g.mjs → server-CF_mjyJi.mjs} +1170 -228
- package/dist/server-CF_mjyJi.mjs.map +1 -0
- package/dist/server.d.mts +190 -30
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +4 -5
- package/dist/{utils-Baw7rThP.mjs → utils-uaBlzyjS.mjs} +15 -9
- package/dist/utils-uaBlzyjS.mjs.map +1 -0
- package/dist/utils.d.mts +4 -5
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +3 -3
- package/dist/workflow-runtime-7GaJ13c9.d.mts +30 -0
- package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -0
- package/dist/workflows-qKtqZhn3.mjs +1338 -0
- package/dist/workflows-qKtqZhn3.mjs.map +1 -0
- package/package.json +49 -20
- package/scripts/install-packages.sh +0 -0
- package/test/attachment-reference-read-model.test.ts +6 -1
- package/test/attachments/auth.test.ts +85 -0
- package/test/attachments/byte-grants.test.ts +290 -0
- package/test/attachments/byte-routes-read-gate.integration.test.ts +314 -0
- package/test/attachments/download-target.test.ts +201 -32
- package/test/attachments/index.test.ts +47 -4
- package/test/attachments/reserve-metadata-parity.test.ts +96 -0
- package/test/attachments/routes-integration.test.ts +60 -4
- package/test/attachments/routes.test.ts +271 -24
- package/test/attachments/service-config.test.ts +13 -3
- package/test/attachments/url-signer.test.ts +105 -0
- package/test/boot-create-signature-policy.test.ts +108 -0
- package/test/boot-inspection-enabled.test.ts +150 -0
- package/test/boot-mcp-enabled.test.ts +130 -0
- package/test/boot-privacy.test.ts +243 -0
- package/test/boot-unsupported-stored-documents.test.ts +213 -0
- package/test/boot-without-renown.test.ts +81 -0
- package/test/boot-without-require-signatures.test.ts +74 -0
- package/test/boot-worker-trust-policy.test.ts +90 -0
- package/test/boot-workflow-singleton-conflict.test.ts +107 -0
- package/test/boot-workflow-singleton-retry.test.ts +133 -0
- package/test/builder-defaults.test.ts +80 -0
- package/test/create-signature-policy.test.ts +69 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +165 -0
- package/test/inspection-flag.test.ts +62 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/mcp-flag.test.ts +56 -0
- package/test/observability-signals.test.ts +131 -0
- package/test/pglite-dialect.test.ts +217 -2
- package/test/pglite-preflight.test.ts +313 -0
- package/test/pglite-storage-dirs.test.ts +103 -0
- package/test/pglite-version.test.ts +9 -1
- package/test/plugin-presence.test.ts +269 -0
- package/test/renown-trust-policy.test.ts +315 -0
- package/test/snapshot-writer.ts +94 -0
- package/test/unsupported-stored-documents.test.ts +72 -0
- package/test/worker-pool.test.ts +27 -1
- package/test/workflow/harness.ts +289 -0
- package/test/workflow/oauth.test.ts +214 -0
- package/test/workflow/resolvers.test.ts +357 -0
- package/test/workflow/webhook-dedupe.test.ts +295 -0
- package/test/workflow/webhook-signed.test.ts +509 -0
- package/test/workflow/webhook-trigger-test.test.ts +82 -0
- package/test/workflow/webhook-unsigned.test.ts +345 -0
- package/test/workflow-reactor-access.test.ts +384 -0
- package/test/workflow-reactor-enforcement.test.ts +808 -0
- package/test/workflow-read-gate.test.ts +213 -0
- package/test/workflow-runtime.test.ts +1122 -0
- package/tsconfig.json +11 -2
- package/tsdown.config.ts +9 -1
- package/dist/server-CiKkVE6g.mjs.map +0 -1
- package/dist/utils-Baw7rThP.mjs.map +0 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { PGlite } from "@electric-sql/pglite";
|
|
2
2
|
import {
|
|
3
|
+
AttachmentAlreadyExists,
|
|
3
4
|
AttachmentBuilder,
|
|
4
5
|
S3AttachmentBackend,
|
|
5
6
|
type AttachmentBuildResult,
|
|
6
7
|
createRemoteAttachmentService,
|
|
7
8
|
} from "@powerhousedao/reactor-attachments";
|
|
8
|
-
import type { API } from "@powerhousedao/reactor-api";
|
|
9
|
+
import type { API, IAttachmentAccessService } from "@powerhousedao/reactor-api";
|
|
9
10
|
import { createHttpAdapter } from "@powerhousedao/reactor-api";
|
|
10
11
|
import { Kysely } from "kysely";
|
|
11
12
|
import { PGliteDialect } from "kysely-pglite-dialect";
|
|
@@ -22,6 +23,17 @@ import { registerAttachmentRoutes } from "../../src/attachments/index.js";
|
|
|
22
23
|
const EMPTY_STRING_SHA256 =
|
|
23
24
|
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
|
|
24
25
|
|
|
26
|
+
const DOC_ID = "doc-1";
|
|
27
|
+
const ALLOW_ALL: IAttachmentAccessService = {
|
|
28
|
+
canReadAttachment: (request) =>
|
|
29
|
+
Promise.resolve({
|
|
30
|
+
kind: "allowed",
|
|
31
|
+
documentId: request.documentId as never,
|
|
32
|
+
ref: request.attachmentRef as never,
|
|
33
|
+
}),
|
|
34
|
+
admitCaller: () => Promise.resolve({ kind: "admitted" }),
|
|
35
|
+
};
|
|
36
|
+
|
|
25
37
|
describe("attachment routes through the real Express middleware stack", () => {
|
|
26
38
|
let attachments: AttachmentBuildResult;
|
|
27
39
|
let kysely: Kysely<unknown>;
|
|
@@ -42,10 +54,11 @@ describe("attachment routes through the real Express middleware stack", () => {
|
|
|
42
54
|
registerAttachmentRoutes({
|
|
43
55
|
httpAdapter: adapter,
|
|
44
56
|
attachments,
|
|
57
|
+
attachmentAccess: ALLOW_ALL,
|
|
45
58
|
authService: undefined,
|
|
46
59
|
} as unknown as API);
|
|
47
60
|
|
|
48
|
-
server = await adapter.listen(0);
|
|
61
|
+
server = await adapter.listen(0, undefined, "127.0.0.1");
|
|
49
62
|
const addr = server.address();
|
|
50
63
|
if (!addr || typeof addr === "string") throw new Error("no addr");
|
|
51
64
|
baseUrl = `http://127.0.0.1:${addr.port}`;
|
|
@@ -82,7 +95,7 @@ describe("attachment routes through the real Express middleware stack", () => {
|
|
|
82
95
|
expect(result.hash).not.toBe(EMPTY_STRING_SHA256);
|
|
83
96
|
expect(result.header.sizeBytes).toBe(bytes.byteLength);
|
|
84
97
|
|
|
85
|
-
const got = await service.get(result.ref);
|
|
98
|
+
const got = await service.get(result.ref, { documentId: DOC_ID });
|
|
86
99
|
expect(got.header.sizeBytes).toBe(bytes.byteLength);
|
|
87
100
|
expect(got.header.mimeType).toBe("application/json");
|
|
88
101
|
const reader = got.body.getReader();
|
|
@@ -101,6 +114,48 @@ describe("attachment routes through the real Express middleware stack", () => {
|
|
|
101
114
|
}
|
|
102
115
|
expect(new TextDecoder().decode(merged)).toBe(payload);
|
|
103
116
|
});
|
|
117
|
+
|
|
118
|
+
it("HEAD and GET /attachments/:hash serve a file name above U+00FF", async () => {
|
|
119
|
+
const fileName = "opłata – 報告 📎.pdf";
|
|
120
|
+
const service = createRemoteAttachmentService({ remoteUrl: baseUrl });
|
|
121
|
+
const upload = await service.reserve({
|
|
122
|
+
mimeType: "application/pdf",
|
|
123
|
+
fileName,
|
|
124
|
+
});
|
|
125
|
+
const bytes = new TextEncoder().encode("%PDF-unicode-name");
|
|
126
|
+
const { hash } = await upload.send(
|
|
127
|
+
new ReadableStream<Uint8Array>({
|
|
128
|
+
start(controller) {
|
|
129
|
+
controller.enqueue(bytes);
|
|
130
|
+
controller.close();
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
for (const method of ["HEAD", "GET"]) {
|
|
136
|
+
const res = await fetch(
|
|
137
|
+
`${baseUrl}/attachments/${hash}?documentId=${DOC_ID}`,
|
|
138
|
+
{ method },
|
|
139
|
+
);
|
|
140
|
+
expect(res.status).toBe(200);
|
|
141
|
+
const meta = JSON.parse(res.headers.get("attachment-metadata")!) as {
|
|
142
|
+
fileName: string;
|
|
143
|
+
};
|
|
144
|
+
expect(meta.fileName).toBe(fileName);
|
|
145
|
+
await res.arrayBuffer();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// A hash-first reserve of the same bytes is what the client sends on the
|
|
149
|
+
// next upload; it stats the hash first.
|
|
150
|
+
await expect(
|
|
151
|
+
service.reserve({
|
|
152
|
+
mimeType: "application/pdf",
|
|
153
|
+
fileName,
|
|
154
|
+
clientHash: hash,
|
|
155
|
+
sizeBytes: bytes.byteLength,
|
|
156
|
+
}),
|
|
157
|
+
).rejects.toBeInstanceOf(AttachmentAlreadyExists);
|
|
158
|
+
});
|
|
104
159
|
});
|
|
105
160
|
|
|
106
161
|
describe("authenticated S3 reservation production path", () => {
|
|
@@ -138,9 +193,10 @@ describe("authenticated S3 reservation production path", () => {
|
|
|
138
193
|
registerAttachmentRoutes({
|
|
139
194
|
httpAdapter: adapter,
|
|
140
195
|
attachments,
|
|
196
|
+
attachmentAccess: ALLOW_ALL,
|
|
141
197
|
authService: { verifyBearer },
|
|
142
198
|
} as unknown as API);
|
|
143
|
-
const server = await adapter.listen(0);
|
|
199
|
+
const server = await adapter.listen(0, undefined, "127.0.0.1");
|
|
144
200
|
const address = server.address();
|
|
145
201
|
if (!address || typeof address === "string") throw new Error("no addr");
|
|
146
202
|
const baseUrl = `http://127.0.0.1:${address.port}`;
|
|
@@ -5,14 +5,21 @@ import {
|
|
|
5
5
|
} from "@powerhousedao/reactor-attachments";
|
|
6
6
|
import { Kysely } from "kysely";
|
|
7
7
|
import { PGliteDialect } from "kysely-pglite-dialect";
|
|
8
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
9
|
-
import
|
|
8
|
+
import { mkdtemp, readdir, rm } from "node:fs/promises";
|
|
9
|
+
import {
|
|
10
|
+
validateHeaderValue,
|
|
11
|
+
type IncomingMessage,
|
|
12
|
+
type ServerResponse,
|
|
13
|
+
} from "node:http";
|
|
10
14
|
import { tmpdir } from "node:os";
|
|
11
15
|
import { join } from "node:path";
|
|
12
16
|
import { Readable, Writable } from "node:stream";
|
|
17
|
+
import type { IAttachmentAccessService } from "@powerhousedao/reactor-api";
|
|
13
18
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
14
19
|
import {
|
|
15
20
|
buildContentDisposition,
|
|
21
|
+
buildMetadataHeader,
|
|
22
|
+
buildPendingHeader,
|
|
16
23
|
makeDeleteReservationHandler,
|
|
17
24
|
makeDownloadHandler,
|
|
18
25
|
makeGetReservationHandler,
|
|
@@ -23,6 +30,22 @@ import {
|
|
|
23
30
|
quoteFilename,
|
|
24
31
|
} from "../../src/attachments/routes.js";
|
|
25
32
|
|
|
33
|
+
// Byte-serving mechanics under a granted read; grant decisions are tested in
|
|
34
|
+
// byte-grants.test.ts.
|
|
35
|
+
const ALLOW_ALL: IAttachmentAccessService = {
|
|
36
|
+
canReadAttachment: (request) =>
|
|
37
|
+
Promise.resolve({
|
|
38
|
+
kind: "allowed",
|
|
39
|
+
documentId: request.documentId as never,
|
|
40
|
+
ref: request.attachmentRef as never,
|
|
41
|
+
}),
|
|
42
|
+
admitCaller: () => Promise.resolve({ kind: "admitted" }),
|
|
43
|
+
};
|
|
44
|
+
const grantedDownload = (attachments: AttachmentBuildResult) =>
|
|
45
|
+
makeDownloadHandler(attachments, ALLOW_ALL, null);
|
|
46
|
+
const grantedStat = (attachments: AttachmentBuildResult) =>
|
|
47
|
+
makeStatHandler(attachments, ALLOW_ALL, null);
|
|
48
|
+
|
|
26
49
|
type CapturedRes = ServerResponse & {
|
|
27
50
|
_headers: Record<string, string>;
|
|
28
51
|
_body: Buffer;
|
|
@@ -46,7 +69,7 @@ function makeReq(opts: {
|
|
|
46
69
|
params?: Record<string, string>;
|
|
47
70
|
};
|
|
48
71
|
req.method = opts.method;
|
|
49
|
-
req.url = opts.url ?? "
|
|
72
|
+
req.url = opts.url ?? "/?documentId=doc-1";
|
|
50
73
|
req.headers = {};
|
|
51
74
|
if (opts.params) req.params = opts.params;
|
|
52
75
|
return req as unknown as IncomingMessage;
|
|
@@ -70,13 +93,25 @@ function makeRes(): CapturedRes {
|
|
|
70
93
|
statusCode: 200,
|
|
71
94
|
_headers: headers,
|
|
72
95
|
setHeader(name: string, value: string | number | readonly string[]) {
|
|
96
|
+
// Same check Node's ServerResponse applies, so a header value it would
|
|
97
|
+
// reject fails here instead of passing silently.
|
|
98
|
+
validateHeaderValue(name, String(value));
|
|
73
99
|
headers[name.toLowerCase()] = String(value);
|
|
74
100
|
},
|
|
75
101
|
getHeader(name: string) {
|
|
76
102
|
return headers[name.toLowerCase()];
|
|
77
103
|
},
|
|
104
|
+
removeHeader(name: string) {
|
|
105
|
+
delete headers[name.toLowerCase()];
|
|
106
|
+
},
|
|
78
107
|
_done: done,
|
|
79
108
|
});
|
|
109
|
+
// Like ServerResponse: headers count as sent once the first byte is written.
|
|
110
|
+
Object.defineProperty(writable, "headersSent", {
|
|
111
|
+
get(): boolean {
|
|
112
|
+
return chunks.length > 0;
|
|
113
|
+
},
|
|
114
|
+
});
|
|
80
115
|
Object.defineProperty(writable, "_body", {
|
|
81
116
|
get(): Buffer {
|
|
82
117
|
return Buffer.concat(chunks);
|
|
@@ -213,7 +248,7 @@ describe("attachment routes", () => {
|
|
|
213
248
|
expect(row!.deleted_at_utc).not.toBeNull();
|
|
214
249
|
|
|
215
250
|
// Download
|
|
216
|
-
const downloadHandler =
|
|
251
|
+
const downloadHandler = grantedDownload(attachments);
|
|
217
252
|
const downloadReq = makeReq({
|
|
218
253
|
method: "GET",
|
|
219
254
|
params: { hash: upload.hash },
|
|
@@ -262,7 +297,7 @@ describe("attachment routes", () => {
|
|
|
262
297
|
hash: string;
|
|
263
298
|
};
|
|
264
299
|
|
|
265
|
-
const downloadHandler =
|
|
300
|
+
const downloadHandler = grantedDownload(attachments);
|
|
266
301
|
const downloadReq = makeReq({
|
|
267
302
|
method: "GET",
|
|
268
303
|
params: { hash: upload.hash },
|
|
@@ -305,7 +340,7 @@ describe("attachment routes", () => {
|
|
|
305
340
|
hash: string;
|
|
306
341
|
};
|
|
307
342
|
|
|
308
|
-
const statHandler =
|
|
343
|
+
const statHandler = grantedStat(attachments);
|
|
309
344
|
const statReq = makeReq({
|
|
310
345
|
method: "HEAD",
|
|
311
346
|
params: { hash: upload.hash },
|
|
@@ -364,9 +399,9 @@ describe("attachment routes", () => {
|
|
|
364
399
|
};
|
|
365
400
|
|
|
366
401
|
const { createServer } = await import("node:http");
|
|
367
|
-
const statHandler =
|
|
402
|
+
const statHandler = grantedStat(attachments);
|
|
368
403
|
const server = createServer((req, res) => {
|
|
369
|
-
const m = /^\/attachments\/([
|
|
404
|
+
const m = /^\/attachments\/([^/?]+)(?:\?|$)/.exec(req.url ?? "/");
|
|
370
405
|
if (!m) {
|
|
371
406
|
res.statusCode = 404;
|
|
372
407
|
res.end();
|
|
@@ -377,12 +412,14 @@ describe("attachment routes", () => {
|
|
|
377
412
|
};
|
|
378
413
|
void statHandler(req, res);
|
|
379
414
|
});
|
|
380
|
-
await new Promise<void>((resolve) =>
|
|
415
|
+
await new Promise<void>((resolve) =>
|
|
416
|
+
server.listen(0, "127.0.0.1", resolve),
|
|
417
|
+
);
|
|
381
418
|
const port = (server.address() as { port: number }).port;
|
|
382
419
|
|
|
383
420
|
try {
|
|
384
421
|
const response = await fetch(
|
|
385
|
-
`http://127.0.0.1:${port}/attachments/${upload.hash}`,
|
|
422
|
+
`http://127.0.0.1:${port}/attachments/${upload.hash}?documentId=doc-1`,
|
|
386
423
|
{
|
|
387
424
|
method: "HEAD",
|
|
388
425
|
},
|
|
@@ -403,7 +440,7 @@ describe("attachment routes", () => {
|
|
|
403
440
|
});
|
|
404
441
|
|
|
405
442
|
it("HEAD stat returns 404 for unknown hash", async () => {
|
|
406
|
-
const handler =
|
|
443
|
+
const handler = grantedStat(attachments);
|
|
407
444
|
const req = makeReq({ method: "HEAD", params: { hash: "a".repeat(64) } });
|
|
408
445
|
const res = makeRes();
|
|
409
446
|
await handler(req, res);
|
|
@@ -412,7 +449,7 @@ describe("attachment routes", () => {
|
|
|
412
449
|
});
|
|
413
450
|
|
|
414
451
|
it("HEAD stat returns 400 for malformed hash", async () => {
|
|
415
|
-
const handler =
|
|
452
|
+
const handler = grantedStat(attachments);
|
|
416
453
|
const req = makeReq({ method: "HEAD", params: { hash: "not-a-hash" } });
|
|
417
454
|
const res = makeRes();
|
|
418
455
|
await handler(req, res);
|
|
@@ -514,7 +551,7 @@ describe("attachment routes", () => {
|
|
|
514
551
|
});
|
|
515
552
|
|
|
516
553
|
it("GET download returns 404 for unknown hash", async () => {
|
|
517
|
-
const handler =
|
|
554
|
+
const handler = grantedDownload(attachments);
|
|
518
555
|
const req = makeReq({
|
|
519
556
|
method: "GET",
|
|
520
557
|
params: { hash: "a".repeat(64) },
|
|
@@ -526,7 +563,7 @@ describe("attachment routes", () => {
|
|
|
526
563
|
});
|
|
527
564
|
|
|
528
565
|
it("GET download returns 400 for malformed hash", async () => {
|
|
529
|
-
const handler =
|
|
566
|
+
const handler = grantedDownload(attachments);
|
|
530
567
|
const req = makeReq({
|
|
531
568
|
method: "GET",
|
|
532
569
|
params: { hash: "not-a-hash" },
|
|
@@ -565,7 +602,7 @@ describe("attachment routes", () => {
|
|
|
565
602
|
hash: string;
|
|
566
603
|
};
|
|
567
604
|
|
|
568
|
-
const handler =
|
|
605
|
+
const handler = grantedDownload(attachments);
|
|
569
606
|
const req = makeReq({
|
|
570
607
|
method: "GET",
|
|
571
608
|
params: { hash: upload.hash.toUpperCase() },
|
|
@@ -603,7 +640,7 @@ describe("attachment routes", () => {
|
|
|
603
640
|
hash: string;
|
|
604
641
|
};
|
|
605
642
|
|
|
606
|
-
const statHandler =
|
|
643
|
+
const statHandler = grantedStat(attachments);
|
|
607
644
|
const statReq = makeReq({
|
|
608
645
|
method: "HEAD",
|
|
609
646
|
params: { hash: upload.hash.toUpperCase() },
|
|
@@ -651,7 +688,7 @@ describe("attachment routes", () => {
|
|
|
651
688
|
throw new Error(secret);
|
|
652
689
|
};
|
|
653
690
|
try {
|
|
654
|
-
const handler =
|
|
691
|
+
const handler = grantedDownload(attachments);
|
|
655
692
|
const req = makeReq({
|
|
656
693
|
method: "GET",
|
|
657
694
|
params: { hash: "a".repeat(64) },
|
|
@@ -668,6 +705,101 @@ describe("attachment routes", () => {
|
|
|
668
705
|
}
|
|
669
706
|
});
|
|
670
707
|
|
|
708
|
+
async function uploadText(payload: string): Promise<string> {
|
|
709
|
+
const reserveRes = makeRes();
|
|
710
|
+
await makeReserveHandler(attachments)(
|
|
711
|
+
makeReq({
|
|
712
|
+
method: "POST",
|
|
713
|
+
body: JSON.stringify({ mimeType: "text/plain", fileName: "a.txt" }),
|
|
714
|
+
}),
|
|
715
|
+
reserveRes,
|
|
716
|
+
);
|
|
717
|
+
await waitFor(reserveRes);
|
|
718
|
+
const { reservationId } = JSON.parse(reserveRes._body.toString("utf8")) as {
|
|
719
|
+
reservationId: string;
|
|
720
|
+
};
|
|
721
|
+
const uploadRes = makeRes();
|
|
722
|
+
await makeUploadHandler(attachments)(
|
|
723
|
+
makeReq({ method: "PUT", params: { reservationId }, body: payload }),
|
|
724
|
+
uploadRes,
|
|
725
|
+
);
|
|
726
|
+
await waitFor(uploadRes);
|
|
727
|
+
return (JSON.parse(uploadRes._body.toString("utf8")) as { hash: string })
|
|
728
|
+
.hash;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// The blob store is a directory; its metadata lives in the database. When
|
|
732
|
+
// the directory is lost (a pod-local tmpdir after a restart) the metadata
|
|
733
|
+
// still says "available". Reading such a blob used to raise an unhandled
|
|
734
|
+
// stream error that took the whole process down.
|
|
735
|
+
it("GET download returns 404 when the blob file is missing from disk", async () => {
|
|
736
|
+
const hash = await uploadText("gone");
|
|
737
|
+
const files = await readdir(storagePath, {
|
|
738
|
+
recursive: true,
|
|
739
|
+
withFileTypes: true,
|
|
740
|
+
});
|
|
741
|
+
const blobs = files.filter((f) => f.isFile() && f.name.startsWith(hash));
|
|
742
|
+
expect(blobs.length).toBeGreaterThan(0);
|
|
743
|
+
for (const f of blobs) await rm(join(f.parentPath, f.name));
|
|
744
|
+
|
|
745
|
+
const res = makeRes();
|
|
746
|
+
await grantedDownload(attachments)(
|
|
747
|
+
makeReq({ method: "GET", params: { hash } }),
|
|
748
|
+
res,
|
|
749
|
+
);
|
|
750
|
+
await waitFor(res);
|
|
751
|
+
|
|
752
|
+
expect(res.statusCode).toBe(404);
|
|
753
|
+
expect(JSON.parse(res._body.toString("utf8"))).toEqual({
|
|
754
|
+
error: "Attachment not found",
|
|
755
|
+
});
|
|
756
|
+
// The download headers were set before the read failed; none may leak
|
|
757
|
+
// onto the JSON error.
|
|
758
|
+
expect(res.getHeader("content-length")).toBeUndefined();
|
|
759
|
+
expect(res.getHeader("content-disposition")).toBeUndefined();
|
|
760
|
+
expect(res.getHeader("attachment-metadata")).toBeUndefined();
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it("GET download aborts the response when the blob fails mid-stream", async () => {
|
|
764
|
+
const hash = await uploadText("partial");
|
|
765
|
+
const originalGet = attachments.store.get.bind(attachments.store);
|
|
766
|
+
const real = await originalGet(hash as never);
|
|
767
|
+
let sentFirst = false;
|
|
768
|
+
attachments.store.get = () =>
|
|
769
|
+
Promise.resolve({
|
|
770
|
+
header: real.header,
|
|
771
|
+
// First chunk flows to the response; the read fails only after it
|
|
772
|
+
// has been written, the way a disk error partway through a file would.
|
|
773
|
+
body: new ReadableStream<Uint8Array>({
|
|
774
|
+
async pull(controller) {
|
|
775
|
+
if (!sentFirst) {
|
|
776
|
+
sentFirst = true;
|
|
777
|
+
controller.enqueue(new TextEncoder().encode("part"));
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
781
|
+
controller.error(new Error("EIO: read failed"));
|
|
782
|
+
},
|
|
783
|
+
}) as never,
|
|
784
|
+
});
|
|
785
|
+
try {
|
|
786
|
+
const res = makeRes();
|
|
787
|
+
const closed = new Promise<void>((resolve) => res.once("close", resolve));
|
|
788
|
+
await grantedDownload(attachments)(
|
|
789
|
+
makeReq({ method: "GET", params: { hash } }),
|
|
790
|
+
res,
|
|
791
|
+
);
|
|
792
|
+
await closed;
|
|
793
|
+
// Bytes were already on the wire: the only honest signal left is to
|
|
794
|
+
// cut the connection, never to finish it as if it were complete.
|
|
795
|
+
expect(res._body.toString("utf8")).toBe("part");
|
|
796
|
+
expect(res.destroyed).toBe(true);
|
|
797
|
+
expect(res.writableFinished).toBe(false);
|
|
798
|
+
} finally {
|
|
799
|
+
attachments.store.get = originalGet;
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
|
|
671
803
|
it("identical uploads dedupe to the same hash", async () => {
|
|
672
804
|
const reserveHandler = makeReserveHandler(attachments);
|
|
673
805
|
const uploadHandler = makeUploadHandler(attachments);
|
|
@@ -899,6 +1031,7 @@ describe("attachment routes", () => {
|
|
|
899
1031
|
describe("pending state: stat and download 202 responses", () => {
|
|
900
1032
|
async function createPendingReservation(
|
|
901
1033
|
content: string,
|
|
1034
|
+
fileName = "pending.txt",
|
|
902
1035
|
): Promise<{ hash: string }> {
|
|
903
1036
|
const { createHash } = await import("node:crypto");
|
|
904
1037
|
const hash = createHash("sha256").update(content, "utf8").digest("hex");
|
|
@@ -908,7 +1041,7 @@ describe("attachment routes", () => {
|
|
|
908
1041
|
method: "POST",
|
|
909
1042
|
body: JSON.stringify({
|
|
910
1043
|
mimeType: "text/plain",
|
|
911
|
-
fileName
|
|
1044
|
+
fileName,
|
|
912
1045
|
clientHash: hash,
|
|
913
1046
|
sizeBytes: Buffer.byteLength(content, "utf8"),
|
|
914
1047
|
}),
|
|
@@ -923,7 +1056,7 @@ describe("attachment routes", () => {
|
|
|
923
1056
|
it("HEAD stat returns 202 with Retry-After and Attachment-Pending for pending hash", async () => {
|
|
924
1057
|
const { hash } = await createPendingReservation("pending content data");
|
|
925
1058
|
|
|
926
|
-
const handler =
|
|
1059
|
+
const handler = grantedStat(attachments);
|
|
927
1060
|
const req = makeReq({ method: "HEAD", params: { hash } });
|
|
928
1061
|
const res = makeRes();
|
|
929
1062
|
await handler(req, res);
|
|
@@ -948,7 +1081,7 @@ describe("attachment routes", () => {
|
|
|
948
1081
|
it("HEAD stat 202 for pending hash does not set Content-Disposition or Attachment-Metadata", async () => {
|
|
949
1082
|
const { hash } = await createPendingReservation("no metadata content");
|
|
950
1083
|
|
|
951
|
-
const handler =
|
|
1084
|
+
const handler = grantedStat(attachments);
|
|
952
1085
|
const req = makeReq({ method: "HEAD", params: { hash } });
|
|
953
1086
|
const res = makeRes();
|
|
954
1087
|
await handler(req, res);
|
|
@@ -962,7 +1095,7 @@ describe("attachment routes", () => {
|
|
|
962
1095
|
it("GET download returns 202 with Retry-After and Attachment-Pending for pending hash", async () => {
|
|
963
1096
|
const { hash } = await createPendingReservation("download pending data");
|
|
964
1097
|
|
|
965
|
-
const handler =
|
|
1098
|
+
const handler = grantedDownload(attachments);
|
|
966
1099
|
const req = makeReq({ method: "GET", params: { hash } });
|
|
967
1100
|
const res = makeRes();
|
|
968
1101
|
await handler(req, res);
|
|
@@ -984,7 +1117,7 @@ describe("attachment routes", () => {
|
|
|
984
1117
|
// the response as a successful zero-byte attachment.
|
|
985
1118
|
const { hash } = await createPendingReservation("check-headers content");
|
|
986
1119
|
|
|
987
|
-
const handler =
|
|
1120
|
+
const handler = grantedDownload(attachments);
|
|
988
1121
|
const req = makeReq({ method: "GET", params: { hash } });
|
|
989
1122
|
const res = makeRes();
|
|
990
1123
|
await handler(req, res);
|
|
@@ -995,10 +1128,36 @@ describe("attachment routes", () => {
|
|
|
995
1128
|
expect(res.getHeader("attachment-metadata")).toBeFalsy();
|
|
996
1129
|
});
|
|
997
1130
|
|
|
1131
|
+
it.each(["opłata.pdf", "a – b’s.txt", "📎.png", "報告書.pdf"])(
|
|
1132
|
+
"HEAD and GET 202 carry a parseable Attachment-Pending for %s",
|
|
1133
|
+
async (fileName) => {
|
|
1134
|
+
const { hash } = await createPendingReservation(
|
|
1135
|
+
`pending ${fileName}`,
|
|
1136
|
+
fileName,
|
|
1137
|
+
);
|
|
1138
|
+
|
|
1139
|
+
for (const [method, handler] of [
|
|
1140
|
+
["HEAD", grantedStat(attachments)],
|
|
1141
|
+
["GET", grantedDownload(attachments)],
|
|
1142
|
+
] as const) {
|
|
1143
|
+
const req = makeReq({ method, params: { hash } });
|
|
1144
|
+
const res = makeRes();
|
|
1145
|
+
await handler(req, res);
|
|
1146
|
+
await waitFor(res);
|
|
1147
|
+
|
|
1148
|
+
expect(res.statusCode).toBe(202);
|
|
1149
|
+
const parsed = JSON.parse(
|
|
1150
|
+
res.getHeader("attachment-pending") as string,
|
|
1151
|
+
) as { fileName: string };
|
|
1152
|
+
expect(parsed.fileName).toBe(fileName);
|
|
1153
|
+
}
|
|
1154
|
+
},
|
|
1155
|
+
);
|
|
1156
|
+
|
|
998
1157
|
it("GET download 202 body is empty (not a zero-byte attachment)", async () => {
|
|
999
1158
|
const { hash } = await createPendingReservation("empty body assertion");
|
|
1000
1159
|
|
|
1001
|
-
const handler =
|
|
1160
|
+
const handler = grantedDownload(attachments);
|
|
1002
1161
|
const req = makeReq({ method: "GET", params: { hash } });
|
|
1003
1162
|
const res = makeRes();
|
|
1004
1163
|
await handler(req, res);
|
|
@@ -1215,6 +1374,54 @@ describe("attachment routes", () => {
|
|
|
1215
1374
|
}
|
|
1216
1375
|
});
|
|
1217
1376
|
|
|
1377
|
+
const NON_LATIN1_NAMES = [
|
|
1378
|
+
"opłata.pdf",
|
|
1379
|
+
"a – b’s.txt",
|
|
1380
|
+
"📎 notes.png",
|
|
1381
|
+
"報告書.pdf",
|
|
1382
|
+
"résumé.pdf",
|
|
1383
|
+
'quote"back\\slash.txt',
|
|
1384
|
+
];
|
|
1385
|
+
|
|
1386
|
+
it.each(NON_LATIN1_NAMES)(
|
|
1387
|
+
"buildMetadataHeader output is a valid header that parses back to %s",
|
|
1388
|
+
(fileName) => {
|
|
1389
|
+
const value = buildMetadataHeader({
|
|
1390
|
+
mimeType: "application/pdf",
|
|
1391
|
+
fileName,
|
|
1392
|
+
sizeBytes: 1,
|
|
1393
|
+
extension: null,
|
|
1394
|
+
createdAtUtc: "2026-01-01T00:00:00.000Z",
|
|
1395
|
+
lastAccessedAtUtc: "2026-01-01T00:00:00.000Z",
|
|
1396
|
+
});
|
|
1397
|
+
expect(() =>
|
|
1398
|
+
validateHeaderValue("Attachment-Metadata", value),
|
|
1399
|
+
).not.toThrow();
|
|
1400
|
+
expect(value).toMatch(/^[\x20-\x7e]*$/);
|
|
1401
|
+
expect((JSON.parse(value) as { fileName: string }).fileName).toBe(
|
|
1402
|
+
fileName,
|
|
1403
|
+
);
|
|
1404
|
+
},
|
|
1405
|
+
);
|
|
1406
|
+
|
|
1407
|
+
it.each(NON_LATIN1_NAMES)(
|
|
1408
|
+
"buildPendingHeader output is a valid header that parses back to %s",
|
|
1409
|
+
(fileName) => {
|
|
1410
|
+
const value = buildPendingHeader({
|
|
1411
|
+
expiresAtUtc: "2026-01-01T00:00:00.000Z",
|
|
1412
|
+
mimeType: "application/pdf",
|
|
1413
|
+
fileName,
|
|
1414
|
+
sizeBytes: 1,
|
|
1415
|
+
});
|
|
1416
|
+
expect(() =>
|
|
1417
|
+
validateHeaderValue("Attachment-Pending", value),
|
|
1418
|
+
).not.toThrow();
|
|
1419
|
+
expect((JSON.parse(value) as { fileName: string }).fileName).toBe(
|
|
1420
|
+
fileName,
|
|
1421
|
+
);
|
|
1422
|
+
},
|
|
1423
|
+
);
|
|
1424
|
+
|
|
1218
1425
|
it("buildContentDisposition encodes RFC-5987-reserved chars in the encoded form", () => {
|
|
1219
1426
|
const value = buildContentDisposition("a'b(c)*!.txt");
|
|
1220
1427
|
expect(value).toContain("filename*=UTF-8''a%27b%28c%29%2A%21.txt");
|
|
@@ -1238,7 +1445,7 @@ describe("attachment routes", () => {
|
|
|
1238
1445
|
it("download with non-ASCII fileName produces RFC 6266 Content-Disposition", async () => {
|
|
1239
1446
|
const reserveHandler = makeReserveHandler(attachments);
|
|
1240
1447
|
const uploadHandler = makeUploadHandler(attachments);
|
|
1241
|
-
const downloadHandler =
|
|
1448
|
+
const downloadHandler = grantedDownload(attachments);
|
|
1242
1449
|
|
|
1243
1450
|
const reserveReq = makeReq({
|
|
1244
1451
|
method: "POST",
|
|
@@ -1281,5 +1488,45 @@ describe("attachment routes", () => {
|
|
|
1281
1488
|
) as { fileName: string };
|
|
1282
1489
|
expect(meta.fileName).toBe("résumé.pdf");
|
|
1283
1490
|
});
|
|
1491
|
+
|
|
1492
|
+
it("HEAD and GET answer 200 with a parseable Attachment-Metadata for a name above U+00FF", async () => {
|
|
1493
|
+
const fileName = "opłata – 報告 📎.pdf";
|
|
1494
|
+
const reserveReq = makeReq({
|
|
1495
|
+
method: "POST",
|
|
1496
|
+
body: JSON.stringify({ mimeType: "application/pdf", fileName }),
|
|
1497
|
+
});
|
|
1498
|
+
const reserveRes = makeRes();
|
|
1499
|
+
await makeReserveHandler(attachments)(reserveReq, reserveRes);
|
|
1500
|
+
await waitFor(reserveRes);
|
|
1501
|
+
expect(reserveRes.statusCode).toBe(201);
|
|
1502
|
+
const { reservationId } = JSON.parse(
|
|
1503
|
+
reserveRes._body.toString("utf8"),
|
|
1504
|
+
) as { reservationId: string };
|
|
1505
|
+
|
|
1506
|
+
const uploadRes = makeRes();
|
|
1507
|
+
await makeUploadHandler(attachments)(
|
|
1508
|
+
makeReq({ method: "PUT", params: { reservationId }, body: "pdf" }),
|
|
1509
|
+
uploadRes,
|
|
1510
|
+
);
|
|
1511
|
+
await waitFor(uploadRes);
|
|
1512
|
+
expect(uploadRes.statusCode).toBe(200);
|
|
1513
|
+
const { hash } = JSON.parse(uploadRes._body.toString("utf8")) as {
|
|
1514
|
+
hash: string;
|
|
1515
|
+
};
|
|
1516
|
+
|
|
1517
|
+
for (const [method, handler] of [
|
|
1518
|
+
["HEAD", grantedStat(attachments)],
|
|
1519
|
+
["GET", grantedDownload(attachments)],
|
|
1520
|
+
] as const) {
|
|
1521
|
+
const res = makeRes();
|
|
1522
|
+
await handler(makeReq({ method, params: { hash } }), res);
|
|
1523
|
+
await waitFor(res);
|
|
1524
|
+
expect(res.statusCode).toBe(200);
|
|
1525
|
+
const meta = JSON.parse(
|
|
1526
|
+
res.getHeader("attachment-metadata") as string,
|
|
1527
|
+
) as { fileName: string };
|
|
1528
|
+
expect(meta.fileName).toBe(fileName);
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1284
1531
|
});
|
|
1285
1532
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
-
import type { API } from "@powerhousedao/reactor-api";
|
|
2
|
+
import type { API, IAttachmentAccessService } from "@powerhousedao/reactor-api";
|
|
3
3
|
import { createHttpAdapter } from "@powerhousedao/reactor-api";
|
|
4
4
|
import {
|
|
5
5
|
AttachmentBuilder,
|
|
@@ -109,10 +109,20 @@ describe("attachment service built from deriveAttachmentServiceConfig round-trip
|
|
|
109
109
|
registerAttachmentRoutes({
|
|
110
110
|
httpAdapter: adapter,
|
|
111
111
|
attachments,
|
|
112
|
+
attachmentAccess: {
|
|
113
|
+
canReadAttachment: (
|
|
114
|
+
request: Parameters<IAttachmentAccessService["canReadAttachment"]>[0],
|
|
115
|
+
) =>
|
|
116
|
+
Promise.resolve({
|
|
117
|
+
kind: "allowed",
|
|
118
|
+
documentId: request.documentId as never,
|
|
119
|
+
ref: request.attachmentRef as never,
|
|
120
|
+
}),
|
|
121
|
+
},
|
|
112
122
|
authService: undefined,
|
|
113
123
|
} as unknown as API);
|
|
114
124
|
|
|
115
|
-
server = await adapter.listen(0);
|
|
125
|
+
server = await adapter.listen(0, undefined, "127.0.0.1");
|
|
116
126
|
const addr = server.address();
|
|
117
127
|
if (!addr || typeof addr === "string") throw new Error("no addr");
|
|
118
128
|
port = addr.port;
|
|
@@ -149,7 +159,7 @@ describe("attachment service built from deriveAttachmentServiceConfig round-trip
|
|
|
149
159
|
const result = await upload.send(stream);
|
|
150
160
|
expect(result.header.sizeBytes).toBe(bytes.byteLength);
|
|
151
161
|
|
|
152
|
-
const got = await service.get(result.ref);
|
|
162
|
+
const got = await service.get(result.ref, { documentId: "doc-1" });
|
|
153
163
|
expect(got.header.mimeType).toBe("text/plain");
|
|
154
164
|
const reader = got.body.getReader();
|
|
155
165
|
const chunks: Uint8Array[] = [];
|