diff --git a/packages/storage/__tests__/providers/s3/utils/client/S3/cases/listCallerAccessGrants.ts b/packages/storage/__tests__/providers/s3/utils/client/S3/cases/listCallerAccessGrants.ts index 29a8e3f4516..1a72a2049bc 100644 --- a/packages/storage/__tests__/providers/s3/utils/client/S3/cases/listCallerAccessGrants.ts +++ b/packages/storage/__tests__/providers/s3/utils/client/S3/cases/listCallerAccessGrants.ts @@ -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, { @@ -71,6 +71,70 @@ 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: ` + + + ${MOCK_NEXT_TOKEN} + + + ${MOCK_APP_ARN} + ${MOCK_GRANT_SCOPE} + ${MOCK_PERMISSION} + + + ${MOCK_APP_ARN} + ${MOCK_GRANT_SCOPE} + ${MOCK_PERMISSION} + + + + `, + }, + { + $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 > = [ @@ -78,8 +142,8 @@ const listCallerAccessGrantsErrorCase: ApiFunctionalTestCase< 'listCallerAccessGrants', listCallerAccessGrants, defaultConfig, - listCallerAccessGrantsHappyCase[4], - listCallerAccessGrantsHappyCase[5], + listCallerAccessGrantsHappyCaseSingleGrant[4], + listCallerAccessGrantsHappyCaseSingleGrant[5], { status: 403, headers: DEFAULT_RESPONSE_HEADERS, @@ -100,6 +164,7 @@ const listCallerAccessGrantsErrorCase: ApiFunctionalTestCase< ]; export default [ - listCallerAccessGrantsHappyCase, + listCallerAccessGrantsHappyCaseSingleGrant, + listCallerAccessGrantsHappyCaseMultipleGrants, listCallerAccessGrantsErrorCase, ]; diff --git a/packages/storage/src/providers/s3/utils/client/s3control/listCallerAccessGrants.ts b/packages/storage/src/providers/s3/utils/client/s3control/listCallerAccessGrants.ts index 3c95369fb99..8728ab19832 100644 --- a/packages/storage/src/providers/s3/utils/client/s3control/listCallerAccessGrants.ts +++ b/packages/storage/src/providers/s3/utils/client/s3control/listCallerAccessGrants.ts @@ -70,7 +70,11 @@ const listCallerAccessGrantsDeserializer = async ( const contents = map(parsed, { CallerAccessGrantsList: [ 'CallerAccessGrantsList', - value => emptyArrayGuard(value, deserializeAccessGrantsList), + value => + emptyArrayGuard( + value.AccessGrantsInstance, + deserializeAccessGrantsList, + ), ], NextToken: 'NextToken', }); @@ -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',