mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-17 20:17:00 +02:00
* refactor parser to pull serial number from subject * refactor pki parser * uninstall pvtutils * remove hideFormSection as attr * remove hideFormSection as attr * add string-list * test removing issueDate * update tests * final answer - make number types * change to unix time - since valueOf() is typically used internally * add algo mapping * add comment to complete in followon * add attrs to pki parser * add conditional operands so parser continues when values dont exist * add error handling WIP * finish tests, add error handling * revert to helper * move helper to util * add parseSubject test * finish tests * move certs to pki helper file * wrap parsing functions in try...catch
121 lines
5.1 KiB
JavaScript
121 lines
5.1 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
import { render, click, fillIn, find } from '@ember/test-helpers';
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
import { setupEngine } from 'ember-engines/test-support';
|
|
import { SELECTORS } from 'vault/tests/helpers/pki/pki-role-form';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
|
|
module('Integration | Component | pki-role-form', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
setupMirage(hooks);
|
|
setupEngine(hooks, 'pki'); // https://github.com/ember-engines/ember-engines/pull/653
|
|
|
|
hooks.beforeEach(function () {
|
|
this.store = this.owner.lookup('service:store');
|
|
this.model = this.store.createRecord('pki/role');
|
|
this.model.backend = 'pki';
|
|
});
|
|
|
|
test('it should render default fields and toggle groups', async function (assert) {
|
|
assert.expect(13);
|
|
await render(
|
|
hbs`
|
|
<PkiRoleForm
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
/>
|
|
`,
|
|
{ owner: this.engine }
|
|
);
|
|
assert.dom(SELECTORS.issuerRef).exists('shows form-field issuer ref');
|
|
assert.dom(SELECTORS.backdateValidity).exists('shows form-field backdate validity');
|
|
assert.dom(SELECTORS.customTtl).exists('shows custom yielded form field');
|
|
assert.dom(SELECTORS.maxTtl).exists('shows form-field max ttl');
|
|
assert.dom(SELECTORS.generateLease).exists('shows form-field generateLease');
|
|
assert.dom(SELECTORS.noStore).exists('shows form-field no store');
|
|
assert.dom(SELECTORS.addBasicConstraints).exists('shows form-field add basic constraints');
|
|
assert.dom(SELECTORS.domainHandling).exists('shows form-field group add domain handling');
|
|
assert.dom(SELECTORS.keyParams).exists('shows form-field group key params');
|
|
assert.dom(SELECTORS.keyUsage).exists('shows form-field group key usage');
|
|
assert.dom(SELECTORS.policyIdentifiers).exists('shows form-field group policy identifiers');
|
|
assert.dom(SELECTORS.san).exists('shows form-field group SAN');
|
|
assert.dom(SELECTORS.additionalSubjectFields).exists('shows form-field group additional subject fields');
|
|
});
|
|
|
|
test('it should save a new pki role with various options selected', async function (assert) {
|
|
// Key usage, Key params and Not valid after options are tested in their respective component tests
|
|
assert.expect(10);
|
|
this.server.post(`/${this.model.backend}/roles/test-role`, (schema, req) => {
|
|
assert.ok(true, 'Request made to save role');
|
|
const request = JSON.parse(req.requestBody);
|
|
const roleName = request.name;
|
|
const allowedDomainsTemplate = request.allowed_domains_template;
|
|
const policyIdentifiers = request.policy_identifiers;
|
|
const allowedUriSansTemplate = request.allow_uri_sans_template;
|
|
const allowedSerialNumbers = request.allowed_serial_numbers;
|
|
|
|
assert.strictEqual(roleName, 'test-role', 'correctly sends the role name');
|
|
assert.true(allowedDomainsTemplate, 'correctly sends allowed_domains_template');
|
|
assert.strictEqual(policyIdentifiers[0], 'some-oid', 'correctly sends policy_identifiers');
|
|
assert.true(allowedUriSansTemplate, 'correctly sends allowed_uri_sans_template');
|
|
assert.strictEqual(
|
|
allowedSerialNumbers[0],
|
|
'some-serial-number',
|
|
'correctly sends allowed_serial_numbers'
|
|
);
|
|
return {};
|
|
});
|
|
|
|
this.onSave = () => assert.ok(true, 'onSave callback fires on save success');
|
|
|
|
await render(
|
|
hbs`
|
|
<PkiRoleForm
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
/>
|
|
`,
|
|
{ owner: this.engine }
|
|
);
|
|
|
|
await click(SELECTORS.roleCreateButton);
|
|
assert
|
|
.dom(SELECTORS.roleName)
|
|
.hasClass('has-error-border', 'shows border error on role name field when no role name is submitted');
|
|
assert
|
|
.dom('[data-test-inline-error-message]')
|
|
.includesText('Name is required.', 'show correct error message');
|
|
|
|
await fillIn(SELECTORS.roleName, 'test-role');
|
|
await click('[data-test-input="addBasicConstraints"]');
|
|
await click(SELECTORS.domainHandling);
|
|
await click('[data-test-input="allowedDomainsTemplate"]');
|
|
await click(SELECTORS.policyIdentifiers);
|
|
await fillIn('[data-test-input="policyIdentifiers"] [data-test-string-list-input="0"]', 'some-oid');
|
|
await click(SELECTORS.san);
|
|
await click('[data-test-input="allowUriSansTemplate"]');
|
|
await click(SELECTORS.additionalSubjectFields);
|
|
await fillIn(
|
|
'[data-test-input="allowedSerialNumbers"] [data-test-string-list-input="0"]',
|
|
'some-serial-number'
|
|
);
|
|
await click(SELECTORS.keyUsage);
|
|
// check is flexbox by checking the height of the box
|
|
const groupBoxHeight = find('[data-test-toggle-div="Key usage"]').clientHeight;
|
|
assert.strictEqual(
|
|
groupBoxHeight,
|
|
567,
|
|
'renders the correct height of the box element if the component is rending as a flexbox'
|
|
);
|
|
await click(SELECTORS.roleCreateButton);
|
|
});
|
|
|
|
/* FUTURE TEST TODO:
|
|
* it should update role
|
|
* it should unload the record on cancel
|
|
*/
|
|
});
|