Skip to content

Commit

Permalink
fix(storage-browser): listCallerAccessGrantsDeserializer not parsing …
Browse files Browse the repository at this point in the history
…multiple AccessGrant instances (#13671)

* fix(storage-browser): listCallerAccessGrantsDeserializernot parsing multiple AccessGrant instances

* chore: add unit tests for single and multiple grants

---------

Co-authored-by: Ashwin Kumar <[email protected]>
  • Loading branch information
ashwinkumar6 and Ashwin Kumar authored Aug 1, 2024
1 parent a06c2f9 commit 08ef01b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 7 deletions.
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>
<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, {
ApplicationArn: 'ApplicationArn',
GrantScope: 'GrantScope',
Permission: 'Permission',
Expand Down

0 comments on commit 08ef01b

Please sign in to comment.