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: parse cognito pools with service role #13365

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -33,11 +33,18 @@ jest.mock('../../configuration-manager', () => {
describe('IdentityPoolService', () => {
it('should correctly parse arn if it contains multiple forward slashes', async () => {
const idpService = await createIdentityPoolService({} as unknown as $TSContext, {});
expect(await idpService.getIdentityPoolRoles('mockIdpId')).toEqual({
const identityPoolRoles = await idpService.getIdentityPoolRoles('mockIdpId');

// ensure role names match regex for IAM
// see: https://docs.aws.amazon.com/IAM/latest/APIReference/API_Role.html
expect(identityPoolRoles.authRoleName).toMatch(/[\w+=,.@-]+/);
rtpascual marked this conversation as resolved.
Show resolved Hide resolved
expect(identityPoolRoles.unauthRoleName).toMatch(/[\w+=,.@-]+/);

expect(identityPoolRoles).toEqual({
authRoleArn: 'arn:aws:iam::123456789012:role/service-role/my-auth-role',
authRoleName: 'service-role/my-auth-role',
authRoleName: 'my-auth-role',
unauthRoleArn: 'arn:aws:iam::123456789012:role/service-role/my-unauth-role',
unauthRoleName: 'service-role/my-unauth-role',
unauthRoleName: 'my-unauth-role',
});
});

Expand All @@ -48,7 +55,14 @@ describe('IdentityPoolService', () => {
unauthenticated: 'arn:aws:iam::123456789012:role/my-unauth-role',
};

expect(await idpService.getIdentityPoolRoles('mockIdpId')).toEqual({
const identityPoolRoles = await idpService.getIdentityPoolRoles('mockIdpId');

// ensure role names match regex for IAM
// see: https://docs.aws.amazon.com/IAM/latest/APIReference/API_Role.html
expect(identityPoolRoles.authRoleName).toMatch(/[\w+=,.@-]+/);
expect(identityPoolRoles.unauthRoleName).toMatch(/[\w+=,.@-]+/);

expect(identityPoolRoles).toEqual({
authRoleArn: 'arn:aws:iam::123456789012:role/my-auth-role',
authRoleName: 'my-auth-role',
unauthRoleArn: 'arn:aws:iam::123456789012:role/my-unauth-role',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class IdentityPoolService implements IIdentityPoolService {
const fullRoleName = parseArn(arn).resource;
const parts = fullRoleName.split('/');
if (parts.length >= 2) {
resourceName = parts.slice(1).join('/');
resourceName = [...parts].pop();
}
}

Expand Down