Skip to content
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

fix(storage-browser): listCallerAccessGrantsDeserializer not parsing multiple AccessGrant instances #13671

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const MOCK_GRANT_SCOPE = 's3://my-bucket/path/to/object.md';
const MOCK_PERMISSION = 'READWRITE';

// API Reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_ListAccessGrants.html
const listCallerAccessGrantsHappyCase: ApiFunctionalTestCase<
const listCallerAccessGrantsHappyCaseSingleGrant: ApiFunctionalTestCase<
typeof listCallerAccessGrants
> = [
'happy case',
'listCallerAccessGrants',
'listCallerAccessGrantsHappyCaseSingleGrant',
listCallerAccessGrants,
defaultConfig,
{
Expand Down Expand Up @@ -71,15 +71,79 @@ const listCallerAccessGrantsHappyCase: ApiFunctionalTestCase<
},
];

const listCallerAccessGrantsHappyCaseMultipleGrants: ApiFunctionalTestCase<
typeof listCallerAccessGrants
> = [
'happy case',
'listCallerAccessGrantsHappyCaseMultipleGrants',
listCallerAccessGrants,
defaultConfig,
{
AccountId: MOCK_ACCOUNT_ID,
GrantScope: 's3://my-bucket/path/to/',
MaxResults: 50,
NextToken: 'mockToken',
},
expect.objectContaining({
url: expect.objectContaining({
href: 'https://accountid.s3-control.us-east-1.amazonaws.com/v20180820/accessgrantsinstance/caller/grants?grantscope=s3%3A%2F%2Fmy-bucket%2Fpath%2Fto%2F&maxResults=50&nextToken=mockToken',
}),
method: 'GET',
headers: expect.objectContaining({
'x-amz-account-id': MOCK_ACCOUNT_ID,
}),
}),
{
status: 200,
headers: {
...DEFAULT_RESPONSE_HEADERS,
},
body: `
<?xml version="1.0" encoding="UTF-8"?>
<ListCallerAccessGrantsResult>
<NextToken>${MOCK_NEXT_TOKEN}</NextToken>
<CallerAccessGrantsList>
<AccessGrantsInstance>
<ApplicationArn>${MOCK_APP_ARN}</ApplicationArn>
<GrantScope>${MOCK_GRANT_SCOPE}</GrantScope>
<Permission>${MOCK_PERMISSION}</Permission>
</AccessGrantsInstance>
<AccessGrantsInstance>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't we also need to test and verify the case of single AccessGrantsInstance?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good callout, can we add an additional test case please?

Copy link
Member Author

@ashwinkumar6 ashwinkumar6 Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx updated,

Considering the fact that the default behavior of xml -> obj parsing is

  • single item = object
  • multiple items = array of object

The underlying parseXmlBody util is used across all storage APIs. Should we add tests for 'single and multiple xml items' test in other places as well (example ListObjectV2 only has multiple items)
(probably in another PR if required)

<ApplicationArn>${MOCK_APP_ARN}</ApplicationArn>
<GrantScope>${MOCK_GRANT_SCOPE}</GrantScope>
<Permission>${MOCK_PERMISSION}</Permission>
</AccessGrantsInstance>
</CallerAccessGrantsList>
</ListCallerAccessGrantsResult>
`,
},
{
$metadata: expect.objectContaining(expectedMetadata),
CallerAccessGrantsList: [
{
ApplicationArn: MOCK_APP_ARN,
GrantScope: MOCK_GRANT_SCOPE,
Permission: MOCK_PERMISSION,
},
{
ApplicationArn: MOCK_APP_ARN,
GrantScope: MOCK_GRANT_SCOPE,
Permission: MOCK_PERMISSION,
},
],
NextToken: MOCK_NEXT_TOKEN,
},
];

const listCallerAccessGrantsErrorCase: ApiFunctionalTestCase<
typeof listCallerAccessGrants
> = [
'error case',
'listCallerAccessGrants',
listCallerAccessGrants,
defaultConfig,
listCallerAccessGrantsHappyCase[4],
listCallerAccessGrantsHappyCase[5],
listCallerAccessGrantsHappyCaseSingleGrant[4],
listCallerAccessGrantsHappyCaseSingleGrant[5],
{
status: 403,
headers: DEFAULT_RESPONSE_HEADERS,
Expand All @@ -100,6 +164,7 @@ const listCallerAccessGrantsErrorCase: ApiFunctionalTestCase<
];

export default [
listCallerAccessGrantsHappyCase,
listCallerAccessGrantsHappyCaseSingleGrant,
listCallerAccessGrantsHappyCaseMultipleGrants,
listCallerAccessGrantsErrorCase,
];
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ const listCallerAccessGrantsDeserializer = async (
const contents = map(parsed, {
CallerAccessGrantsList: [
'CallerAccessGrantsList',
value => emptyArrayGuard(value, deserializeAccessGrantsList),
value =>
emptyArrayGuard(
value.AccessGrantsInstance,
deserializeAccessGrantsList,
),
],
NextToken: 'NextToken',
});
Expand All @@ -86,7 +90,7 @@ const deserializeAccessGrantsList = (output: any[]) =>
output.map(deserializeCallerAccessGrant);

const deserializeCallerAccessGrant = (output: any) =>
map(output.AccessGrantsInstance, {
map(output, {
calebpollman marked this conversation as resolved.
Show resolved Hide resolved
ApplicationArn: 'ApplicationArn',
GrantScope: 'GrantScope',
Permission: 'Permission',
Expand Down
Loading