Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
257 lines
6.8 KiB
TypeScript
257 lines
6.8 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
import { fetchViaHTTP } from 'next-test-utils'
|
|
|
|
describe('client-max-body-size', () => {
|
|
describe('default 10MB limit', () => {
|
|
const { next, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
// Deployed environment has it's own configured limits.
|
|
skipDeployment: true,
|
|
})
|
|
|
|
if (skipped) return
|
|
|
|
it('should accept request body over 10MB but only buffer up to limit', async () => {
|
|
const bodySize = 11 * 1024 * 1024 // 11MB
|
|
const body = 'x'.repeat(bodySize)
|
|
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api/echo',
|
|
{},
|
|
{
|
|
body,
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
const responseBody = await res.json()
|
|
expect(responseBody.message).toBe('Hello World')
|
|
// Should only buffer up to 10MB, not the full 11MB
|
|
expect(responseBody.bodySize).toBeLessThanOrEqual(10 * 1024 * 1024)
|
|
expect(responseBody.bodySize).toBeLessThan(bodySize)
|
|
expect(next.cliOutput).toContain(
|
|
'Request body exceeded 10MB for /api/echo'
|
|
)
|
|
})
|
|
|
|
it('should accept request body at exactly 10MB', async () => {
|
|
const bodySize = 10 * 1024 * 1024 // 10MB
|
|
const body = 'y'.repeat(bodySize)
|
|
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api/echo',
|
|
{},
|
|
{
|
|
body,
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
const responseBody = await res.json()
|
|
expect(responseBody.message).toBe('Hello World')
|
|
expect(responseBody.bodySize).toBe(bodySize)
|
|
})
|
|
|
|
it('should accept request body under 10MB', async () => {
|
|
const bodySize = 5 * 1024 * 1024 // 5MB
|
|
const body = 'z'.repeat(bodySize)
|
|
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api/echo',
|
|
{},
|
|
{
|
|
body,
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
const responseBody = await res.json()
|
|
expect(responseBody.message).toBe('Hello World')
|
|
expect(responseBody.bodySize).toBe(bodySize)
|
|
})
|
|
})
|
|
|
|
describe('custom limit with string format', () => {
|
|
const { next, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipDeployment: true,
|
|
nextConfig: {
|
|
experimental: {
|
|
proxyClientMaxBodySize: '5mb',
|
|
},
|
|
},
|
|
})
|
|
|
|
if (skipped) return
|
|
|
|
it('should accept request body over custom 5MB limit but only buffer up to limit', async () => {
|
|
const bodySize = 6 * 1024 * 1024 // 6MB
|
|
const body = 'a'.repeat(bodySize)
|
|
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api/echo',
|
|
{},
|
|
{
|
|
body,
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
const responseBody = await res.json()
|
|
expect(responseBody.message).toBe('Hello World')
|
|
// Should only buffer up to 5MB, not the full 6MB
|
|
expect(responseBody.bodySize).toBeLessThanOrEqual(5 * 1024 * 1024)
|
|
expect(responseBody.bodySize).toBeLessThan(bodySize)
|
|
expect(next.cliOutput).toContain(
|
|
'Request body exceeded 5MB for /api/echo'
|
|
)
|
|
})
|
|
|
|
it('should accept request body under custom 5MB limit', async () => {
|
|
const bodySize = 4 * 1024 * 1024 // 4MB
|
|
const body = 'b'.repeat(bodySize)
|
|
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api/echo',
|
|
{},
|
|
{
|
|
body,
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
const responseBody = await res.json()
|
|
expect(responseBody.message).toBe('Hello World')
|
|
expect(responseBody.bodySize).toBe(bodySize)
|
|
})
|
|
})
|
|
|
|
describe('custom limit with number format', () => {
|
|
const { next, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipDeployment: true,
|
|
nextConfig: {
|
|
experimental: {
|
|
proxyClientMaxBodySize: 2 * 1024 * 1024, // 2MB in bytes
|
|
},
|
|
},
|
|
})
|
|
|
|
if (skipped) return
|
|
|
|
it('should accept request body over custom 2MB limit but only buffer up to limit', async () => {
|
|
const bodySize = 3 * 1024 * 1024 // 3MB
|
|
const body = 'c'.repeat(bodySize)
|
|
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api/echo',
|
|
{},
|
|
{
|
|
body,
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
const responseBody = await res.json()
|
|
expect(responseBody.message).toBe('Hello World')
|
|
// Should only buffer up to 2MB, not the full 3MB
|
|
expect(responseBody.bodySize).toBeLessThanOrEqual(2 * 1024 * 1024)
|
|
expect(responseBody.bodySize).toBeLessThan(bodySize)
|
|
expect(next.cliOutput).toContain(
|
|
'Request body exceeded 2MB for /api/echo'
|
|
)
|
|
})
|
|
|
|
it('should accept request body under custom 2MB limit', async () => {
|
|
const bodySize = 1 * 1024 * 1024 // 1MB
|
|
const body = 'd'.repeat(bodySize)
|
|
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api/echo',
|
|
{},
|
|
{
|
|
body,
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
const responseBody = await res.json()
|
|
expect(responseBody.message).toBe('Hello World')
|
|
expect(responseBody.bodySize).toBe(bodySize)
|
|
})
|
|
})
|
|
|
|
describe('large custom limit', () => {
|
|
const { next, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipDeployment: true,
|
|
nextConfig: {
|
|
experimental: {
|
|
proxyClientMaxBodySize: '50mb',
|
|
},
|
|
},
|
|
})
|
|
|
|
if (skipped) return
|
|
|
|
it('should accept request body up to 50MB with custom limit', async () => {
|
|
const bodySize = 20 * 1024 * 1024 // 20MB
|
|
const body = 'e'.repeat(bodySize)
|
|
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api/echo',
|
|
{},
|
|
{
|
|
body,
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
const responseBody = await res.json()
|
|
expect(responseBody.message).toBe('Hello World')
|
|
expect(responseBody.bodySize).toBe(bodySize)
|
|
})
|
|
|
|
it('should accept request body over custom 50MB limit but only buffer up to limit', async () => {
|
|
const bodySize = 51 * 1024 * 1024 // 51MB
|
|
const body = 'f'.repeat(bodySize)
|
|
|
|
const res = await fetchViaHTTP(
|
|
next.url,
|
|
'/api/echo',
|
|
{},
|
|
{
|
|
body,
|
|
method: 'POST',
|
|
}
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
const responseBody = await res.json()
|
|
expect(responseBody.message).toBe('Hello World')
|
|
// Should only buffer up to 50MB, not the full 51MB
|
|
expect(responseBody.bodySize).toBeLessThanOrEqual(50 * 1024 * 1024)
|
|
expect(responseBody.bodySize).toBeLessThan(bodySize)
|
|
expect(next.cliOutput).toContain(
|
|
'Request body exceeded 50MB for /api/echo'
|
|
)
|
|
})
|
|
})
|
|
})
|