mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
* UI: [VAULT-21521] Initial config-ui engine and routes set up (#23922) * UI: [VAULT-21526] Create adapter, serializer, and model files (#23947) * UI: [VAULT-21588] Add Custom Messages to the sidebar (#23946) * UI: [VAULT-21527] Mirage setup (#24000) * UI: [VAULT-21530] Custom Messages List View w/ Pagination and LazyPaginatedQuery (#24133) * UI: Add list to adapter query param (#24187) * UI: [VAULT-21532] Create message (#24407) * WIP create message * Add breadcrumns * Create and edit form * Add save to create/edit form * Add cancel and todo * Fix cancel route * Fix breadcrumb label to be title case * add start time logic * Update breadcrumb * Fix breadcrumbs and merge conflict test * Update create form description * Fix sidenav so it always highlights * Fix up forms * Mostly working create form * Form cleanup * Fix link title and href form fields * Default startTime * Fix messages * Update dropdown to use the updated ConfirmAction component * Update create and edit form * Add wip tests * Fix breadcrumb formatter * Comment out test * Update create message test * Update more tests * Add comment for fixing date on edit * Update Message form * Code cleanup! * Add validation tests * Remove authenticated from route model * SOme more code cleanup * Add controller so authenticated is parsed * Working radio buttons * Use an object instead of arrays * Wip date form * Fix license headers * Fix license headers addition of files * Fix copyright format issues and clean up code * Fix tests * Rename FormField radio getter and ay11 improvements * Address feedback * Fix specific date so it remembers the values * Address feedback! * Update more form fields * Use formfield action instead * Update to every * Update syntax of onchange * Fix tests * Update willDestroy so it doesnt break tests * Remove set and brodcast datetimelocal * Put FormField back the way it was in favor of putting FormField to a seperate PR * Remove getter in formfield component file * Address more feedback * Put back test * Update datetime string format var name and location * UI: [VAULT-21534 VAULT-21533 VAULT-21536] edit, preview, and delete custom message (#24603) * Working edit * VAULT-21536 update delete message and create/update flash message * VAULT-21533 add preview modal * Update serializer * Preview refinements * Move preview to its own component * Move breadcrumbs to setupController * Add more tests * Address some feedback * Address more feedback! * Update serailizer * Remove stylesheet * Add comment * UI: [VAULT-21435] Message details (#24645) * WIP * Fix timezone bug * Fix date issues on create/edit form * Add details screen * Use allFields instead of formFields * Fix tests * Address comments! * UI: VAULT-21538 unauth endpoint message display (#24665) * WIP unauth display * Add modal custom message * Close multiple modals * Update todo with ticket number * On init make custom message request * Use serializer * Update fetchMessages * Add copyright headers * Add services and serializers * Send null instead of empty strings * Fix tests! * Add copywrite headers * Add some acceptance tests * Test cleanup * Put tests back * pass hooks to module * Move module out * Seperate tests * Copywrite * Add aria-prohibited-attr runList options * Code cleanup * Add date-time-local transform * Add copyright headers * Remove comments * Remove date transform stuff for now! * Put getISODateFormat back into the serailize function * UI: Date time local transform (#24694) * Date time local * Add deserialize * Add copyright header * check if date exists * Use parseISO for date strings since datefns requires this in new update * Update tests * Ensure we cehck for an ISOString * Add checks so tests wont fail * Update parseISO * Address feedback * UI: multiple banner message on create and edit form (#24742) * WIP multiple banner message on create and edit form * Fix tests * Put checks back * Add try/catch to query * Fix breadcrumbs * Add page size to pagination * Add multiple modal message tests * Address feedback * Check for valid form first * Add extra checks * Address feedback * Move getter to the route * Fix tests! * Address more feedback * Use still when cancelling * Update multiple banner modal * Fix tests * Set user confirmation to empty string * UI: VAULT-21539 auth messages display (#24842) * WIP auth message display * Move block to show only when authenticated * VAULT-22046 working search by name * Some code clean up * Fix merge conflict * Add tests * Fetch messages again after creation * UI: [VAULT-22908] Update kv object editor, add max number of messages reached modal, small improvements (#24918) * Update kv object editor to only use a single row * continute using kv editype * Fix failing dashboard tests! * Fix failing test on sidebranch * Fix tests and update validations * Add optional tag * Address feedback * Add documentation * Clear messages when logging out * Fix tests! * Add 100 message limit modal * Add max message modal test * Do more checks! * Pair with Claire on the refactor of validator! * Only show validationerror for multiple rows * Update pageSize to 100 since when paginations are active it causes accessbility errors * Fix tests! * Add links to test * Make banners dismissable * Add cancel button * Address feedback! * Update test selectors * Update validator * Remove validations check in kvobjecteditor * Revert validationError in kvobjecteditor template * Put back if/else statements for link * Add changelog * UI: fix link bug and add colors (#24977) * Fix edit bug and put transform back * Edit badgeColor * Add tests * Revert changes to transform * Edit badge colors * remove universal object transform * Update changelog filename * UI: Add form inline warning (#24986) * Add form inline warning * Remove title * Only show form warning for unauth * Address feedback!
268 lines
10 KiB
JavaScript
268 lines
10 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
import { render, click, fillIn } from '@ember/test-helpers';
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
import { setRunOptions } from 'ember-a11y-testing/test-support';
|
|
|
|
module('Integration | Component | mfa-login-enforcement-form', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.store = this.owner.lookup('service:store');
|
|
this.model = this.store.createRecord('mfa-login-enforcement');
|
|
this.server.get('/sys/auth', () => ({
|
|
data: { 'userpass/': { type: 'userpass', accessor: 'auth_userpass_1234' } },
|
|
}));
|
|
this.server.get('/identity/mfa/method', () => ({
|
|
data: {
|
|
key_info: {
|
|
123456: { type: 'totp' },
|
|
},
|
|
keys: ['123456'],
|
|
},
|
|
}));
|
|
setRunOptions({
|
|
rules: {
|
|
// TODO: Fix SearchSelect component
|
|
'aria-required-attr': { enabled: false },
|
|
label: { enabled: false },
|
|
// TODO: add labels to enforcement targets key/value style inputs
|
|
'select-name': { enabled: false },
|
|
'aria-prohibited-attr': { enabled: false },
|
|
},
|
|
});
|
|
});
|
|
|
|
test('it should render correct fields', async function (assert) {
|
|
await render(hbs`
|
|
<Mfa::MfaLoginEnforcementForm
|
|
@model={{this.model}}
|
|
@onClose={{fn (mut this.didClose)}}
|
|
@onSave={{fn (mut this.didSave)}}
|
|
/>
|
|
`);
|
|
|
|
const fields = {
|
|
name: {
|
|
label: 'Name',
|
|
subText:
|
|
'The name for this enforcement. Giving it a name means that you can refer to it again later. This name will not be editable later.',
|
|
},
|
|
methods: {
|
|
label: 'MFA methods',
|
|
subText: 'The MFA method(s) that this enforcement will apply to.',
|
|
},
|
|
targets: {
|
|
label: 'Targets',
|
|
subText:
|
|
'The list of authentication types, authentication mounts, groups, and/or entities that will require this MFA configuration.',
|
|
},
|
|
};
|
|
|
|
const subTexts = this.element.querySelectorAll('[data-test-label-subtext]');
|
|
Object.keys(fields).forEach((field, index) => {
|
|
const { label, subText } = fields[field];
|
|
assert.dom(`[data-test-mlef-label="${field}"]`).hasText(label, `${field} field label renders`);
|
|
assert.dom(subTexts[index]).hasText(subText, `${subText} field label sub text renders`);
|
|
});
|
|
assert.dom('[data-test-mlef-input="name"]').exists(`Name field input renders`);
|
|
assert.dom('[data-test-mlef-search="methods"]').exists('MFA method search select renders');
|
|
assert.dom('[data-test-mlef-select="target-type"]').exists('Target type selector renders');
|
|
assert.dom('[data-test-mlef-select="accessor"]').exists('Auth mount target selector renders by default');
|
|
});
|
|
|
|
test('it should render inline', async function (assert) {
|
|
this.errors = this.model.validate().state;
|
|
await render(hbs`
|
|
<Mfa::MfaLoginEnforcementForm
|
|
@model={{this.model}}
|
|
@isInline={{true}}
|
|
@modelErrors={{this.errors}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom('[data-test-mlef-input="name"]').exists(`Name field input renders`);
|
|
assert.dom('[data-test-mlef-search="methods"]').doesNotExist('MFA method search select does not render');
|
|
assert.dom('[data-test-mlef-select="target-type"]').exists('Target type selector renders');
|
|
assert
|
|
.dom('[data-test-inline-error-message]')
|
|
.exists({ count: 2 }, 'External validation errors are displayed');
|
|
});
|
|
|
|
test('it should display field validation errors on save', async function (assert) {
|
|
await render(hbs`
|
|
<Mfa::MfaLoginEnforcementForm
|
|
@model={{this.model}}
|
|
@onClose={{fn (mut this.didClose)}}
|
|
@onSave={{fn (mut this.didSave)}}
|
|
/>
|
|
`);
|
|
|
|
await click('[data-test-mlef-save]');
|
|
const errors = this.element.querySelectorAll('[data-test-inline-error-message]');
|
|
assert.dom(errors[0]).hasText('Name is required', 'Name error message renders');
|
|
assert.dom(errors[1]).hasText('At least one MFA method is required', 'Methods error message renders');
|
|
assert
|
|
.dom(errors[2])
|
|
.hasText(
|
|
"At least one target is required. If you've selected one, click 'Add' to make sure it's added to this enforcement.",
|
|
'Targets error message renders'
|
|
);
|
|
});
|
|
|
|
test('it should save new enforcement', async function (assert) {
|
|
assert.expect(5);
|
|
|
|
this.server.post('/identity/mfa/login-enforcement/bar', () => {
|
|
assert.ok(true, 'save request sent to server');
|
|
return {};
|
|
});
|
|
|
|
await render(hbs`
|
|
<Mfa::MfaLoginEnforcementForm
|
|
@model={{this.model}}
|
|
@onClose={{fn (mut this.didClose)}}
|
|
@onSave={{fn (mut this.didSave) true}}
|
|
/>
|
|
`);
|
|
|
|
await fillIn('[data-test-mlef-input="name"]', 'bar');
|
|
await click('.ember-basic-dropdown-trigger');
|
|
await click('.ember-power-select-option');
|
|
await fillIn('[data-test-mlef-select="accessor"] select', 'auth_userpass_1234');
|
|
await click('[data-test-mlef-add-target]');
|
|
await click('[data-test-mlef-save]');
|
|
assert.true(this.didSave, 'onSave callback triggered');
|
|
assert.strictEqual(this.model.name, 'bar', 'Name property set on model');
|
|
assert.strictEqual(this.model.mfa_methods.firstObject.id, '123456', 'Mfa method added to model');
|
|
assert.deepEqual(
|
|
this.model.auth_method_accessors,
|
|
['auth_userpass_1234'],
|
|
'Target saved to correct model property'
|
|
);
|
|
});
|
|
|
|
test('it should populate fields with model data', async function (assert) {
|
|
this.model.name = 'foo';
|
|
const [method] = (await this.store.query('mfa-method', {})).toArray();
|
|
this.model.mfa_methods.addObject(method);
|
|
this.model.auth_method_accessors.addObject('auth_userpass_1234');
|
|
|
|
await render(hbs`
|
|
<Mfa::MfaLoginEnforcementForm
|
|
@model={{this.model}}
|
|
@onClose={{fn (mut this.didClose)}}
|
|
@onSave={{fn (mut this.didSave) true}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom('[data-test-mlef-input="name"]').hasValue('foo', 'Name input is populated');
|
|
assert.dom('.search-select-list-item').includesText('TOTP', 'MFA method type renders in selected option');
|
|
assert
|
|
.dom('.search-select-list-item small')
|
|
.hasText('123456', 'MFA method id renders in selected option');
|
|
assert
|
|
.dom('[data-test-row-label="Authentication mount"]')
|
|
.hasText('Authentication mount', 'Selected target type renders');
|
|
assert
|
|
.dom('[data-test-value-div="Authentication mount"]')
|
|
.hasText('auth_userpass_1234', 'Selected target value renders');
|
|
|
|
await click('[data-test-mlef-remove-target]');
|
|
await click('[data-test-mlef-save]');
|
|
assert
|
|
.dom('[data-test-inline-error-message]')
|
|
.includesText('At least one target is required', 'Target is removed');
|
|
assert.notOk(this.model.auth_method_accessors.length, 'Target is removed from appropriate model prop');
|
|
|
|
await fillIn('[data-test-mlef-select="accessor"] select', 'auth_userpass_1234');
|
|
await click('[data-test-mlef-add-target]');
|
|
await click('[data-test-selected-list-button="delete"]');
|
|
await click('[data-test-mlef-save]');
|
|
assert
|
|
.dom('[data-test-inline-error-message]')
|
|
.hasText('At least one MFA method is required', 'Target is removed');
|
|
});
|
|
|
|
test('it should add and remove targets', async function (assert) {
|
|
assert.expect();
|
|
|
|
this.server.get('/identity/entity/id', () => ({
|
|
data: {
|
|
key_info: { 1234: { name: 'foo entity' } },
|
|
keys: ['1234'],
|
|
},
|
|
}));
|
|
this.server.get('/identity/group/id', () => ({
|
|
data: {
|
|
key_info: { 1234: { name: 'bar group' } },
|
|
keys: ['1234'],
|
|
},
|
|
}));
|
|
this.model.auth_method_accessors.addObject('auth_userpass_1234');
|
|
this.model.auth_method_types.addObject('userpass');
|
|
const [entity] = (await this.store.query('identity/entity', {})).toArray();
|
|
this.model.identity_entities.addObject(entity);
|
|
const [group] = (await this.store.query('identity/group', {})).toArray();
|
|
this.model.identity_groups.addObject(group);
|
|
|
|
await render(hbs`
|
|
<Mfa::MfaLoginEnforcementForm
|
|
@model={{this.model}}
|
|
@onClose={{fn (mut this.didClose)}}
|
|
@onSave={{fn (mut this.didSave) true}}
|
|
/>
|
|
`);
|
|
|
|
const targets = [
|
|
{
|
|
label: 'Authentication mount',
|
|
value: 'auth_userpass_1234',
|
|
key: 'auth_method_accessors',
|
|
type: 'accessor',
|
|
},
|
|
{ label: 'Authentication method', value: 'userpass', key: 'auth_method_types', type: 'method' },
|
|
{ label: 'Group', value: 'bar group 1234', key: 'identity_groups', type: 'identity/group' },
|
|
{ label: 'Entity', value: 'foo entity 1234', key: 'identity_entities', type: 'identity/entity' },
|
|
];
|
|
|
|
for (const [index, target] of targets.entries()) {
|
|
// target populated from model
|
|
assert
|
|
.dom(`[data-test-row-label="${target.label}"]`)
|
|
.hasText(target.label, `${target.label} target populated with correct type label`);
|
|
assert
|
|
.dom(`[data-test-value-div="${target.label}"]`)
|
|
.hasText(target.value, `${target.label} target populated with correct value`);
|
|
// remove target
|
|
await click(`[data-test-mlef-remove-target="${target.label}"]`);
|
|
assert
|
|
.dom('[data-test-mlef-target]')
|
|
.exists({ count: targets.length - (index + 1) }, `${target.label} target removed`);
|
|
assert.notOk(this.model[target.key].length, `${target.label} removed from correct model prop`);
|
|
}
|
|
// add targets
|
|
for (const target of targets) {
|
|
await fillIn('[data-test-mlef-select="target-type"] select', target.type);
|
|
if (['Group', 'Entity'].includes(target.label)) {
|
|
await click(`[data-test-mlef-search="${target.type}"] .ember-basic-dropdown-trigger`);
|
|
await click('.ember-power-select-option');
|
|
} else {
|
|
const key = target.label === 'Authentication method' ? 'auth-method' : 'accessor';
|
|
const value = target.label === 'Authentication method' ? 'userpass' : 'auth_userpass_1234';
|
|
await fillIn(`[data-test-mlef-select="${key}"] select`, value);
|
|
}
|
|
await click('[data-test-mlef-add-target]');
|
|
assert.ok(this.model[target.key].length, `${target.label} added to correct model prop`);
|
|
}
|
|
assert.dom('[data-test-mlef-target]').exists({ count: 4 }, 'All targets were added back');
|
|
});
|
|
});
|