@powerhousedao/switchboard 6.2.3-dev.10 → 6.2.3-dev.101
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/ai-gateway.test.d.ts +2 -0
- package/.tsbuild/test/ai-gateway.test.d.ts.map +1 -0
- 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-auth-config.test.d.ts +2 -0
- package/.tsbuild/test/boot-auth-config.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-desktop-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-desktop-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-helpers.d.ts +5 -0
- package/.tsbuild/test/boot-helpers.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-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-auth.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-port-zero.test.d.ts +2 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
- package/.tsbuild/test/boot-preconditions.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-ready-drives.test.d.ts +2 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
- package/.tsbuild/test/boot-undo-v3-flag.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/config-from-env.test.d.ts +2 -0
- package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
- package/.tsbuild/test/config-merge.test.d.ts +2 -0
- package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
- package/.tsbuild/test/config-schema.test.d.ts +2 -0
- package/.tsbuild/test/config-schema.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/default-drive-protocol-versions.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
- package/.tsbuild/test/delegated-publish.test.d.ts +2 -0
- package/.tsbuild/test/delegated-publish.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-throttle.test.d.ts +2 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
- package/.tsbuild/test/keyframe-reclaim-store.test.d.ts +2 -0
- package/.tsbuild/test/keyframe-reclaim-store.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/permissions-backfill.test.d.ts +2 -0
- package/.tsbuild/test/permissions-backfill.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/pglite-store.test.d.ts +2 -0
- package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
- package/.tsbuild/test/plugin-config-schemas.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/port-probe.test.d.ts +2 -0
- package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
- package/.tsbuild/test/processor-timing-log.test.d.ts +2 -0
- package/.tsbuild/test/processor-timing-log.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
- package/.tsbuild/test/renown-storage-path.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/served-schemas.test.d.ts +2 -0
- package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/shutdown.test.d.ts +2 -0
- package/.tsbuild/test/shutdown.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/store-lock.test.d.ts +2 -0
- package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
- package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
- package/.tsbuild/test/two-switchboards.test.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-apps-config.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.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/runtime-host.test.d.ts +2 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.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/test/workflows-plugin-config.test.d.ts +2 -0
- package/.tsbuild/test/workflows-plugin-config.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 +1299 -0
- package/README.md +102 -22
- package/dist/boot.d.mts +46 -0
- package/dist/boot.d.mts.map +1 -0
- package/dist/boot.mjs +67 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/config/from-env.d.mts +15 -0
- package/dist/config/from-env.d.mts.map +1 -0
- package/dist/config/from-env.mjs +4 -0
- package/dist/config/schema.d.mts +3 -0
- package/dist/config/schema.mjs +4 -0
- package/dist/from-env-FH4fPeIE.mjs +481 -0
- package/dist/from-env-FH4fPeIE.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +84 -84
- 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-SsBK14Jm.mjs +32 -0
- package/dist/mcp-SsBK14Jm.mjs.map +1 -0
- package/dist/migrate.d.mts +2 -1
- package/dist/migrate.mjs +7 -5
- package/dist/migrate.mjs.map +1 -1
- package/dist/plugin-host-CK9_tVak.d.mts +46 -0
- package/dist/plugin-host-CK9_tVak.d.mts.map +1 -0
- package/dist/plugins/ai.d.mts +37 -0
- package/dist/plugins/ai.d.mts.map +1 -0
- package/dist/plugins/ai.mjs +400 -0
- package/dist/plugins/ai.mjs.map +1 -0
- package/dist/plugins/attachments.d.mts +33 -0
- package/dist/plugins/attachments.d.mts.map +1 -0
- package/dist/plugins/attachments.mjs +4 -0
- package/dist/plugins/mcp.d.mts +31 -0
- package/dist/plugins/mcp.d.mts.map +1 -0
- package/dist/plugins/mcp.mjs +4 -0
- package/dist/plugins/privacy.d.mts +22 -0
- package/dist/plugins/privacy.d.mts.map +1 -0
- package/dist/plugins/privacy.mjs +4 -0
- package/dist/plugins/workflows.d.mts +79 -0
- package/dist/plugins/workflows.d.mts.map +1 -0
- package/dist/plugins/workflows.mjs +4 -0
- package/dist/postgres-url-DTDhBjXX.mjs +11 -0
- package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
- package/dist/privacy-BO8Q25xI.mjs +44 -0
- package/dist/privacy-BO8Q25xI.mjs.map +1 -0
- package/dist/privacy-DxIJGH4P.mjs +91 -0
- package/dist/privacy-DxIJGH4P.mjs.map +1 -0
- package/dist/renown-layers-DmbWLt46.mjs +42 -0
- package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
- package/dist/schema-CsY8bjsu.mjs +329 -0
- package/dist/schema-CsY8bjsu.mjs.map +1 -0
- package/dist/schema-MAUTnmj1.d.mts +251 -0
- package/dist/schema-MAUTnmj1.d.mts.map +1 -0
- package/dist/server-CirQ9hyu.mjs +2732 -0
- package/dist/server-CirQ9hyu.mjs.map +1 -0
- package/dist/server.d.mts +129 -189
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -5
- package/dist/types-CidZdkhU.d.mts +314 -0
- package/dist/types-CidZdkhU.d.mts.map +1 -0
- package/dist/utils-Cm0TE6dP.mjs +148 -0
- package/dist/utils-Cm0TE6dP.mjs.map +1 -0
- package/dist/utils.d.mts +30 -5
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -4
- package/dist/worker-pool-gyxJnCxA.mjs +304 -0
- package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
- package/dist/workflows-C9BQlyT0.mjs +1943 -0
- package/dist/workflows-C9BQlyT0.mjs.map +1 -0
- package/package.json +85 -24
- package/scripts/install-packages.sh +0 -0
- package/test/ai-gateway.test.ts +612 -0
- package/test/attachment-reference-read-model.test.ts +28 -20
- 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 +211 -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 +297 -35
- package/test/attachments/service-config.test.ts +41 -19
- package/test/attachments/url-signer.test.ts +105 -0
- package/test/boot-auth-config.test.ts +109 -0
- package/test/boot-create-signature-policy.test.ts +110 -0
- package/test/boot-desktop-auth.test.ts +278 -0
- package/test/boot-env-isolation.test.ts +26 -0
- package/test/boot-helpers.ts +19 -0
- package/test/boot-inspection-enabled.test.ts +140 -0
- package/test/boot-mcp-auth.test.ts +449 -0
- package/test/boot-mcp-enabled.test.ts +119 -0
- package/test/boot-port-zero.test.ts +101 -0
- package/test/boot-preconditions.test.ts +213 -0
- package/test/boot-privacy.test.ts +232 -0
- package/test/boot-ready-drives.test.ts +141 -0
- package/test/boot-undo-v3-flag.test.ts +120 -0
- package/test/boot-unsupported-stored-documents.test.ts +214 -0
- package/test/boot-without-renown.test.ts +83 -0
- package/test/boot-without-require-signatures.test.ts +76 -0
- package/test/boot-worker-trust-policy.test.ts +91 -0
- package/test/boot-workflow-singleton-conflict.test.ts +109 -0
- package/test/boot-workflow-singleton-retry.test.ts +122 -0
- package/test/builder-defaults.test.ts +80 -0
- package/test/config-from-env.test.ts +963 -0
- package/test/config-merge.test.ts +248 -0
- package/test/config-schema.test.ts +167 -0
- package/test/create-signature-policy.test.ts +69 -0
- package/test/default-drive-protocol-versions.test.ts +79 -0
- package/test/default-drive-slug.test.ts +265 -0
- package/test/delegated-publish.test.ts +435 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +205 -0
- package/test/goldens/packages.graphql +797 -0
- package/test/goldens/privacy.graphql +853 -0
- package/test/goldens/reactor-drive-nodes.graphql +827 -0
- package/test/goldens/resolvers.json +327 -0
- package/test/goldens/supergraph.graphql +5918 -0
- package/test/goldens/workflow-runtime.graphql +1548 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/keyframe-reclaim-store.test.ts +156 -0
- package/test/observability-signals.test.ts +131 -0
- package/test/permissions-backfill.test.ts +486 -0
- package/test/pglite-dialect.test.ts +237 -2
- package/test/pglite-preflight.test.ts +313 -0
- package/test/pglite-storage-dirs.test.ts +113 -0
- package/test/pglite-store.test.ts +441 -0
- package/test/pglite-version.test.ts +9 -1
- package/test/plugin-config-schemas.test.ts +83 -0
- package/test/plugin-presence.test.ts +262 -0
- package/test/port-probe.test.ts +45 -0
- package/test/processor-timing-log.test.ts +109 -0
- package/test/reactor-feature-flags.test.ts +20 -0
- package/test/redact-webhook-path.test.ts +9 -0
- package/test/renown-storage-path.test.ts +40 -0
- package/test/renown-trust-policy.test.ts +313 -0
- package/test/served-schemas.test.ts +134 -0
- package/test/shutdown.test.ts +278 -0
- package/test/snapshot-writer.ts +94 -0
- package/test/store-lock.test.ts +65 -0
- package/test/two-switchboards.test.ts +146 -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-apps-config.test.ts +66 -0
- package/test/workflow/oauth.test.ts +286 -0
- package/test/workflow/resolvers.test.ts +488 -0
- package/test/workflow/runtime-host.test.ts +19 -0
- package/test/workflow/waitpoint-routes.test.ts +306 -0
- package/test/workflow/waitpoint-runtime.test.ts +204 -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 +1254 -0
- package/test/workflows-plugin-config.test.ts +77 -0
- package/tsconfig.json +11 -2
- package/tsdown.config.ts +13 -1
- package/vitest.config.ts +66 -1
- package/dist/server-CiKkVE6g.mjs +0 -1555
- package/dist/server-CiKkVE6g.mjs.map +0 -1
- package/dist/utils-Baw7rThP.mjs +0 -80
- package/dist/utils-Baw7rThP.mjs.map +0 -1
|
@@ -8,16 +8,39 @@ import type {
|
|
|
8
8
|
AttachmentAccessResult,
|
|
9
9
|
IAttachmentAccessService,
|
|
10
10
|
} from "@powerhousedao/reactor-api";
|
|
11
|
+
import type { ILogger } from "document-model";
|
|
11
12
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
12
13
|
import { describe, expect, it, vi } from "vitest";
|
|
13
14
|
import type { AttachmentActorContext } from "../../src/attachments/auth.js";
|
|
14
15
|
import { registerAttachmentRoutes } from "../../src/attachments/index.js";
|
|
15
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
downloadTargetTtlCapSeconds,
|
|
18
|
+
makeDownloadTargetHandler,
|
|
19
|
+
} from "../../src/attachments/routes.js";
|
|
20
|
+
import { AttachmentUrlSigner } from "../../src/attachments/url-signer.js";
|
|
21
|
+
import { switchboardConfigFromEnv } from "../../src/config/from-env.js";
|
|
22
|
+
|
|
23
|
+
const silentLogger = {
|
|
24
|
+
verbose: () => {},
|
|
25
|
+
debug: () => {},
|
|
26
|
+
info: () => {},
|
|
27
|
+
warn: () => {},
|
|
28
|
+
error: () => {},
|
|
29
|
+
child: () => silentLogger,
|
|
30
|
+
} as unknown as ILogger;
|
|
16
31
|
|
|
17
32
|
const HASH = "a".repeat(64) as AttachmentHash;
|
|
18
33
|
const REF = `attachment://v1:${HASH}`;
|
|
19
34
|
const DOC_ID = "doc-1";
|
|
20
35
|
const EXPIRES = "2026-07-23T00:00:00.000Z";
|
|
36
|
+
const NOW_MS = Date.parse("2026-07-22T00:00:00.000Z");
|
|
37
|
+
const SIGNER = new AttachmentUrlSigner("s".repeat(32), () => NOW_MS);
|
|
38
|
+
|
|
39
|
+
function signedUrlParts(body: string) {
|
|
40
|
+
const target = JSON.parse(body) as { url: string; expiresAtUtc: string };
|
|
41
|
+
const url = new URL(target.url);
|
|
42
|
+
return { target, url, params: url.searchParams };
|
|
43
|
+
}
|
|
21
44
|
|
|
22
45
|
const ACTOR: AttachmentActorContext = {
|
|
23
46
|
user: {
|
|
@@ -82,7 +105,13 @@ function makeAccess(result: AttachmentAccessResult): {
|
|
|
82
105
|
spy: ReturnType<typeof vi.fn>;
|
|
83
106
|
} {
|
|
84
107
|
const spy = vi.fn().mockResolvedValue(result);
|
|
85
|
-
return {
|
|
108
|
+
return {
|
|
109
|
+
access: {
|
|
110
|
+
canReadAttachment: spy,
|
|
111
|
+
admitCaller: () => Promise.resolve({ kind: "admitted" }),
|
|
112
|
+
},
|
|
113
|
+
spy,
|
|
114
|
+
};
|
|
86
115
|
}
|
|
87
116
|
|
|
88
117
|
function makeAttachments(opts: {
|
|
@@ -106,27 +135,118 @@ const ALLOWED: AttachmentAccessResult = {
|
|
|
106
135
|
};
|
|
107
136
|
|
|
108
137
|
describe("makeDownloadTargetHandler", () => {
|
|
109
|
-
it("returns a switchboard target for filesystem with no-store", async () => {
|
|
138
|
+
it("returns a signed switchboard target for filesystem with no-store", async () => {
|
|
110
139
|
const { access, spy } = makeAccess(ALLOWED);
|
|
111
140
|
const attachments = makeAttachments({});
|
|
112
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
141
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
113
142
|
const res = makeRes();
|
|
114
143
|
|
|
115
144
|
await handler(makeReq({}), res, undefined, ACTOR);
|
|
116
145
|
|
|
117
146
|
expect(res.statusCode).toBe(200);
|
|
118
147
|
expect(res._headers["cache-control"]).toBe("no-store");
|
|
119
|
-
|
|
148
|
+
const { target, url, params } = signedUrlParts(res._body);
|
|
149
|
+
expect(target).toMatchObject({
|
|
120
150
|
kind: "switchboard",
|
|
121
151
|
method: "GET",
|
|
122
|
-
url: `http://sb.example.com/attachments/${HASH}`,
|
|
123
152
|
headers: {},
|
|
153
|
+
expiresAtUtc: new Date(NOW_MS + 300_000).toISOString(),
|
|
124
154
|
});
|
|
155
|
+
expect(`${url.origin}${url.pathname}`).toBe(
|
|
156
|
+
`http://sb.example.com/attachments/${HASH}`,
|
|
157
|
+
);
|
|
158
|
+
expect(params.get("documentId")).toBe(DOC_ID);
|
|
159
|
+
expect(
|
|
160
|
+
SIGNER.verify(
|
|
161
|
+
HASH,
|
|
162
|
+
DOC_ID,
|
|
163
|
+
params.get("expires")!,
|
|
164
|
+
params.get("signature")!,
|
|
165
|
+
),
|
|
166
|
+
).toBe(true);
|
|
125
167
|
expect(spy).toHaveBeenCalledWith({
|
|
126
168
|
documentId: DOC_ID,
|
|
127
169
|
attachmentRef: REF,
|
|
128
170
|
userAddress: "0xverified",
|
|
171
|
+
appKey: "did:key:zAppTest",
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("signs for the requested expiresIn, clamped to the download-target ceiling", async () => {
|
|
176
|
+
const { access } = makeAccess(ALLOWED);
|
|
177
|
+
const handler = makeDownloadTargetHandler(
|
|
178
|
+
makeAttachments({}),
|
|
179
|
+
access,
|
|
180
|
+
SIGNER,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
for (const [requested, granted] of [
|
|
184
|
+
[60, 60],
|
|
185
|
+
[3600, 300],
|
|
186
|
+
[99999999, 300],
|
|
187
|
+
]) {
|
|
188
|
+
const res = makeRes();
|
|
189
|
+
await handler(
|
|
190
|
+
makeReq({
|
|
191
|
+
url: `/attachments/${HASH}/download-target?documentId=${DOC_ID}&expiresIn=${requested}`,
|
|
192
|
+
}),
|
|
193
|
+
res,
|
|
194
|
+
undefined,
|
|
195
|
+
ACTOR,
|
|
196
|
+
);
|
|
197
|
+
expect(signedUrlParts(res._body).target.expiresAtUtc).toBe(
|
|
198
|
+
new Date(NOW_MS + granted * 1000).toISOString(),
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("signs the canonical document id the access decision resolved", async () => {
|
|
204
|
+
const { access } = makeAccess({ ...ALLOWED, documentId: "canon" as never });
|
|
205
|
+
const handler = makeDownloadTargetHandler(
|
|
206
|
+
makeAttachments({}),
|
|
207
|
+
access,
|
|
208
|
+
SIGNER,
|
|
209
|
+
);
|
|
210
|
+
const res = makeRes();
|
|
211
|
+
|
|
212
|
+
await handler(makeReq({}), res, undefined, ACTOR);
|
|
213
|
+
|
|
214
|
+
expect(signedUrlParts(res._body).params.get("documentId")).toBe("canon");
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("fails closed with 503 on filesystem when no signer is configured", async () => {
|
|
218
|
+
const { access } = makeAccess(ALLOWED);
|
|
219
|
+
const handler = makeDownloadTargetHandler(
|
|
220
|
+
makeAttachments({}),
|
|
221
|
+
access,
|
|
222
|
+
null,
|
|
223
|
+
);
|
|
224
|
+
const res = makeRes();
|
|
225
|
+
|
|
226
|
+
await handler(makeReq({}), res, undefined, ACTOR);
|
|
227
|
+
|
|
228
|
+
expect(res.statusCode).toBe(503);
|
|
229
|
+
expect(res._body).not.toContain("/attachments/");
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("needs no signer for S3 presigned targets", async () => {
|
|
233
|
+
const { access } = makeAccess(ALLOWED);
|
|
234
|
+
const prepareDownloadTarget = vi.fn().mockResolvedValue({
|
|
235
|
+
kind: "presigned-get",
|
|
236
|
+
method: "GET",
|
|
237
|
+
url: "https://bucket.example.com/attachments/aa?sig=1",
|
|
238
|
+
headers: {},
|
|
239
|
+
expiresAtUtc: EXPIRES,
|
|
240
|
+
});
|
|
241
|
+
const attachments = makeAttachments({
|
|
242
|
+
backend: { kind: "s3", prepareDownloadTarget } as never,
|
|
129
243
|
});
|
|
244
|
+
const handler = makeDownloadTargetHandler(attachments, access, null);
|
|
245
|
+
const res = makeRes();
|
|
246
|
+
|
|
247
|
+
await handler(makeReq({}), res, undefined, ACTOR);
|
|
248
|
+
|
|
249
|
+
expect(res.statusCode).toBe(200);
|
|
130
250
|
});
|
|
131
251
|
|
|
132
252
|
it("returns the backend presigned-get target in S3 mode", async () => {
|
|
@@ -141,14 +261,14 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
141
261
|
const attachments = makeAttachments({
|
|
142
262
|
backend: { kind: "s3", prepareDownloadTarget } as never,
|
|
143
263
|
});
|
|
144
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
264
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
145
265
|
const res = makeRes();
|
|
146
266
|
|
|
147
267
|
await handler(makeReq({}), res, undefined, ACTOR);
|
|
148
268
|
|
|
149
269
|
expect(res.statusCode).toBe(200);
|
|
150
270
|
expect(JSON.parse(res._body)).toMatchObject({ kind: "presigned-get" });
|
|
151
|
-
expect(prepareDownloadTarget).toHaveBeenCalledWith(HASH,
|
|
271
|
+
expect(prepareDownloadTarget).toHaveBeenCalledWith(HASH, 300);
|
|
152
272
|
});
|
|
153
273
|
|
|
154
274
|
it("passes a requested expiresIn through to the backend presigner", async () => {
|
|
@@ -163,12 +283,12 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
163
283
|
const attachments = makeAttachments({
|
|
164
284
|
backend: { kind: "s3", prepareDownloadTarget } as never,
|
|
165
285
|
});
|
|
166
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
286
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
167
287
|
const res = makeRes();
|
|
168
288
|
|
|
169
289
|
await handler(
|
|
170
290
|
makeReq({
|
|
171
|
-
url: `/attachments/${HASH}/download-target?documentId=${DOC_ID}&expiresIn=
|
|
291
|
+
url: `/attachments/${HASH}/download-target?documentId=${DOC_ID}&expiresIn=60`,
|
|
172
292
|
}),
|
|
173
293
|
res,
|
|
174
294
|
undefined,
|
|
@@ -176,10 +296,10 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
176
296
|
);
|
|
177
297
|
|
|
178
298
|
expect(res.statusCode).toBe(200);
|
|
179
|
-
expect(prepareDownloadTarget).toHaveBeenCalledWith(HASH,
|
|
299
|
+
expect(prepareDownloadTarget).toHaveBeenCalledWith(HASH, 60);
|
|
180
300
|
});
|
|
181
301
|
|
|
182
|
-
it("clamps expiresIn to the
|
|
302
|
+
it("clamps a requested expiresIn to the ceiling", async () => {
|
|
183
303
|
const { access } = makeAccess(ALLOWED);
|
|
184
304
|
const prepareDownloadTarget = vi.fn().mockResolvedValue({
|
|
185
305
|
kind: "presigned-get",
|
|
@@ -191,7 +311,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
191
311
|
const attachments = makeAttachments({
|
|
192
312
|
backend: { kind: "s3", prepareDownloadTarget } as never,
|
|
193
313
|
});
|
|
194
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
314
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
195
315
|
const res = makeRes();
|
|
196
316
|
|
|
197
317
|
await handler(
|
|
@@ -203,10 +323,10 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
203
323
|
ACTOR,
|
|
204
324
|
);
|
|
205
325
|
|
|
206
|
-
expect(prepareDownloadTarget).toHaveBeenCalledWith(HASH,
|
|
326
|
+
expect(prepareDownloadTarget).toHaveBeenCalledWith(HASH, 300);
|
|
207
327
|
});
|
|
208
328
|
|
|
209
|
-
it("
|
|
329
|
+
it("applies the ceiling when expiresIn is absent, rather than the backend default", async () => {
|
|
210
330
|
const { access } = makeAccess(ALLOWED);
|
|
211
331
|
const prepareDownloadTarget = vi.fn().mockResolvedValue({
|
|
212
332
|
kind: "presigned-get",
|
|
@@ -218,11 +338,69 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
218
338
|
const attachments = makeAttachments({
|
|
219
339
|
backend: { kind: "s3", prepareDownloadTarget } as never,
|
|
220
340
|
});
|
|
221
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
341
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
222
342
|
|
|
223
343
|
await handler(makeReq({}), makeRes(), undefined, ACTOR);
|
|
224
344
|
|
|
225
|
-
expect(prepareDownloadTarget).toHaveBeenCalledWith(HASH,
|
|
345
|
+
expect(prepareDownloadTarget).toHaveBeenCalledWith(HASH, 300);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
describe("ATTACHMENT_DOWNLOAD_TARGET_MAX_TTL_SECONDS, mapped at the edge", () => {
|
|
349
|
+
async function ttlFor(configured: string | undefined, query = "") {
|
|
350
|
+
const config = switchboardConfigFromEnv(
|
|
351
|
+
{ ATTACHMENT_DOWNLOAD_TARGET_MAX_TTL_SECONDS: configured },
|
|
352
|
+
{ logger: silentLogger },
|
|
353
|
+
);
|
|
354
|
+
const { access } = makeAccess(ALLOWED);
|
|
355
|
+
const prepareDownloadTarget = vi.fn().mockResolvedValue({
|
|
356
|
+
kind: "presigned-get",
|
|
357
|
+
method: "GET",
|
|
358
|
+
url: "https://bucket.example.com/attachments/aa?sig=1",
|
|
359
|
+
headers: {},
|
|
360
|
+
expiresAtUtc: EXPIRES,
|
|
361
|
+
});
|
|
362
|
+
const attachments = makeAttachments({
|
|
363
|
+
backend: { kind: "s3", prepareDownloadTarget } as never,
|
|
364
|
+
});
|
|
365
|
+
const handler = makeDownloadTargetHandler(
|
|
366
|
+
attachments,
|
|
367
|
+
access,
|
|
368
|
+
SIGNER,
|
|
369
|
+
downloadTargetTtlCapSeconds(
|
|
370
|
+
config.attachments?.downloadTargetMaxTtlSeconds,
|
|
371
|
+
),
|
|
372
|
+
);
|
|
373
|
+
await handler(
|
|
374
|
+
makeReq({
|
|
375
|
+
url: `/attachments/${HASH}/download-target?documentId=${DOC_ID}${query}`,
|
|
376
|
+
}),
|
|
377
|
+
makeRes(),
|
|
378
|
+
undefined,
|
|
379
|
+
ACTOR,
|
|
380
|
+
);
|
|
381
|
+
return (prepareDownloadTarget.mock.calls[0] as unknown[])[1];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
it("raises the ceiling when a deployment configures one", async () => {
|
|
385
|
+
await expect(ttlFor("1800")).resolves.toBe(1800);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it("never lets a configured ceiling exceed the signing maximum", async () => {
|
|
389
|
+
await expect(ttlFor("99999999")).resolves.toBe(604800);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it.each(["not-a-number", "0", "-5", "12.5"])(
|
|
393
|
+
"falls back to the default, not the maximum, on %s",
|
|
394
|
+
async (configured) => {
|
|
395
|
+
// A typo must narrow nothing and widen nothing: falling back to the
|
|
396
|
+
// signing ceiling would turn a misconfiguration into a week-long URL.
|
|
397
|
+
await expect(ttlFor(configured)).resolves.toBe(300);
|
|
398
|
+
},
|
|
399
|
+
);
|
|
400
|
+
|
|
401
|
+
it("still clamps a caller's request to the configured ceiling", async () => {
|
|
402
|
+
await expect(ttlFor("1800", "&expiresIn=99999")).resolves.toBe(1800);
|
|
403
|
+
});
|
|
226
404
|
});
|
|
227
405
|
|
|
228
406
|
it.each([
|
|
@@ -234,7 +412,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
234
412
|
])("rejects a %s expiresIn with 400 before authorization", async (_, qs) => {
|
|
235
413
|
const { access, spy } = makeAccess(ALLOWED);
|
|
236
414
|
const attachments = makeAttachments({});
|
|
237
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
415
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
238
416
|
const res = makeRes();
|
|
239
417
|
|
|
240
418
|
await handler(
|
|
@@ -253,7 +431,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
253
431
|
it("normalizes an uppercase path hash before authorization and lookup", async () => {
|
|
254
432
|
const { access, spy } = makeAccess(ALLOWED);
|
|
255
433
|
const attachments = makeAttachments({});
|
|
256
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
434
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
257
435
|
const res = makeRes();
|
|
258
436
|
|
|
259
437
|
await handler(makeReq({ hash: HASH.toUpperCase() }), res, undefined, ACTOR);
|
|
@@ -268,7 +446,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
268
446
|
it("rejects an invalid hash before any access or storage call", async () => {
|
|
269
447
|
const { access, spy } = makeAccess(ALLOWED);
|
|
270
448
|
const attachments = makeAttachments({});
|
|
271
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
449
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
272
450
|
const res = makeRes();
|
|
273
451
|
|
|
274
452
|
await handler(makeReq({ hash: "nothex" }), res, undefined, ACTOR);
|
|
@@ -292,7 +470,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
292
470
|
])("rejects a %s documentId before authorization", async (_, url) => {
|
|
293
471
|
const { access, spy } = makeAccess(ALLOWED);
|
|
294
472
|
const attachments = makeAttachments({});
|
|
295
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
473
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
296
474
|
const res = makeRes();
|
|
297
475
|
|
|
298
476
|
await handler(makeReq({ url }), res, undefined, ACTOR);
|
|
@@ -307,7 +485,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
307
485
|
const attachments = makeAttachments({
|
|
308
486
|
backend: { kind: "s3", prepareDownloadTarget } as never,
|
|
309
487
|
});
|
|
310
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
488
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
311
489
|
const res = makeRes();
|
|
312
490
|
|
|
313
491
|
await handler(makeReq({}), res, undefined, ACTOR);
|
|
@@ -321,7 +499,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
321
499
|
it("maps projection-unavailable to a generic non-cacheable 503 before storage", async () => {
|
|
322
500
|
const { access } = makeAccess({ kind: "projection-unavailable" });
|
|
323
501
|
const attachments = makeAttachments({});
|
|
324
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
502
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
325
503
|
const res = makeRes();
|
|
326
504
|
|
|
327
505
|
await handler(makeReq({}), res, undefined, ACTOR);
|
|
@@ -337,7 +515,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
337
515
|
const { AttachmentNotFound } =
|
|
338
516
|
await import("@powerhousedao/reactor-attachments");
|
|
339
517
|
attachments.statSpy.mockRejectedValue(new AttachmentNotFound(HASH));
|
|
340
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
518
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
341
519
|
const res = makeRes();
|
|
342
520
|
|
|
343
521
|
await handler(makeReq({}), res, undefined, ACTOR);
|
|
@@ -351,7 +529,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
351
529
|
const attachments = makeAttachments({
|
|
352
530
|
stat: () => Promise.resolve({ ...AVAILABLE_HEADER, status: "pending" }),
|
|
353
531
|
});
|
|
354
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
532
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
355
533
|
const res = makeRes();
|
|
356
534
|
|
|
357
535
|
await handler(makeReq({}), res, undefined, ACTOR);
|
|
@@ -371,7 +549,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
371
549
|
const attachments = makeAttachments({
|
|
372
550
|
backend: { kind: "s3", prepareDownloadTarget } as never,
|
|
373
551
|
});
|
|
374
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
552
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
375
553
|
const res = makeRes();
|
|
376
554
|
|
|
377
555
|
await handler(makeReq({}), res, undefined, ACTOR);
|
|
@@ -384,7 +562,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
384
562
|
it("passes an anonymous actor as an undefined address (OPEN mode)", async () => {
|
|
385
563
|
const { access, spy } = makeAccess(ALLOWED);
|
|
386
564
|
const attachments = makeAttachments({});
|
|
387
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
565
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
388
566
|
const res = makeRes();
|
|
389
567
|
|
|
390
568
|
await handler(makeReq({}), res, undefined, {
|
|
@@ -400,7 +578,7 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
400
578
|
it("honours x-forwarded proto/host when building the switchboard target", async () => {
|
|
401
579
|
const { access } = makeAccess(ALLOWED);
|
|
402
580
|
const attachments = makeAttachments({});
|
|
403
|
-
const handler = makeDownloadTargetHandler(attachments, access);
|
|
581
|
+
const handler = makeDownloadTargetHandler(attachments, access, SIGNER);
|
|
404
582
|
const res = makeRes();
|
|
405
583
|
|
|
406
584
|
await handler(
|
|
@@ -415,9 +593,10 @@ describe("makeDownloadTargetHandler", () => {
|
|
|
415
593
|
ACTOR,
|
|
416
594
|
);
|
|
417
595
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
596
|
+
const { url } = signedUrlParts(res._body);
|
|
597
|
+
expect(`${url.origin}${url.pathname}`).toBe(
|
|
598
|
+
`https://public.example.com/attachments/${HASH}`,
|
|
599
|
+
);
|
|
421
600
|
});
|
|
422
601
|
});
|
|
423
602
|
|
|
@@ -435,7 +614,7 @@ describe("registerAttachmentRoutes inventory", () => {
|
|
|
435
614
|
attachmentAccess: { canReadAttachment: vi.fn() },
|
|
436
615
|
} as unknown as API;
|
|
437
616
|
|
|
438
|
-
registerAttachmentRoutes(api);
|
|
617
|
+
registerAttachmentRoutes(api, { urlSigner: null });
|
|
439
618
|
|
|
440
619
|
expect(captured).toEqual([
|
|
441
620
|
{ method: "POST", path: "/attachments/reservations" },
|
|
@@ -11,10 +11,19 @@ type Captured = {
|
|
|
11
11
|
res: ServerResponse,
|
|
12
12
|
body?: unknown,
|
|
13
13
|
) => void | Promise<void>;
|
|
14
|
+
options?: unknown;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
type FakeApi = Pick<
|
|
18
|
+
API,
|
|
19
|
+
"httpAdapter" | "authService" | "requireAuthenticatedCaller"
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
function makeFakeApi(
|
|
23
|
+
authService: AuthService | undefined,
|
|
24
|
+
requireAuthenticatedCaller = false,
|
|
25
|
+
): {
|
|
26
|
+
api: FakeApi;
|
|
18
27
|
captured: Captured[];
|
|
19
28
|
} {
|
|
20
29
|
const captured: Captured[] = [];
|
|
@@ -24,12 +33,14 @@ function makeFakeApi(authService: AuthService | undefined): {
|
|
|
24
33
|
method: string,
|
|
25
34
|
path: string,
|
|
26
35
|
handler: Captured["handler"],
|
|
36
|
+
options?: unknown,
|
|
27
37
|
) => {
|
|
28
|
-
captured.push({ method, path, handler });
|
|
38
|
+
captured.push({ method, path, handler, options });
|
|
29
39
|
},
|
|
30
40
|
},
|
|
31
41
|
authService,
|
|
32
|
-
|
|
42
|
+
requireAuthenticatedCaller,
|
|
43
|
+
} as unknown as FakeApi;
|
|
33
44
|
return { api, captured };
|
|
34
45
|
}
|
|
35
46
|
|
|
@@ -138,6 +149,28 @@ describe("mountAuthenticatedNodeRoute", () => {
|
|
|
138
149
|
});
|
|
139
150
|
});
|
|
140
151
|
|
|
152
|
+
it("carries the deployment's authenticated-caller floor onto the route, over allowAnonymous", async () => {
|
|
153
|
+
// auth_enabled false is the shape a deployment running the document
|
|
154
|
+
// policies has: the boundary policy is OPEN, and this floor is what keeps
|
|
155
|
+
// an anonymous caller off the attachment routes.
|
|
156
|
+
const verifyBearer = vi.fn(() =>
|
|
157
|
+
Promise.resolve({ user: undefined, admins: [], auth_enabled: false }),
|
|
158
|
+
);
|
|
159
|
+
const authService = { verifyBearer } as unknown as AuthService;
|
|
160
|
+
const { api, captured } = makeFakeApi(authService, true);
|
|
161
|
+
const inner = vi.fn();
|
|
162
|
+
|
|
163
|
+
mountAuthenticatedNodeRoute(api, "GET", "/x", inner, {
|
|
164
|
+
allowAnonymous: true,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const res = makeRes();
|
|
168
|
+
await captured[0].handler(makeReq(), res);
|
|
169
|
+
|
|
170
|
+
expect(res.statusCode).toBe(401);
|
|
171
|
+
expect(inner).not.toHaveBeenCalled();
|
|
172
|
+
});
|
|
173
|
+
|
|
141
174
|
it("mounts a wrapper that forwards the anonymous actor when authService is undefined", async () => {
|
|
142
175
|
const { api, captured } = makeFakeApi(undefined);
|
|
143
176
|
const inner = vi.fn();
|
|
@@ -155,4 +188,14 @@ describe("mountAuthenticatedNodeRoute", () => {
|
|
|
155
188
|
authEnabled: false,
|
|
156
189
|
});
|
|
157
190
|
});
|
|
191
|
+
|
|
192
|
+
it("forwards rawBody to the adapter and keeps it out of the auth options", () => {
|
|
193
|
+
const { api, captured } = makeFakeApi(undefined);
|
|
194
|
+
|
|
195
|
+
mountAuthenticatedNodeRoute(api, "PUT", "/x", vi.fn(), { rawBody: true });
|
|
196
|
+
mountAuthenticatedNodeRoute(api, "GET", "/y", vi.fn());
|
|
197
|
+
|
|
198
|
+
expect(captured[0].options).toEqual({ rawBody: true });
|
|
199
|
+
expect(captured[1].options).toEqual({ rawBody: false });
|
|
200
|
+
});
|
|
158
201
|
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InvalidAttachmentMetadata,
|
|
3
|
+
validateReserveMetadata,
|
|
4
|
+
type ReserveMetadata,
|
|
5
|
+
} from "@powerhousedao/reactor-attachments";
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
import { parseReserveOptions } from "../../src/attachments/routes.js";
|
|
8
|
+
|
|
9
|
+
type Case = [name: string, meta: Record<string, unknown>];
|
|
10
|
+
|
|
11
|
+
const base = { mimeType: "text/plain", fileName: "note.txt" };
|
|
12
|
+
|
|
13
|
+
// The download route's setHeader throws on each of these.
|
|
14
|
+
const headerBreaking: Case[] = [
|
|
15
|
+
["CRLF before a parameter", { ...base, mimeType: "text/plain\r\n;a=b" }],
|
|
16
|
+
["LF after a ;", { ...base, mimeType: "text/plain;\na=b" }],
|
|
17
|
+
["a control char quoted", { ...base, mimeType: 'text/plain; a="\x01"' }],
|
|
18
|
+
["a DEL quoted", { ...base, mimeType: 'text/plain; a="\x7f"' }],
|
|
19
|
+
["a char above 0xFF quoted", { ...base, mimeType: 'text/plain;a="\u0100"' }],
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const cases: Case[] = [
|
|
23
|
+
["plain metadata", base],
|
|
24
|
+
["an extension", { ...base, extension: "txt" }],
|
|
25
|
+
["a null extension", { ...base, extension: null }],
|
|
26
|
+
["a parameter", { ...base, mimeType: "text/plain; charset=utf-8" }],
|
|
27
|
+
["a quoted parameter", { ...base, mimeType: 'text/plain; a="b c"' }],
|
|
28
|
+
["a unicode file name", { ...base, fileName: "résumé.pdf" }],
|
|
29
|
+
["a 255-char mimeType", { ...base, mimeType: `a/${"b".repeat(253)}` }],
|
|
30
|
+
["a 256-char mimeType", { ...base, mimeType: `a/${"b".repeat(254)}` }],
|
|
31
|
+
["a 255-char fileName", { ...base, fileName: "f".repeat(255) }],
|
|
32
|
+
["a 256-char fileName", { ...base, fileName: "f".repeat(256) }],
|
|
33
|
+
["an empty mimeType", { ...base, mimeType: "" }],
|
|
34
|
+
["an empty fileName", { ...base, fileName: "" }],
|
|
35
|
+
["an empty extension", { ...base, extension: "" }],
|
|
36
|
+
["a mimeType with no slash", { ...base, mimeType: "text" }],
|
|
37
|
+
["a mimeType with no subtype", { ...base, mimeType: "text/" }],
|
|
38
|
+
["a mimeType with no type", { ...base, mimeType: "/plain" }],
|
|
39
|
+
["a mimeType with two slashes", { ...base, mimeType: "text/plain/x" }],
|
|
40
|
+
["a mimeType with a space", { ...base, mimeType: "text plain" }],
|
|
41
|
+
["a mimeType with a dangling ;", { ...base, mimeType: "text/plain;" }],
|
|
42
|
+
["a non-string mimeType", { ...base, mimeType: 5 }],
|
|
43
|
+
["a trailing CRLF in mimeType", { ...base, mimeType: "text/plain\r\n" }],
|
|
44
|
+
[
|
|
45
|
+
"an injected header in mimeType",
|
|
46
|
+
{ ...base, mimeType: "text/plain\nX-Injected: 1" },
|
|
47
|
+
],
|
|
48
|
+
["a NUL in mimeType", { ...base, mimeType: "text/pl\x00ain" }],
|
|
49
|
+
...headerBreaking,
|
|
50
|
+
["a NUL in fileName", { ...base, fileName: "a\x00b" }],
|
|
51
|
+
["a LF in fileName", { ...base, fileName: "a\nb" }],
|
|
52
|
+
["a CR in fileName", { ...base, fileName: "a\rb" }],
|
|
53
|
+
["a tab in fileName", { ...base, fileName: "a\tb" }],
|
|
54
|
+
["a DEL in fileName", { ...base, fileName: "a\x7fb" }],
|
|
55
|
+
["a non-string fileName", { ...base, fileName: null }],
|
|
56
|
+
["a slash in extension", { ...base, extension: "a/b" }],
|
|
57
|
+
["a backslash in extension", { ...base, extension: "a\\b" }],
|
|
58
|
+
["a bare slash extension", { ...base, extension: "/" }],
|
|
59
|
+
["a non-string extension", { ...base, extension: 5 }],
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
function routeAccepts(meta: Record<string, unknown>): boolean {
|
|
63
|
+
return parseReserveOptions(meta) !== null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function validatorAccepts(meta: Record<string, unknown>): boolean {
|
|
67
|
+
try {
|
|
68
|
+
validateReserveMetadata(meta as ReserveMetadata);
|
|
69
|
+
return true;
|
|
70
|
+
} catch (err) {
|
|
71
|
+
if (err instanceof InvalidAttachmentMetadata) return false;
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
describe("reserve metadata parity between the route and validateReserveMetadata", () => {
|
|
77
|
+
it("covers both accepted and rejected metadata", () => {
|
|
78
|
+
const verdicts = cases.map(([, meta]) => routeAccepts(meta));
|
|
79
|
+
expect(verdicts).toContain(true);
|
|
80
|
+
expect(verdicts).toContain(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it.each(cases)("agrees on %s", (_name, meta) => {
|
|
84
|
+
expect(validatorAccepts(meta)).toBe(routeAccepts(meta));
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("header-breaking mimeType values", () => {
|
|
89
|
+
it.each(headerBreaking)("the route rejects %s", (_name, meta) => {
|
|
90
|
+
expect(routeAccepts(meta)).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it.each(headerBreaking)("the validator rejects %s", (_name, meta) => {
|
|
94
|
+
expect(validatorAccepts(meta)).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
});
|