-
Notifications
You must be signed in to change notification settings - Fork 329
fix(api): accept presigned s3Key for MCP uploads (attachment/document/evidence) #3042
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
a7ffbb7
fix(api): accept presigned s3Key for MCP uploads (attachment/document…
tofikwest 4e167b0
fix(api): guard presigned-upload reads against oversized files
tofikwest f076789
fix(api): cap inline upload base64 at the true 100MB limit (UI-safe)
tofikwest 8d1f757
Merge branch 'main' into fix/mcp-uploads-presigned-s3key
tofikwest 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { BadRequestException } from '@nestjs/common'; | ||
|
|
||
| // Mocks must be declared before importing the service under test. | ||
| jest.mock('@/app/s3', () => ({ | ||
| s3Client: { send: jest.fn().mockResolvedValue({}) }, | ||
| getSignedUrl: jest.fn().mockResolvedValue('https://signed.example/file'), | ||
| })); | ||
|
|
||
| jest.mock('@db', () => ({ | ||
| db: { attachment: { create: jest.fn() } }, | ||
| AttachmentType: { | ||
| image: 'image', | ||
| video: 'video', | ||
| audio: 'audio', | ||
| document: 'document', | ||
| other: 'other', | ||
| }, | ||
| AttachmentEntityType: { task: 'task', offboarding_checklist: 'offboarding_checklist' }, | ||
| })); | ||
|
|
||
| jest.mock('../utils/file-type-validation', () => ({ | ||
| validateFileContent: jest.fn(), | ||
| })); | ||
|
|
||
| import { db } from '@db'; | ||
| import { AttachmentsService } from './attachments.service'; | ||
|
|
||
| const mockUploadsService = { readUploadAsBase64: jest.fn() }; | ||
|
|
||
| describe('AttachmentsService — presigned s3Key uploads', () => { | ||
| let service: AttachmentsService; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| process.env.APP_AWS_BUCKET_NAME = 'test-bucket'; | ||
| service = new AttachmentsService(mockUploadsService as never); | ||
| }); | ||
|
|
||
| it('resolves the file from s3Key (presigned) — no base64 through the LLM — and uploads it', async () => { | ||
| mockUploadsService.readUploadAsBase64.mockResolvedValue( | ||
| Buffer.from('hello world').toString('base64'), | ||
| ); | ||
| (db.attachment.create as jest.Mock).mockResolvedValue({ | ||
| id: 'att_1', | ||
| name: 'rbac.pdf', | ||
| type: 'document', | ||
| url: 'org_1/attachments/task/tsk_1/key', | ||
| createdAt: new Date(), | ||
| }); | ||
|
|
||
| const result = await service.uploadAttachment( | ||
| 'org_1', | ||
| 'tsk_1', | ||
| 'task' as never, | ||
| { | ||
| fileName: 'rbac.pdf', | ||
| fileType: 'application/pdf', | ||
| s3Key: 'org_1/uploads/attachment/123-rbac.pdf', | ||
| } as never, | ||
| 'usr_1', | ||
| ); | ||
|
|
||
| // Fetched the bytes from the org-scoped presigned key instead of base64. | ||
| expect(mockUploadsService.readUploadAsBase64).toHaveBeenCalledWith( | ||
| 'org_1', | ||
| 'org_1/uploads/attachment/123-rbac.pdf', | ||
| ); | ||
| expect(db.attachment.create).toHaveBeenCalled(); | ||
| expect(result.id).toBe('att_1'); | ||
| }); | ||
|
|
||
| it('throws when neither fileData nor s3Key is provided', async () => { | ||
| await expect( | ||
| service.uploadAttachment( | ||
| 'org_1', | ||
| 'tsk_1', | ||
| 'task' as never, | ||
| { fileName: 'rbac.pdf', fileType: 'application/pdf' } as never, | ||
| 'usr_1', | ||
| ), | ||
| ).rejects.toBeInstanceOf(BadRequestException); | ||
|
|
||
| expect(mockUploadsService.readUploadAsBase64).not.toHaveBeenCalled(); | ||
| expect(db.attachment.create).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Missing pre-decode base64 length cap allows oversized payloads to allocate memory before file-size validation.
(Based on your team's feedback about base64 upload length limits for 100MB policy.) .
View Feedback
Prompt for AI agents