-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor project import functionality to support zip file uploads and enforce size limits #559
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
Open
stijnpotters1
wants to merge
9
commits into
master
Choose a base branch
from
fix/import-project-zipping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ff15fdc
efactor project import functionality to support zip file uploads and …
stijnpotters1 79dd6ab
Enforce maximum import size limit of 80 MB for project uploads and ha…
stijnpotters1 5d2f393
Refactor import size constants and buffer size for improved readabili…
stijnpotters1 0147856
Remove outdated comments in project import functionality for clarity
stijnpotters1 c623347
Add mock for arrayBuffer in file creation for improved test coverage
stijnpotters1 8e77a28
Remove outdated comment regarding maximum import zip size for clarity
stijnpotters1 f311720
rebased on master and solved merge conflicts
stijnpotters1 e2a5b0e
feat: Implemented dynamic import size config property
stijnpotters1 237f2ed
refactor: Replace async zip function with synchronous zipSync for imp…
stijnpotters1 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,56 @@ | ||
| import { DEFAULT_MAX_IMPORT_BYTES, importProjectFolder, ImportTooLargeError } from './project-service' | ||
|
|
||
| vi.mock('../utils/api', () => ({ | ||
| apiFetch: vi.fn(() => Promise.resolve({ name: 'proj', rootPath: '/tmp/proj', filepaths: [] })), | ||
| apiUrl: (path: string) => path, | ||
| })) | ||
|
|
||
| vi.mock('fflate', () => ({ | ||
| zipSync: (_entries: Record<string, Uint8Array>, _options: unknown) => new Uint8Array(8), | ||
| })) | ||
|
|
||
| function makeFile(relativePath: string, sizeOverride?: number): File { | ||
| const file = new File([new Uint8Array(4)], relativePath.split('/').pop() ?? 'file') | ||
| Object.defineProperty(file, 'webkitRelativePath', { value: relativePath }) | ||
| Object.defineProperty(file, 'arrayBuffer', { value: () => Promise.resolve(new ArrayBuffer(4)) }) | ||
| if (sizeOverride !== undefined) { | ||
| Object.defineProperty(file, 'size', { value: sizeOverride }) | ||
| } | ||
| return file | ||
| } | ||
|
|
||
| function fileList(...files: File[]): FileList { | ||
| return files as unknown as FileList | ||
| } | ||
|
|
||
| describe('importProjectFolder', () => { | ||
| afterEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it('rejects with an uncompressed ImportTooLargeError when the folder exceeds the limit', async () => { | ||
| const half = DEFAULT_MAX_IMPORT_BYTES / 2 | ||
| const files = fileList(makeFile('proj/big1.bin', half + 1), makeFile('proj/big2.bin', half + 1)) | ||
|
|
||
| const error = await importProjectFolder(files, DEFAULT_MAX_IMPORT_BYTES).catch((error_: unknown) => error_) | ||
|
|
||
| expect(error).toBeInstanceOf(ImportTooLargeError) | ||
| expect((error as ImportTooLargeError).kind).toBe('uncompressed') | ||
| expect((error as ImportTooLargeError).bytes).toBe((half + 1) * 2) | ||
| }) | ||
|
|
||
| it('ignores the top-level folder entry (empty relative path) when summing sizes', async () => { | ||
| const files = fileList(makeFile('proj', DEFAULT_MAX_IMPORT_BYTES), makeFile('proj/Configuration.xml', 10)) | ||
|
|
||
| await expect(importProjectFolder(files, DEFAULT_MAX_IMPORT_BYTES)).resolves.toMatchObject({ name: 'proj' }) | ||
| }) | ||
|
|
||
| it('uploads folders that stay within the limit', async () => { | ||
| const files = fileList( | ||
| makeFile('proj/Configuration.xml', 100), | ||
| makeFile('proj/src/main/resources/application.properties', 50), | ||
| ) | ||
|
|
||
| await expect(importProjectFolder(files, DEFAULT_MAX_IMPORT_BYTES)).resolves.toMatchObject({ name: 'proj' }) | ||
| }) | ||
| }) |
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.
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.
This could be an async function to get the reject behaviour you throw the error
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.
Oh it didnt grab the correct lines, sorry
But it is that whole function since it now just return new promise which an async function does automatically