mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-15 19:17:02 +02:00
* 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
205 lines
7.2 KiB
JavaScript
205 lines
7.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 { setupMirage } from 'ember-cli-mirage/test-support';
|
|
import ENV from 'vault/config/environment';
|
|
import {
|
|
OIDC_BASE_URL,
|
|
CLIENT_LIST_RESPONSE,
|
|
SELECTORS,
|
|
overrideMirageResponse,
|
|
overrideCapabilities,
|
|
} from 'vault/tests/helpers/oidc-config';
|
|
|
|
module('Integration | Component | oidc/key-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.get('/identity/oidc/client', () => overrideMirageResponse(null, CLIENT_LIST_RESPONSE));
|
|
});
|
|
|
|
test('it should save new key', async function (assert) {
|
|
assert.expect(9);
|
|
this.server.post('/identity/oidc/key/test-key', (schema, req) => {
|
|
assert.ok(true, 'Request made to save key');
|
|
return JSON.parse(req.requestBody);
|
|
});
|
|
this.model = this.store.createRecord('oidc/key');
|
|
this.onSave = () => assert.ok(true, 'onSave callback fires on save success');
|
|
await render(hbs`
|
|
<Oidc::KeyForm
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom('[data-test-oidc-key-title]').hasText('Create key', 'Form title renders correct text');
|
|
assert.dom(SELECTORS.keySaveButton).hasText('Create', 'Save button has correct text');
|
|
assert.dom('[data-test-input="algorithm"]').hasValue('RS256', 'default algorithm is correct');
|
|
assert.strictEqual(findAll('[data-test-field]').length, 4, 'renders all input fields');
|
|
|
|
// check validation errors
|
|
await fillIn('[data-test-input="name"]', ' ');
|
|
await click(SELECTORS.keySaveButton);
|
|
|
|
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('There are 2 errors with this form.', 'Renders form error count');
|
|
|
|
assert.dom('label[for=limited] input').isDisabled('limit radio button disabled on create');
|
|
await fillIn('[data-test-input="name"]', 'test-key');
|
|
await click(SELECTORS.keySaveButton);
|
|
});
|
|
|
|
test('it should update key and limit access to selected applications', async function (assert) {
|
|
assert.expect(12);
|
|
|
|
this.server.post('/identity/oidc/key/test-key', (schema, req) => {
|
|
assert.ok(true, 'Request made to update key');
|
|
return JSON.parse(req.requestBody);
|
|
});
|
|
|
|
this.store.pushPayload('oidc/key', {
|
|
modelName: 'oidc/key',
|
|
name: 'test-key',
|
|
allowed_client_ids: ['*'],
|
|
});
|
|
|
|
this.model = this.store.peekRecord('oidc/key', 'test-key');
|
|
this.onSave = () => assert.ok(true, 'onSave callback fires on update success');
|
|
|
|
await render(hbs`
|
|
<Oidc::KeyForm
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom('[data-test-oidc-key-title]').hasText('Edit key', 'Title renders correct text');
|
|
assert.dom(SELECTORS.keySaveButton).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-key', 'Name input is populated with model value');
|
|
assert.dom('input#allow-all').isChecked('Allow all radio button is selected');
|
|
|
|
await click('label[for=limited]');
|
|
assert
|
|
.dom('[data-test-component="search-select"]#allowedClientIds')
|
|
.exists('Limited radio button shows clients search select');
|
|
await click('[data-test-component="search-select"]#allowedClientIds .ember-basic-dropdown-trigger');
|
|
assert.strictEqual(findAll('li.ember-power-select-option').length, 1, 'dropdown only renders one option');
|
|
assert
|
|
.dom('li.ember-power-select-option')
|
|
.hasTextContaining('app-1', 'dropdown contains client that references key');
|
|
assert.dom('[data-test-smaller-id]').exists('renders smaller client id in dropdown');
|
|
|
|
await click('label[for=allow-all]');
|
|
assert
|
|
.dom('[data-test-component="search-select"]#allowedClientIds')
|
|
.doesNotExist('Allow all radio button hides search select');
|
|
|
|
await click(SELECTORS.keySaveButton);
|
|
});
|
|
|
|
test('it should rollback attributes or unload record on cancel', async function (assert) {
|
|
assert.expect(4);
|
|
this.model = this.store.createRecord('oidc/key');
|
|
this.onCancel = () => assert.ok(true, 'onCancel callback fires');
|
|
|
|
await render(hbs`
|
|
<Oidc::KeyForm
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
/>
|
|
`);
|
|
|
|
await click(SELECTORS.keyCancelButton);
|
|
assert.true(this.model.isDestroyed, 'New model is unloaded on cancel');
|
|
|
|
this.store.pushPayload('oidc/key', {
|
|
modelName: 'oidc/key',
|
|
name: 'test-key',
|
|
allowed_client_ids: ['*'],
|
|
});
|
|
|
|
this.model = this.store.peekRecord('oidc/key', 'test-key');
|
|
|
|
await render(hbs`
|
|
<Oidc::KeyForm
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
/>
|
|
`);
|
|
|
|
await click('label[for=limited]');
|
|
await click(SELECTORS.keyCancelButton);
|
|
assert.strictEqual(this.model.allowed_client_ids, undefined, 'Model attributes rolled back on cancel');
|
|
});
|
|
|
|
test('it should render fallback for search select', async function (assert) {
|
|
assert.expect(1);
|
|
|
|
this.server.post('/identity/oidc/key/test-key', (schema, req) => {
|
|
assert.ok(true, 'Request made to update key');
|
|
return JSON.parse(req.requestBody);
|
|
});
|
|
|
|
this.store.pushPayload('oidc/key', {
|
|
modelName: 'oidc/key',
|
|
name: 'test-key',
|
|
allowed_client_ids: ['*'],
|
|
});
|
|
|
|
this.model = this.store.peekRecord('oidc/key', 'test-key');
|
|
|
|
this.server.get('/identity/oidc/client', () => overrideMirageResponse(403));
|
|
await render(hbs`
|
|
<Oidc::KeyForm
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
/>
|
|
`);
|
|
|
|
await click('label[for=limited]');
|
|
assert
|
|
.dom('[data-test-component="search-select"]#allowedClientIds [data-test-component="string-list"]')
|
|
.exists('Radio toggle shows client 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/key');
|
|
this.server.post('/sys/capabilities-self', () => overrideCapabilities(OIDC_BASE_URL + '/keys'));
|
|
await render(hbs`
|
|
<Oidc::KeyForm
|
|
@model={{this.model}}
|
|
@onCancel={{this.onCancel}}
|
|
@onSave={{this.onSave}}
|
|
/>
|
|
`);
|
|
await fillIn('[data-test-input="name"]', 'test-app');
|
|
await click(SELECTORS.keySaveButton);
|
|
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');
|
|
});
|
|
});
|