Skip to content

Commit

Permalink
updates k8s config validation (#19123)
Browse files Browse the repository at this point in the history
  • Loading branch information
zofskeez authored Feb 10, 2023
1 parent b0218ce commit d9c8a8f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ui/app/models/kubernetes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
25 changes: 25 additions & 0 deletions ui/tests/integration/components/kubernetes/page/configure-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`<Page::Configure @model={{this.newModel}} @breadcrumbs={{this.breadcrumbs}} />`, {
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'
);
});
});

0 comments on commit d9c8a8f

Please sign in to comment.