-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Feat: Add pagination to Amplify Default Auth storage Browser #13897
Merged
ashika112
merged 21 commits into
aws-amplify:storage-browser/integrity
from
ashika112:feat/sb-path-pagination
Oct 25, 2024
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
61ebc51
first draft poc
ashika112 a834fcc
upadtes
ashika112 337068b
add listPaths API
ashika112 9d209e1
update new file structure
ashika112 537275c
fix types
ashika112 631dd7f
refactor types and utils
ashika112 ee5dceb
update tests
ashika112 70882a7
fix test
ashika112 6fdf40a
Merge branch 'storage-browser/integrity' into feat/sb-default-auth
ashika112 19468f2
fix bundle size test
ashika112 9cbc71d
update the listLocation handler
ashika112 2eae7b5
implement memoization
ashika112 c8af454
add pagination logic
ashika112 76da904
upadte usergroup logic & test
ashika112 87e8766
update getPaginated Locations
ashika112 5bbf146
Merge branch 'storage-browser/integrity' of github.com:aws-amplify/am…
ashika112 6f8b968
fix failing test
ashika112 22dd0c2
update userGroup logic and tests
ashika112 5596742
update for readbility
ashika112 ffd3ff8
update bundle size
ashika112 3fcd481
address feedbacks
ashika112 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 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
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
57 changes: 57 additions & 0 deletions
57
...ages/storage/__tests__/internals/amplifyAuthAdapter/getHighestPrecedenceUserGroup.test.ts
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,57 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { | ||
UserGroupConfig, | ||
getHighestPrecedenceUserGroup, | ||
} from '../../../src/internals/amplifyAuthConfigAdapter/getHighestPrecedenceUserGroup'; | ||
|
||
const userGroupsFromConfig: UserGroupConfig = [ | ||
{ | ||
editor: { | ||
precedence: 0, | ||
}, | ||
}, | ||
{ | ||
admin: { | ||
precedence: 1, | ||
}, | ||
}, | ||
{ | ||
auditor: { | ||
precedence: 2, | ||
}, | ||
}, | ||
]; | ||
const currentUserGroups = ['guest', 'user', 'admin']; | ||
|
||
describe('getHighestPrecedenceUserGroup', () => { | ||
it('should return the user group with the highest precedence', () => { | ||
const result = getHighestPrecedenceUserGroup( | ||
userGroupsFromConfig, | ||
currentUserGroups, | ||
); | ||
expect(result).toBe('admin'); | ||
}); | ||
|
||
it('should return undefined if userGroupsFromConfig is undefined', () => { | ||
const result = getHighestPrecedenceUserGroup(undefined, currentUserGroups); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should return undefined if currentUserGroups is undefined', () => { | ||
const result = getHighestPrecedenceUserGroup( | ||
userGroupsFromConfig, | ||
undefined, | ||
); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should handle currentUserGroups containing groups not present in userGroupsFromConfig', () => { | ||
const result = getHighestPrecedenceUserGroup(userGroupsFromConfig, [ | ||
'unknown', | ||
'user', | ||
]); | ||
expect(result).toBe(undefined); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
packages/storage/__tests__/internals/amplifyAuthAdapter/getPaginatedLocations.test.ts
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,90 @@ | ||
import { getPaginatedLocations } from '../../../src/internals/amplifyAuthConfigAdapter/getPaginatedLocations'; | ||
import { PathAccess } from '../../../src/internals/types/credentials'; | ||
|
||
describe('getPaginatedLocations', () => { | ||
const mockLocations: PathAccess[] = [ | ||
{ | ||
type: 'PREFIX', | ||
permission: ['read'], | ||
bucket: 'bucket1', | ||
prefix: 'path1/', | ||
}, | ||
{ | ||
type: 'PREFIX', | ||
permission: ['write'], | ||
bucket: 'bucket2', | ||
prefix: 'path2/', | ||
}, | ||
{ | ||
type: 'PREFIX', | ||
permission: ['read', 'write'], | ||
bucket: 'bucket3', | ||
prefix: 'path3/', | ||
}, | ||
]; | ||
|
||
it('should return all locations when no pagination is specified', () => { | ||
const result = getPaginatedLocations({ locations: mockLocations }); | ||
expect(result).toEqual({ locations: mockLocations }); | ||
}); | ||
|
||
it('should return paginated locations when pageSize is specified', () => { | ||
const result = getPaginatedLocations({ | ||
locations: mockLocations, | ||
pageSize: 2, | ||
}); | ||
expect(result).toEqual({ | ||
locations: mockLocations.slice(0, 2), | ||
nextToken: '1', | ||
}); | ||
}); | ||
|
||
it('should return paginated locations when pageSize and nextToken are specified', () => { | ||
const result = getPaginatedLocations({ | ||
locations: mockLocations, | ||
pageSize: 1, | ||
nextToken: '2', | ||
}); | ||
expect(result).toEqual({ | ||
locations: mockLocations.slice(1, 2), | ||
nextToken: '1', | ||
}); | ||
}); | ||
|
||
it('should return empty locations when locations array is empty', () => { | ||
const result = getPaginatedLocations({ locations: [], pageSize: 2 }); | ||
expect(result).toEqual({ locations: [] }); | ||
}); | ||
|
||
it('should return empty location when nextToken is beyond array length', () => { | ||
const result = getPaginatedLocations({ | ||
locations: mockLocations, | ||
pageSize: 2, | ||
nextToken: '5', | ||
}); | ||
expect(result).toEqual({ locations: [], nextToken: undefined }); | ||
}); | ||
|
||
it('should return all remaining location when page size is greater than remaining locations length', () => { | ||
const result = getPaginatedLocations({ | ||
locations: mockLocations, | ||
pageSize: 5, | ||
nextToken: '2', | ||
}); | ||
expect(result).toEqual({ | ||
locations: mockLocations.slice(-2), | ||
nextToken: undefined, | ||
}); | ||
}); | ||
|
||
it('should return undefined nextToken when end of array is reached', () => { | ||
const result = getPaginatedLocations({ | ||
locations: mockLocations, | ||
pageSize: 5, | ||
}); | ||
expect(result).toEqual({ | ||
locations: mockLocations.slice(0, 3), | ||
nextToken: undefined, | ||
}); | ||
}); | ||
}); |
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
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.
Sanity check, a user pool can have multiple records each containing multiple user group names? What's the case for multiple user group names in the record?
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 is auth config. Basically possible user group a user could belong to.