mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Enterprise Search] Import correct exception identifier (#161935)
## Summary The access control deletion function was importing the wrong `isIndexNotFoundException` to identify when an index doesn't exist. This would cause index deletion to fail if a search index is missing an access control index.
This commit is contained in:
parent
091643c9a9
commit
3077919bb8
2 changed files with 93 additions and 2 deletions
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { IScopedClusterClient } from '@kbn/core/server';
|
||||
|
||||
import { ElasticsearchResponseError } from '../../utils/identify_exceptions';
|
||||
|
||||
import { deleteAccessControlIndex } from './delete_access_control_index';
|
||||
|
||||
describe('deleteAccessControlIndex lib function', () => {
|
||||
const mockClient = {
|
||||
asCurrentUser: {
|
||||
indices: {
|
||||
delete: jest.fn(),
|
||||
},
|
||||
},
|
||||
asInternalUser: {},
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('when ACL index exists', () => {
|
||||
it('should delete index', async () => {
|
||||
mockClient.asCurrentUser.indices.delete.mockImplementation(() => true);
|
||||
await expect(
|
||||
deleteAccessControlIndex(mockClient as unknown as IScopedClusterClient, 'indexName')
|
||||
).resolves.toEqual(true);
|
||||
expect(mockClient.asCurrentUser.indices.delete).toHaveBeenCalledWith({
|
||||
index: 'indexName',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when ACL index is missing', () => {
|
||||
const mockErrorRejection: ElasticsearchResponseError = {
|
||||
meta: {
|
||||
body: {
|
||||
error: {
|
||||
type: 'index_not_found_exception',
|
||||
},
|
||||
},
|
||||
statusCode: 404,
|
||||
},
|
||||
name: 'ResponseError',
|
||||
};
|
||||
|
||||
it('exits gracefully', async () => {
|
||||
mockClient.asCurrentUser.indices.delete.mockImplementation(() => {
|
||||
return Promise.reject(mockErrorRejection);
|
||||
});
|
||||
await expect(
|
||||
deleteAccessControlIndex(mockClient as unknown as IScopedClusterClient, 'indexName')
|
||||
).resolves.not.toThrowError();
|
||||
expect(mockClient.asCurrentUser.indices.delete).toHaveBeenCalledWith({
|
||||
index: 'indexName',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when index exists but another error is thrown', () => {
|
||||
const mockErrorRejection: ElasticsearchResponseError = {
|
||||
meta: {
|
||||
body: {
|
||||
error: {
|
||||
type: 'uncaught_exception',
|
||||
},
|
||||
},
|
||||
statusCode: 500,
|
||||
},
|
||||
name: 'ResponseError',
|
||||
};
|
||||
|
||||
it('throws the error', async () => {
|
||||
mockClient.asCurrentUser.indices.delete.mockImplementation(() => {
|
||||
return Promise.reject(mockErrorRejection);
|
||||
});
|
||||
await expect(
|
||||
deleteAccessControlIndex(mockClient as unknown as IScopedClusterClient, 'indexName')
|
||||
).rejects.toEqual(mockErrorRejection);
|
||||
expect(mockClient.asCurrentUser.indices.delete).toHaveBeenCalledWith({
|
||||
index: 'indexName',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -5,14 +5,14 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { isIndexNotFoundException } from '@kbn/core-saved-objects-migration-server-internal';
|
||||
import { IScopedClusterClient } from '@kbn/core/server';
|
||||
|
||||
import { CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX } from '../../../common/constants';
|
||||
import { isIndexNotFoundException } from '../../utils/identify_exceptions';
|
||||
|
||||
export const deleteAccessControlIndex = async (client: IScopedClusterClient, index: string) => {
|
||||
try {
|
||||
await client.asCurrentUser.indices.delete({
|
||||
return await client.asCurrentUser.indices.delete({
|
||||
index: index.replace('search-', CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX),
|
||||
});
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue