mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 17:52:32 +00:00
* replaced each instance of MaskedInput in PKI with CertificateCard * modify tests for pki-generate-csr * add test for pki-issuer-details. modify test for pki-certificate-details * added test for pki-key-details. modified test for pki-sign-intermediate-form * update 2 test helper files and modify test for pki-issuer-rotate-root * update test for certificate-card-test.js, update test for the kubernetes configuration-test.js * modify pki-action-forms-test.js to no longer look for masked input. expand test for pki-issuer-details-test.js to check for all issuer details * change CertificateCard to show different format types (PEM, DER, nothing) depending on the value provided. update 2 test files to account for this. * change CertificateCard arg name from @certficateValue to @data to be more inclusive of different uses of CertificateCard (i.e when used for a private key, not a certificate). add description to certificate-card.js * change naming for attr.options.masked to attr.options.displayCard to reflect the change from MaskedInput to CertificateCard * add changelog * change attribute to isCertificate to better fit the title of the component CertificateCard. edit pki-certificate-details.hbs to get rid of extraneous code
103 lines
4.2 KiB
JavaScript
103 lines
4.2 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'vault/tests/helpers';
|
|
import { click, fillIn, render } from '@ember/test-helpers';
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
import Sinon from 'sinon';
|
|
import { setupEngine } from 'ember-engines/test-support';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
|
|
const selectors = {
|
|
form: '[data-test-sign-intermediate-form]',
|
|
csrInput: '[data-test-input="csr"]',
|
|
toggleSigningOptions: '[data-test-toggle-group="Signing options"]',
|
|
toggleSANOptions: '[data-test-toggle-group="Subject Alternative Name (SAN) Options"]',
|
|
toggleAdditionalFields: '[data-test-toggle-group="Additional subject fields"]',
|
|
fieldByName: (name) => `[data-test-field="${name}"]`,
|
|
saveButton: '[data-test-pki-sign-intermediate-save]',
|
|
cancelButton: '[data-test-pki-sign-intermediate-cancel]',
|
|
fieldError: '[data-test-inline-alert]',
|
|
formError: '[data-test-form-error]',
|
|
resultsContainer: '[data-test-sign-intermediate-result]',
|
|
rowByName: (name) => `[data-test-row-label="${name}"]`,
|
|
valueByName: (name) => `[data-test-value-div="${name}"]`,
|
|
};
|
|
module('Integration | Component | pki-sign-intermediate-form', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
setupEngine(hooks, 'pki');
|
|
setupMirage(hooks);
|
|
|
|
hooks.beforeEach(async function () {
|
|
this.store = this.owner.lookup('service:store');
|
|
this.secretMountPath = this.owner.lookup('service:secret-mount-path');
|
|
this.secretMountPath.currentPath = 'pki-test';
|
|
this.model = this.store.createRecord('pki/sign-intermediate', { issuerRef: 'some-issuer' });
|
|
this.onCancel = Sinon.spy();
|
|
});
|
|
|
|
test('renders correctly on load', async function (assert) {
|
|
assert.expect(9);
|
|
await render(hbs`<PkiSignIntermediateForm @onCancel={{this.onCancel}} @model={{this.model}} />`, {
|
|
owner: this.engine,
|
|
});
|
|
|
|
assert.dom(selectors.form).exists('Form is rendered');
|
|
assert.dom(selectors.resultsContainer).doesNotExist('Results display not rendered');
|
|
assert.dom('[data-test-field]').exists({ count: 9 }, '9 default fields shown');
|
|
assert.dom(selectors.toggleSigningOptions).exists();
|
|
assert.dom(selectors.toggleSANOptions).exists();
|
|
assert.dom(selectors.toggleAdditionalFields).exists();
|
|
|
|
await click(selectors.toggleSigningOptions);
|
|
['usePss', 'skid', 'signatureBits'].forEach((name) => {
|
|
assert.dom(selectors.fieldByName(name)).exists();
|
|
});
|
|
});
|
|
|
|
test('it shows the returned values on successful save', async function (assert) {
|
|
assert.expect(13);
|
|
await render(hbs`<PkiSignIntermediateForm @onCancel={{this.onCancel}} @model={{this.model}} />`, {
|
|
owner: this.engine,
|
|
});
|
|
|
|
this.server.post(`/pki-test/issuer/some-issuer/sign-intermediate`, function (schema, req) {
|
|
const payload = JSON.parse(req.requestBody);
|
|
assert.strictEqual(payload.csr, 'example-data', 'Request made to correct endpoint on save');
|
|
return {
|
|
request_id: 'some-id',
|
|
data: {
|
|
serial_number: '31:52:b9:09:40',
|
|
ca_chain: ['-----BEGIN CERTIFICATE-----'],
|
|
issuing_ca: '-----BEGIN CERTIFICATE-----',
|
|
certificate: '-----BEGIN CERTIFICATE-----',
|
|
},
|
|
};
|
|
});
|
|
await click(selectors.saveButton);
|
|
assert.dom(selectors.formError).hasText('There is an error with this form.', 'Shows validation errors');
|
|
assert.dom(selectors.csrInput).hasClass('has-error-border');
|
|
assert.dom(selectors.fieldError).hasText('CSR is required.');
|
|
|
|
await fillIn(selectors.csrInput, 'example-data');
|
|
await click(selectors.saveButton);
|
|
[
|
|
{ label: 'Serial number' },
|
|
{ label: 'CA Chain', isCertificate: true },
|
|
{ label: 'Certificate', isCertificate: true },
|
|
{ label: 'Issuing CA', isCertificate: true },
|
|
].forEach(({ label, isCertificate }) => {
|
|
assert.dom(selectors.rowByName(label)).exists();
|
|
if (isCertificate) {
|
|
assert.dom(selectors.valueByName(label)).includesText('PEM Format', `${label} is isCertificate`);
|
|
} else {
|
|
assert.dom(selectors.valueByName(label)).hasText('31:52:b9:09:40', `Renders ${label}`);
|
|
assert.dom(`${selectors.valueByName(label)} a`).exists(`${label} is a link`);
|
|
}
|
|
});
|
|
});
|
|
});
|