@crvouga/mockingbird-service-s3 3.9.0 → 4.0.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog — @crvouga/mockingbird-service-s3
2
2
 
3
+ ## 4.0.0 (2026-10-28)
4
+
5
+ ### ⚠️ Breaking changes
6
+
7
+ - rebuild the S3 emulator to answer exactly as MinIO does ([ce30063](https://github.com/crvouga/mockingbird/commit/ce30063d2ef4cbdd1ef0991e836033a144261fcf))
8
+
9
+ ## 3.10.0 (2026-10-24)
10
+
11
+ ### Features
12
+
13
+ - add buffered SQL durability ([288bdcc](https://github.com/crvouga/mockingbird/commit/288bdcca84582787a54c4fdf9e803db9aac0b8d7))
14
+ - add efficient browser durability ([a8be579](https://github.com/crvouga/mockingbird/commit/a8be5799a883ddf6f731208e06f399410de4661a))
15
+
3
16
  ## 3.9.0 (2026-10-21)
4
17
 
5
18
  ### Features
package/DISCOVERY.md CHANGED
@@ -21,11 +21,11 @@ consumer-side workaround.
21
21
 
22
22
  ## Parity and oracle
23
23
 
24
- - Declared parity surface: **Objects, multipart, and presigned URLs**.
24
+ - Declared parity surface: **Every MinIO S3 API, byte-exact against recorded MinIO transcripts**.
25
25
  - Parity tier: **cold** (the repository controls when live checks run).
26
- - Oracle: **Live vendor API or sandbox**.
26
+ - Oracle: **Pinned self-hosted MinIO (RELEASE.2025-10-15T17-29-55Z) and its recorded transcripts**.
27
27
  - Repository command: `bun run parity:service -- s3`.
28
- - Evidence model: Run from a Mockingbird checkout; credentials come only from .env.local or GitHub Actions secrets. Missing credentials exit 2.
28
+ - Evidence model: bun test replays every recorded MinIO transcript against the emulator offline; the live run needs a MinIO you start (packages/service/s3/oracle/README.md) and exits 2 when it is unreachable.
29
29
 
30
30
  The npm package contains evidence summaries and the exact contract, not credentials or the
31
31
  repository-only parity harness. Self-parity/property and acceptance tests run in the Mockingbird
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Local emulators. Real API contracts. Part of [Mockingbird](https://github.com/crvouga/mockingbird).
4
4
 
5
- Stateful Amazon S3 emulator for AWS SDK v3. It preserves binary objects and the metadata applications read, supports path-style endpoints, multipart uploads, copies, ranges, pagination, presigned URLs, XML errors, namespace isolation, faults, and object notifications without contacting AWS.
5
+ Stateful S3 emulator that answers exactly as [MinIO](https://github.com/minio/minio) does, so it drops in for MinIO, Amazon S3 and other S3-compatible storage in tests. Every behavior is pinned by a differential oracle: 370 scripted scenarios (about 3,800 HTTP exchanges) were recorded against MinIO `RELEASE.2025-10-15T17-29-55Z`, and `bun test` replays each one against the emulator and requires the same status, headers and XML byte for byte.
6
6
 
7
7
  ## Install
8
8
 
@@ -40,18 +40,37 @@ console.log(await object.Body?.transformToByteArray()) // Uint8Array(2) [ 0, 255
40
40
  await server.close()
41
41
  ```
42
42
 
43
- Set an application's S3 endpoint environment variable to the server URL and its region to `us-east-1`. Supported REST operations are CreateBucket, HeadBucket, PutObject, GetObject, HeadObject, DeleteObject, DeleteObjects, CopyObject, ListObjectsV2, and multipart create/upload/complete/abort. SDK `GetObject` bodies retain its streaming helpers.
43
+ Set an application's S3 endpoint environment variable to the server URL and its region to `us-east-1`.
44
44
 
45
- ### Request semantics
45
+ ### Supported operations
46
46
 
47
- Each behavior follows the linked Amazon S3 reference.
47
+ Everything MinIO's S3 router serves, with MinIO's precedence, validation order, error codes and messages (generated from MinIO's own error table):
48
48
 
49
- - **Response header overrides** ([GetObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html)): `response-cache-control`, `response-content-disposition`, `response-content-encoding`, `response-content-language`, `response-content-type` and `response-expires` replace the stored header on a 200 or 206 GetObject and on HeadObject. Like S3, they are refused with `400 InvalidRequest` on anonymous requests.
50
- - **Copy-source preconditions** ([CopyObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html)): `x-amz-copy-source-if-match`, `-if-none-match`, `-if-modified-since` and `-if-unmodified-since` are evaluated against the source object. An unmet precondition answers `412 PreconditionFailed` and copies nothing; a true `if-match` overrides a false `if-unmodified-since`, and a matching `if-none-match` is `412` whatever `if-modified-since` says, as documented. When `if-none-match` is present, `if-modified-since` is not consulted (best guess, not oracle-verified: the reference does not state it).
51
- - **Streaming uploads** ([SigV4 streaming](https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html), [with trailers](https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming-trailers.html)): `Content-Encoding: aws-chunked` bodies (signed and `STREAMING-UNSIGNED-PAYLOAD-TRAILER`) are decoded before storing, on PutObject and UploadPart. The stored length is `x-amz-decoded-content-length`; a trailer or header `x-amz-checksum-*` that does not match, or a wrong decoded length, is rejected with `400` (`BadDigest` / `IncompleteBody`) and stores nothing. Chunk signatures are not verified.
52
- - **Body size** ([upload limits](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html)): `createServer` accepts bodies up to 5 GiB, the S3 maximum for one PUT or part, and answers larger ones with S3's `EntityTooLarge`. `createServer({ maxBodyBytes })` lowers the limit. `mockingbird-s3 serve` and fleet entries use the same 5 GiB limit (the target sets `maxBodyBytes`; other services keep the adapter's 16 MiB default).
53
- - **Virtual-hosted-style addressing** ([VirtualHosting](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html)): `Host: <bucket>.<base host>` names the bucket and the path is the key, so an SDK client without `forcePathStyle` works against `AWS_ENDPOINT_URL_S3=http://localhost:<port>`. The base hosts default to `localhost` (so `docs.localhost`); set `virtualHosts` (`--virtual-host a,b`, empty for path-style only) to change them. Path-style requests and IP or other hosts are unchanged, an unknown bucket is `NoSuchBucket`, no request ever creates a bucket as a side effect, presigned URLs are verified against the virtual host, and the admin prefix keeps its path on any host.
54
- - **Bucket CORS** ([CORS](https://docs.aws.amazon.com/AmazonS3/latest/userguide/cors.html), [PutBucketCors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketCors.html), [OPTIONS object](https://docs.aws.amazon.com/AmazonS3/latest/API/RESTOPTIONSobject.html)): the stored `CORSConfiguration` is enforced. An unauthenticated `OPTIONS` preflight (any `X-Amz-*` query is ignored) is answered by the first rule matching origin, method and requested headers with `Access-Control-Allow-Origin/-Methods/-Headers/-Max-Age/-Expose-Headers` and `Vary`; otherwise it is `403 AccessForbidden` ("CORSResponse: This CORS request is not allowed.", or "CORS is not enabled for this bucket." with no rules or after `DeleteBucketCors`) with no `Access-Control-*` headers. Actual requests with an allowed `Origin` and method get `Access-Control-Allow-Origin`, `Access-Control-Expose-Headers` and `Vary: Origin`, errors included. `PutBucketCors` rejects empty rule sets, unsupported methods and multiple wildcards. Best guess, not oracle-verified: the exact set and ordering of preflight headers beyond what the docs list (the `AccessForbidden` error code matches what S3 and s3rver return for a disabled bucket); no live AWS bucket was exercised.
49
+ - **Buckets**: CreateBucket (location constraint, object-lock flag), HeadBucket, DeleteBucket (incl. `x-minio-force-delete`), ListBuckets, GetBucketLocation, Get/PutBucketVersioning (incl. MinIO's excluded prefixes), Get/Put/DeleteBucketPolicy and GetBucketPolicyStatus, Get/Put/DeleteBucketTagging, Get/Put/DeleteBucketLifecycle, Get/Put/DeleteBucketEncryption, Get/PutBucketNotification, Get/Put/DeleteBucketReplication, Get/PutObjectLockConfiguration, the ACL, website, accelerate, request-payment and logging stubs, and MinIO's ListenNotification and replication extensions.
50
+ - **Objects**: PutObject, GetObject, HeadObject (system and user metadata, conditional reads and writes, every Range form, `partNumber`, `response-*` overrides, checksums CRC32/CRC32C/CRC64NVME/SHA1/SHA256 with `x-amz-checksum-mode`), CopyObject (metadata and tagging directives, copy-source conditionals, versions), DeleteObject and DeleteObjects (delete markers, null versions), Get/Put/DeleteObjectTagging, Get/PutObjectRetention, Get/PutObjectLegalHold, Get/PutObjectAcl, GetObjectAttributes, RestoreObject, SelectObjectContent (CSV and JSON input, basic SQL, event-stream framing), and browser POST uploads (POST policy, V4 and V2 form signatures).
51
+ - **Listing**: ListObjects V1, V2 and `metadata=true`, ListObjectVersions, including MinIO's marker and truncation behavior.
52
+ - **Multipart**: Create, UploadPart, UploadPartCopy, Complete, Abort, ListParts, ListMultipartUploads, with part checksums and the `<md5>-N` ETag.
53
+ - **Authentication**: SigV4 header and presigned, streaming `aws-chunked` (signed chunks and signed or unsigned trailers), SigV2 header and presigned, request-time skew, and anonymous access through bucket policies.
54
+
55
+ `GetObjectLambda` and `PutObjectExtract` (snowball auto-extract) answer `NotImplemented`.
56
+
57
+ ### Authentication modes
58
+
59
+ - `authentication: "lenient"` (default): unsigned requests act as the bucket owner and header signatures are not checked, so plain `fetch` works in tests. Presigned URLs are still verified against `credentials` (default `fixture` / `fixture`).
60
+ - `authentication: "strict"`: MinIO's authentication exactly. Every request must be signed by a key in `credentials`, and an anonymous request is allowed only where the bucket policy grants it. The oracle runs in this mode.
61
+
62
+ `region` (default `us-east-1`) is the signing region and the `x-amz-bucket-region` header.
63
+
64
+ ### Where it departs from MinIO
65
+
66
+ - **Bucket CORS**: MinIO only stubs the bucket CORS API, so the emulator keeps Amazon S3's documented behavior. The stored `CORSConfiguration` is enforced: a preflight is answered by the first matching rule or refused with `403 AccessForbidden`, and matching actual requests get `Access-Control-*` headers. This is not oracle-verified.
67
+ - **Virtual-hosted-style addressing**: `Host: <bucket>.<base host>` names the bucket (base hosts default to `localhost`; set `virtualHosts`, or `--virtual-host a,b`, empty for path-style only).
68
+ - **Body size**: `createServer` accepts up to 5 GiB per PUT or part (S3's limit; MinIO's is 5 TiB). `createServer({ maxBodyBytes })` lowers it.
69
+ - **Listings** always read live data, where MinIO serves later pages from a snapshot taken on the first page.
70
+
71
+ ### The oracle
72
+
73
+ `oracle/` in the repository holds the harness, the scenarios and the recorded MinIO transcripts. `bun oracle/run.ts` replays them against a live MinIO, `--record` refreshes the transcripts; see [oracle/README.md](https://github.com/crvouga/mockingbird/tree/main/packages/service/s3/oracle).
55
74
 
56
75
  ### Admin and deterministic controls
57
76
 
@@ -65,16 +84,16 @@ The shared runtime also provides health, reset, journal, metrics, timeline, and
65
84
 
66
85
  ### Deliberately not modelled
67
86
 
68
- Operations outside the surface listed above, object versioning, ACL/IAM policy evaluation, storage classes, checksums beyond ETags, production quotas, AWS dashboards and billing, and real SQS delivery are not modelled. SQS consumers can use the same captured notification payload through a configured HTTP sink.
87
+ SSE-C and SSE-KMS encryption (MinIO needs TLS and a KMS for them), IAM users and policies other than the root credentials and bucket policies, actually applying lifecycle rules or replicating, and real SQS delivery. SQS consumers can use the captured notification payload through a configured HTTP sink.
69
88
 
70
89
  ## API
71
90
 
72
91
  - `S3API`, `S3APIOptions`: Fetch handler and configuration.
73
- - `S3Notification`, `S3Object`, `S3SeedObject`: notification, state, and fixture types.
92
+ - `S3Notification`, `S3Object` (`ObjectVersion`), `S3SeedObject`, `BucketRecord`, `MultipartUpload`, `MultipartPart`: notification, state, and fixture types.
74
93
  - `createRuntime`, `S3Runtime`, `S3RuntimeOptions`: full Mockingbird runtime and webhook hub.
75
94
  - `S3_NAMESPACE`, `S3_PRESETS`, `accessKeyCredential`: constants and fault controls.
76
95
  - `S3_MAX_UPLOAD_BYTES`: the default request body limit (5 GiB) for `createServer`.
77
96
  - `document`, `operationIds`, `supportedOperationIds`: generated OpenAPI metadata.
78
97
  - `createServer`, `S3ServerOptions`, `DEFAULT_PORT`, `serveTarget` from `./server`: Node HTTP adapter and CLI integration.
79
98
 
80
- Official oracle: [Amazon S3 API Reference](https://docs.aws.amazon.com/AmazonS3/latest/API/Welcome.html) and [AWS Signature Version 4 query authentication](https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html).
99
+ Oracle: [MinIO](https://github.com/minio/minio) `RELEASE.2025-10-15T17-29-55Z`, with the [Amazon S3 API Reference](https://docs.aws.amazon.com/AmazonS3/latest/API/Welcome.html) for bucket CORS.
@@ -0,0 +1,165 @@
1
+ import {
2
+ SIGN_V4,
3
+ checkKey,
4
+ fail,
5
+ hmacRaw
6
+ } from "./chunk-Y75YGK7R.js";
7
+
8
+ // src/auth-v2.ts
9
+ var encoder = new TextEncoder();
10
+ var RESOURCES = [
11
+ "acl",
12
+ "cors",
13
+ "delete",
14
+ "encryption",
15
+ "legal-hold",
16
+ "lifecycle",
17
+ "location",
18
+ "logging",
19
+ "notification",
20
+ "partNumber",
21
+ "policy",
22
+ "requestPayment",
23
+ "response-cache-control",
24
+ "response-content-disposition",
25
+ "response-content-encoding",
26
+ "response-content-language",
27
+ "response-content-type",
28
+ "response-expires",
29
+ "retention",
30
+ "select",
31
+ "select-type",
32
+ "tagging",
33
+ "torrent",
34
+ "uploadId",
35
+ "uploads",
36
+ "versionId",
37
+ "versioning",
38
+ "versions",
39
+ "website"
40
+ ];
41
+ var base64 = (bytes) => btoa(String.fromCharCode(...bytes));
42
+ var queryUnescape = (value) => {
43
+ if (/%(?![0-9A-Fa-f]{2})/.test(value)) return void 0;
44
+ try {
45
+ return decodeURIComponent(value.replace(/\+/g, " "));
46
+ } catch {
47
+ return value.replace(/\+/g, " ").replace(
48
+ /%([0-9A-Fa-f]{2})/g,
49
+ (_, code) => String.fromCharCode(Number.parseInt(code, 16))
50
+ );
51
+ }
52
+ };
53
+ var unescapeQueries = (rawQuery) => {
54
+ const out = [];
55
+ for (const query of rawQuery.split("&")) {
56
+ const value = queryUnescape(query);
57
+ if (value === void 0) fail("InvalidQueryParams");
58
+ out.push(value);
59
+ }
60
+ return out;
61
+ };
62
+ var canonicalAmzHeaders = (headers) => {
63
+ const lines = [];
64
+ for (const [name, value] of headers) if (name.startsWith("x-amz-")) lines.push([name, value]);
65
+ return lines.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, value]) => `${name}:${value}`).join("\n");
66
+ };
67
+ var canonicalResource = (resource, query) => {
68
+ const values = /* @__PURE__ */ new Map();
69
+ for (const entry of query.split("&")) {
70
+ const index = entry.indexOf("=");
71
+ if (index < 0) values.set(entry, "");
72
+ else values.set(entry.slice(0, index), entry.slice(index + 1));
73
+ }
74
+ const parts = [];
75
+ for (const name of RESOURCES) {
76
+ const value = values.get(name);
77
+ if (value === void 0) continue;
78
+ parts.push(value === "" ? name : `${name}=${value}`);
79
+ }
80
+ return parts.length ? `${resource}?${parts.join("&")}` : resource;
81
+ };
82
+ var stringToSign = (request, query, date) => {
83
+ let amz = canonicalAmzHeaders(request.headers);
84
+ if (amz) amz += "\n";
85
+ return [
86
+ request.method,
87
+ request.headers.get("content-md5") ?? "",
88
+ request.headers.get("content-type") ?? "",
89
+ date,
90
+ amz
91
+ ].join("\n") + canonicalResource(request.rawPath, query);
92
+ };
93
+ var sign = async (secret, value) => base64(await hmacRaw("SHA-1", encoder.encode(secret), value));
94
+ var decode64 = (value) => {
95
+ if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value))
96
+ return void 0;
97
+ return atob(value);
98
+ };
99
+ var sameSignature = (a, b) => {
100
+ const left = decode64(a);
101
+ const right = decode64(b);
102
+ return left !== void 0 && right !== void 0 && left === right;
103
+ };
104
+ var requestAccessKeyV2 = (request, lookup) => {
105
+ const presigned = request.query.get("AWSAccessKeyId");
106
+ if (presigned) {
107
+ checkKey(lookup, presigned);
108
+ return presigned;
109
+ }
110
+ const fields = (request.headers.get("authorization") ?? "").split(" ");
111
+ if (fields.length !== 2) fail("MissingFields");
112
+ const keySign = fields[1].trim().split(":");
113
+ if (keySign.length !== 2) fail("MissingFields");
114
+ checkKey(lookup, keySign[0]);
115
+ return keySign[0];
116
+ };
117
+ var verifyHeaderV2 = async (request, lookup) => {
118
+ const header = request.headers.get("authorization") ?? "";
119
+ if (!header) fail("AuthHeaderEmpty");
120
+ if (!header.startsWith("AWS") || header.startsWith(SIGN_V4)) fail("SignatureVersionNotSupported");
121
+ const accessKey = requestAccessKeyV2(request, lookup);
122
+ const secret = checkKey(lookup, accessKey);
123
+ const queries = unescapeQueries(request.rawQuery);
124
+ const prefix = `AWS ${accessKey}:`;
125
+ if (!header.startsWith(prefix)) fail("SignatureDoesNotMatch");
126
+ const expected = await sign(
127
+ secret,
128
+ stringToSign(request, queries.join("&"), request.headers.get("date") ?? "")
129
+ );
130
+ if (!sameSignature(header.slice(prefix.length), expected)) fail("SignatureDoesNotMatch");
131
+ return accessKey;
132
+ };
133
+ var verifyPresignV2 = async (request, lookup, now) => {
134
+ const filtered = [];
135
+ let signature = "";
136
+ let expires = "";
137
+ let accessKey = "";
138
+ for (const query of unescapeQueries(request.rawQuery)) {
139
+ const index = query.indexOf("=");
140
+ if (index < 0) fail("InvalidQueryParams");
141
+ const name = query.slice(0, index);
142
+ const value = query.slice(index + 1);
143
+ if (name === "AWSAccessKeyId") accessKey = value;
144
+ else if (name === "Signature") signature = value;
145
+ else if (name === "Expires") expires = value;
146
+ else filtered.push(query);
147
+ }
148
+ if (!accessKey || !signature || !expires) fail("InvalidQueryParams");
149
+ const secret = checkKey(lookup, accessKey);
150
+ if (!/^[+-]?\d+$/.test(expires)) fail("MalformedExpires");
151
+ if (Number(expires) < Math.floor(now / 1e3)) fail("ExpiredPresignRequest");
152
+ const expected = await sign(secret, stringToSign(request, filtered.join("&"), expires));
153
+ if (!sameSignature(signature, expected)) fail("SignatureDoesNotMatch");
154
+ return accessKey;
155
+ };
156
+ var verifyV2 = async (request, lookup, now, presigned) => {
157
+ if (presigned) await verifyPresignV2(request, lookup, now);
158
+ else await verifyHeaderV2(request, lookup);
159
+ return requestAccessKeyV2(request, lookup);
160
+ };
161
+ export {
162
+ requestAccessKeyV2,
163
+ verifyV2
164
+ };
165
+ //# sourceMappingURL=auth-v2-YGYT7VVQ.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/auth-v2.ts"],
4
+ "sourcesContent": ["/** AWS Signature Version 2 (header and presigned), as MinIO's `cmd/signature-v2.go` checks it. */\nimport { checkKey, hmacRaw, type Lookup, SIGN_V4, type SignedRequest } from \"./auth.js\"\nimport { fail } from \"./errors.js\"\n\nconst encoder = new TextEncoder()\n\n/** The sub-resources a V2 signature covers, in MinIO's `resourceList` order. */\nconst RESOURCES = [\n \"acl\",\n \"cors\",\n \"delete\",\n \"encryption\",\n \"legal-hold\",\n \"lifecycle\",\n \"location\",\n \"logging\",\n \"notification\",\n \"partNumber\",\n \"policy\",\n \"requestPayment\",\n \"response-cache-control\",\n \"response-content-disposition\",\n \"response-content-encoding\",\n \"response-content-language\",\n \"response-content-type\",\n \"response-expires\",\n \"retention\",\n \"select\",\n \"select-type\",\n \"tagging\",\n \"torrent\",\n \"uploadId\",\n \"uploads\",\n \"versionId\",\n \"versioning\",\n \"versions\",\n \"website\",\n]\n\nconst base64 = (bytes: Uint8Array) => btoa(String.fromCharCode(...bytes))\n\n/** Go's `url.QueryUnescape`: `+` is a space, a bad `%` escape is an error (`undefined`). */\nconst queryUnescape = (value: string) => {\n if (/%(?![0-9A-Fa-f]{2})/.test(value)) return undefined\n try {\n return decodeURIComponent(value.replace(/\\+/g, \" \"))\n } catch {\n // Go keeps invalid UTF-8 bytes; decode them one by one.\n return value\n .replace(/\\+/g, \" \")\n .replace(/%([0-9A-Fa-f]{2})/g, (_, code: string) =>\n String.fromCharCode(Number.parseInt(code, 16)),\n )\n }\n}\n\nconst unescapeQueries = (rawQuery: string) => {\n const out: string[] = []\n for (const query of rawQuery.split(\"&\")) {\n const value = queryUnescape(query)\n if (value === undefined) fail(\"InvalidQueryParams\")\n out.push(value as string)\n }\n return out\n}\n\n/** `x-amz-*` headers, lowercased, sorted, multi-values joined with `,`. */\nconst canonicalAmzHeaders = (headers: Headers) => {\n const lines: [string, string][] = []\n for (const [name, value] of headers) if (name.startsWith(\"x-amz-\")) lines.push([name, value])\n return lines\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n .map(([name, value]) => `${name}:${value}`)\n .join(\"\\n\")\n}\n\nconst canonicalResource = (resource: string, query: string) => {\n const values = new Map<string, string>()\n for (const entry of query.split(\"&\")) {\n const index = entry.indexOf(\"=\")\n if (index < 0) values.set(entry, \"\")\n else values.set(entry.slice(0, index), entry.slice(index + 1))\n }\n const parts: string[] = []\n for (const name of RESOURCES) {\n const value = values.get(name)\n if (value === undefined) continue\n parts.push(value === \"\" ? name : `${name}=${value}`)\n }\n return parts.length ? `${resource}?${parts.join(\"&\")}` : resource\n}\n\nconst stringToSign = (request: SignedRequest, query: string, date: string) => {\n let amz = canonicalAmzHeaders(request.headers)\n if (amz) amz += \"\\n\"\n return (\n [\n request.method,\n request.headers.get(\"content-md5\") ?? \"\",\n request.headers.get(\"content-type\") ?? \"\",\n date,\n amz,\n ].join(\"\\n\") + canonicalResource(request.rawPath, query)\n )\n}\n\nconst sign = async (secret: string, value: string) =>\n base64(await hmacRaw(\"SHA-1\", encoder.encode(secret), value))\n\n/** Go's `base64.StdEncoding.DecodeString`, or undefined. */\nconst decode64 = (value: string) => {\n if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value))\n return undefined\n return atob(value)\n}\nconst sameSignature = (a: string, b: string) => {\n const left = decode64(a)\n const right = decode64(b)\n return left !== undefined && right !== undefined && left === right\n}\n\n/** MinIO's `getReqAccessKeyV2`: the presigned `AWSAccessKeyId`, else `AWS <key>:<signature>`. */\nexport const requestAccessKeyV2 = (request: SignedRequest, lookup: Lookup) => {\n const presigned = request.query.get(\"AWSAccessKeyId\")\n if (presigned) {\n checkKey(lookup, presigned)\n return presigned\n }\n const fields = (request.headers.get(\"authorization\") ?? \"\").split(\" \")\n if (fields.length !== 2) fail(\"MissingFields\")\n const keySign = (fields[1] as string).trim().split(\":\")\n if (keySign.length !== 2) fail(\"MissingFields\")\n checkKey(lookup, keySign[0] as string)\n return keySign[0] as string\n}\n\n/** MinIO's `doesSignV2Match`. */\nconst verifyHeaderV2 = async (request: SignedRequest, lookup: Lookup) => {\n const header = request.headers.get(\"authorization\") ?? \"\"\n if (!header) fail(\"AuthHeaderEmpty\")\n if (!header.startsWith(\"AWS\") || header.startsWith(SIGN_V4)) fail(\"SignatureVersionNotSupported\")\n const accessKey = requestAccessKeyV2(request, lookup)\n const secret = checkKey(lookup, accessKey)\n const queries = unescapeQueries(request.rawQuery)\n const prefix = `AWS ${accessKey}:`\n if (!header.startsWith(prefix)) fail(\"SignatureDoesNotMatch\")\n const expected = await sign(\n secret,\n stringToSign(request, queries.join(\"&\"), request.headers.get(\"date\") ?? \"\"),\n )\n if (!sameSignature(header.slice(prefix.length), expected)) fail(\"SignatureDoesNotMatch\")\n return accessKey\n}\n\n/** MinIO's `doesPresignV2SignatureMatch`. */\nconst verifyPresignV2 = async (request: SignedRequest, lookup: Lookup, now: number) => {\n const filtered: string[] = []\n let signature = \"\"\n let expires = \"\"\n let accessKey = \"\"\n for (const query of unescapeQueries(request.rawQuery)) {\n const index = query.indexOf(\"=\")\n if (index < 0) fail(\"InvalidQueryParams\")\n const name = query.slice(0, index)\n const value = query.slice(index + 1)\n if (name === \"AWSAccessKeyId\") accessKey = value\n else if (name === \"Signature\") signature = value\n else if (name === \"Expires\") expires = value\n else filtered.push(query)\n }\n if (!accessKey || !signature || !expires) fail(\"InvalidQueryParams\")\n const secret = checkKey(lookup, accessKey)\n if (!/^[+-]?\\d+$/.test(expires)) fail(\"MalformedExpires\")\n if (Number(expires) < Math.floor(now / 1000)) fail(\"ExpiredPresignRequest\")\n const expected = await sign(secret, stringToSign(request, filtered.join(\"&\"), expires))\n if (!sameSignature(signature, expected)) fail(\"SignatureDoesNotMatch\")\n return accessKey\n}\n\n/** MinIO's `isReqAuthenticatedV2` then `getReqAccessKeyV2`: the verified access key. */\nexport const verifyV2 = async (\n request: SignedRequest,\n lookup: Lookup,\n now: number,\n presigned: boolean,\n): Promise<string> => {\n if (presigned) await verifyPresignV2(request, lookup, now)\n else await verifyHeaderV2(request, lookup)\n return requestAccessKeyV2(request, lookup)\n}\n"],
5
+ "mappings": ";;;;;;;;AAIA,IAAM,UAAU,IAAI,YAAY;AAGhC,IAAM,YAAY;AAAA,EAChB;AAAA,E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