turn off image signing to save CPU

This commit is contained in:
Devin Zuczek
2026-08-07 15:10:09 -04:00
parent 7bbbac6dc9
commit 4e578f7771
6 changed files with 66 additions and 9 deletions
+21 -2
View File
@@ -1,8 +1,8 @@
import { PhotonImage } from '@cf-wasm/photon'
import { env, SELF } from 'cloudflare:test'
import { createExecutionContext, env, SELF, waitOnExecutionContext } from 'cloudflare:test'
import { beforeAll, describe, expect, it } from 'vitest'
import '../../img.app'
import app from '../../img.app'
import type { Env } from '../../context'
@@ -188,6 +188,25 @@ describe('img endpoints', () => {
expect(res.headers.get('content-signature')).toBeNull()
})
it('ignores ?sig=p1 when IMG_SIGNING_ENABLED is off', async () => {
// The deployed default (see wrangler.jsonc): the param is accepted but does
// nothing, so the object streams straight from R2 instead of being buffered,
// hashed and RSA-signed. Vitest binds the flag ON, so override it here.
const ctx = createExecutionContext()
const res = await app.fetch(
new Request(`${ORIGIN}/${R2_KEY}?sig=p1`),
{ ...env, IMG_SIGNING_ENABLED: false },
ctx
)
await waitOnExecutionContext(ctx)
expect(res.status).toBe(200)
expect(res.headers.get('content-signature')).toBeNull()
// Unsigned responses keep the source etag, and the body is untouched.
expect(res.headers.get('etag')).toBeTruthy()
expect(new Uint8Array(await res.arrayBuffer())).toEqual(IMAGE_BYTES)
})
it('resizes a static asset to ?width, preserving aspect ratio', async () => {
const full = new Uint8Array(await (await SELF.fetch(`${ORIGIN}/RecCenter.jpg`)).arrayBuffer())
const original = jpegSize(full)