-
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.
[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.
- Loading branch information
1 parent
091643c
commit 3077919
Showing
2 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
x-pack/plugins/enterprise_search/server/lib/indices/delete_access_control_index.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,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', | ||
}); | ||
}); | ||
}); | ||
}); |
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