Skip to content

Commit

Permalink
Support caBundle plain text
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <[email protected]>
  • Loading branch information
torchiaf committed Jan 2, 2025
1 parent 9fe1f4a commit 93e59ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script>
import { clone } from '@shell/utils/object';
import ArrayListGrouped from '@shell/components/form/ArrayListGrouped';
import { LabeledInput } from '@components/Form/LabeledInput';
import { Checkbox } from '@components/Form/Checkbox';
import SelectOrCreateAuthSecret from '@shell/components/form/SelectOrCreateAuthSecret';
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 isBase64 from 'is-base64';
import { base64Decode, base64Encode } from '@shell/utils/crypto';
export default {
Expand Down Expand Up @@ -42,7 +44,7 @@ export default {
},
data() {
const configMap = this.value.spec.rkeConfig?.registries?.configs || {};
const configMap = clone(this.value.spec.rkeConfig?.registries?.configs) || {};
const entries = [];
const defaultAddValue = {
Expand All @@ -57,7 +59,10 @@ export default {
if (configMap[hostname]) {
configMap[hostname].insecureSkipVerify = configMap[hostname].insecureSkipVerify ?? defaultAddValue.insecureSkipVerify;
configMap[hostname].authConfigSecretName = configMap[hostname].authConfigSecretName ?? defaultAddValue.authConfigSecretName;
configMap[hostname].caBundle = base64Decode(configMap[hostname].caBundle ?? defaultAddValue.caBundle);

Check warning on line 62 in shell/edit/provisioning.cattle.io.cluster/tabs/registries/RegistryConfigs.vue

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
const caBundle = configMap[hostname].caBundle ?? defaultAddValue.caBundle;
configMap[hostname].caBundle = isBase64(caBundle) ? base64Decode(caBundle) : caBundle;

Check warning on line 64 in shell/edit/provisioning.cattle.io.cluster/tabs/registries/RegistryConfigs.vue

View workflow job for this annotation

GitHub Actions / lint

Expected blank line before this statement
configMap[hostname].tlsSecretName = configMap[hostname].tlsSecretName ?? defaultAddValue.tlsSecretName;
}
entries.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ describe('component: RegistryConfigs', () => {
};

describe('key CA Cert Bundle', () => {
it('should display default key', () => {
it.each([
['source is plain text', 'Zm9vYmFy','foobar'],

Check warning on line 27 in shell/edit/provisioning.cattle.io.cluster/tabs/registries/__tests__/RegistryConfigs.test.ts

View workflow job for this annotation

GitHub Actions / lint

A space is required after ','
['source is base64', 'foobar','foobar'],

Check warning on line 28 in shell/edit/provisioning.cattle.io.cluster/tabs/registries/__tests__/RegistryConfigs.test.ts

View workflow job for this annotation

GitHub Actions / lint

A space is required after ','
])('should display key, %p', (_, sourceCaBundle, displayedCaBundle) => {
const value = clone(PROV_CLUSTER);

value.spec.rkeConfig.registries.configs = { foo: { caBundle: 'Zm9vYmFy' } };
value.spec.rkeConfig.registries.configs = { foo: { caBundle: sourceCaBundle } };

mountOptions.propsData.value = value;

Expand All @@ -37,7 +40,7 @@ describe('component: RegistryConfigs', () => {

const registry = wrapper.findComponent('[data-testid^="registry-caBundle"]');

expect(registry.props().value).toBe('foobar');
expect(registry.props().value).toBe(displayedCaBundle);
});

it('should update key in base64 format', async() => {
Expand Down

0 comments on commit 93e59ad

Please sign in to comment.