diff --git a/src/react/ui-elements/SelectAccountIAMRole.tsx b/src/react/ui-elements/SelectAccountIAMRole.tsx
index 868d98b9e..96e4fc48a 100644
--- a/src/react/ui-elements/SelectAccountIAMRole.tsx
+++ b/src/react/ui-elements/SelectAccountIAMRole.tsx
@@ -96,6 +96,12 @@ const AssumeDefaultIAMRole = ({
(acc) => acc.name === defaultValue?.accountName,
);
+ /**
+ * This set state will trigger a warning because it's not in a useEffect.
+ * This is fine because the set state is under an if and it should not be called too many times.
+ * The only time it could break is if for some reason the user use an account that is named like
+ * INTERNAL_DEFAULT_ACCOUNT_NAME_FOR_INITIALIZATION and use the component with a defaultValue.
+ */
setAssumeRole({
roleArn: acc?.preferredAssumableRoleArn ?? '',
});
@@ -163,18 +169,17 @@ const SelectAccountIAMRoleWithAccount = (
const rolesQuery = getListRolesQuery(accountName, IAMClient);
const queryClient = useQueryClient();
- const id1 = regexArn.exec(assumedRole?.AssumedRoleUser?.Arn)?.groups?.[
- 'account_id'
- ];
- const id2 = regexArn.exec(account?.preferredAssumableRoleArn)?.groups?.[
- 'account_id'
- ];
+ const assumedRoleAccountId = regexArn.exec(assumedRole?.AssumedRoleUser?.Arn)
+ ?.groups?.['account_id'];
+ const selectedAccountId = regexArn.exec(account?.preferredAssumableRoleArn)
+ ?.groups?.['account_id'];
/**
* When we change account, it will take some time to assume the role for the new account.
* We need this check to make sure we don't show the roles for the old account.
*/
- const assumedRoleAccountMatchSelectedAccount = id1 === id2;
+ const assumedRoleAccountMatchSelectedAccount =
+ assumedRoleAccountId === selectedAccountId;
const listRolesQuery = {
...rolesQuery,
diff --git a/src/react/ui-elements/__tests__/SelectAccountIAMRole.test.tsx b/src/react/ui-elements/__tests__/SelectAccountIAMRole.test.tsx
index a014dc8c1..00906a0d1 100644
--- a/src/react/ui-elements/__tests__/SelectAccountIAMRole.test.tsx
+++ b/src/react/ui-elements/__tests__/SelectAccountIAMRole.test.tsx
@@ -24,11 +24,9 @@ const genFn = (getPayloadFn: jest.Mock) => {
return rest.post(`${TEST_API_BASE_URL}/`, (req, res, ctx) => {
//@ts-ignore
const params = new URLSearchParams(req.body);
- console.log('reqbody', req.body);
getPayloadFn(params);
- // Assume Role
+
if (params.get('Action') === 'AssumeRoleWithWebIdentity') {
- console.log('return assume role');
return res(
ctx.status(200),
ctx.xml(`
@@ -217,7 +215,7 @@ describe('SelectAccountIAMRole', () => {
screen.getByRole('option', {
name: new RegExp(name, 'i'),
}),
- loading: () => screen.getByText(/Loading.../i),
+ loadingAccount: () => screen.getByText(/Loading.../i),
};
beforeAll(() => {
server.listen({ onUnhandledRequest: 'error' });
@@ -248,7 +246,7 @@ describe('SelectAccountIAMRole', () => {
await userEvent.click(seletors.selectOption(/no\-bucket/i));
- await waitForElementToBeRemoved(() => seletors.loading());
+ await waitForElementToBeRemoved(() => seletors.loadingAccount());
await waitFor(() => {
expect(seletors.roleSelect()).toBeInTheDocument();
@@ -313,6 +311,29 @@ describe('SelectAccountIAMRole', () => {
debug();
});
+ it('renders with wrong default value', async () => {
+ const getPayloadFn = jest.fn();
+ server.use(genFn(getPayloadFn));
+ const onChange = jest.fn();
+ render(
+
+
+ ,
+ );
+
+ await waitFor(() => {
+ expect(seletors.accountSelect()).toBeInTheDocument();
+ });
+
+ expect(seletors.accountSelect()).toBeInTheDocument();
+ });
+
it('renders with hidden account roles', async () => {
const getPayloadFn = jest.fn();
server.use(genFn(getPayloadFn));
@@ -348,25 +369,4 @@ describe('SelectAccountIAMRole', () => {
debug();
});
-
- it('renders with wrong default value', async () => {
- const getPayloadFn = jest.fn();
- server.use(genFn(getPayloadFn));
- const onChange = jest.fn();
- render(
-
-
- ,
- );
-
- await waitFor(() => {
- expect(seletors.accountSelect()).toBeInTheDocument();
- });
- });
});