-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Omit runtime fields from FLS suggestions (#78330)
Co-authored-by: Aleh Zasypkin <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
d793040
commit 4525f0c
Showing
4 changed files
with
160 additions
and
9 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
x-pack/plugins/security/server/routes/indices/get_fields.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { httpServerMock, elasticsearchServiceMock } from '../../../../../../src/core/server/mocks'; | ||
import { kibanaResponseFactory } from '../../../../../../src/core/server'; | ||
|
||
import { routeDefinitionParamsMock } from '../index.mock'; | ||
import { defineGetFieldsRoutes } from './get_fields'; | ||
|
||
const createFieldMapping = (field: string, type: string) => ({ | ||
[field]: { mapping: { [field]: { type } } }, | ||
}); | ||
|
||
const createEmptyFieldMapping = (field: string) => ({ [field]: { mapping: {} } }); | ||
|
||
const mockFieldMappingResponse = { | ||
foo: { | ||
mappings: { | ||
...createFieldMapping('fooField', 'keyword'), | ||
...createFieldMapping('commonField', 'keyword'), | ||
...createEmptyFieldMapping('emptyField'), | ||
}, | ||
}, | ||
bar: { | ||
mappings: { | ||
...createFieldMapping('commonField', 'keyword'), | ||
...createFieldMapping('barField', 'keyword'), | ||
...createFieldMapping('runtimeField', 'runtime'), | ||
}, | ||
}, | ||
}; | ||
|
||
describe('GET /internal/security/fields/{query}', () => { | ||
it('returns a list of deduplicated fields, omitting empty and runtime fields', async () => { | ||
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); | ||
|
||
const scopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); | ||
scopedClient.callAsCurrentUser.mockResolvedValue(mockFieldMappingResponse); | ||
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(scopedClient); | ||
|
||
defineGetFieldsRoutes(mockRouteDefinitionParams); | ||
|
||
const [[, handler]] = mockRouteDefinitionParams.router.get.mock.calls; | ||
|
||
const headers = { authorization: 'foo' }; | ||
const mockRequest = httpServerMock.createKibanaRequest({ | ||
method: 'get', | ||
path: `/internal/security/fields/foo`, | ||
headers, | ||
}); | ||
const response = await handler({} as any, mockRequest, kibanaResponseFactory); | ||
expect(response.status).toBe(200); | ||
expect(response.payload).toEqual(['fooField', 'commonField', 'barField']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters