open-vault/ui/tests/integration/components/pki/pki-generate-toggle-groups-test.js
claire bontempo 069b00b031
UI: pki rotate root cert (#19739)
* 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
2023-03-31 15:47:23 -06:00

132 lines
5 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, render, settled } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupEngine } from 'ember-engines/test-support';
const selectors = {
keys: '[data-test-toggle-group="Key parameters"]',
sanOptions: '[data-test-toggle-group="Subject Alternative Name (SAN) Options"]',
subjectFields: '[data-test-toggle-group="Additional subject fields"]',
toggleByName: (name) => `[data-test-toggle-group="${name}"]`,
};
module('Integration | Component | PkiGenerateToggleGroups', function (hooks) {
setupRenderingTest(hooks);
setupEngine(hooks, 'pki');
hooks.beforeEach(async function () {
this.model = this.owner
.lookup('service:store')
.createRecord('pki/action', { actionType: 'generate-root' });
});
test('it should render key parameters', async function (assert) {
await render(hbs`<PkiGenerateToggleGroups @model={{this.model}} />`, { owner: this.engine });
assert.dom(selectors.keys).hasText('Key parameters', 'Key parameters group renders');
await click(selectors.keys);
assert
.dom('[data-test-toggle-group-description]')
.hasText(
'Please choose a type to see key parameter options.',
'Placeholder renders for key params when type is not selected'
);
const fields = {
exported: ['keyName', 'keyType', 'keyBits', 'privateKeyFormat'],
internal: ['keyName', 'keyType', 'keyBits'],
existing: ['keyRef'],
kms: ['keyName', 'managedKeyName', 'managedKeyId'],
};
for (const type in fields) {
this.model.type = type;
await settled();
assert
.dom('[data-test-field]')
.exists({ count: fields[type].length }, `Correct number of fields render for ${type} type`);
fields[type].forEach((key) => {
assert.dom(`[data-test-input="${key}"]`).exists(`${key} input renders for ${type} type`);
});
}
});
test('it should render SAN options', async function (assert) {
await render(hbs`<PkiGenerateToggleGroups @model={{this.model}} />`, { owner: this.engine });
assert
.dom(selectors.sanOptions)
.hasText('Subject Alternative Name (SAN) Options', 'SAN options group renders');
await click(selectors.sanOptions);
const fields = ['excludeCnFromSans', 'subjectSerialNumber', 'altNames', 'ipSans', 'uriSans', 'otherSans'];
assert.dom('[data-test-field]').exists({ count: 6 }, `Correct number of fields render`);
fields.forEach((key) => {
assert.dom(`[data-test-input="${key}"]`).exists(`${key} input renders for generate-root actionType`);
});
this.model.actionType = 'generate-csr';
await settled();
assert
.dom('[data-test-field]')
.exists({ count: 4 }, 'Correct number of fields render for generate-csr actionType');
assert
.dom('[data-test-input="excludeCnFromSans"]')
.doesNotExist('excludeCnFromSans field hidden for generate-csr actionType');
assert
.dom('[data-test-input="serialNumber"]')
.doesNotExist('serialNumber field hidden for generate-csr actionType');
});
test('it should render additional subject fields', async function (assert) {
await render(hbs`<PkiGenerateToggleGroups @model={{this.model}} />`, { owner: this.engine });
assert.dom(selectors.subjectFields).hasText('Additional subject fields', 'SAN options group renders');
await click(selectors.subjectFields);
const fields = ['ou', 'organization', 'country', 'locality', 'province', 'streetAddress', 'postalCode'];
assert.dom('[data-test-field]').exists({ count: fields.length }, 'Correct number of fields render');
fields.forEach((key) => {
assert.dom(`[data-test-input="${key}"]`).exists(`${key} input renders`);
});
});
test('it should render groups according to the passed @groups', async function (assert) {
assert.expect(11);
const fieldsA = ['ou', 'organization'];
const fieldsZ = ['country', 'locality', 'province', 'streetAddress', 'postalCode'];
this.set('groups', {
'Group A': fieldsA,
'Group Z': fieldsZ,
});
await render(hbs`<PkiGenerateToggleGroups @model={{this.model}} @groups={{this.groups}} />`, {
owner: this.engine,
});
assert.dom(selectors.toggleByName('Group A')).hasText('Group A', 'First group renders');
assert.dom(selectors.toggleByName('Group Z')).hasText('Group Z', 'Second group renders');
await click(selectors.toggleByName('Group A'));
assert.dom('[data-test-field]').exists({ count: fieldsA.length }, 'Correct number of fields render');
fieldsA.forEach((key) => {
assert.dom(`[data-test-input="${key}"]`).exists(`${key} input renders`);
});
await click(selectors.toggleByName('Group Z'));
assert.dom('[data-test-field]').exists({ count: fieldsZ.length }, 'Correct number of fields render');
fieldsZ.forEach((key) => {
assert.dom(`[data-test-input="${key}"]`).exists(`${key} input renders`);
});
});
});