vault/ui/tests/integration/components/pki/pki-generate-toggle-groups-test.js
hashicorp-copywrite[bot] 0b12cdcfd1
[COMPLIANCE] License changes (#22290)
* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License.

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUS-1.1

* Fix test that expected exact offset on hcl file

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
2023-08-10 18:14:03 -07:00

132 lines
5.0 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
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`);
});
});
});