Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

share collections in middleware vm context #31043

Merged
merged 8 commits into from Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/next/server/web/sandbox/sandbox.ts
Expand Up @@ -87,6 +87,30 @@ export async function run(params: {
TransformStream,
URL,
URLSearchParams,

// Indexed collections
Array,
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array,
BigInt64Array,
BigUint64Array,

// Keyed collections
Map,
Set,
WeakMap,
WeakSet,

// Structured data
ArrayBuffer,
SharedArrayBuffer,
}

context.self = context
Expand Down
Expand Up @@ -2,7 +2,7 @@

import { NextResponse } from 'next/server'

export function middleware(request) {
export async function middleware(request) {
const url = request.nextUrl

if (url.pathname.endsWith('/globalthis')) {
Expand All @@ -13,6 +13,28 @@ export function middleware(request) {
})
}

if (url.pathname.endsWith('/webcrypto')) {
const response = {}
try {
const algorithm = {
name: 'RSA-PSS',
hash: 'SHA-256',
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
modulusLength: 2048,
}
const keyUsages = ['sign', 'verify']
await crypto.subtle.generateKey(algorithm, false, keyUsages)
} catch (err) {
response.error = true
} finally {
return new NextResponse(JSON.stringify(response), {
headers: {
'content-type': 'application/json; charset=utf-8',
},
})
}
}

return new Response(null, {
headers: {
'req-url-basepath': request.nextUrl.basePath,
Expand Down
6 changes: 6 additions & 0 deletions test/integration/middleware/core/test/index.test.js
Expand Up @@ -350,6 +350,12 @@ function interfaceTests(locale = '') {
expect(globals.length > 0).toBe(true)
})

it(`${locale} collection constructors are shared`, async () => {
const res = await fetchViaHTTP(context.appPort, '/interface/webcrypto')
const response = await res.json()
expect('error' in response).toBe(false)
})

it(`${locale} should validate request url parameters from a static route`, async () => {
const res = await fetchViaHTTP(
context.appPort,
Expand Down