From d9c8a8f62910ac0a394397f9f3bdb64901a51e38 Mon Sep 17 00:00:00 2001 From: Jordan Reimer Date: Fri, 10 Feb 2023 10:33:26 -0700 Subject: [PATCH] updates k8s config validation (#19123) --- ui/app/models/kubernetes/config.js | 7 +++++- .../kubernetes/page/configure-test.js | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ui/app/models/kubernetes/config.js b/ui/app/models/kubernetes/config.js index 5f4093271554..25b409d1fba4 100644 --- a/ui/app/models/kubernetes/config.js +++ b/ui/app/models/kubernetes/config.js @@ -3,7 +3,12 @@ import { withFormFields } from 'vault/decorators/model-form-fields'; import { withModelValidations } from 'vault/decorators/model-validations'; const validations = { - kubernetesHost: [{ type: 'presence', message: 'Kubernetes host is required' }], + kubernetesHost: [ + { + validator: (model) => (model.disableLocalCaJwt && !model.kubernetesHost ? false : true), + message: 'Kubernetes host is required', + }, + ], }; @withModelValidations(validations) @withFormFields(['kubernetesHost', 'serviceAccountJwt', 'kubernetesCaCert']) diff --git a/ui/tests/integration/components/kubernetes/page/configure-test.js b/ui/tests/integration/components/kubernetes/page/configure-test.js index f625074fabb1..d3bc1e824af0 100644 --- a/ui/tests/integration/components/kubernetes/page/configure-test.js +++ b/ui/tests/integration/components/kubernetes/page/configure-test.js @@ -216,4 +216,29 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks .hasText('Kubernetes host is required', 'Error renders for required field'); assert.dom('[data-test-alert] p').hasText('There is an error with this form.', 'Alert renders'); }); + + test('it should save inferred config', async function (assert) { + assert.expect(2); + + this.server.get('/:path/check', () => new Response(204, {})); + this.server.post('/:path/config', (schema, req) => { + const json = JSON.parse(req.requestBody); + assert.deepEqual(json, { disable_local_ca_jwt: false }, 'Values are passed to create endpoint'); + return new Response(204, {}); + }); + + const stub = sinon.stub(this.owner.lookup('service:router'), 'transitionTo'); + + await render(hbs``, { + owner: this.engine, + }); + + await click('[data-test-config] button'); + await click('[data-test-config-save]'); + + assert.ok( + stub.calledWith('vault.cluster.secrets.backend.kubernetes.configuration'), + 'Transitions to configuration route on save success' + ); + }); });