mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-03 20:40:45 -05:00
* parse error * add test coverage * update test so original code fails the same way * remove unused vars Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
This commit is contained in:
parent
964ab5a9b4
commit
b7b7002d71
3 changed files with 37 additions and 7 deletions
|
|
@ -9,7 +9,6 @@ import { action } from '@ember/object';
|
|||
import { service } from '@ember/service';
|
||||
import { task } from 'ember-concurrency';
|
||||
import { waitFor } from '@ember/test-waiters';
|
||||
import errorMessage from 'vault/utils/error-message';
|
||||
|
||||
import { LdapRolesCreateRouteModel } from 'ldap/routes/roles/create';
|
||||
import { Breadcrumb, ValidationMap } from 'vault/vault/app-types';
|
||||
|
|
@ -133,7 +132,11 @@ export default class LdapCreateAndEditRolePageComponent extends Component<Args>
|
|||
name
|
||||
);
|
||||
} catch (error) {
|
||||
this.error = errorMessage(error, 'Error saving role. Please try again or contact support.');
|
||||
const { message } = await this.api.parseError(
|
||||
error,
|
||||
'Error saving role. Please try again or contact support.'
|
||||
);
|
||||
this.error = message;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -66,11 +66,7 @@ export function allowAllCapabilitiesStub(capabilitiesList = ['root']) {
|
|||
*/
|
||||
export function overrideResponse(httpStatus = 200, payload = {}) {
|
||||
if (httpStatus === 403) {
|
||||
return new Response(
|
||||
403,
|
||||
{ 'Content-Type': 'application/json' },
|
||||
JSON.stringify({ errors: ['permission denied'] })
|
||||
);
|
||||
return new Response(403, { 'Content-Type': 'application/json' }, formatError('permission denied'));
|
||||
}
|
||||
if (httpStatus === 404) {
|
||||
return new Response(404, { 'Content-Type': 'application/json' });
|
||||
|
|
@ -80,3 +76,5 @@ export function overrideResponse(httpStatus = 200, payload = {}) {
|
|||
}
|
||||
return new Response(httpStatus, { 'Content-Type': 'application/json' }, payload);
|
||||
}
|
||||
|
||||
export const formatError = (msg) => JSON.stringify({ errors: [msg] });
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import sinon from 'sinon';
|
|||
import { GENERAL } from 'vault/tests/helpers/general-selectors';
|
||||
import LdapStaticRoleForm from 'vault/forms/secrets/ldap/roles/static';
|
||||
import LdapDynamicRoleForm from 'vault/forms/secrets/ldap/roles/dynamic';
|
||||
import { formatError, overrideResponse } from 'vault/tests/helpers/stubs';
|
||||
|
||||
module('Integration | Component | ldap | Page::Role::CreateAndEdit', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
|
@ -234,4 +235,32 @@ module('Integration | Component | ldap | Page::Role::CreateAndEdit', function (h
|
|||
'Transitions to role details route on save success'
|
||||
);
|
||||
});
|
||||
|
||||
test('it should display api error when creating static roles fails', async function (assert) {
|
||||
this.server.post('/:backend/static-role/:name', () => {
|
||||
return overrideResponse(500, formatError('uh oh!'));
|
||||
});
|
||||
this.model = this.createModel;
|
||||
await this.renderComponent();
|
||||
await fillIn(GENERAL.inputByAttr('name'), 'test-role');
|
||||
await fillIn(GENERAL.inputByAttr('dn'), 'foo');
|
||||
await fillIn(GENERAL.inputByAttr('username'), 'bar');
|
||||
await fillIn(GENERAL.ttl.input('Rotation period'), 5);
|
||||
await click(GENERAL.submitButton);
|
||||
assert
|
||||
.dom(GENERAL.messageError)
|
||||
.hasText('Error uh oh!', 'it renders error message returned from the API');
|
||||
});
|
||||
|
||||
test('it should display api error when creating dynamic roles fails', async function (assert) {
|
||||
this.server.post('/:backend/role/:name', () => {
|
||||
return overrideResponse(500, formatError('uh oh!'));
|
||||
});
|
||||
this.model = this.dynamicEditModel;
|
||||
await this.renderComponent();
|
||||
await click(GENERAL.submitButton);
|
||||
assert
|
||||
.dom(GENERAL.messageError)
|
||||
.hasText('Error uh oh!', 'it renders error message returned from the API');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue