mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-24 16:11:08 +02:00
* add rotate root route * add page component * add modal * fix modal image styling * add radio buttons * add jsonToCert function to pki parser * add verify function * add verify to details route * nest rotate-root under issuer/ * copy values from old root ca * pull detail info rows into a separate component * add type declaration files * add parsing error warning to rotate root component file * add comments * add capabilities to controller * update icon * revert issuer details * refactor pki info table rows * add parsedparameters to pki helper * add alert banner * update attrs, fix info rows * add endpoint to action router * update alert banner * hide toolbar from generate root display * add download buttons to toolbar * add banner getter * fix typo in issuer details * fix assertion * move alert banner after generating root to parent * rename issuer index route file * refactor routing so model can be passed from route * add confirmLeave and done button to use existin settings done form * rename serial number to differentiate between two types * fix links, update ids to issuerId not response id * update ts declaration * change variable names add comments * update existing tests * fix comment typo * add download button test * update serializer to change subject_serial_number to serial_number for backend * remove pageTitle getter * remove old arg * round 1 of testing complete.. * finish endpoint tests * finish component tests * move toolbars to parent route * add acceptance test for rotate route * add const to hold radio button string values * remove action, fix link
150 lines
5.8 KiB
JavaScript
150 lines
5.8 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 { setupEngine } from 'ember-engines/test-support';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
|
|
module('Integration | Component | ', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
setupEngine(hooks, 'pki');
|
|
setupMirage(hooks);
|
|
|
|
hooks.beforeEach(async function () {
|
|
this.owner.lookup('service:secretMountPath').update('pki-test');
|
|
this.store = this.owner.lookup('service:store');
|
|
this.model = this.owner
|
|
.lookup('service:store')
|
|
.createRecord('pki/action', { actionType: 'generate-csr' });
|
|
|
|
this.server.post('/sys/capabilities-self', () => ({
|
|
data: {
|
|
capabilities: ['root'],
|
|
'pki-test/issuers/generate/intermediate/exported': ['root'],
|
|
},
|
|
}));
|
|
});
|
|
|
|
test('it should render fields and save', async function (assert) {
|
|
assert.expect(9);
|
|
|
|
this.server.post('/pki-test/issuers/generate/intermediate/exported', (schema, req) => {
|
|
const payload = JSON.parse(req.requestBody);
|
|
assert.strictEqual(payload.common_name, 'foo', 'Request made to correct endpoint on save');
|
|
});
|
|
|
|
await render(hbs`<PkiGenerateCsr @model={{this.model}} @onComplete={{this.onComplete}} />`, {
|
|
owner: this.engine,
|
|
});
|
|
|
|
const fields = [
|
|
'type',
|
|
'commonName',
|
|
'excludeCnFromSans',
|
|
'format',
|
|
'subjectSerialNumber',
|
|
'addBasicConstraints',
|
|
];
|
|
fields.forEach((key) => {
|
|
assert.dom(`[data-test-input="${key}"]`).exists(`${key} form field renders`);
|
|
});
|
|
|
|
assert.dom('[data-test-toggle-group]').exists({ count: 3 }, 'Toggle groups render');
|
|
|
|
await fillIn('[data-test-input="type"]', 'exported');
|
|
await fillIn('[data-test-input="commonName"]', 'foo');
|
|
await click('[data-test-save]');
|
|
|
|
const savedRecord = this.store.peekAll('pki/action').firstObject;
|
|
assert.false(savedRecord.isNew, 'record is saved');
|
|
});
|
|
|
|
test('it should display validation errors', async function (assert) {
|
|
assert.expect(4);
|
|
|
|
this.onCancel = () => assert.ok(true, 'onCancel action fires');
|
|
|
|
await render(hbs`<PkiGenerateCsr @model={{this.model}} @onCancel={{this.onCancel}} />`, {
|
|
owner: this.engine,
|
|
});
|
|
|
|
await click('[data-test-save]');
|
|
|
|
assert
|
|
.dom('[data-test-field-validation="type"]')
|
|
.hasText('Type is required.', 'Type validation error renders');
|
|
assert
|
|
.dom('[data-test-field="commonName"] [data-test-inline-alert]')
|
|
.hasText('Common name is required.', 'Common name validation error renders');
|
|
assert.dom('[data-test-alert]').hasText('There are 2 errors with this form.', 'Alert renders');
|
|
|
|
await click('[data-test-cancel]');
|
|
});
|
|
|
|
test('it should show generated CSR for type=exported', async function (assert) {
|
|
assert.expect(6);
|
|
this.model.id = '1235-someId';
|
|
this.model.csr = '-----BEGIN CERTIFICATE REQUEST-----...-----END CERTIFICATE REQUEST-----';
|
|
this.model.keyId = '9179de78-1275-a1cf-ebb0-a4eb2e376636';
|
|
this.model.privateKey = '-----BEGIN RSA PRIVATE KEY-----...-----END RSA PRIVATE KEY-----';
|
|
this.model.privateKeyType = 'rsa';
|
|
this.onComplete = () => assert.ok(true, 'onComplete action fires');
|
|
|
|
await render(hbs`<PkiGenerateCsr @model={{this.model}} @onComplete={{this.onComplete}} />`, {
|
|
owner: this.engine,
|
|
});
|
|
assert
|
|
.dom('[data-test-alert-banner="alert"]')
|
|
.hasText(
|
|
'Next steps Copy the CSR below for a parent issuer to sign and then import the signed certificate back into this mount. The private_key is only available once. Make sure you copy and save it now.',
|
|
'renders Next steps alert banner'
|
|
);
|
|
assert
|
|
.dom('[data-test-value-div="CSR"] [data-test-masked-input] button')
|
|
.hasAttribute('data-clipboard-text', this.model.csr, 'it renders copyable csr');
|
|
assert
|
|
.dom('[data-test-value-div="Key ID"] button')
|
|
.hasAttribute('data-clipboard-text', this.model.keyId, 'it renders copyable key_id');
|
|
assert
|
|
.dom('[data-test-value-div="Private key"] [data-test-masked-input] button')
|
|
.hasAttribute('data-clipboard-text', this.model.privateKey, 'it renders copyable private_key');
|
|
assert
|
|
.dom('[data-test-value-div="Private key type"]')
|
|
.hasText(this.model.privateKeyType, 'renders private_key_type');
|
|
await click('[data-test-done]');
|
|
});
|
|
|
|
test('it should show generated CSR for type=internal', async function (assert) {
|
|
assert.expect(5);
|
|
this.model.id = '1235-someId';
|
|
this.model.csr = '-----BEGIN CERTIFICATE REQUEST-----...-----END CERTIFICATE REQUEST-----';
|
|
this.model.keyId = '9179de78-1275-a1cf-ebb0-a4eb2e376636';
|
|
this.onComplete = () => {};
|
|
|
|
await render(hbs`<PkiGenerateCsr @model={{this.model}} @onComplete={{this.onComplete}} />`, {
|
|
owner: this.engine,
|
|
});
|
|
assert
|
|
.dom('[data-test-alert-banner="alert"]')
|
|
.hasText(
|
|
'Next steps Copy the CSR below for a parent issuer to sign and then import the signed certificate back into this mount.',
|
|
'renders Next steps alert banner'
|
|
);
|
|
assert
|
|
.dom('[data-test-value-div="CSR"] [data-test-masked-input] button')
|
|
.hasAttribute('data-clipboard-text', this.model.csr, 'it renders copyable csr');
|
|
assert
|
|
.dom('[data-test-value-div="Key ID"] button')
|
|
.hasAttribute('data-clipboard-text', this.model.keyId, 'it renders copyable key_id');
|
|
assert.dom('[data-test-value-div="Private key"]').hasText('internal', 'does not render private key');
|
|
assert
|
|
.dom('[data-test-value-div="Private key type"]')
|
|
.hasText('internal', 'does not render private key type');
|
|
});
|
|
});
|