Skip to content
Open
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 @@ -61,9 +61,16 @@ export async function getConnectionAccounts(
context.projectId,
);

return roles.map((role) => ({
id: parseArn(role.assumeRoleArn).accountId,
displayName: role.accountName,
...(imageLogoUrl && { imageLogoUrl }),
}));
const accountMap = new Map<string, BenchmarkWizardOption>();
for (const role of roles) {
const accountId = parseArn(role.assumeRoleArn).accountId;
if (!accountMap.has(accountId)) {
accountMap.set(accountId, {
id: accountId,
displayName: role.accountName,
...(imageLogoUrl && { imageLogoUrl }),
});
}
}
return Array.from(accountMap.values());
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,55 @@ describe('resolveOptions', () => {
]);
});

it('deduplicates accounts with the same account ID for getConnectionAccounts', async () => {
mockGetOneOrThrow.mockResolvedValue({
authProviderKey: 'AWS',
value: {
type: 'CUSTOM_AUTH',
props: {
roles: [
{
assumeRoleArn: 'arn:aws:iam::111111111111:role/OpenOpsApp',
accountName: 'my-sandbox-1',
},
{
assumeRoleArn: 'arn:aws:iam::111111111111:role/OpenOpsApp2',
accountName: 'my-sandbox-2',
},
{
assumeRoleArn: 'arn:aws:iam::222222222222:role/ReadOnly',
accountName: 'another-account',
},
],
},
},
});
mockGetAuthProviderMetadata.mockResolvedValue({
authProviderKey: 'AWS',
authProviderLogoUrl: '/blocks/aws.png',
});

const result = await resolveOptions('getConnectionAccounts', {
projectId,
provider,
benchmarkConfiguration: { connection: ['conn-123'] },
});

expect(result).toHaveLength(2);
expect(result).toEqual([
{
id: '111111111111',
displayName: 'my-sandbox-1',
imageLogoUrl: '/blocks/aws.png',
},
{
id: '222222222222',
displayName: 'another-account',
imageLogoUrl: '/blocks/aws.png',
},
]);
});

it('omits imageLogoUrl for getConnectionAccounts when auth metadata has no logo', async () => {
mockGetOneOrThrow.mockResolvedValue({
authProviderKey: 'SomeProvider',
Expand Down
Loading