updates GET /api/security/role to sort on role name (#26491) (#26546)

This commit is contained in:
Larry Gregory 2018-12-03 13:29:12 -05:00 committed by GitHub
parent 629c5b67b7
commit 555acc7d62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 122 additions and 1 deletions

View file

@ -68,7 +68,7 @@ export function initGetRolesApi(server, callWithRequest, routePreCheckLicenseFn,
async handler(request) {
try {
const response = await callWithRequest(request, 'shield.getRole');
return transformRolesFromEs(response);
return _.sortBy(transformRolesFromEs(response), 'name');
} catch (error) {
return wrapError(error);
}

View file

@ -376,6 +376,127 @@ describe('GET roles', () => {
],
},
});
getRolesTest(`returns a sorted list of roles`, {
callWithRequestImpl: async () => ({
z_role: {
cluster: [],
indices: [],
applications: [
{
application: 'kibana-.another-kibana',
privileges: ['read'],
resources: ['*'],
},
],
run_as: [],
metadata: {
_reserved: true,
},
transient_metadata: {
enabled: true,
},
},
a_role: {
cluster: [],
indices: [],
applications: [
{
application: 'kibana-.another-kibana',
privileges: ['read'],
resources: ['*'],
},
],
run_as: [],
metadata: {
_reserved: true,
},
transient_metadata: {
enabled: true,
},
},
b_role: {
cluster: [],
indices: [],
applications: [
{
application: 'kibana-.another-kibana',
privileges: ['read'],
resources: ['*'],
},
],
run_as: [],
metadata: {
_reserved: true,
},
transient_metadata: {
enabled: true,
},
},
}),
asserts: {
statusCode: 200,
result: [
{
name: 'a_role',
metadata: {
_reserved: true,
},
transient_metadata: {
enabled: true,
},
elasticsearch: {
cluster: [],
indices: [],
run_as: [],
},
kibana: {
global: [],
space: {},
},
_unrecognized_applications: ['kibana-.another-kibana']
},
{
name: 'b_role',
metadata: {
_reserved: true,
},
transient_metadata: {
enabled: true,
},
elasticsearch: {
cluster: [],
indices: [],
run_as: [],
},
kibana: {
global: [],
space: {},
},
_unrecognized_applications: ['kibana-.another-kibana']
},
{
name: 'z_role',
metadata: {
_reserved: true,
},
transient_metadata: {
enabled: true,
},
elasticsearch: {
cluster: [],
indices: [],
run_as: [],
},
kibana: {
global: [],
space: {},
},
_unrecognized_applications: ['kibana-.another-kibana']
},
],
},
});
});
});