vault/ui/tests/integration/components/pki/config-pki-test.js
Jordan Reimer d4766766f2
Ember Upgrade to 4.4 (#17086)
* runs ember-cli-update to 4.4.0

* updates yarn.lock

* updates dependencies causing runtime errors (#17135)

* Inject Store Service When Accessed Implicitly (#17345)

* adds codemod for injecting store service

* adds custom babylon parser with decorators-legacy plugin for jscodeshift transforms

* updates inject-store-service codemod to only look for .extend object expressions and adds recast options

* runs inject-store-service codemod on js files

* replace query-params helper with hash (#17404)

* Updates/removes dependencies throwing errors in Ember 4.4 (#17396)

* updates ember-responsive to latest

* updates ember-composable-helpers to latest and uses includes helper since contains was removed

* updates ember-concurrency to latest

* updates ember-cli-clipboard to latest

* temporary workaround for toolbar-link component throwing errors for using params arg with LinkTo

* adds missing store injection to auth configure route

* fixes issue with string-list component throwing error for accessing prop in same computation

* fixes non-iterable query params issue in mfa methods controller

* refactors field-to-attrs to handle belongsTo rather than fragments

* converts mount-config fragment to belongsTo on auth-method model

* removes ember-api-actions and adds tune method to auth-method adapter

* converts cluster replication attributes from fragment to relationship

* updates ember-data, removes ember-data-fragments and updates yarn to latest

* removes fragments from secret-engine model

* removes fragment from test-form-model

* removes commented out code

* minor change to inject-store-service codemod and runs again on js files

* Remove LinkTo positional params (#17421)

* updates ember-cli-page-object to latest version

* update toolbar-link to support link-to args and not positional params

* adds replace arg to toolbar-link component

* Clean up js lint errors (#17426)

* replaces assert.equal to assert.strictEqual

* update eslint no-console to error and disables invididual intended uses of console

* cleans up hbs lint warnings (#17432)

* Upgrade bug and test fixes (#17500)

* updates inject-service codemod to take arg for service name and runs for flashMessages service

* fixes hbs lint error after merging main

* fixes flash messages

* updates more deps

* bug fixes

* test fixes

* updates ember-cli-content-security-policy and prevents default form submission throwing errors

* more bug and test fixes

* removes commented out code

* fixes issue with code-mirror modifier sending change event on setup causing same computation error

* Upgrade Clean Up (#17543)

* updates deprecation workflow and filter

* cleans up build errors, removes unused ivy-codemirror and sass and updates ember-cli-sass and node-sass to latest

* fixes control groups test that was skipped after upgrade

* updates control group service tests

* addresses review feedback

* updates control group service handleError method to use router.currentURL rather that transition.intent.url

* adds changelog entry
2022-10-18 09:46:02 -06:00

147 lines
6.0 KiB
JavaScript

import { resolve } from 'rsvp';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { click, render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { create } from 'ember-cli-page-object';
import configPki from 'vault/tests/pages/components/pki/config-pki';
const component = create(configPki);
module('Integration | Component | config pki', function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(async function () {
this.owner.lookup('service:flash-messages').registerTypes(['success']);
this.store = this.owner.lookup('service:store');
this.config = await this.store.createRecord('pki/pki-config');
this.mockConfigSave = function (saveFn) {
const { tidyAttrs, crlAttrs, urlsAttrs } = this.config;
return {
save: saveFn,
rollbackAttributes: () => {},
tidyAttrs,
crlAttrs,
urlsAttrs,
set: () => {},
};
};
});
const setupAndRender = async function (context, config, section = 'tidy') {
context.set('config', config);
context.set('section', section);
await context.render(hbs`<Pki::ConfigPki @section={{this.section}} @config={{this.config}} />`);
};
test('it renders tidy section', async function (assert) {
await setupAndRender(this, this.config);
assert.ok(component.text.startsWith('You can tidy up the backend'));
assert.notOk(component.hasTitle, 'No title for tidy section');
assert.strictEqual(component.fields.length, 3, 'renders all three tidy fields');
assert.ok(component.fields.objectAt(0).labelText, 'Tidy the Certificate Store');
assert.ok(component.fields.objectAt(1).labelText, 'Tidy the Revocation List (CRL)');
assert.ok(component.fields.objectAt(1).labelText, 'Safety buffer');
});
test('it renders crl section', async function (assert) {
await setupAndRender(this, this.config, 'crl');
assert.false(this.config.disable, 'CRL config defaults disable=false');
assert.ok(component.hasTitle, 'renders form title');
assert.strictEqual(component.title, 'Certificate Revocation List (CRL) config');
assert.ok(
component.text.startsWith('Set the duration for which the generated CRL'),
'renders form subtext'
);
assert
.dom('[data-test-toggle-label]')
.hasText('CRL building enabled The CRL will expire after', 'renders enabled field title and subtext');
assert.dom('[data-test-input="expiry"] input').isChecked('defaults to enabling CRL build');
assert.dom('[data-test-ttl-value="CRL building enabled"]').hasValue('3', 'default value is 3 (72h)');
assert.dom('[data-test-select="ttl-unit"]').hasValue('d', 'default unit value is days');
await click('[data-test-input="expiry"] input');
assert
.dom('[data-test-toggle-label]')
.hasText('CRL building disabled The CRL will not be built.', 'renders disabled text when toggled off');
// assert 'disable' attr on pki-config model updates with toggle
assert.true(this.config.disable, 'when toggled off, sets CRL config to disable=true');
await click('[data-test-input="expiry"] input');
assert
.dom('[data-test-toggle-label]')
.hasText('CRL building enabled The CRL will expire after', 'toggles back to enabled text');
assert.false(this.config.disable, 'CRL config toggles back to disable=false');
});
test('it renders urls section', async function (assert) {
await setupAndRender(this, this.config, 'urls');
assert.notOk(component.hasTitle, 'No title for urls section');
assert.strictEqual(component.fields.length, 3);
assert.ok(component.fields.objectAt(0).labelText, 'Issuing certificates');
assert.ok(component.fields.objectAt(1).labelText, 'CRL Distribution Points');
assert.ok(component.fields.objectAt(2).labelText, 'OCSP Servers');
});
test('it calls save with the correct arguments for tidy', async function (assert) {
assert.expect(3);
const section = 'tidy';
this.set('onRefresh', () => {
assert.ok(true, 'refresh called');
});
this.set(
'config',
this.mockConfigSave((options) => {
assert.strictEqual(options.adapterOptions.method, section, 'method passed to save');
assert.deepEqual(
options.adapterOptions.fields,
['tidyCertStore', 'tidyRevocationList', 'safetyBuffer'],
'tidy fields passed to save'
);
return resolve();
})
);
this.set('section', section);
await render(
hbs`<Pki::ConfigPki @section={{this.section}} @config={{this.config}} @onRefresh={{this.onRefresh}} />`
);
component.submit();
});
test('it calls save with the correct arguments for crl', async function (assert) {
assert.expect(3);
const section = 'crl';
this.set('onRefresh', () => {
assert.ok(true, 'refresh called');
});
this.set(
'config',
this.mockConfigSave((options) => {
assert.strictEqual(options.adapterOptions.method, section, 'method passed to save');
assert.deepEqual(options.adapterOptions.fields, ['expiry', 'disable'], 'CRL fields passed to save');
return resolve();
})
);
this.set('section', section);
await render(
hbs`<Pki::ConfigPki @section={{this.section}} @config={{this.config}} @onRefresh={{this.onRefresh}} />`
);
component.submit();
});
test('it correctly sets toggle when initial CRL config is disable=true', async function (assert) {
assert.expect(3);
// change default config attrs
let configDisabled = this.config;
configDisabled.expiry = '1m';
configDisabled.disable = true;
await setupAndRender(this, configDisabled, 'crl');
assert.dom('[data-test-input="expiry"] input').isNotChecked('toggle disabled when CRL config disabled');
await click('[data-test-input="expiry"] input');
assert
.dom('[data-test-ttl-value="CRL building enabled"]')
.hasValue('1', 'when toggled on shows last set expired value');
assert.dom('[data-test-select="ttl-unit"]').hasValue('m', 'when toggled back on shows last set unit');
});
});