vault/ui/tests/integration/components/oidc/client-form-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

252 lines
9.2 KiB
JavaScript

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, fillIn, click, findAll } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { create } from 'ember-cli-page-object';
import { clickTrigger } from 'ember-power-select/test-support/helpers';
import ss from 'vault/tests/pages/components/search-select';
import { setupMirage } from 'ember-cli-mirage/test-support';
import ENV from 'vault/config/environment';
import {
OIDC_BASE_URL,
SELECTORS,
overrideMirageResponse,
overrideCapabilities,
} from 'vault/tests/helpers/oidc-config';
const searchSelect = create(ss);
module('Integration | Component | oidc/client-form', function (hooks) {
setupRenderingTest(hooks);
setupMirage(hooks);
hooks.before(function () {
ENV['ember-cli-mirage'].handler = 'oidcConfig';
});
hooks.after(function () {
ENV['ember-cli-mirage'].handler = null;
});
hooks.beforeEach(function () {
this.store = this.owner.lookup('service:store');
this.server.post('/sys/capabilities-self', () => {});
this.server.get('/identity/oidc/key', () => {
return {
request_id: 'key-list-id',
data: {
keys: ['default'],
},
};
});
this.server.get('/identity/oidc/assignment', () => {
return {
request_id: 'assignment-list-id',
data: {
keys: ['allow_all', 'assignment-1'],
},
};
});
this.server.get('/identity/oidc/assignment/assignment-1', () => {
return {
request_id: 'assignment-1-id',
data: {
entity_ids: ['1234-12345'],
group_ids: ['abcdef-123'],
},
};
});
});
test('it should save new client', async function (assert) {
assert.expect(14);
this.server.post('/identity/oidc/client/test-app', (schema, req) => {
assert.ok(true, 'Request made to save client');
return JSON.parse(req.requestBody);
});
this.model = this.store.createRecord('oidc/client');
this.onSave = () => assert.ok(true, 'onSave callback fires on save success');
await render(hbs`
<Oidc::ClientForm
@model={{this.model}}
@onCancel={{this.onCancel}}
@onSave={{this.onSave}}
/>
`);
await click('[data-test-toggle-group="More options"]');
assert
.dom('[data-test-oidc-client-title]')
.hasText('Create application', 'Form title renders correct text');
assert.dom(SELECTORS.clientSaveButton).hasText('Create', 'Save button has correct text');
assert.strictEqual(findAll('[data-test-field]').length, 6, 'renders all attribute fields');
assert.dom('input#allow-all').isChecked('Allow all radio button selected by default');
assert.dom('[data-test-ttl-value="ID Token TTL"]').hasValue('1', 'ttl defaults to 24h');
assert.dom('[data-test-ttl-value="Access Token TTL"]').hasValue('1', 'ttl defaults to 24h');
assert.dom('[data-test-selected-option]').hasText('default', 'Search select has default key selected');
// check validation errors
await fillIn('[data-test-input="name"]', ' ');
await click('[data-test-selected-list-button="delete"]');
await click(SELECTORS.clientSaveButton);
let validationErrors = findAll(SELECTORS.inlineAlert);
assert
.dom(validationErrors[0])
.hasText('Name is required. Name cannot contain whitespace.', 'Validation messages are shown for name');
assert.dom(validationErrors[1]).hasText('Key is required.', 'Validation message is shown for key');
assert.dom(validationErrors[2]).hasText('There are 3 errors with this form.', 'Renders form error count');
// fill out form with valid inputs
await clickTrigger();
await fillIn('.ember-power-select-search input', 'default');
await searchSelect.options.objectAt(0).click();
await click('label[for=limited]');
assert
.dom('[data-test-search-select-with-modal]')
.exists('Limited radio button shows assignments search select');
await clickTrigger();
assert.dom('li.ember-power-select-option').hasText('assignment-1', 'dropdown renders assignments');
await fillIn('[data-test-input="name"]', 'test-app');
await click(SELECTORS.clientSaveButton);
});
test('it should update client', async function (assert) {
assert.expect(11);
this.server.post('/identity/oidc/client/test-app', (schema, req) => {
assert.ok(true, 'Request made to save client');
return JSON.parse(req.requestBody);
});
this.store.pushPayload('oidc/client', {
modelName: 'oidc/client',
name: 'test-app',
clientType: 'public',
});
this.model = this.store.peekRecord('oidc/client', 'test-app');
this.onSave = () => assert.ok(true, 'onSave callback fires on save success');
await render(hbs`
<Oidc::ClientForm
@model={{this.model}}
@onCancel={{this.onCancel}}
@onSave={{this.onSave}}
/>
`);
await click('[data-test-toggle-group="More options"]');
assert.dom('[data-test-oidc-client-title]').hasText('Edit application', 'Title renders correct text');
assert.dom(SELECTORS.clientSaveButton).hasText('Update', 'Save button has correct text');
assert.dom('[data-test-input="name"]').isDisabled('Name input is disabled when editing');
assert.dom('[data-test-input="name"]').hasValue('test-app', 'Name input is populated with model value');
assert.dom('[data-test-input="key"]').isDisabled('Signing key input is disabled');
assert.dom('[data-test-input="key"]').hasValue('default', 'Key input populated with default');
assert.dom('[data-test-input="clientType"] input').isDisabled('client type input is disabled on edit');
assert
.dom('[data-test-input="clientType"] input#confidential')
.isChecked('Correct radio button is selected');
assert.dom('input#allow-all').isChecked('Allow all radio button is selected');
await click(SELECTORS.clientSaveButton);
});
test('it should rollback attributes or unload record on cancel', async function (assert) {
assert.expect(4);
this.model = this.store.createRecord('oidc/client');
this.onCancel = () => assert.ok(true, 'onCancel callback fires');
await render(hbs`
<Oidc::ClientForm
@model={{this.model}}
@onCancel={{this.onCancel}}
@onSave={{this.onSave}}
/>
`);
await click(SELECTORS.clientCancelButton);
assert.true(this.model.isDestroyed, 'New model is unloaded on cancel');
this.store.pushPayload('oidc/client', {
modelName: 'oidc/client',
name: 'test-app',
assignments: ['allow_all'],
redirectUris: [],
});
this.model = this.store.peekRecord('oidc/client', 'test-app');
await render(hbs`
<Oidc::ClientForm
@model={{this.model}}
@onCancel={{this.onCancel}}
@onSave={{this.onSave}}
/>
`);
await fillIn('[data-test-input="redirectUris"] [data-test-string-list-input="0"]', 'some-url.com');
await click('[data-test-string-list-button="add"]');
await click(SELECTORS.clientCancelButton);
assert.strictEqual(this.model.redirectUris, undefined, 'Model attributes rolled back on cancel');
});
test('it should show create assignment modal', async function (assert) {
assert.expect(2);
this.model = this.store.createRecord('oidc/client');
await render(hbs`
<Oidc::ClientForm
@model={{this.model}}
@onCancel={{this.onCancel}}
@onSave={{this.onSave}}
/>
<div id="modal-wormhole"></div>
`);
await click('label[for=limited]');
await clickTrigger();
await fillIn('.ember-power-select-search input', 'test-new');
await searchSelect.options.objectAt(0).click();
assert.dom('[data-test-modal-title]').hasText('Create new assignment', 'Create assignment modal renders');
await click(SELECTORS.assignmentCancelButton);
assert.dom('[data-test-modal-div]').doesNotExist('Modal disappears after clicking cancel');
});
test('it should render fallback for search select', async function (assert) {
assert.expect(1);
this.model = this.store.createRecord('oidc/client');
this.server.get('/identity/oidc/assignment', () => overrideMirageResponse(403));
await render(hbs`
<Oidc::ClientForm
@model={{this.model}}
@onCancel={{this.onCancel}}
@onSave={{this.onSave}}
/>
`);
await click('label[for=limited]');
assert
.dom('[data-test-component="string-list"]')
.exists('Radio toggle shows assignments string-list input');
});
test('it should render error alerts when API returns an error', async function (assert) {
assert.expect(2);
this.model = this.store.createRecord('oidc/client');
this.server.post('/sys/capabilities-self', () => overrideCapabilities(OIDC_BASE_URL + '/clients'));
await render(hbs`
<Oidc::ClientForm
@model={{this.model}}
@onCancel={{this.onCancel}}
@onSave={{this.onSave}}
/>
`);
await fillIn('[data-test-input="name"]', 'test-app');
await click(SELECTORS.clientSaveButton);
assert
.dom(SELECTORS.inlineAlert)
.hasText('There was an error submitting this form.', 'form error alert renders ');
assert.dom('[data-test-alert-banner="alert"]').exists('alert banner renders');
});
});