-
Notifications
You must be signed in to change notification settings - Fork 13
[_]: fix/etag-management #638
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
larryrider
wants to merge
5
commits into
main
Choose a base branch
from
feat/fix-etag-management
base: main
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
5 commits
Select commit
Hold shift + click to select a range
9ec4cc6
feat: implement ETag generation for WebDAV items and update PROPFIND …
larryrider 052dd2b
feat: add ETag header to GET handler and fix tests
larryrider 928e658
feat: add ETag header to HEAD response and update tests
larryrider 988369f
feat: add ETag header to PUT response and update tests
larryrider 1bcb7bc
fix: ETag generation tests to use toBe matcher
larryrider 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
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 |
|---|---|---|
|
|
@@ -166,6 +166,82 @@ describe('Webdav utils', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('generateETag', () => { | ||
| test('when the same parts are given, then the same etag is generated', () => { | ||
| const date = new Date('2024-03-04T15:11:01.000Z'); | ||
| const etag1 = WebDavUtils.generateETag(['uuid-1', 100, date]); | ||
| const etag2 = WebDavUtils.generateETag(['uuid-1', 100, date]); | ||
|
|
||
| expect(etag1).to.be.equal(etag2); | ||
| }); | ||
|
|
||
| test('when the parts are wrapped in quotes, then a quoted etag is returned', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldnt this test be better described as: |
||
| const etag = WebDavUtils.generateETag(['uuid-1']); | ||
|
|
||
| expect(etag.startsWith('"')).toBe(true); | ||
| expect(etag.endsWith('"')).toBe(true); | ||
| }); | ||
|
|
||
| test('when any part differs, then a different etag is generated', () => { | ||
| const date = new Date('2024-03-04T15:11:01.000Z'); | ||
| const baseEtag = WebDavUtils.generateETag(['uuid-1', 100, date]); | ||
|
|
||
| expect(WebDavUtils.generateETag(['uuid-2', 100, date])).to.not.be.equal(baseEtag); | ||
| expect(WebDavUtils.generateETag(['uuid-1', 200, date])).to.not.be.equal(baseEtag); | ||
| expect(WebDavUtils.generateETag(['uuid-1', 100, new Date('2024-03-04T15:11:02.000Z')])).to.not.be.equal(baseEtag); | ||
| }); | ||
|
|
||
| test('when a Date is given, then it is normalized using its timestamp', () => { | ||
| const date = new Date('2024-03-04T15:11:01.000Z'); | ||
| const etagFromDate = WebDavUtils.generateETag(['uuid-1', date]); | ||
| const etagFromTimestamp = WebDavUtils.generateETag(['uuid-1', date.getTime()]); | ||
|
|
||
| expect(etagFromDate).to.be.equal(etagFromTimestamp); | ||
| }); | ||
|
|
||
| test('when null or undefined parts are given, then they are treated as equal empty values', () => { | ||
| const etagFromNull = WebDavUtils.generateETag(['uuid-1', null]); | ||
| const etagFromUndefined = WebDavUtils.generateETag(['uuid-1', undefined]); | ||
|
|
||
| expect(etagFromNull).to.be.equal(etagFromUndefined); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getItemETag', () => { | ||
| test('when the same file is given, then the same etag is generated', () => { | ||
| const fileItem = newFileItem(); | ||
|
|
||
| expect(WebDavUtils.getItemETag(fileItem)).to.be.equal(WebDavUtils.getItemETag(fileItem)); | ||
| }); | ||
|
|
||
| test('when a file changes size, then the etag changes', () => { | ||
| const fileItem = newFileItem({ size: 100 }); | ||
| const resizedFileItem = { ...fileItem, size: 200 }; | ||
|
|
||
| expect(WebDavUtils.getItemETag(resizedFileItem)).to.not.be.equal(WebDavUtils.getItemETag(fileItem)); | ||
| }); | ||
|
|
||
| test('when a file changes modificationTime, then the etag changes', () => { | ||
| const fileItem = newFileItem({ modificationTime: new Date('2024-01-01T00:00:00.000Z') }); | ||
| const touchedFileItem = { ...fileItem, modificationTime: new Date('2024-02-02T00:00:00.000Z') }; | ||
|
|
||
| expect(WebDavUtils.getItemETag(touchedFileItem)).to.not.be.equal(WebDavUtils.getItemETag(fileItem)); | ||
| }); | ||
|
|
||
| test('when two folders share uuid and dates, then they get the same etag regardless of size', () => { | ||
| const folderItem = newFolderItem(); | ||
|
|
||
| expect(WebDavUtils.getItemETag(folderItem)).to.be.equal(WebDavUtils.getItemETag({ ...folderItem })); | ||
| }); | ||
|
|
||
| test('when two items have different uuids, then they get different etags', () => { | ||
| const fileItem = newFileItem({ uuid: 'uuid-1' }); | ||
| const otherFileItem = { ...fileItem, uuid: 'uuid-2' }; | ||
|
|
||
| expect(WebDavUtils.getItemETag(fileItem)).to.not.be.equal(WebDavUtils.getItemETag(otherFileItem)); | ||
| }); | ||
| }); | ||
|
|
||
| describe('deleteOrTrashItem', () => { | ||
| test('when permanent deletion is enabled for files, then files are deleted permanently and cache is cleared', async () => { | ||
| const fileItem = newFileItem(); | ||
|
|
||
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.
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.
wouldnt it be better here to pass already the .getTime() propety? then we can avoid using the ternary on L115