diff --git a/pkg/eks/components/CruEKS.vue b/pkg/eks/components/CruEKS.vue index e577ceb6ac4..ca08cb9e538 100644 --- a/pkg/eks/components/CruEKS.vue +++ b/pkg/eks/components/CruEKS.vue @@ -557,15 +557,14 @@ export default defineComponent({ const keyPairRes: {KeyPairs: {KeyName: string}[]} = await ec2Client.describeKeyPairs({ DryRun: false }); - this['sshKeyPairs'] = (keyPairRes.KeyPairs || [].map((key) => { + this.sshKeyPairs = (keyPairRes.KeyPairs || []).map((key) => { return key.KeyName; - }).sort()); + }).sort(); } catch (err: any) { const errors = this.errors as any[]; errors.push(err); } - this.loadingSshKeyPairs = false; }, } diff --git a/pkg/eks/components/__mocks__/describeKeyPairs.js b/pkg/eks/components/__mocks__/describeKeyPairs.js new file mode 100644 index 00000000000..a69c1d42eca --- /dev/null +++ b/pkg/eks/components/__mocks__/describeKeyPairs.js @@ -0,0 +1,31 @@ +export default { + KeyPairs: [ + { + CreateTime: 'Date Mon Jul 24 2023 14:53:22 GMT-0700 (Pacific Daylight Time)', + + KeyFingerprint: 'a1:b2:c3:12345678987654321', + + KeyName: 'test-key1', + + KeyPairId: 'key-123456789', + + KeyType: 'rsa', + + Tags: [] + }, + + { + CreateTime: 'Date Mon Jul 24 2023 14:53:22 GMT-0700 (Pacific Daylight Time)', + + KeyFingerprint: 'a1:b2:c3:12345678987654321', + + KeyName: 'test-key2', + + KeyPairId: 'key-123456789', + + KeyType: 'rsa', + + Tags: [] + } + ] +}; diff --git a/pkg/eks/components/__tests__/CruEKS.test.ts b/pkg/eks/components/__tests__/CruEKS.test.ts index a28cb5db9cc..44a66e6cee9 100644 --- a/pkg/eks/components/__tests__/CruEKS.test.ts +++ b/pkg/eks/components/__tests__/CruEKS.test.ts @@ -1,7 +1,10 @@ +/* eslint-disable jest/no-mocks-import */ import flushPromises from 'flush-promises'; import { mount, shallowMount, Wrapper } from '@vue/test-utils'; import { EKSConfig, EKSNodeGroup } from 'types'; import CruEKS, { DEFAULT_EKS_CONFIG } from '@pkg/eks/components/CruEKS.vue'; +import describeKeyPairs from '../__mocks__/describeKeyPairs'; +import describeLaunchTemplates from '../__mocks__/describeLaunchTemplates'; const mockedStore = (versionSetting: any) => { return { @@ -19,7 +22,19 @@ const mockedStore = (versionSetting: any) => { return {}; } }, - dispatch: jest.fn() + dispatch: () => { + return { + describeKeyPairs: () => { + return describeKeyPairs; + }, + describeLaunchTemplates: () => { + return describeLaunchTemplates; + }, + listRoles: () => { + return { Roles: [] }; + } + }; + } }; }; @@ -39,8 +54,9 @@ const requiredSetup = (versionSetting = { value: '<=1.27.x' }) => { }; const setCredential = async(wrapper :Wrapper, config = {} as EKSConfig) => { - config.amazonCredentialSecret = 'foo'; wrapper.setData({ config }); + wrapper.vm.updateCredential('foo'); + wrapper.vm.updateRegion('bar'); await flushPromises(); }; @@ -216,4 +232,17 @@ describe('eKS provisioning form', () => { expect(wrapper.vm.fvUnreportedValidationErrors).toStrictEqual([]); }); + + it('should fetch ssh keys from the aws api and save response as list of keypair KeyNames', async() => { + const setup = requiredSetup(); + + const wrapper = shallowMount(CruEKS, { + propsData: { value: {}, mode: 'create' }, + ...setup + }); + + await setCredential(wrapper); + + expect(wrapper.vm.sshKeyPairs).toStrictEqual(['test-key1', 'test-key2']); + }); });