-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parsing arn with multiple slashes when importing auth (#13009)
- Loading branch information
Showing
7 changed files
with
94 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ARN, parse } from '@aws-sdk/util-arn-parser'; | ||
|
||
export const parseArn = (arn: string): ARN => { | ||
return parse(arn); | ||
}; |
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
68 changes: 68 additions & 0 deletions
68
...es/amplify-provider-awscloudformation/src/__tests__/aws-utils/IdentityPoolService.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,68 @@ | ||
import { $TSContext } from '@aws-amplify/amplify-cli-core'; | ||
import { createIdentityPoolService } from '../../aws-utils/IdentityPoolService'; | ||
import { loadConfiguration } from '../../configuration-manager'; | ||
|
||
let mockCognitoIdentityRoles = { | ||
authenticated: 'arn:aws:iam::123456789012:role/service-role/my-auth-role', | ||
unauthenticated: 'arn:aws:iam::123456789012:role/service-role/my-unauth-role', | ||
}; | ||
|
||
jest.mock('aws-sdk', () => { | ||
return { | ||
CognitoIdentity: jest.fn(() => { | ||
return { | ||
config: {}, | ||
getIdentityPoolRoles: jest.fn().mockImplementation(() => ({ | ||
promise: async () => { | ||
return { | ||
Roles: mockCognitoIdentityRoles, | ||
}; | ||
}, | ||
})), | ||
}; | ||
}), | ||
}; | ||
}); | ||
|
||
jest.mock('../../configuration-manager', () => { | ||
return { | ||
loadConfiguration: jest.fn().mockReturnValue({}) as jest.MockedFunction<typeof loadConfiguration>, | ||
}; | ||
}); | ||
|
||
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({ | ||
authRoleArn: 'arn:aws:iam::123456789012:role/service-role/my-auth-role', | ||
authRoleName: 'service-role/my-auth-role', | ||
unauthRoleArn: 'arn:aws:iam::123456789012:role/service-role/my-unauth-role', | ||
unauthRoleName: 'service-role/my-unauth-role', | ||
}); | ||
}); | ||
|
||
it('should correctly parse arn if it contains a single forward slash', async () => { | ||
const idpService = await createIdentityPoolService({} as unknown as $TSContext, {}); | ||
mockCognitoIdentityRoles = { | ||
authenticated: 'arn:aws:iam::123456789012:role/my-auth-role', | ||
unauthenticated: 'arn:aws:iam::123456789012:role/my-unauth-role', | ||
}; | ||
|
||
expect(await idpService.getIdentityPoolRoles('mockIdpId')).toEqual({ | ||
authRoleArn: 'arn:aws:iam::123456789012:role/my-auth-role', | ||
authRoleName: 'my-auth-role', | ||
unauthRoleArn: 'arn:aws:iam::123456789012:role/my-unauth-role', | ||
unauthRoleName: 'my-unauth-role', | ||
}); | ||
}); | ||
|
||
it('should fail to parse arn if it contains no forward slash', async () => { | ||
const idpService = await createIdentityPoolService({} as unknown as $TSContext, {}); | ||
mockCognitoIdentityRoles = { | ||
authenticated: 'arn:aws:iam::123456789012:my-auth-role', | ||
unauthenticated: 'arn:aws:iam::123456789012:my-unauth-role', | ||
}; | ||
|
||
await expect(idpService.getIdentityPoolRoles('mockIdpId')).rejects.toBeDefined(); | ||
}); | ||
}); |
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