Skip to content

Commit 5016dd7

Browse files
Merge remote-tracking branch 'remotes/from/ce/main'
2 parents 363b8a9 + 7592c21 commit 5016dd7

File tree

5 files changed

+51
-9
lines changed

5 files changed

+51
-9
lines changed

ui/lib/ldap/addon/components/page/overview.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ export default class LdapLibrariesPageComponent extends Component<Args> {
9797
);
9898
this.checkInCapabilities = await this.capabilities.fetch(paths);
9999
} catch (error) {
100-
// Hierarchical discovery failed - display inline error
101-
this.librariesError = 'Unable to load complete library information. Please try refreshing the page.';
100+
const { status } = await this.api.parseError(error);
101+
// Only set error message if status is not a 404 which just means an empty response.
102+
if (status !== 404) {
103+
// Hierarchical discovery failed - display inline error
104+
this.librariesError = 'Unable to load complete library information. Please try refreshing the page.';
105+
}
102106
this.allLibraries = [];
103107
}
104108
});

ui/lib/ldap/addon/components/page/role/create-and-edit.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { action } from '@ember/object';
99
import { service } from '@ember/service';
1010
import { task } from 'ember-concurrency';
1111
import { waitFor } from '@ember/test-waiters';
12-
import errorMessage from 'vault/utils/error-message';
1312

1413
import { LdapRolesCreateRouteModel } from 'ldap/routes/roles/create';
1514
import { Breadcrumb, ValidationMap } from 'vault/vault/app-types';
@@ -133,7 +132,11 @@ export default class LdapCreateAndEditRolePageComponent extends Component<Args>
133132
name
134133
);
135134
} catch (error) {
136-
this.error = errorMessage(error, 'Error saving role. Please try again or contact support.');
135+
const { message } = await this.api.parseError(
136+
error,
137+
'Error saving role. Please try again or contact support.'
138+
);
139+
this.error = message;
137140
}
138141
}
139142
})

ui/tests/helpers/stubs.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ export function allowAllCapabilitiesStub(capabilitiesList = ['root']) {
6666
*/
6767
export function overrideResponse(httpStatus = 200, payload = {}) {
6868
if (httpStatus === 403) {
69-
return new Response(
70-
403,
71-
{ 'Content-Type': 'application/json' },
72-
JSON.stringify({ errors: ['permission denied'] })
73-
);
69+
return new Response(403, { 'Content-Type': 'application/json' }, formatError('permission denied'));
7470
}
7571
if (httpStatus === 404) {
7672
return new Response(404, { 'Content-Type': 'application/json' });
@@ -80,3 +76,5 @@ export function overrideResponse(httpStatus = 200, payload = {}) {
8076
}
8177
return new Response(httpStatus, { 'Content-Type': 'application/json' }, payload);
8278
}
79+
80+
export const formatError = (msg) => JSON.stringify({ errors: [msg] });

ui/tests/integration/components/ldap/page/overview-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,12 @@ module('Integration | Component | ldap | Page::Overview', function (hooks) {
197197
.dom('[data-test-overview-card-container="Accounts checked-out"]')
198198
.exists('AccountsCheckedOut component still renders when library discovery fails');
199199
});
200+
201+
test('it should display "None" when library request returns a 404', async function (assert) {
202+
// Override server to return empty 404 response for library requests
203+
this.apiLibraryStub.rejects(getErrorResponse({}, 404));
204+
await this.renderComponent();
205+
assert.dom('[data-test-libraries-error]').doesNotExist();
206+
assert.dom('[data-test-libraries-count]').hasText('None');
207+
});
200208
});

ui/tests/integration/components/ldap/page/role/create-and-edit-test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import sinon from 'sinon';
1313
import { GENERAL } from 'vault/tests/helpers/general-selectors';
1414
import LdapStaticRoleForm from 'vault/forms/secrets/ldap/roles/static';
1515
import LdapDynamicRoleForm from 'vault/forms/secrets/ldap/roles/dynamic';
16+
import { formatError, overrideResponse } from 'vault/tests/helpers/stubs';
1617

1718
module('Integration | Component | ldap | Page::Role::CreateAndEdit', function (hooks) {
1819
setupRenderingTest(hooks);
@@ -234,4 +235,32 @@ module('Integration | Component | ldap | Page::Role::CreateAndEdit', function (h
234235
'Transitions to role details route on save success'
235236
);
236237
});
238+
239+
test('it should display api error when creating static roles fails', async function (assert) {
240+
this.server.post('/:backend/static-role/:name', () => {
241+
return overrideResponse(500, formatError('uh oh!'));
242+
});
243+
this.model = this.createModel;
244+
await this.renderComponent();
245+
await fillIn(GENERAL.inputByAttr('name'), 'test-role');
246+
await fillIn(GENERAL.inputByAttr('dn'), 'foo');
247+
await fillIn(GENERAL.inputByAttr('username'), 'bar');
248+
await fillIn(GENERAL.ttl.input('Rotation period'), 5);
249+
await click(GENERAL.submitButton);
250+
assert
251+
.dom(GENERAL.messageError)
252+
.hasText('Error uh oh!', 'it renders error message returned from the API');
253+
});
254+
255+
test('it should display api error when creating dynamic roles fails', async function (assert) {
256+
this.server.post('/:backend/role/:name', () => {
257+
return overrideResponse(500, formatError('uh oh!'));
258+
});
259+
this.model = this.dynamicEditModel;
260+
await this.renderComponent();
261+
await click(GENERAL.submitButton);
262+
assert
263+
.dom(GENERAL.messageError)
264+
.hasText('Error uh oh!', 'it renders error message returned from the API');
265+
});
237266
});

0 commit comments

Comments
 (0)