Skip to content

Commit

Permalink
fix(functions): stop providing clientContext to background functions (#…
Browse files Browse the repository at this point in the history
…4395)

* fix(functions): stop providing clientContext to background functions

* test: add test

Co-authored-by: Erez Rokah <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 2, 2022
1 parent 4e74045 commit e14feb2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/functions/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ const createHandler = function (options) {
if (func.isBackground) {
handleBackgroundFunction(functionName, response)

const { error } = await func.invoke(event, clientContext)
// background functions do not receive a clientContext
const { error } = await func.invoke(event)

handleBackgroundFunctionResult(functionName, error)
} else if (await func.isScheduled()) {
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/100.command.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,29 @@ testMatrix.forEach(({ args }) => {
})
})

test(testName('background function clientContext,identity should be null', args), async (t) => {
await withSiteBuilder('site-with-background-function', async (builder) => {
await builder
.withNetlifyToml({ config: { functions: { directory: 'functions' } } })
.withFunction({
path: 'hello-background.js',
handler: (_, context) => {
console.log(`__CLIENT_CONTEXT__START__${JSON.stringify(context)}__CLIENT_CONTEXT__END__`)
},
})
.buildAsync()

await withDevServer({ cwd: builder.directory, args }, async ({ outputBuffer, url }) => {
await got(`${url}/.netlify/functions/hello-background`)

const output = outputBuffer.toString()
const context = JSON.parse(output.match(/__CLIENT_CONTEXT__START__(.*)__CLIENT_CONTEXT__END__/)[1])
t.is(context.clientContext, null)
t.is(context.identity, null)
})
})
})

test(testName('should enforce role based redirects with default secret and role path', args), async (t) => {
await withSiteBuilder('site-with-default-role-based-redirects', async (builder) => {
setupRoleBasedRedirectsSite(builder)
Expand Down

1 comment on commit e14feb2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 443 MB

Please sign in to comment.