Skip to content

Commit

Permalink
Encode CA bundle key in base64 format
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
  • Loading branch information
torchiaf committed Jul 12, 2024
1 parent d612277 commit 88a69fa
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -94,7 +95,11 @@ export default {
continue;
}
configs[h] = { ...entry };
configs[h] = {
...entry,
caBundle: base64Encode(entry.caBundle)
};
delete configs[h].hostname;
}
Expand Down Expand Up @@ -175,6 +180,7 @@ export default {
<LabeledInput
v-model="row.value.caBundle"
:data-testid="`registry-caBundle-${i}`"
class="mt-20"
type="multiline"
label="CA Cert Bundle"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { mount, Wrapper } from '@vue/test-utils';
import { clone } from '@shell/utils/object';
import { _EDIT } from '@shell/config/query-params';
import { PROV_CLUSTER } from '@shell/edit/provisioning.cattle.io.cluster/__tests__/utils/cluster';
import RegistryConfigs from '@shell/edit/provisioning.cattle.io.cluster/tabs/registries/RegistryConfigs.vue';

describe('component: RegistryConfigs', () => {
let wrapper: Wrapper<InstanceType<typeof RegistryConfigs> & { [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==');
});
});
});

0 comments on commit 88a69fa

Please sign in to comment.