vault/ui/tests/integration/components/pki/pki-tidy-form-test.js
claire bontempo ec6a1f2934
UI: pki auto-tidy views (#20685)
* UI: plumbing for pki tidy work (#20611)

* update tidy model

* Dynamic group on tidy based on version

* UI: VAULT-16261 PKI autotidy config view (#20641)

* UI: VAULT-16203 tidy status page (#20635)

* ui: pki tidy form (#20630)

* order routes to match tabs

* add tidy routes

* add tidy-status page component

* update routes rename edit to configure, remove manage

* add page component to route template

* add comment

* finish routing

* change to queryRecord, delete old tidy file

* remove findRecord

* fix serializer name

* tidy.index only needs controller empty state logic

* build form and page components

* update tidy model

* alphabetize!

* revert model changes

* finish adapter

* move form out of page folder in tests

* refactor to accommodate model changes from chelseas pr

* WIP tests

* reuse shared fields in model

* finish tests

* update model hook and breadcrumbs

* remove subtext for checkbox

* fix tests add ACME fields

* Update ui/app/adapters/pki/tidy.js

* Update ui/app/adapters/pki/tidy.js

* refactor intervalDuration using feedback suggested

* move errors to second line, inside conditional brackets

* add ternary operator to allByKey attr

* surface error message

* make polling request longer

* UI: VAULT-16368 pki tidy custom method (#20696)

* ui: adds empty state and updates modal (#20695)

* add empty state to status page

* update tidy modal

* conditionally change cancel transition route for auto tidy form

* teeny copy update

* organize tidy-status conditoionals

* a couple more template cleanups

* fix conditional, change to settings

* UI: VAULT-16367 VAULT-16378 Tidy acceptance tests + tidy toolbar cleanup (#20698)

* update copy

* move tidyRevokedCertIssuerAssociations up to applicable section

* add tidy info to readme

* update copy

* UI: Add tidy as a tab to the error route (#20723)

* small cleanup items

* fix prettier

* cancel polling when we leave tidy.index (status view)

* revert changes to declaration file

* remove space

---------

Co-authored-by: Chelsea Shaw <cshaw@hashicorp.com>
Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com>
Co-authored-by: Kianna <30884335+kiannaquach@users.noreply.github.com>
2023-05-23 23:05:15 +00:00

316 lines
10 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { click, render, fillIn } 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';
import { SELECTORS } from 'vault/tests/helpers/pki/page/pki-tidy-form';
module('Integration | Component | pki tidy form', function (hooks) {
setupRenderingTest(hooks);
setupEngine(hooks, 'pki');
setupMirage(hooks);
hooks.beforeEach(function () {
this.store = this.owner.lookup('service:store');
this.version = this.owner.lookup('service:version');
this.version.version = '1.14.1+ent';
this.server.post('/sys/capabilities-self', () => {});
this.onSave = () => {};
this.onCancel = () => {};
this.manualTidy = this.store.createRecord('pki/tidy', { backend: 'pki-manual-tidy' });
this.store.pushPayload('pki/tidy', {
modelName: 'pki/tidy',
id: 'pki-auto-tidy',
});
this.autoTidy = this.store.peekRecord('pki/tidy', 'pki-auto-tidy');
});
test('it hides or shows fields depending on auto-tidy toggle', async function (assert) {
assert.expect(37);
this.version.version = '1.14.1+ent';
const sectionHeaders = [
'Universal operations',
'ACME operations',
'Issuer operations',
'Cross-cluster operations',
];
await render(
hbs`
<PkiTidyForm
@tidy={{this.autoTidy}}
@tidyType="auto"
@onSave={{this.onSave}}
@onCancel={{this.onCancel}}
/>
`,
{ owner: this.engine }
);
assert.dom(SELECTORS.toggleInput('intervalDuration')).isNotChecked('Automatic tidy is disabled');
assert.dom(`[data-test-ttl-form-label="Automatic tidy disabled"]`).exists('renders disabled label text');
this.autoTidy.eachAttribute((attr) => {
if (attr === 'enabled' || attr === 'intervalDuration') return;
assert.dom(SELECTORS.inputByAttr(attr)).doesNotExist(`does not render ${attr} when auto tidy disabled`);
});
sectionHeaders.forEach((group) => {
assert.dom(SELECTORS.tidySectionHeader(group)).doesNotExist(`does not render ${group} header`);
});
// ENABLE AUTO TIDY
await click(SELECTORS.toggleInput('intervalDuration'));
assert.dom(SELECTORS.toggleInput('intervalDuration')).isChecked('Automatic tidy is enabled');
assert.dom(`[data-test-ttl-form-label="Automatic tidy enabled"]`).exists('renders enabled text');
this.autoTidy.eachAttribute((attr) => {
const skipFields = ['enabled', 'tidyAcme', 'intervalDuration'];
if (skipFields.includes(attr)) return; // combined with duration ttl or asserted elsewhere
assert.dom(SELECTORS.inputByAttr(attr)).exists(`renders ${attr} when auto tidy enabled`);
});
sectionHeaders.forEach((group) => {
assert.dom(SELECTORS.tidySectionHeader(group)).exists(`renders ${group} header`);
});
});
test('it renders all attribute fields, including enterprise', async function (assert) {
assert.expect(25);
this.version.version = '1.14.1+ent';
this.autoTidy.enabled = true;
const skipFields = ['enabled', 'tidyAcme', 'intervalDuration']; // combined with duration ttl or asserted separately
await render(
hbs`
<PkiTidyForm
@tidy={{this.autoTidy}}
@tidyType="auto"
@onSave={{this.onSave}}
@onCancel={{this.onCancel}}
/>
`,
{ owner: this.engine }
);
this.autoTidy.eachAttribute((attr) => {
if (skipFields.includes(attr)) return;
assert.dom(SELECTORS.inputByAttr(attr)).exists(`renders ${attr} for auto tidyType`);
});
await render(
hbs`
<PkiTidyForm
@tidy={{this.manualTidy}}
@tidyType="manual"
@onSave={{this.onSave}}
@onCancel={{this.onCancel}}
/>
`,
{ owner: this.engine }
);
assert.dom(SELECTORS.toggleInput('intervalDuration')).doesNotExist('hides automatic tidy toggle');
this.manualTidy.eachAttribute((attr) => {
if (skipFields.includes(attr)) return;
assert.dom(SELECTORS.inputByAttr(attr)).exists(`renders ${attr} for manual tidyType`);
});
});
test('it hides enterprise fields for OSS', async function (assert) {
assert.expect(7);
this.version.version = '1.14.1';
this.autoTidy.enabled = true;
const enterpriseFields = [
'tidyRevocationQueue',
'tidyCrossClusterRevokedCerts',
'revocationQueueSafetyBuffer',
];
// tidyType = auto
await render(
hbs`
<PkiTidyForm
@tidy={{this.autoTidy}}
@tidyType="auto"
@onSave={{this.onSave}}
@onCancel={{this.onCancel}}
/>
`,
{ owner: this.engine }
);
assert
.dom(SELECTORS.tidySectionHeader('Cross-cluster operations'))
.doesNotExist(`does not render ent header`);
enterpriseFields.forEach((entAttr) => {
assert.dom(SELECTORS.inputByAttr(entAttr)).doesNotExist(`does not render ${entAttr} for auto tidyType`);
});
// tidyType = manual
await render(
hbs`
<PkiTidyForm
@tidy={{this.manualTidy}}
@tidyType="manual"
@onSave={{this.onSave}}
@onCancel={{this.onCancel}}
/>
`,
{ owner: this.engine }
);
enterpriseFields.forEach((entAttr) => {
assert
.dom(SELECTORS.inputByAttr(entAttr))
.doesNotExist(`does not render ${entAttr} for manual tidyType`);
});
});
test('it should change the attributes on the model', async function (assert) {
assert.expect(12);
this.server.post('/pki-auto-tidy/config/auto-tidy', (schema, req) => {
assert.propEqual(
JSON.parse(req.requestBody),
{
acme_account_safety_buffer: '60s',
enabled: true,
interval_duration: '10s',
issuer_safety_buffer: '20s',
pause_duration: '30s',
revocation_queue_safety_buffer: '40s',
safety_buffer: '50s',
tidy_acme: true,
tidy_cert_store: true,
tidy_cross_cluster_revoked_certs: true,
tidy_expired_issuers: true,
tidy_move_legacy_ca_bundle: true,
tidy_revocation_queue: true,
tidy_revoked_cert_issuer_associations: true,
tidy_revoked_certs: true,
},
'response contains updated model values'
);
});
await render(
hbs`
<PkiTidyForm
@tidy={{this.autoTidy}}
@tidyType="auto"
@onSave={{this.onSave}}
@onCancel={{this.onCancel}}
/>
`,
{ owner: this.engine }
);
assert.dom(SELECTORS.toggleInput('intervalDuration')).isNotChecked('Automatic tidy is disabled');
assert.dom(SELECTORS.toggleLabel('Automatic tidy disabled')).exists('auto tidy has disabled label');
assert.false(this.autoTidy.enabled, 'enabled is false on model');
// enable auto-tidy
await click(SELECTORS.toggleInput('intervalDuration'));
await fillIn(SELECTORS.intervalDuration, 10);
assert.dom(SELECTORS.toggleInput('intervalDuration')).isChecked('toggle enabled auto tidy');
assert.dom(SELECTORS.toggleLabel('Automatic tidy enabled')).exists('auto tidy has enabled label');
assert.dom(SELECTORS.toggleInput('acmeAccountSafetyBuffer')).isNotChecked('ACME tidy is disabled');
assert.dom(SELECTORS.toggleLabel('Tidy ACME disabled')).exists('ACME label has correct disabled text');
assert.false(this.autoTidy.tidyAcme, 'tidyAcme is false on model');
await click(SELECTORS.toggleInput('acmeAccountSafetyBuffer'));
await fillIn(SELECTORS.acmeAccountSafetyBuffer, 60);
assert.true(this.autoTidy.tidyAcme, 'tidyAcme toggles to true');
const fillInValues = {
issuerSafetyBuffer: 20,
pauseDuration: 30,
revocationQueueSafetyBuffer: 40,
safetyBuffer: 50,
};
this.autoTidy.eachAttribute(async (attr, { type }) => {
const skipFields = ['enabled', 'tidyAcme', 'intervalDuration', 'acmeAccountSafetyBuffer']; // combined with duration ttl or asserted separately
if (skipFields.includes(attr)) return;
if (type === 'boolean') {
await click(SELECTORS.inputByAttr(attr));
}
if (type === 'string') {
await fillIn(SELECTORS.toggleInput(attr), `${fillInValues[attr]}`);
}
});
assert.dom(SELECTORS.toggleInput('acmeAccountSafetyBuffer')).isChecked('ACME tidy is enabled');
assert.dom(SELECTORS.toggleLabel('Tidy ACME enabled')).exists('ACME label has correct enabled text');
await click(SELECTORS.tidySave);
});
test('it updates auto-tidy config', async function (assert) {
assert.expect(4);
this.server.post('/pki-auto-tidy/config/auto-tidy', (schema, req) => {
assert.ok(true, 'Request made to update auto-tidy');
assert.propEqual(
JSON.parse(req.requestBody),
{
enabled: false,
tidy_acme: false,
},
'response contains auto-tidy params'
);
});
this.onSave = () => assert.ok(true, 'onSave callback fires on save success');
this.onCancel = () => assert.ok(true, 'onCancel callback fires on save success');
await render(
hbs`
<PkiTidyForm
@tidy={{this.autoTidy}}
@tidyType="auto"
@onSave={{this.onSave}}
@onCancel={{this.onCancel}}
/>
`,
{ owner: this.engine }
);
await click(SELECTORS.tidySave);
await click(SELECTORS.tidyCancel);
});
test('it saves and performs manual tidy', async function (assert) {
assert.expect(4);
this.server.post('/pki-manual-tidy/tidy', (schema, req) => {
assert.ok(true, 'Request made to perform manual tidy');
assert.propEqual(
JSON.parse(req.requestBody),
{ tidy_acme: false },
'response contains manual tidy params'
);
});
this.onSave = () => assert.ok(true, 'onSave callback fires on save success');
this.onCancel = () => assert.ok(true, 'onCancel callback fires on save success');
await render(
hbs`
<PkiTidyForm
@tidy={{this.manualTidy}}
@tidyType="manual"
@onSave={{this.onSave}}
@onCancel={{this.onCancel}}
/>
`,
{ owner: this.engine }
);
await click(SELECTORS.tidySave);
await click(SELECTORS.tidyCancel);
});
});