From 88a69fae8cf6f33666450279f2209e54897ec893 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Thu, 11 Jul 2024 18:06:30 +0200 Subject: [PATCH] Encode CA bundle key in base64 format Signed-off-by: Francesco Torchia --- .../tabs/registries/RegistryConfigs.vue | 10 ++- .../__tests__/RegistryConfigs.test.ts | 61 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 shell/edit/provisioning.cattle.io.cluster/tabs/registries/__tests__/RegistryConfigs.test.ts diff --git a/shell/edit/provisioning.cattle.io.cluster/tabs/registries/RegistryConfigs.vue b/shell/edit/provisioning.cattle.io.cluster/tabs/registries/RegistryConfigs.vue index 559eb6f30c2..a462d1d83de 100644 --- a/shell/edit/provisioning.cattle.io.cluster/tabs/registries/RegistryConfigs.vue +++ b/shell/edit/provisioning.cattle.io.cluster/tabs/registries/RegistryConfigs.vue @@ -7,6 +7,7 @@ import SelectOrCreateAuthSecret from '@shell/components/form/SelectOrCreateAuthS import CreateEditView from '@shell/mixins/create-edit-view'; import SecretSelector from '@shell/components/form/SecretSelector'; import { SECRET_TYPES as TYPES } from '@shell/config/secret'; +import { base64Decode, base64Encode } from '@shell/utils/crypto'; export default { components: { @@ -55,7 +56,7 @@ export default { if (configMap[hostname]) { configMap[hostname].insecureSkipVerify = configMap[hostname].insecureSkipVerify ?? defaultAddValue.insecureSkipVerify; configMap[hostname].authConfigSecretName = configMap[hostname].authConfigSecretName ?? defaultAddValue.authConfigSecretName; - configMap[hostname].caBundle = configMap[hostname].caBundle ?? defaultAddValue.caBundle; + configMap[hostname].caBundle = base64Decode(configMap[hostname].caBundle ?? defaultAddValue.caBundle); configMap[hostname].tlsSecretName = configMap[hostname].tlsSecretName ?? defaultAddValue.tlsSecretName; } entries.push({ @@ -94,7 +95,11 @@ export default { continue; } - configs[h] = { ...entry }; + configs[h] = { + ...entry, + caBundle: base64Encode(entry.caBundle) + }; + delete configs[h].hostname; } @@ -175,6 +180,7 @@ export default { { + let wrapper: Wrapper & { [key: string]: any }>; + + const mountOptions = { + propsData: { + value: {}, + mode: _EDIT, + clusterRegisterBeforeHook: () => {} + }, + stubs: { + SelectOrCreateAuthSecret: true, + SecretSelector: true, + }, + mocks: { $store: { getters: { 'i18n/t': jest.fn() } } } + }; + + describe('key CA Cert Bundle', () => { + it('should display default key', () => { + const value = clone(PROV_CLUSTER); + + value.spec.rkeConfig.registries.configs = { foo: { caBundle: 'Zm9vYmFy' } }; + + mountOptions.propsData.value = value; + + wrapper = mount( + RegistryConfigs, + mountOptions + ); + + const registry = wrapper.find('[data-testid^="registry-caBundle"]').element as HTMLTextAreaElement; + + expect(registry.value).toBe('foobar'); + }); + + it('should update key in base64 format', async() => { + const value = clone(PROV_CLUSTER); + + value.spec.rkeConfig.registries.configs = { foo: { caBundle: 'Zm9vYmFy' } }; + + mountOptions.propsData.value = value; + + wrapper = mount( + RegistryConfigs, + mountOptions + ); + + const registry = wrapper.find('[data-testid^="registry-caBundle"]'); + + await registry.setValue('ssh key'); + wrapper.vm.update(); + + expect(wrapper.emitted('updateConfigs')![0][0]['foo']['caBundle']).toBe('c3NoIGtleQ=='); + }); + }); +});