Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions apps/sim/app/api/v2/files/[fileId]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,6 @@ describe('v2 single-file routes', () => {
expect(response.headers.get('X-Content-Type-Options')).toBe('nosniff')
})

it('downloads a file named by its files/ VFS path', async () => {
const vfsPath = 'files/Docs/data.csv'
const response = await GET(
new NextRequest(
`http://localhost:3000/api/v2/files/${encodeURIComponent(vfsPath)}?workspaceId=${WORKSPACE_ID}`
),
{ params: Promise.resolve({ fileId: vfsPath }) }
)

expect(response.status).toBe(200)
expect(mocks.download).toHaveBeenCalledWith(
expect.objectContaining({
input: { fileId: vfsPath, acceptVfsPath: true, assertedWorkspaceId: WORKSPACE_ID },
})
)
})

it('conceals cross-workspace download authorization', async () => {
mocks.download.mockRejectedValue(new NoWorkspaceAccessError())

Expand Down
33 changes: 31 additions & 2 deletions apps/sim/scripts/test-file-delivery-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ async function create(
owner: 'workspace' | 'project',
name: string,
contentType: string,
content: string
content: string,
folderId?: string
) {
const response = await request(
`/api/${owner === 'workspace' ? `workspaces/${workspaceId}` : `projects/${projectId}`}/files`,
{ method: 'POST', body: JSON.stringify({ name, contentType, content, encoding: 'utf-8' }) }
{
method: 'POST',
body: JSON.stringify({ name, contentType, content, encoding: 'utf-8', folderId }),
}
)
assert.ok(response.ok, `Create returned ${response.status}: ${await response.clone().text()}`)
return toRecord(toRecord(await response.json()).file)
Expand Down Expand Up @@ -204,6 +208,31 @@ await check(
}
}
)
await check('v2 workspace download routes a %2F-encoded files/ VFS path to its file', async () => {
const folderResponse = await request(`/api/workspaces/${workspaceId}/files/folders`, {
method: 'POST',
body: JSON.stringify({ name: 'VfsDocs' }),
})
assert.ok(folderResponse.ok, `Folder create returned ${folderResponse.status}`)
const folderId = required(toRecord(toRecord(await folderResponse.json()).folder).id)
await create('workspace', 'vfs-report.csv', 'text/csv', 'root copy')
await create('workspace', 'vfs-report.csv', 'text/csv', 'folder copy', folderId)
const download = (path: string) =>
request(
`/api/v2/files/${encodeURIComponent(path)}?workspaceId=${workspaceId}`,
{ headers: { 'X-API-Key': personalKey } },
true
)
for (const [path, content] of [
['files/VfsDocs/vfs-report.csv', 'folder copy'],
['files/vfs-report.csv', 'root copy'],
]) {
const response = await download(path)
assert.equal(response.status, 200, `${path} returned ${response.status}`)
assert.equal(await response.text(), content)
}
assert.equal((await download('files/VfsDocs/missing.csv')).status, 404)
})
await check('Workspace immutable URLs, authorized 304 and browser cache reuse', async () => {
const file = await create('workspace', 'cache.txt', 'text/plain', 'workspace cache bytes')
const path = `/api/files/serve/${required(file.key)}`
Expand Down
Loading