Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] Fixes signals index when spaces are disabled #57244

Merged
merged 4 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
transformBulkError,
BulkError,
createSuccessObject,
getIndex,
ImportSuccessError,
createImportErrorObject,
transformImportError,
Expand Down Expand Up @@ -292,4 +293,36 @@ describe('utils', () => {
expect(transformed).toEqual(expected);
});
});

describe('getIndex', () => {
it('appends the space ID to the configured index if spaces are enabled', () => {
const mockGet = jest.fn();
const mockGetSpaceId = jest.fn();
const config = jest.fn(() => ({ get: mockGet, has: jest.fn() }));
const server = { plugins: { spaces: { getSpaceId: mockGetSpaceId } }, config };

mockGet.mockReturnValue('mockSignalsIndex');
mockGetSpaceId.mockReturnValue('myspace');
// @ts-ignore-next-line TODO these dependencies are simplified on
// https://github.com/elastic/kibana/pull/56814. We're currently mocking
// out what we need.
const index = getIndex(null, server);

expect(index).toEqual('mockSignalsIndex-myspace');
});

it('appends the default space ID to the configured index if spaces are disabled', () => {
const mockGet = jest.fn();
const config = jest.fn(() => ({ get: mockGet, has: jest.fn() }));
const server = { plugins: {}, config };

mockGet.mockReturnValue('mockSignalsIndex');
// @ts-ignore-next-line TODO these dependencies are simplified on
// https://github.com/elastic/kibana/pull/56814. We're currently mocking
// out what we need.
const index = getIndex(null, server);

expect(index).toEqual('mockSignalsIndex-default');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const getIndex = (
request: RequestFacade | Omit<RequestFacade, 'query'>,
server: ServerFacade
): string => {
const spaceId = server.plugins.spaces.getSpaceId(request);
const spaceId = server.plugins.spaces?.getSpaceId?.(request) ?? 'default';
const signalsIndex = server.config().get(`xpack.${APP_ID}.${SIGNALS_INDEX_KEY}`);
return `${signalsIndex}-${spaceId}`;
};
Expand Down