Skip to content
Merged
7 changes: 7 additions & 0 deletions apps/sim/app/api/tools/supabase/storage-upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
'Content-Type': uploadContentType,
}

if (validatedData.cacheControl) {
const cacheControl = validatedData.cacheControl.trim()
headers['cache-control'] = /^\d+$/.test(cacheControl)
? `max-age=${cacheControl}`
: cacheControl
}
Comment thread
waleedlatif1 marked this conversation as resolved.

if (validatedData.upsert) {
headers['x-upsert'] = 'true'
}
Expand Down
60 changes: 60 additions & 0 deletions apps/sim/blocks/blocks/supabase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @vitest-environment node
*/
import { describe, expect, it } from 'vitest'
import { SupabaseBlock } from '@/blocks/blocks/supabase'

describe('SupabaseBlock', () => {
const buildParams = SupabaseBlock.tools.config.params!
const selectTool = SupabaseBlock.tools.config.tool!

it('maps each operation to its tool id', () => {
expect(selectTool({ operation: 'query' })).toBe('supabase_query')
expect(selectTool({ operation: 'invoke_function' })).toBe('supabase_invoke_function')
expect(selectTool({ operation: 'delete' })).toBe('supabase_delete')
})

it('does not leak the Edge Function method onto other operations', () => {
// A stale `method` from the Edge Function field must never reach a tool with a
// static verb — otherwise the executor would let it override e.g. GET with DELETE.
const params = buildParams({
operation: 'query',
projectId: 'proj',
apiKey: 'key',
table: 'users',
method: 'DELETE',
})

expect(params).not.toHaveProperty('method')
expect(params).not.toHaveProperty('body')
expect(params).not.toHaveProperty('headers')
})

it('passes method, body, and headers through for invoke_function', () => {
const params = buildParams({
operation: 'invoke_function',
projectId: 'proj',
apiKey: 'key',
functionName: 'hello-world',
method: 'POST',
functionBody: '{"name":"world"}',
functionHeaders: '{"x-trace":"1"}',
})

expect(params.method).toBe('POST')
expect(params.body).toEqual({ name: 'world' })
expect(params.headers).toEqual({ 'x-trace': '1' })
})

it('rejects non-object Edge Function headers', () => {
expect(() =>
buildParams({
operation: 'invoke_function',
projectId: 'proj',
apiKey: 'key',
functionName: 'hello-world',
functionHeaders: '["a","b"]',
})
).toThrow('Edge Function headers must be a JSON object')
})
})
Loading
Loading