-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Limit the upload size of an attachment in the attachment plugin. Currently the maximum size size of data that can be scanned by the Malware Scanning Service on BTP is 400MB. So we would limit the file upload size to 400 MB. 1. Handling PUT request with 'before' handler to fetch the content length of the uploaded attachment in plugin.js. 2. Impose validation checks for size limit and rejecting the request which are above size limit. 3. Currently cannot access the UI part but validation checks are both imposed for hybrid and local mode. --------- Co-authored-by: jeevitha011 <118245189+jeevitha011@users.noreply.github.com>
- Loading branch information
1 parent
d014729
commit 376a8c0
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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,35 @@ | ||
const { validateAttachmentSize } = require('../../lib/plugin'); | ||
|
||
describe('validateAttachmentSize', () => { | ||
let req; // Define a mock request object | ||
|
||
beforeEach(() => { | ||
req = { | ||
headers: {}, | ||
reject: jest.fn(), // Mocking the reject function | ||
}; | ||
}); | ||
|
||
it('should pass validation for a file size under 400 MB', () => { | ||
req.headers['content-length'] = '51200765'; | ||
|
||
validateAttachmentSize(req); | ||
|
||
expect(req.reject).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should reject for a file size over 400 MB', () => { | ||
req.headers['content-length'] = '20480000000'; | ||
|
||
validateAttachmentSize(req); | ||
|
||
expect(req.reject).toHaveBeenCalledWith(403, 'File Size limit exceeded beyond 400 MB.'); | ||
}); | ||
|
||
it('should reject when content-length header is missing', () => { | ||
validateAttachmentSize(req); | ||
|
||
expect(req.reject).toHaveBeenCalledWith(403, 'Invalid Content Size'); | ||
}); | ||
}); | ||
|