Skip to content

Commit 982e84c

Browse files
committed
fix tests
1 parent 767006b commit 982e84c

File tree

1 file changed

+12
-35
lines changed

1 file changed

+12
-35
lines changed

apps/sim/app/api/files/upload/route.test.ts

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,10 @@ describe('File Upload Security Tests', () => {
420420
}
421421
})
422422

423-
it('should reject HTML files to prevent XSS', async () => {
423+
it('should accept HTML files (supported document type)', async () => {
424424
const formData = new FormData()
425-
const maliciousContent = '<script>alert("XSS")</script>'
426-
const file = new File([maliciousContent], 'malicious.html', { type: 'text/html' })
425+
const htmlContent = '<h1>Hello World</h1>'
426+
const file = new File([htmlContent], 'document.html', { type: 'text/html' })
427427
formData.append('file', file)
428428
formData.append('context', 'workspace')
429429
formData.append('workspaceId', 'test-workspace-id')
@@ -435,35 +435,14 @@ describe('File Upload Security Tests', () => {
435435

436436
const response = await POST(req as unknown as NextRequest)
437437

438-
expect(response.status).toBe(400)
439-
const data = await response.json()
440-
expect(data.message).toContain("File type 'html' is not allowed")
441-
})
442-
443-
it('should reject HTML files to prevent XSS', async () => {
444-
const formData = new FormData()
445-
const maliciousContent = '<script>alert("XSS")</script>'
446-
const file = new File([maliciousContent], 'malicious.html', { type: 'text/html' })
447-
formData.append('file', file)
448-
formData.append('context', 'workspace')
449-
formData.append('workspaceId', 'test-workspace-id')
450-
451-
const req = new Request('http://localhost/api/files/upload', {
452-
method: 'POST',
453-
body: formData,
454-
})
455-
456-
const response = await POST(req as unknown as NextRequest)
457-
458-
expect(response.status).toBe(400)
459-
const data = await response.json()
460-
expect(data.message).toContain("File type 'html' is not allowed")
438+
expect(response.status).toBe(200)
461439
})
462440

463-
it('should reject SVG files to prevent XSS', async () => {
441+
it('should accept SVG files (supported image type)', async () => {
464442
const formData = new FormData()
465-
const maliciousSvg = '<svg onload="alert(\'XSS\')" xmlns="http://www.w3.org/2000/svg"></svg>'
466-
const file = new File([maliciousSvg], 'malicious.svg', { type: 'image/svg+xml' })
443+
const svgContent =
444+
'<svg xmlns="http://www.w3.org/2000/svg"><rect width="100" height="100"/></svg>'
445+
const file = new File([svgContent], 'image.svg', { type: 'image/svg+xml' })
467446
formData.append('file', file)
468447
formData.append('context', 'workspace')
469448
formData.append('workspaceId', 'test-workspace-id')
@@ -475,9 +454,7 @@ describe('File Upload Security Tests', () => {
475454

476455
const response = await POST(req as unknown as NextRequest)
477456

478-
expect(response.status).toBe(400)
479-
const data = await response.json()
480-
expect(data.message).toContain("File type 'svg' is not allowed")
457+
expect(response.status).toBe(200)
481458
})
482459

483460
it('should reject JavaScript files', async () => {
@@ -525,8 +502,8 @@ describe('File Upload Security Tests', () => {
525502
const validFile = new File(['valid content'], 'valid.pdf', { type: 'application/pdf' })
526503
formData.append('file', validFile)
527504

528-
const invalidFile = new File(['<script>alert("XSS")</script>'], 'malicious.html', {
529-
type: 'text/html',
505+
const invalidFile = new File(['binary content'], 'malicious.exe', {
506+
type: 'application/x-msdownload',
530507
})
531508
formData.append('file', invalidFile)
532509
formData.append('context', 'workspace')
@@ -541,7 +518,7 @@ describe('File Upload Security Tests', () => {
541518

542519
expect(response.status).toBe(400)
543520
const data = await response.json()
544-
expect(data.message).toContain("File type 'html' is not allowed")
521+
expect(data.message).toContain("File type 'exe' is not allowed")
545522
})
546523
})
547524

0 commit comments

Comments
 (0)