From 315b520c3ca6f64fb3cb42f893c745951afab79f Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 6 Aug 2025 22:17:14 +0000 Subject: [PATCH] [autofix.ci] apply automated fixes --- test/js/bun/s3/s3.test.ts | 71 ++++++++++--------- .../issue/s3-content-length.test.ts | 12 ++-- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/test/js/bun/s3/s3.test.ts b/test/js/bun/s3/s3.test.ts index c496758bce..4782909c4d 100644 --- a/test/js/bun/s3/s3.test.ts +++ b/test/js/bun/s3/s3.test.ts @@ -180,7 +180,7 @@ describe.skipIf(!r2Credentials.endpoint && !isCI)("Virtual Hosted-Style", () => { const client = new Bun.S3Client({ - bucket: "bucket", + bucket: "bucket", accessKeyId: "test", secretAccessKey: "test", region: "us-east-1", @@ -459,16 +459,16 @@ for (let credentials of allCredentials) { const testContent = "Test data for S3Client"; const contentLength = testContent.length; const uploadFilename = bucketInName ? `${S3Bucket}/${randomUUID()}-s3client` : `${randomUUID()}-s3client`; - + { const presignedUrl = bucket.presign(uploadFilename, { method: "PUT", expiresIn: 3600, contentLength: contentLength, }); - + expect(presignedUrl.includes(`Content-Length=${contentLength}`)).toBe(true); - + const response = await fetch(presignedUrl, { method: "PUT", body: testContent, @@ -476,23 +476,23 @@ for (let credentials of allCredentials) { "Content-Type": "text/plain", }, }); - + expect(response.status).toBe(200); - + const file = bucket.file(uploadFilename, options); const downloaded = await file.text(); expect(downloaded).toBe(testContent); - + await file.unlink(); } - + { const presignedUrl = bucket.presign(uploadFilename + "-less", { - method: "PUT", + method: "PUT", expiresIn: 3600, contentLength: contentLength, }); - + const shortContent = "Short"; const response = await fetch(presignedUrl, { method: "PUT", @@ -501,18 +501,19 @@ for (let credentials of allCredentials) { "Content-Type": "text/plain", }, }); - + expect([400, 403]).toContain(response.status); } - + { const presignedUrl = bucket.presign(uploadFilename + "-more", { method: "PUT", expiresIn: 3600, contentLength: contentLength, }); - - const longContent = "This content is definitely much longer than the expected 23 bytes and should cause a failure"; + + const longContent = + "This content is definitely much longer than the expected 23 bytes and should cause a failure"; const response = await fetch(presignedUrl, { method: "PUT", body: longContent, @@ -520,7 +521,7 @@ for (let credentials of allCredentials) { "Content-Type": "text/plain", }, }); - + expect([400, 403]).toContain(response.status); } }); @@ -800,7 +801,7 @@ for (let credentials of allCredentials) { const testContent = "Hello, Bun!"; const contentLength = testContent.length; const uploadFilename = tmp_filename + "-contentlength-test"; - + { const s3file = s3(uploadFilename, options); const presignedUrl = s3file.presign({ @@ -808,9 +809,9 @@ for (let credentials of allCredentials) { expiresIn: 3600, contentLength: contentLength, }); - + expect(presignedUrl.includes(`Content-Length=${contentLength}`)).toBe(true); - + const response = await fetch(presignedUrl, { method: "PUT", body: testContent, @@ -818,23 +819,23 @@ for (let credentials of allCredentials) { "Content-Type": "text/plain", }, }); - + expect(response.status).toBe(200); - + const downloaded = await s3file.text(); expect(downloaded).toBe(testContent); - + await s3file.unlink(); } - + { const s3file = s3(uploadFilename + "-less", options); const presignedUrl = s3file.presign({ - method: "PUT", + method: "PUT", expiresIn: 3600, contentLength: contentLength, }); - + const shortContent = "Short"; const response = await fetch(presignedUrl, { method: "PUT", @@ -843,10 +844,10 @@ for (let credentials of allCredentials) { "Content-Type": "text/plain", }, }); - + expect([400, 403]).toContain(response.status); } - + { const s3file = s3(uploadFilename + "-more", options); const presignedUrl = s3file.presign({ @@ -854,7 +855,7 @@ for (let credentials of allCredentials) { expiresIn: 3600, contentLength: contentLength, }); - + const longContent = "This is a much longer content than expected"; const response = await fetch(presignedUrl, { method: "PUT", @@ -863,24 +864,24 @@ for (let credentials of allCredentials) { "Content-Type": "text/plain", }, }); - + expect([400, 403]).toContain(response.status); } }); it("should work with ContentLength (AWS SDK style) restrictions", async () => { - const testData = Buffer.alloc(100, 'x'); + const testData = Buffer.alloc(100, "x"); const uploadFilename = tmp_filename + "-aws-style"; - + const s3file = s3(uploadFilename, options); const presignedUrl = s3file.presign({ method: "PUT", expiresIn: 3600, ContentLength: 100, }); - + expect(presignedUrl.includes("Content-Length=100")).toBe(true); - + const response = await fetch(presignedUrl, { method: "PUT", body: testData, @@ -888,12 +889,12 @@ for (let credentials of allCredentials) { "Content-Type": "application/octet-stream", }, }); - + expect(response.status).toBe(200); - + const stat = await s3file.stat(); expect(stat.size).toBe(100); - + await s3file.unlink(); }); diff --git a/test/regression/issue/s3-content-length.test.ts b/test/regression/issue/s3-content-length.test.ts index 5ead1b82eb..db45df7baa 100644 --- a/test/regression/issue/s3-content-length.test.ts +++ b/test/regression/issue/s3-content-length.test.ts @@ -25,7 +25,7 @@ describe("S3 contentLength option in presign (Issue #18240)", () => { it("should support ContentLength option (AWS SDK style)", () => { const url = s3Client.presign("test/abc", { expiresIn: 3600, - method: "PUT", + method: "PUT", ContentLength: 200, }); @@ -69,16 +69,16 @@ describe("S3 contentLength option in presign (Issue #18240)", () => { it("should match the exact use case from issue #18240", () => { // This is the exact code snippet from the GitHub issue - const url = s3Client.presign('test/abc', { + const url = s3Client.presign("test/abc", { expiresIn: 3600, // 1 hour - method: 'PUT', - ContentLength: 200 + method: "PUT", + ContentLength: 200, }); expect(url).toBeDefined(); expect(typeof url).toBe("string"); expect(url.includes("Content-Length=200")).toBe(true); - + // Verify other required AWS S3 signature components are present expect(url.includes("X-Amz-Expires=3600")).toBe(true); expect(url.includes("X-Amz-Algorithm=AWS4-HMAC-SHA256")).toBe(true); @@ -87,4 +87,4 @@ describe("S3 contentLength option in presign (Issue #18240)", () => { expect(url.includes("X-Amz-SignedHeaders")).toBe(true); expect(url.includes("X-Amz-Signature")).toBe(true); }); -}); \ No newline at end of file +});