-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(uploads): allow images/video/audio in mothership presigned route #4534
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c508a0d
fix(uploads): allow image/video/audio attachments in mothership presi…
waleedlatif1 c44177b
fix(uploads): allow non-document execution outputs in presigned route
waleedlatif1 93b1565
test(uploads): add coverage for attachment validator and dedupe exten…
waleedlatif1 a70f6f2
fix(uploads): restore SUPPORTED_IMAGE_EXTENSIONS import in upload route
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { | ||
| SUPPORTED_ATTACHMENT_EXTENSIONS, | ||
| validateAttachmentFileType, | ||
| } from '@/lib/uploads/utils/validation' | ||
|
|
||
| describe('validateAttachmentFileType', () => { | ||
| it('accepts image files (png, jpg, gif, webp, svg)', () => { | ||
| expect(validateAttachmentFileType('screenshot.png')).toBeNull() | ||
| expect(validateAttachmentFileType('photo.jpg')).toBeNull() | ||
| expect(validateAttachmentFileType('photo.JPEG')).toBeNull() | ||
| expect(validateAttachmentFileType('animation.gif')).toBeNull() | ||
| expect(validateAttachmentFileType('image.webp')).toBeNull() | ||
| expect(validateAttachmentFileType('icon.svg')).toBeNull() | ||
| }) | ||
|
|
||
| it('accepts video files (mp4, mov, webm)', () => { | ||
| expect(validateAttachmentFileType('clip.mp4')).toBeNull() | ||
| expect(validateAttachmentFileType('clip.mov')).toBeNull() | ||
| expect(validateAttachmentFileType('clip.webm')).toBeNull() | ||
| }) | ||
|
|
||
| it('accepts audio files (mp3, wav, m4a)', () => { | ||
| expect(validateAttachmentFileType('voice.mp3')).toBeNull() | ||
| expect(validateAttachmentFileType('voice.wav')).toBeNull() | ||
| expect(validateAttachmentFileType('voice.m4a')).toBeNull() | ||
| }) | ||
|
|
||
| it('accepts document files (pdf, docx, csv, md)', () => { | ||
| expect(validateAttachmentFileType('report.pdf')).toBeNull() | ||
| expect(validateAttachmentFileType('letter.docx')).toBeNull() | ||
| expect(validateAttachmentFileType('data.csv')).toBeNull() | ||
| expect(validateAttachmentFileType('notes.md')).toBeNull() | ||
| }) | ||
|
|
||
| it('accepts code files (ts, py, sh, json)', () => { | ||
| expect(validateAttachmentFileType('app.ts')).toBeNull() | ||
| expect(validateAttachmentFileType('main.py')).toBeNull() | ||
| expect(validateAttachmentFileType('script.sh')).toBeNull() | ||
| expect(validateAttachmentFileType('config.json')).toBeNull() | ||
| }) | ||
|
|
||
| it('rejects executables and unknown extensions', () => { | ||
| expect(validateAttachmentFileType('virus.exe')?.code).toBe('UNSUPPORTED_FILE_TYPE') | ||
| expect(validateAttachmentFileType('installer.msi')?.code).toBe('UNSUPPORTED_FILE_TYPE') | ||
| expect(validateAttachmentFileType('archive.dmg')?.code).toBe('UNSUPPORTED_FILE_TYPE') | ||
| expect(validateAttachmentFileType('binary.bin')?.code).toBe('UNSUPPORTED_FILE_TYPE') | ||
| }) | ||
|
|
||
| it('rejects files with no extension', () => { | ||
| const result = validateAttachmentFileType('README') | ||
| expect(result?.code).toBe('UNSUPPORTED_FILE_TYPE') | ||
| expect(result?.message).toContain('README') | ||
| }) | ||
|
|
||
| it('rejects files with non-alphanumeric extensions', () => { | ||
| expect(validateAttachmentFileType('odd.<>')?.code).toBe('UNSUPPORTED_FILE_TYPE') | ||
| expect(validateAttachmentFileType('foo. ')?.code).toBe('UNSUPPORTED_FILE_TYPE') | ||
| }) | ||
|
|
||
| it('does not contain duplicate extensions (e.g. webm)', () => { | ||
| const seen = new Set<string>() | ||
| for (const ext of SUPPORTED_ATTACHMENT_EXTENSIONS) { | ||
| expect(seen.has(ext)).toBe(false) | ||
| seen.add(ext) | ||
| } | ||
| }) | ||
|
|
||
| it('returns supportedTypes list in error', () => { | ||
| const result = validateAttachmentFileType('foo.exe') | ||
| expect(result?.supportedTypes).toEqual(expect.arrayContaining(['png', 'pdf', 'mp4', 'mp3'])) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.