From 05c868a35de9f5f0796c187c2202f82c7461993e Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Tue, 30 Jun 2020 23:06:41 +0200 Subject: [PATCH 1/5] rename legacy client mocks --- .../elasticsearch_service.mock.ts | 8 ++--- .../elasticsearch_service.test.ts | 1 + .../core_service.test.mocks.ts | 4 +-- src/core/server/mocks.ts | 2 +- .../actions/server/actions_client.test.ts | 2 +- x-pack/plugins/actions/server/mocks.ts | 2 +- x-pack/plugins/alerts/server/mocks.ts | 2 +- .../server/routes/_mock_handler_arguments.ts | 2 +- .../alerts/server/routes/health.test.ts | 14 ++++---- .../server/routes/es_fields/es_fields.test.ts | 4 ++- .../server/es/cluster_client_adapter.test.ts | 2 +- .../event_log/server/es/context.test.ts | 2 +- .../plugins/licensing/server/plugin.test.ts | 33 ++++++++++--------- .../oss_telemetry/server/test_utils/index.ts | 2 +- .../server/routes/api/add_route.test.ts | 6 ++-- .../server/routes/api/delete_route.test.ts | 6 ++-- .../server/routes/api/get_route.test.ts | 6 ++-- .../server/routes/api/update_route.test.ts | 6 ++-- .../server/authentication/api_keys.test.ts | 4 +-- .../authentication/authenticator.test.ts | 2 +- .../server/authentication/index.test.ts | 4 +-- .../authentication/providers/base.mock.ts | 2 +- .../authentication/providers/basic.test.ts | 8 ++--- .../authentication/providers/http.test.ts | 4 +-- .../authentication/providers/kerberos.test.ts | 28 ++++++++-------- .../authentication/providers/oidc.test.ts | 16 ++++----- .../authentication/providers/pki.test.ts | 18 +++++----- .../authentication/providers/saml.test.ts | 30 ++++++++--------- .../authentication/providers/token.test.ts | 24 +++++++------- .../server/authentication/tokens.test.ts | 2 +- .../authorization_service.test.ts | 6 ++-- .../authorization/check_privileges.test.ts | 8 ++--- .../register_privileges_with_cluster.test.ts | 2 +- x-pack/plugins/security/server/plugin.test.ts | 2 +- .../server/routes/api_keys/get.test.ts | 2 +- .../server/routes/api_keys/invalidate.test.ts | 2 +- .../server/routes/api_keys/privileges.test.ts | 2 +- .../routes/authorization/roles/delete.test.ts | 2 +- .../routes/authorization/roles/get.test.ts | 2 +- .../authorization/roles/get_all.test.ts | 2 +- .../routes/authorization/roles/put.test.ts | 2 +- .../security/server/routes/index.mock.ts | 2 +- .../server/routes/role_mapping/delete.test.ts | 2 +- .../routes/role_mapping/feature_check.test.ts | 2 +- .../server/routes/role_mapping/get.test.ts | 6 ++-- .../server/routes/role_mapping/post.test.ts | 2 +- .../routes/users/change_password.test.ts | 2 +- .../endpoint/alerts/handlers/alerts.test.ts | 4 +-- .../endpoint/routes/metadata/metadata.test.ts | 4 +-- .../routes/metadata/support/unenroll.test.ts | 8 ++--- .../endpoint/routes/policy/handlers.test.ts | 2 +- .../routes/__mocks__/request_context.ts | 2 +- .../server/lib/machine_learning/mocks.ts | 2 +- .../lib/es_deprecation_logging_apis.test.ts | 6 ++-- .../server/lib/es_migration_apis.test.ts | 2 +- .../lib/telemetry/usage_collector.test.ts | 2 +- .../server/routes/__mocks__/routes.mock.ts | 2 +- .../__tests__/get_monitor_status.test.ts | 2 +- 58 files changed, 168 insertions(+), 162 deletions(-) diff --git a/src/core/server/elasticsearch/elasticsearch_service.mock.ts b/src/core/server/elasticsearch/elasticsearch_service.mock.ts index fdfc48fa9f754..cdbe358bf8b5f 100644 --- a/src/core/server/elasticsearch/elasticsearch_service.mock.ts +++ b/src/core/server/elasticsearch/elasticsearch_service.mock.ts @@ -175,8 +175,8 @@ export const elasticsearchServiceMock = { createInternalSetup: createInternalSetupContractMock, createSetup: createSetupContractMock, createStart: createStartContractMock, - createClusterClient: createClusterClientMock, - createCustomClusterClient: createCustomClusterClientMock, - createScopedClusterClient: createScopedClusterClientMock, - createElasticsearchClient: createElasticsearchClientMock, + createLegacyClusterClient: createClusterClientMock, + createLegacyCustomClusterClient: createCustomClusterClientMock, + createLegacyScopedClusterClient: createScopedClusterClientMock, + createLegacyElasticsearchClient: createElasticsearchClientMock, }; diff --git a/src/core/server/elasticsearch/elasticsearch_service.test.ts b/src/core/server/elasticsearch/elasticsearch_service.test.ts index 0a7068903e15c..2e210be5c09d1 100644 --- a/src/core/server/elasticsearch/elasticsearch_service.test.ts +++ b/src/core/server/elasticsearch/elasticsearch_service.test.ts @@ -31,6 +31,7 @@ import { httpServiceMock } from '../http/http_service.mock'; import { ElasticsearchConfig } from './elasticsearch_config'; import { ElasticsearchService } from './elasticsearch_service'; import { elasticsearchServiceMock } from './elasticsearch_service.mock'; +import { elasticsearchClientMock } from './client/mocks'; import { duration } from 'moment'; const delay = async (durationMs: number) => diff --git a/src/core/server/http/integration_tests/core_service.test.mocks.ts b/src/core/server/http/integration_tests/core_service.test.mocks.ts index 6f9b4b96eae9d..f7ebd18b9c488 100644 --- a/src/core/server/http/integration_tests/core_service.test.mocks.ts +++ b/src/core/server/http/integration_tests/core_service.test.mocks.ts @@ -21,7 +21,7 @@ import { elasticsearchServiceMock } from '../../elasticsearch/elasticsearch_serv export const clusterClientMock = jest.fn(); jest.doMock('../../elasticsearch/legacy/scoped_cluster_client', () => ({ LegacyScopedClusterClient: clusterClientMock.mockImplementation(function () { - return elasticsearchServiceMock.createScopedClusterClient(); + return elasticsearchServiceMock.createLegacyScopedClusterClient(); }), })); @@ -31,7 +31,7 @@ jest.doMock('elasticsearch', () => { ...realES, // eslint-disable-next-line object-shorthand Client: function () { - return elasticsearchServiceMock.createElasticsearchClient(); + return elasticsearchServiceMock.createLegacyElasticsearchClient(); }, }; }); diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 4491942951c50..73d8e79069ce3 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -190,7 +190,7 @@ function createCoreRequestHandlerContextMock() { }, elasticsearch: { legacy: { - client: elasticsearchServiceMock.createScopedClusterClient(), + client: elasticsearchServiceMock.createLegacyScopedClusterClient(), }, }, uiSettings: { diff --git a/x-pack/plugins/actions/server/actions_client.test.ts b/x-pack/plugins/actions/server/actions_client.test.ts index 69fab828e63de..807d75cd0d701 100644 --- a/x-pack/plugins/actions/server/actions_client.test.ts +++ b/x-pack/plugins/actions/server/actions_client.test.ts @@ -25,7 +25,7 @@ import { KibanaRequest } from 'kibana/server'; const defaultKibanaIndex = '.kibana'; const savedObjectsClient = savedObjectsClientMock.create(); -const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); +const scopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); const actionExecutor = actionExecutorMock.create(); const executionEnqueuer = jest.fn(); const request = {} as KibanaRequest; diff --git a/x-pack/plugins/actions/server/mocks.ts b/x-pack/plugins/actions/server/mocks.ts index 1763d275c6fb0..87aa571ce6b8a 100644 --- a/x-pack/plugins/actions/server/mocks.ts +++ b/x-pack/plugins/actions/server/mocks.ts @@ -37,7 +37,7 @@ const createServicesMock = () => { savedObjectsClient: ReturnType; } > = { - callCluster: elasticsearchServiceMock.createScopedClusterClient().callAsCurrentUser, + callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser, getScopedCallCluster: jest.fn(), savedObjectsClient: savedObjectsClientMock.create(), }; diff --git a/x-pack/plugins/alerts/server/mocks.ts b/x-pack/plugins/alerts/server/mocks.ts index c94a7aba46cfa..84f79d53f218c 100644 --- a/x-pack/plugins/alerts/server/mocks.ts +++ b/x-pack/plugins/alerts/server/mocks.ts @@ -58,7 +58,7 @@ const createAlertServicesMock = () => { alertInstanceFactory: jest .fn, [string]>() .mockReturnValue(alertInstanceFactoryMock), - callCluster: elasticsearchServiceMock.createScopedClusterClient().callAsCurrentUser, + callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser, getScopedCallCluster: jest.fn(), savedObjectsClient: savedObjectsClientMock.create(), }; diff --git a/x-pack/plugins/alerts/server/routes/_mock_handler_arguments.ts b/x-pack/plugins/alerts/server/routes/_mock_handler_arguments.ts index 7d86d4fde7e61..548495866ec21 100644 --- a/x-pack/plugins/alerts/server/routes/_mock_handler_arguments.ts +++ b/x-pack/plugins/alerts/server/routes/_mock_handler_arguments.ts @@ -20,7 +20,7 @@ export function mockHandlerArguments( { alertsClient = alertsClientMock.create(), listTypes: listTypesRes = [], - esClient = elasticsearchServiceMock.createClusterClient(), + esClient = elasticsearchServiceMock.createLegacyClusterClient(), }: { alertsClient?: AlertsClientMock; listTypes?: AlertType[]; diff --git a/x-pack/plugins/alerts/server/routes/health.test.ts b/x-pack/plugins/alerts/server/routes/health.test.ts index b3f41e03ebdc9..ce782dbd631a5 100644 --- a/x-pack/plugins/alerts/server/routes/health.test.ts +++ b/x-pack/plugins/alerts/server/routes/health.test.ts @@ -43,7 +43,7 @@ describe('healthRoute', () => { healthRoute(router, licenseState, encryptedSavedObjects); const [, handler] = router.get.mock.calls[0]; - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockReturnValue(Promise.resolve({})); const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']); @@ -72,7 +72,7 @@ describe('healthRoute', () => { healthRoute(router, licenseState, encryptedSavedObjects); const [, handler] = router.get.mock.calls[0]; - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockReturnValue(Promise.resolve({})); const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']); @@ -96,7 +96,7 @@ describe('healthRoute', () => { healthRoute(router, licenseState, encryptedSavedObjects); const [, handler] = router.get.mock.calls[0]; - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockReturnValue(Promise.resolve({})); const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']); @@ -120,7 +120,7 @@ describe('healthRoute', () => { healthRoute(router, licenseState, encryptedSavedObjects); const [, handler] = router.get.mock.calls[0]; - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockReturnValue(Promise.resolve({ security: {} })); const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']); @@ -144,7 +144,7 @@ describe('healthRoute', () => { healthRoute(router, licenseState, encryptedSavedObjects); const [, handler] = router.get.mock.calls[0]; - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockReturnValue(Promise.resolve({ security: { enabled: true } })); const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']); @@ -168,7 +168,7 @@ describe('healthRoute', () => { healthRoute(router, licenseState, encryptedSavedObjects); const [, handler] = router.get.mock.calls[0]; - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockReturnValue( Promise.resolve({ security: { enabled: true, ssl: {} } }) ); @@ -194,7 +194,7 @@ describe('healthRoute', () => { healthRoute(router, licenseState, encryptedSavedObjects); const [, handler] = router.get.mock.calls[0]; - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockReturnValue( Promise.resolve({ security: { enabled: true, ssl: { http: { enabled: true } } } }) ); diff --git a/x-pack/plugins/canvas/server/routes/es_fields/es_fields.test.ts b/x-pack/plugins/canvas/server/routes/es_fields/es_fields.test.ts index c1918feb7f4ec..c2cff83f85f0d 100644 --- a/x-pack/plugins/canvas/server/routes/es_fields/es_fields.test.ts +++ b/x-pack/plugins/canvas/server/routes/es_fields/es_fields.test.ts @@ -15,7 +15,9 @@ import { const mockRouteContext = ({ core: { - elasticsearch: { legacy: { client: elasticsearchServiceMock.createScopedClusterClient() } }, + elasticsearch: { + legacy: { client: elasticsearchServiceMock.createLegacyScopedClusterClient() }, + }, }, } as unknown) as RequestHandlerContext; diff --git a/x-pack/plugins/event_log/server/es/cluster_client_adapter.test.ts b/x-pack/plugins/event_log/server/es/cluster_client_adapter.test.ts index feec1ee9ba008..ee6f0a301e9f8 100644 --- a/x-pack/plugins/event_log/server/es/cluster_client_adapter.test.ts +++ b/x-pack/plugins/event_log/server/es/cluster_client_adapter.test.ts @@ -18,7 +18,7 @@ let clusterClientAdapter: IClusterClientAdapter; beforeEach(() => { logger = loggingSystemMock.createLogger(); - clusterClient = elasticsearchServiceMock.createClusterClient(); + clusterClient = elasticsearchServiceMock.createLegacyClusterClient(); clusterClientAdapter = new ClusterClientAdapter({ logger, clusterClientPromise: Promise.resolve(clusterClient), diff --git a/x-pack/plugins/event_log/server/es/context.test.ts b/x-pack/plugins/event_log/server/es/context.test.ts index 3fd7e12ed8a0c..a78e47446fef8 100644 --- a/x-pack/plugins/event_log/server/es/context.test.ts +++ b/x-pack/plugins/event_log/server/es/context.test.ts @@ -17,7 +17,7 @@ let clusterClient: EsClusterClient; beforeEach(() => { logger = loggingSystemMock.createLogger(); - clusterClient = elasticsearchServiceMock.createClusterClient(); + clusterClient = elasticsearchServiceMock.createLegacyClusterClient(); }); describe('createEsContext', () => { diff --git a/x-pack/plugins/licensing/server/plugin.test.ts b/x-pack/plugins/licensing/server/plugin.test.ts index bf549c18da303..6e8327e151543 100644 --- a/x-pack/plugins/licensing/server/plugin.test.ts +++ b/x-pack/plugins/licensing/server/plugin.test.ts @@ -31,11 +31,14 @@ const flushPromises = (ms = 50) => new Promise((res) => setTimeout(res, ms)); function createCoreSetupWith(esClient: ILegacyClusterClient) { const coreSetup = coreMock.createSetup(); - + const coreStart = coreMock.createStart(); coreSetup.getStartServices.mockResolvedValue([ { - ...coreMock.createStart(), - elasticsearch: { legacy: { client: esClient, createClient: jest.fn() } }, + ...coreStart, + elasticsearch: { + ...coreStart.elasticsearch, + legacy: { client: esClient, createClient: jest.fn() }, + }, }, {}, {}, @@ -61,7 +64,7 @@ describe('licensing plugin', () => { }); it('returns license', async () => { - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockResolvedValue({ license: buildRawLicense(), features: {}, @@ -77,7 +80,7 @@ describe('licensing plugin', () => { it('observable receives updated licenses', async () => { const types: LicenseType[] = ['basic', 'gold', 'platinum']; - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockImplementation(() => Promise.resolve({ license: buildRawLicense({ type: types.shift() }), @@ -96,7 +99,7 @@ describe('licensing plugin', () => { }); it('returns a license with error when request fails', async () => { - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockRejectedValue(new Error('test')); const coreSetup = createCoreSetupWith(esClient); @@ -109,7 +112,7 @@ describe('licensing plugin', () => { }); it('generate error message when x-pack plugin was not installed', async () => { - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); const error: ElasticsearchError = new Error('reason'); error.status = 400; esClient.callAsInternalUser.mockRejectedValue(error); @@ -127,7 +130,7 @@ describe('licensing plugin', () => { const error1 = new Error('reason-1'); const error2 = new Error('reason-2'); - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser .mockRejectedValueOnce(error1) @@ -145,7 +148,7 @@ describe('licensing plugin', () => { }); it('fetch license immediately without subscriptions', async () => { - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockResolvedValue({ license: buildRawLicense(), features: {}, @@ -161,7 +164,7 @@ describe('licensing plugin', () => { }); it('logs license details without subscriptions', async () => { - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockResolvedValue({ license: buildRawLicense(), features: {}, @@ -187,7 +190,7 @@ describe('licensing plugin', () => { it('generates signature based on fetched license content', async () => { const types: LicenseType[] = ['basic', 'gold', 'basic']; - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockImplementation(() => Promise.resolve({ license: buildRawLicense({ type: types.shift() }), @@ -218,7 +221,7 @@ describe('licensing plugin', () => { api_polling_frequency: moment.duration(50000), }) ); - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockResolvedValue({ license: buildRawLicense(), features: {}, @@ -253,7 +256,7 @@ describe('licensing plugin', () => { }) ); - const esClient = elasticsearchServiceMock.createClusterClient(); + const esClient = elasticsearchServiceMock.createLegacyClusterClient(); esClient.callAsInternalUser.mockResolvedValue({ license: buildRawLicense(), features: {}, @@ -262,7 +265,7 @@ describe('licensing plugin', () => { await plugin.setup(coreSetup); const { createLicensePoller, license$ } = await plugin.start(); - const customClient = elasticsearchServiceMock.createClusterClient(); + const customClient = elasticsearchServiceMock.createLegacyClusterClient(); customClient.callAsInternalUser.mockResolvedValue({ license: buildRawLicense({ type: 'gold' }), features: {}, @@ -297,7 +300,7 @@ describe('licensing plugin', () => { await plugin.setup(coreSetup); const { createLicensePoller } = await plugin.start(); - const customClient = elasticsearchServiceMock.createClusterClient(); + const customClient = elasticsearchServiceMock.createLegacyClusterClient(); customClient.callAsInternalUser.mockResolvedValue({ license: buildRawLicense({ type: 'gold' }), features: {}, diff --git a/x-pack/plugins/oss_telemetry/server/test_utils/index.ts b/x-pack/plugins/oss_telemetry/server/test_utils/index.ts index 7ac9819680839..3eee1978d4f1c 100644 --- a/x-pack/plugins/oss_telemetry/server/test_utils/index.ts +++ b/x-pack/plugins/oss_telemetry/server/test_utils/index.ts @@ -49,7 +49,7 @@ const defaultMockTaskDocs = [getMockTaskInstance()]; export const getMockEs = async ( mockCallWithInternal: LegacyAPICaller = getMockCallWithInternal() ) => { - const client = elasticsearchServiceMock.createClusterClient(); + const client = elasticsearchServiceMock.createLegacyClusterClient(); (client.callAsInternalUser as any) = mockCallWithInternal; return client; }; diff --git a/x-pack/plugins/remote_clusters/server/routes/api/add_route.test.ts b/x-pack/plugins/remote_clusters/server/routes/api/add_route.test.ts index d28e95834ca0b..406d5661c0915 100644 --- a/x-pack/plugins/remote_clusters/server/routes/api/add_route.test.ts +++ b/x-pack/plugins/remote_clusters/server/routes/api/add_route.test.ts @@ -28,7 +28,7 @@ describe('ADD remote clusters', () => { { licenseCheckResult = { valid: true }, apiResponses = [], asserts, payload }: TestOptions ) => { test(description, async () => { - const elasticsearchMock = elasticsearchServiceMock.createClusterClient(); + const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient(); const mockRouteDependencies = { router: httpServiceMock.createRouter(), @@ -40,10 +40,10 @@ describe('ADD remote clusters', () => { }, }; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); elasticsearchServiceMock - .createClusterClient() + .createLegacyClusterClient() .asScoped.mockReturnValue(mockScopedClusterClient); for (const apiResponse of apiResponses) { diff --git a/x-pack/plugins/remote_clusters/server/routes/api/delete_route.test.ts b/x-pack/plugins/remote_clusters/server/routes/api/delete_route.test.ts index d1e3cf89e94d9..bd2ad10c4013d 100644 --- a/x-pack/plugins/remote_clusters/server/routes/api/delete_route.test.ts +++ b/x-pack/plugins/remote_clusters/server/routes/api/delete_route.test.ts @@ -30,7 +30,7 @@ describe('DELETE remote clusters', () => { { licenseCheckResult = { valid: true }, apiResponses = [], asserts, params }: TestOptions ) => { test(description, async () => { - const elasticsearchMock = elasticsearchServiceMock.createClusterClient(); + const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient(); const mockRouteDependencies = { router: httpServiceMock.createRouter(), @@ -42,10 +42,10 @@ describe('DELETE remote clusters', () => { }, }; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); elasticsearchServiceMock - .createClusterClient() + .createLegacyClusterClient() .asScoped.mockReturnValue(mockScopedClusterClient); for (const apiResponse of apiResponses) { diff --git a/x-pack/plugins/remote_clusters/server/routes/api/get_route.test.ts b/x-pack/plugins/remote_clusters/server/routes/api/get_route.test.ts index 24e469c9ec9b2..910f9e69ea80c 100644 --- a/x-pack/plugins/remote_clusters/server/routes/api/get_route.test.ts +++ b/x-pack/plugins/remote_clusters/server/routes/api/get_route.test.ts @@ -29,7 +29,7 @@ describe('GET remote clusters', () => { { licenseCheckResult = { valid: true }, apiResponses = [], asserts }: TestOptions ) => { test(description, async () => { - const elasticsearchMock = elasticsearchServiceMock.createClusterClient(); + const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient(); const mockRouteDependencies = { router: httpServiceMock.createRouter(), @@ -41,10 +41,10 @@ describe('GET remote clusters', () => { }, }; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); elasticsearchServiceMock - .createClusterClient() + .createLegacyClusterClient() .asScoped.mockReturnValue(mockScopedClusterClient); for (const apiResponse of apiResponses) { diff --git a/x-pack/plugins/remote_clusters/server/routes/api/update_route.test.ts b/x-pack/plugins/remote_clusters/server/routes/api/update_route.test.ts index 9669c98e1349e..c20ba0a1ec7a9 100644 --- a/x-pack/plugins/remote_clusters/server/routes/api/update_route.test.ts +++ b/x-pack/plugins/remote_clusters/server/routes/api/update_route.test.ts @@ -37,7 +37,7 @@ describe('UPDATE remote clusters', () => { }: TestOptions ) => { test(description, async () => { - const elasticsearchMock = elasticsearchServiceMock.createClusterClient(); + const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient(); const mockRouteDependencies = { router: httpServiceMock.createRouter(), @@ -49,10 +49,10 @@ describe('UPDATE remote clusters', () => { }, }; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); elasticsearchServiceMock - .createClusterClient() + .createLegacyClusterClient() .asScoped.mockReturnValue(mockScopedClusterClient); for (const apiResponse of apiResponses) { diff --git a/x-pack/plugins/security/server/authentication/api_keys.test.ts b/x-pack/plugins/security/server/authentication/api_keys.test.ts index 0cdd452d459d1..631a6f9ab213c 100644 --- a/x-pack/plugins/security/server/authentication/api_keys.test.ts +++ b/x-pack/plugins/security/server/authentication/api_keys.test.ts @@ -24,8 +24,8 @@ describe('API Keys', () => { let mockLicense: jest.Mocked; beforeEach(() => { - mockClusterClient = elasticsearchServiceMock.createClusterClient(); - mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient(); + mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockClusterClient.asScoped.mockReturnValue( (mockScopedClusterClient as unknown) as jest.Mocked ); diff --git a/x-pack/plugins/security/server/authentication/authenticator.test.ts b/x-pack/plugins/security/server/authentication/authenticator.test.ts index 3b77ea3248173..300447096af99 100644 --- a/x-pack/plugins/security/server/authentication/authenticator.test.ts +++ b/x-pack/plugins/security/server/authentication/authenticator.test.ts @@ -45,7 +45,7 @@ function getMockOptions({ return { auditLogger: securityAuditLoggerMock.create(), getCurrentUser: jest.fn(), - clusterClient: elasticsearchServiceMock.createClusterClient(), + clusterClient: elasticsearchServiceMock.createLegacyClusterClient(), basePath: httpServiceMock.createSetupContract().basePath, license: licenseMock.create(), loggers: loggingSystemMock.create(), diff --git a/x-pack/plugins/security/server/authentication/index.test.ts b/x-pack/plugins/security/server/authentication/index.test.ts index 4157f0598b3d0..56d44e6628a87 100644 --- a/x-pack/plugins/security/server/authentication/index.test.ts +++ b/x-pack/plugins/security/server/authentication/index.test.ts @@ -69,7 +69,7 @@ describe('setupAuthentication()', () => { loggingSystemMock.create().get(), { isTLSEnabled: false } ), - clusterClient: elasticsearchServiceMock.createClusterClient(), + clusterClient: elasticsearchServiceMock.createLegacyClusterClient(), license: licenseMock.create(), loggers: loggingSystemMock.create(), getFeatureUsageService: jest @@ -77,7 +77,7 @@ describe('setupAuthentication()', () => { .mockReturnValue(securityFeatureUsageServiceMock.createStartContract()), }; - mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockSetupAuthenticationParams.clusterClient.asScoped.mockReturnValue( (mockScopedClusterClient as unknown) as jest.Mocked ); diff --git a/x-pack/plugins/security/server/authentication/providers/base.mock.ts b/x-pack/plugins/security/server/authentication/providers/base.mock.ts index 7c71348bb8ca0..1b574e6e44c10 100644 --- a/x-pack/plugins/security/server/authentication/providers/base.mock.ts +++ b/x-pack/plugins/security/server/authentication/providers/base.mock.ts @@ -16,7 +16,7 @@ export type MockAuthenticationProviderOptions = ReturnType< export function mockAuthenticationProviderOptions(options?: { name: string }) { return { - client: elasticsearchServiceMock.createClusterClient(), + client: elasticsearchServiceMock.createLegacyClusterClient(), logger: loggingSystemMock.create().get(), basePath: httpServiceMock.createBasePath(), tokens: { refresh: jest.fn(), invalidate: jest.fn() }, diff --git a/x-pack/plugins/security/server/authentication/providers/basic.test.ts b/x-pack/plugins/security/server/authentication/providers/basic.test.ts index 95de8ca9d00e7..22d10d1cec347 100644 --- a/x-pack/plugins/security/server/authentication/providers/basic.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/basic.test.ts @@ -43,7 +43,7 @@ describe('BasicAuthenticationProvider', () => { const credentials = { username: 'user', password: 'password' }; const authorization = generateAuthorizationHeader(credentials.username, credentials.password); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -65,7 +65,7 @@ describe('BasicAuthenticationProvider', () => { const authorization = generateAuthorizationHeader(credentials.username, credentials.password); const authenticationError = new Error('Some error'); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -147,7 +147,7 @@ describe('BasicAuthenticationProvider', () => { const user = mockAuthenticatedUser(); const authorization = generateAuthorizationHeader('user', 'password'); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -163,7 +163,7 @@ describe('BasicAuthenticationProvider', () => { const authorization = generateAuthorizationHeader('user', 'password'); const authenticationError = new Error('Forbidden'); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); diff --git a/x-pack/plugins/security/server/authentication/providers/http.test.ts b/x-pack/plugins/security/server/authentication/providers/http.test.ts index e6949269e3fc7..c221ecd3f1e20 100644 --- a/x-pack/plugins/security/server/authentication/providers/http.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/http.test.ts @@ -126,7 +126,7 @@ describe('HTTPAuthenticationProvider', () => { ]) { const request = httpServerMock.createKibanaRequest({ headers: { authorization: header } }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockClear(); @@ -156,7 +156,7 @@ describe('HTTPAuthenticationProvider', () => { ]) { const request = httpServerMock.createKibanaRequest({ headers: { authorization: header } }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockClear(); diff --git a/x-pack/plugins/security/server/authentication/providers/kerberos.test.ts b/x-pack/plugins/security/server/authentication/providers/kerberos.test.ts index c00374efd59b4..f04506eb01593 100644 --- a/x-pack/plugins/security/server/authentication/providers/kerberos.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/kerberos.test.ts @@ -47,7 +47,7 @@ describe('KerberosAuthenticationProvider', () => { it('does not handle requests that can be authenticated without `Negotiate` header.', async () => { const request = httpServerMock.createKibanaRequest({ headers: {} }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({}); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -61,7 +61,7 @@ describe('KerberosAuthenticationProvider', () => { it('does not handle requests if backend does not support Kerberos.', async () => { const request = httpServerMock.createKibanaRequest({ headers: {} }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -82,7 +82,7 @@ describe('KerberosAuthenticationProvider', () => { body: { error: { header: { 'WWW-Authenticate': 'Negotiate' } } }, }) ); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -101,7 +101,7 @@ describe('KerberosAuthenticationProvider', () => { const request = httpServerMock.createKibanaRequest({ headers: {} }); const failureReason = new errors.ServiceUnavailable(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -118,7 +118,7 @@ describe('KerberosAuthenticationProvider', () => { headers: { authorization: 'negotiate spnego' }, }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.callAsInternalUser.mockResolvedValue({ @@ -153,7 +153,7 @@ describe('KerberosAuthenticationProvider', () => { headers: { authorization: 'negotiate spnego' }, }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.callAsInternalUser.mockResolvedValue({ @@ -257,7 +257,7 @@ describe('KerberosAuthenticationProvider', () => { }); const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.callAsInternalUser.mockResolvedValue({ @@ -323,7 +323,7 @@ describe('KerberosAuthenticationProvider', () => { const tokenPair = { accessToken: 'token', refreshToken: 'refresh-token' }; const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.tokens.refresh.mockResolvedValue(null); @@ -355,7 +355,7 @@ describe('KerberosAuthenticationProvider', () => { }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -378,7 +378,7 @@ describe('KerberosAuthenticationProvider', () => { mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -386,7 +386,7 @@ describe('KerberosAuthenticationProvider', () => { } if (scopeableRequest?.headers.authorization === 'Bearer newfoo') { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); return mockScopedClusterClient; } @@ -423,7 +423,7 @@ describe('KerberosAuthenticationProvider', () => { }; const failureReason = new errors.InternalServerError('Token is not valid!'); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -450,7 +450,7 @@ describe('KerberosAuthenticationProvider', () => { body: { error: { header: { 'WWW-Authenticate': 'Negotiate' } } }, }) ); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -475,7 +475,7 @@ describe('KerberosAuthenticationProvider', () => { body: { error: { header: { 'WWW-Authenticate': 'Negotiate' } } }, }) ); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); diff --git a/x-pack/plugins/security/server/authentication/providers/oidc.test.ts b/x-pack/plugins/security/server/authentication/providers/oidc.test.ts index d787e76628d6d..aea5994e3ba3e 100644 --- a/x-pack/plugins/security/server/authentication/providers/oidc.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/oidc.test.ts @@ -389,7 +389,7 @@ describe('OIDCAuthenticationProvider', () => { }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -446,7 +446,7 @@ describe('OIDCAuthenticationProvider', () => { const authorization = `Bearer ${tokenPair.accessToken}`; const failureReason = new Error('Token is not valid!'); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -466,7 +466,7 @@ describe('OIDCAuthenticationProvider', () => { mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -474,7 +474,7 @@ describe('OIDCAuthenticationProvider', () => { } if (scopeableRequest?.headers.authorization === 'Bearer new-access-token') { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); return mockScopedClusterClient; } @@ -514,7 +514,7 @@ describe('OIDCAuthenticationProvider', () => { const tokenPair = { accessToken: 'expired-token', refreshToken: 'invalid-refresh-token' }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -554,7 +554,7 @@ describe('OIDCAuthenticationProvider', () => { '&redirect_uri=https%3A%2F%2Ftest-hostname:1234%2Ftest-base-path%2Fapi%2Fsecurity%2Fv1%2F/oidc', }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -602,7 +602,7 @@ describe('OIDCAuthenticationProvider', () => { const tokenPair = { accessToken: 'expired-token', refreshToken: 'expired-refresh-token' }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -631,7 +631,7 @@ describe('OIDCAuthenticationProvider', () => { const tokenPair = { accessToken: 'expired-token', refreshToken: 'expired-refresh-token' }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); diff --git a/x-pack/plugins/security/server/authentication/providers/pki.test.ts b/x-pack/plugins/security/server/authentication/providers/pki.test.ts index fd014e1a7cb81..fec03c5d04b0d 100644 --- a/x-pack/plugins/security/server/authentication/providers/pki.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/pki.test.ts @@ -120,7 +120,7 @@ describe('PKIAuthenticationProvider', () => { }), }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); @@ -162,7 +162,7 @@ describe('PKIAuthenticationProvider', () => { }), }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); @@ -220,7 +220,7 @@ describe('PKIAuthenticationProvider', () => { }); const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); @@ -349,7 +349,7 @@ describe('PKIAuthenticationProvider', () => { }); const state = { accessToken: 'existing-token', peerCertificateFingerprint256: '3A:9A:C5:DD' }; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); @@ -392,7 +392,7 @@ describe('PKIAuthenticationProvider', () => { }); const state = { accessToken: 'existing-token', peerCertificateFingerprint256: '2A:7A:C2:DD' }; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser // In response to call with an expired token. .mockRejectedValueOnce( @@ -436,7 +436,7 @@ describe('PKIAuthenticationProvider', () => { }); const state = { accessToken: 'existing-token', peerCertificateFingerprint256: '2A:7A:C2:DD' }; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValueOnce( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -454,7 +454,7 @@ describe('PKIAuthenticationProvider', () => { const request = httpServerMock.createKibanaRequest({ socket: getMockSocket() }); const state = { accessToken: 'existing-token', peerCertificateFingerprint256: '2A:7A:C2:DD' }; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -480,7 +480,7 @@ describe('PKIAuthenticationProvider', () => { }), }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -509,7 +509,7 @@ describe('PKIAuthenticationProvider', () => { }); const failureReason = new errors.ServiceUnavailable(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); diff --git a/x-pack/plugins/security/server/authentication/providers/saml.test.ts b/x-pack/plugins/security/server/authentication/providers/saml.test.ts index e9af806b36f04..851ecf8107ad2 100644 --- a/x-pack/plugins/security/server/authentication/providers/saml.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/saml.test.ts @@ -319,7 +319,7 @@ describe('SAMLAuthenticationProvider', () => { beforeEach(() => { mockOptions.basePath.get.mockReturnValue(mockOptions.basePath.serverBasePath); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => Promise.resolve(mockAuthenticatedUser()) ); @@ -448,7 +448,7 @@ describe('SAMLAuthenticationProvider', () => { const authorization = 'Bearer some-valid-token'; const user = mockAuthenticatedUser(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -489,7 +489,7 @@ describe('SAMLAuthenticationProvider', () => { const authorization = `Bearer ${state.accessToken}`; const user = mockAuthenticatedUser(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -543,7 +543,7 @@ describe('SAMLAuthenticationProvider', () => { }; const authorization = `Bearer ${state.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => response); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -598,7 +598,7 @@ describe('SAMLAuthenticationProvider', () => { }; const authorization = `Bearer ${state.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => response); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -663,7 +663,7 @@ describe('SAMLAuthenticationProvider', () => { }; const authorization = `Bearer ${state.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => response); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -1061,7 +1061,7 @@ describe('SAMLAuthenticationProvider', () => { }; const authorization = `Bearer ${state.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -1088,7 +1088,7 @@ describe('SAMLAuthenticationProvider', () => { const authorization = `Bearer ${state.accessToken}`; const failureReason = { statusCode: 500, message: 'Token is not valid!' }; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -1113,7 +1113,7 @@ describe('SAMLAuthenticationProvider', () => { mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { if (scopeableRequest?.headers.authorization === `Bearer ${state.accessToken}`) { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -1121,7 +1121,7 @@ describe('SAMLAuthenticationProvider', () => { } if (scopeableRequest?.headers.authorization === 'Bearer new-access-token') { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); return mockScopedClusterClient; } @@ -1165,7 +1165,7 @@ describe('SAMLAuthenticationProvider', () => { }; const authorization = `Bearer ${state.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -1199,7 +1199,7 @@ describe('SAMLAuthenticationProvider', () => { }; const authorization = `Bearer ${state.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -1231,7 +1231,7 @@ describe('SAMLAuthenticationProvider', () => { }; const authorization = `Bearer ${state.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -1263,7 +1263,7 @@ describe('SAMLAuthenticationProvider', () => { }; const authorization = `Bearer ${state.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -1304,7 +1304,7 @@ describe('SAMLAuthenticationProvider', () => { redirect: 'https://idp-host/path/login?SAMLRequest=some%20request%20', }); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); diff --git a/x-pack/plugins/security/server/authentication/providers/token.test.ts b/x-pack/plugins/security/server/authentication/providers/token.test.ts index ba0f23a3393ae..f83331d84e43c 100644 --- a/x-pack/plugins/security/server/authentication/providers/token.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/token.test.ts @@ -49,7 +49,7 @@ describe('TokenAuthenticationProvider', () => { const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -106,7 +106,7 @@ describe('TokenAuthenticationProvider', () => { }); const authenticationError = new Error('Some error'); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -190,7 +190,7 @@ describe('TokenAuthenticationProvider', () => { const user = mockAuthenticatedUser(); const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -213,7 +213,7 @@ describe('TokenAuthenticationProvider', () => { mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -221,7 +221,7 @@ describe('TokenAuthenticationProvider', () => { } if (scopeableRequest?.headers.authorization === 'Bearer newfoo') { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); return mockScopedClusterClient; } @@ -256,7 +256,7 @@ describe('TokenAuthenticationProvider', () => { const authorization = `Bearer ${tokenPair.accessToken}`; const authenticationError = new errors.InternalServerError('something went wrong'); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); @@ -274,7 +274,7 @@ describe('TokenAuthenticationProvider', () => { const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -300,7 +300,7 @@ describe('TokenAuthenticationProvider', () => { const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -331,7 +331,7 @@ describe('TokenAuthenticationProvider', () => { const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -362,7 +362,7 @@ describe('TokenAuthenticationProvider', () => { const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -389,7 +389,7 @@ describe('TokenAuthenticationProvider', () => { const authenticationError = new errors.AuthenticationException('Some error'); mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) ); @@ -397,7 +397,7 @@ describe('TokenAuthenticationProvider', () => { } if (scopeableRequest?.headers.authorization === 'Bearer newfoo') { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); return mockScopedClusterClient; } diff --git a/x-pack/plugins/security/server/authentication/tokens.test.ts b/x-pack/plugins/security/server/authentication/tokens.test.ts index 8ad04672fdfad..e8cf37330aff2 100644 --- a/x-pack/plugins/security/server/authentication/tokens.test.ts +++ b/x-pack/plugins/security/server/authentication/tokens.test.ts @@ -18,7 +18,7 @@ describe('Tokens', () => { let tokens: Tokens; let mockClusterClient: jest.Mocked; beforeEach(() => { - mockClusterClient = elasticsearchServiceMock.createClusterClient(); + mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient(); const tokensOptions = { client: mockClusterClient, diff --git a/x-pack/plugins/security/server/authorization/authorization_service.test.ts b/x-pack/plugins/security/server/authorization/authorization_service.test.ts index 4d0ab1c964741..f67e0863086bb 100644 --- a/x-pack/plugins/security/server/authorization/authorization_service.test.ts +++ b/x-pack/plugins/security/server/authorization/authorization_service.test.ts @@ -56,7 +56,7 @@ afterEach(() => { }); it(`#setup returns exposed services`, () => { - const mockClusterClient = elasticsearchServiceMock.createClusterClient(); + const mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient(); const mockGetSpacesService = jest .fn() .mockReturnValue({ getSpaceId: jest.fn(), namespaceToSpaceId: jest.fn() }); @@ -119,7 +119,7 @@ describe('#start', () => { let licenseSubject: BehaviorSubject; let mockLicense: jest.Mocked; beforeEach(() => { - const mockClusterClient = elasticsearchServiceMock.createClusterClient(); + const mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient(); licenseSubject = new BehaviorSubject(({} as unknown) as SecurityLicenseFeatures); mockLicense = licenseMock.create(); @@ -221,7 +221,7 @@ describe('#start', () => { }); it('#stop unsubscribes from license and ES updates.', () => { - const mockClusterClient = elasticsearchServiceMock.createClusterClient(); + const mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient(); const licenseSubject = new BehaviorSubject(({} as unknown) as SecurityLicenseFeatures); const mockLicense = licenseMock.create(); diff --git a/x-pack/plugins/security/server/authorization/check_privileges.test.ts b/x-pack/plugins/security/server/authorization/check_privileges.test.ts index 65a3d1bf1650b..b380f45a12d81 100644 --- a/x-pack/plugins/security/server/authorization/check_privileges.test.ts +++ b/x-pack/plugins/security/server/authorization/check_privileges.test.ts @@ -21,10 +21,10 @@ const mockActions = { const savedObjectTypes = ['foo-type', 'bar-type']; const createMockClusterClient = (response: any) => { - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(response); - const mockClusterClient = elasticsearchServiceMock.createClusterClient(); + const mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient(); mockClusterClient.asScoped.mockReturnValue(mockScopedClusterClient); return { mockClusterClient, mockScopedClusterClient }; @@ -737,7 +737,7 @@ describe('#atSpaces', () => { [`saved_object:${savedObjectTypes[0]}/get`]: false, [`saved_object:${savedObjectTypes[1]}/get`]: true, }, - // @ts-ignore this is wrong on purpose + // @ts-expect-error this is wrong on purpose 'space:space_1': { [mockActions.login]: true, [mockActions.version]: true, @@ -765,7 +765,7 @@ describe('#atSpaces', () => { [mockActions.login]: true, [mockActions.version]: true, }, - // @ts-ignore this is wrong on purpose + // @ts-expect-error this is wrong on purpose 'space:space_1': { [mockActions.login]: true, [mockActions.version]: true, diff --git a/x-pack/plugins/security/server/authorization/register_privileges_with_cluster.test.ts b/x-pack/plugins/security/server/authorization/register_privileges_with_cluster.test.ts index 0ce7eae932fea..c102af76805b0 100644 --- a/x-pack/plugins/security/server/authorization/register_privileges_with_cluster.test.ts +++ b/x-pack/plugins/security/server/authorization/register_privileges_with_cluster.test.ts @@ -100,7 +100,7 @@ const registerPrivilegesWithClusterTest = ( }; test(description, async () => { - const mockClusterClient = elasticsearchServiceMock.createClusterClient(); + const mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient(); mockClusterClient.callAsInternalUser.mockImplementation(async (api) => { switch (api) { case 'shield.getPrivilege': { diff --git a/x-pack/plugins/security/server/plugin.test.ts b/x-pack/plugins/security/server/plugin.test.ts index 64af6fc857273..a7b958ee02de5 100644 --- a/x-pack/plugins/security/server/plugin.test.ts +++ b/x-pack/plugins/security/server/plugin.test.ts @@ -43,7 +43,7 @@ describe('Security Plugin', () => { protocol: 'https', }); - mockClusterClient = elasticsearchServiceMock.createCustomClusterClient(); + mockClusterClient = elasticsearchServiceMock.createLegacyCustomClusterClient(); mockCoreSetup.elasticsearch.legacy.createClient.mockReturnValue(mockClusterClient); mockDependencies = ({ diff --git a/x-pack/plugins/security/server/routes/api_keys/get.test.ts b/x-pack/plugins/security/server/routes/api_keys/get.test.ts index f77469552d980..40065e757e999 100644 --- a/x-pack/plugins/security/server/routes/api_keys/get.test.ts +++ b/x-pack/plugins/security/server/routes/api_keys/get.test.ts @@ -27,7 +27,7 @@ describe('Get API keys', () => { test(description, async () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); if (apiResponse) { mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse); diff --git a/x-pack/plugins/security/server/routes/api_keys/invalidate.test.ts b/x-pack/plugins/security/server/routes/api_keys/invalidate.test.ts index 2889cf78aff83..33c52688ce8e3 100644 --- a/x-pack/plugins/security/server/routes/api_keys/invalidate.test.ts +++ b/x-pack/plugins/security/server/routes/api_keys/invalidate.test.ts @@ -27,7 +27,7 @@ describe('Invalidate API keys', () => { ) => { test(description, async () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); for (const apiResponse of apiResponses) { mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(apiResponse); diff --git a/x-pack/plugins/security/server/routes/api_keys/privileges.test.ts b/x-pack/plugins/security/server/routes/api_keys/privileges.test.ts index afb67dc3bbfca..a506cc6306c53 100644 --- a/x-pack/plugins/security/server/routes/api_keys/privileges.test.ts +++ b/x-pack/plugins/security/server/routes/api_keys/privileges.test.ts @@ -48,7 +48,7 @@ describe('Check API keys privileges', () => { apiKeys.areAPIKeysEnabled() ); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); for (const apiResponse of callAsCurrentUserResponses) { mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(apiResponse); diff --git a/x-pack/plugins/security/server/routes/authorization/roles/delete.test.ts b/x-pack/plugins/security/server/routes/authorization/roles/delete.test.ts index ada6a1c8d2dc3..399f79f44744d 100644 --- a/x-pack/plugins/security/server/routes/authorization/roles/delete.test.ts +++ b/x-pack/plugins/security/server/routes/authorization/roles/delete.test.ts @@ -30,7 +30,7 @@ describe('DELETE role', () => { test(description, async () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); if (apiResponse) { mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse); diff --git a/x-pack/plugins/security/server/routes/authorization/roles/get.test.ts b/x-pack/plugins/security/server/routes/authorization/roles/get.test.ts index 49123fe9c74d7..d9062bcfa2efe 100644 --- a/x-pack/plugins/security/server/routes/authorization/roles/get.test.ts +++ b/x-pack/plugins/security/server/routes/authorization/roles/get.test.ts @@ -33,7 +33,7 @@ describe('GET role', () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); mockRouteDefinitionParams.authz.applicationName = application; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); if (apiResponse) { mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse); diff --git a/x-pack/plugins/security/server/routes/authorization/roles/get_all.test.ts b/x-pack/plugins/security/server/routes/authorization/roles/get_all.test.ts index 5dbe8682c5426..66e8086d49c66 100644 --- a/x-pack/plugins/security/server/routes/authorization/roles/get_all.test.ts +++ b/x-pack/plugins/security/server/routes/authorization/roles/get_all.test.ts @@ -33,7 +33,7 @@ describe('GET all roles', () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); mockRouteDefinitionParams.authz.applicationName = application; - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); if (apiResponse) { mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse); diff --git a/x-pack/plugins/security/server/routes/authorization/roles/put.test.ts b/x-pack/plugins/security/server/routes/authorization/roles/put.test.ts index bec60fa149bcf..8f115f11329d3 100644 --- a/x-pack/plugins/security/server/routes/authorization/roles/put.test.ts +++ b/x-pack/plugins/security/server/routes/authorization/roles/put.test.ts @@ -72,7 +72,7 @@ const putRoleTest = ( mockRouteDefinitionParams.authz.applicationName = application; mockRouteDefinitionParams.authz.privileges.get.mockReturnValue(privilegeMap); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); for (const apiResponse of apiResponses) { mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(apiResponse); diff --git a/x-pack/plugins/security/server/routes/index.mock.ts b/x-pack/plugins/security/server/routes/index.mock.ts index c7ff2a1e68b02..24de2af5e9703 100644 --- a/x-pack/plugins/security/server/routes/index.mock.ts +++ b/x-pack/plugins/security/server/routes/index.mock.ts @@ -21,7 +21,7 @@ export const routeDefinitionParamsMock = { basePath: httpServiceMock.createBasePath(), csp: httpServiceMock.createSetupContract().csp, logger: loggingSystemMock.create().get(), - clusterClient: elasticsearchServiceMock.createClusterClient(), + clusterClient: elasticsearchServiceMock.createLegacyClusterClient(), config: createConfig(ConfigSchema.validate(config), loggingSystemMock.create().get(), { isTLSEnabled: false, }), diff --git a/x-pack/plugins/security/server/routes/role_mapping/delete.test.ts b/x-pack/plugins/security/server/routes/role_mapping/delete.test.ts index 34961dbe27675..aec0310129f6e 100644 --- a/x-pack/plugins/security/server/routes/role_mapping/delete.test.ts +++ b/x-pack/plugins/security/server/routes/role_mapping/delete.test.ts @@ -13,7 +13,7 @@ describe('DELETE role mappings', () => { it('allows a role mapping to be deleted', async () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({ acknowledged: true }); diff --git a/x-pack/plugins/security/server/routes/role_mapping/feature_check.test.ts b/x-pack/plugins/security/server/routes/role_mapping/feature_check.test.ts index 8070b3371fcb3..ee1d550bbe24d 100644 --- a/x-pack/plugins/security/server/routes/role_mapping/feature_check.test.ts +++ b/x-pack/plugins/security/server/routes/role_mapping/feature_check.test.ts @@ -76,7 +76,7 @@ describe('GET role mappings feature check', () => { test(description, async () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.callAsInternalUser.mockImplementation( internalUserClusterClientImpl diff --git a/x-pack/plugins/security/server/routes/role_mapping/get.test.ts b/x-pack/plugins/security/server/routes/role_mapping/get.test.ts index e0df59ebe7a00..9af7268a57f9c 100644 --- a/x-pack/plugins/security/server/routes/role_mapping/get.test.ts +++ b/x-pack/plugins/security/server/routes/role_mapping/get.test.ts @@ -53,7 +53,7 @@ describe('GET role mappings', () => { it('returns all role mappings', async () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(mockRoleMappingResponse); @@ -128,7 +128,7 @@ describe('GET role mappings', () => { it('returns role mapping by name', async () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({ mapping1: { @@ -216,7 +216,7 @@ describe('GET role mappings', () => { it('returns a 404 when the role mapping is not found', async () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( Boom.notFound('role mapping not found!') diff --git a/x-pack/plugins/security/server/routes/role_mapping/post.test.ts b/x-pack/plugins/security/server/routes/role_mapping/post.test.ts index ed3d1bbd0fca2..8f61d2a122f0c 100644 --- a/x-pack/plugins/security/server/routes/role_mapping/post.test.ts +++ b/x-pack/plugins/security/server/routes/role_mapping/post.test.ts @@ -13,7 +13,7 @@ describe('POST role mappings', () => { it('allows a role mapping to be created', async () => { const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); - const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({ created: true }); diff --git a/x-pack/plugins/security/server/routes/users/change_password.test.ts b/x-pack/plugins/security/server/routes/users/change_password.test.ts index 721c020c7431b..21c7fc1340437 100644 --- a/x-pack/plugins/security/server/routes/users/change_password.test.ts +++ b/x-pack/plugins/security/server/routes/users/change_password.test.ts @@ -56,7 +56,7 @@ describe('Change password', () => { provider: { type: 'basic', name: 'basic' }, }); - mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); + mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockClusterClient = routeParamsMock.clusterClient; mockClusterClient.asScoped.mockReturnValue(mockScopedClusterClient); diff --git a/x-pack/plugins/security_solution/server/endpoint/alerts/handlers/alerts.test.ts b/x-pack/plugins/security_solution/server/endpoint/alerts/handlers/alerts.test.ts index 24af9917186ba..addfae4ed16cc 100644 --- a/x-pack/plugins/security_solution/server/endpoint/alerts/handlers/alerts.test.ts +++ b/x-pack/plugins/security_solution/server/endpoint/alerts/handlers/alerts.test.ts @@ -22,8 +22,8 @@ describe('test alerts route', () => { let endpointAppContextService: EndpointAppContextService; beforeEach(() => { - mockClusterClient = elasticsearchServiceMock.createClusterClient(); - mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); + mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient(); + mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockClusterClient.asScoped.mockReturnValue(mockScopedClient); routerMock = httpServiceMock.createRouter(); diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/metadata/metadata.test.ts b/x-pack/plugins/security_solution/server/endpoint/routes/metadata/metadata.test.ts index f6ae2c584a346..310b9e7136a04 100644 --- a/x-pack/plugins/security_solution/server/endpoint/routes/metadata/metadata.test.ts +++ b/x-pack/plugins/security_solution/server/endpoint/routes/metadata/metadata.test.ts @@ -59,10 +59,10 @@ describe('test endpoint route', () => { } as unknown) as SearchResponse); beforeEach(() => { - mockClusterClient = elasticsearchServiceMock.createClusterClient() as jest.Mocked< + mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient() as jest.Mocked< ILegacyClusterClient >; - mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); + mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockSavedObjectClient = savedObjectsClientMock.create(); mockClusterClient.asScoped.mockReturnValue(mockScopedClient); routerMock = httpServiceMock.createRouter(); diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/metadata/support/unenroll.test.ts b/x-pack/plugins/security_solution/server/endpoint/routes/metadata/support/unenroll.test.ts index 545095a6a0c16..8ea30315c6a8c 100644 --- a/x-pack/plugins/security_solution/server/endpoint/routes/metadata/support/unenroll.test.ts +++ b/x-pack/plugins/security_solution/server/endpoint/routes/metadata/support/unenroll.test.ts @@ -29,7 +29,7 @@ describe('test find all unenrolled HostId', () => { it('can find all hits with scroll', async () => { const firstHostId = '1fdca33f-799f-49f4-939c-ea4383c77671'; const secondHostId = '2fdca33f-799f-49f4-939c-ea4383c77672'; - mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); + mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClient.callAsCurrentUser .mockImplementationOnce(() => Promise.resolve(createSearchResponse(secondHostId, 'scrollId'))) .mockImplementationOnce(noUnenrolledEndpoint); @@ -46,7 +46,7 @@ describe('test find all unenrolled HostId', () => { it('can find all unerolled endpoint host ids', async () => { const firstEndpointHostId = '1fdca33f-799f-49f4-939c-ea4383c77671'; const secondEndpointHostId = '2fdca33f-799f-49f4-939c-ea4383c77672'; - mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); + mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClient.callAsCurrentUser .mockImplementationOnce(() => Promise.resolve(createSearchResponse(firstEndpointHostId, 'initialScrollId')) @@ -86,7 +86,7 @@ describe('test find unenrolled endpoint host id by hostId', () => { it('can find unenrolled endpoint by the host id when unenrolled', async () => { const firstEndpointHostId = '1fdca33f-799f-49f4-939c-ea4383c77671'; - mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); + mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClient.callAsCurrentUser.mockImplementationOnce(() => Promise.resolve(createSearchResponse(firstEndpointHostId, 'initialScrollId')) ); @@ -119,7 +119,7 @@ describe('test find unenrolled endpoint host id by hostId', () => { it('find unenrolled endpoint host by the host id return undefined when no unenrolled host', async () => { const firstHostId = '1fdca33f-799f-49f4-939c-ea4383c77671'; - mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); + mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockScopedClient.callAsCurrentUser.mockImplementationOnce(noUnenrolledEndpoint); const hostId = await findUnenrolledHostByHostId(mockScopedClient, firstHostId); expect(hostId).toBeFalsy(); diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/policy/handlers.test.ts b/x-pack/plugins/security_solution/server/endpoint/routes/policy/handlers.test.ts index 0578f795f4a4e..8d4524e06c49f 100644 --- a/x-pack/plugins/security_solution/server/endpoint/routes/policy/handlers.test.ts +++ b/x-pack/plugins/security_solution/server/endpoint/routes/policy/handlers.test.ts @@ -32,7 +32,7 @@ describe('test policy response handler', () => { let mockResponse: jest.Mocked; beforeEach(() => { - mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); + mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockSavedObjectClient = savedObjectsClientMock.create(); mockResponse = httpServerMock.createResponseFactory(); endpointAppContextService = new EndpointAppContextService(); diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/request_context.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/request_context.ts index 7289eb6dea161..c45dd5bd8a281 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/request_context.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/__mocks__/request_context.ts @@ -16,7 +16,7 @@ import { siemMock } from '../../../../mocks'; const createMockClients = () => ({ alertsClient: alertsClientMock.create(), - clusterClient: elasticsearchServiceMock.createScopedClusterClient(), + clusterClient: elasticsearchServiceMock.createLegacyScopedClusterClient(), licensing: { license: licensingMock.createLicenseMock() }, savedObjectsClient: savedObjectsClientMock.create(), appClient: siemMock.createClient(), diff --git a/x-pack/plugins/security_solution/server/lib/machine_learning/mocks.ts b/x-pack/plugins/security_solution/server/lib/machine_learning/mocks.ts index f044022d6db69..e9b692e4731aa 100644 --- a/x-pack/plugins/security_solution/server/lib/machine_learning/mocks.ts +++ b/x-pack/plugins/security_solution/server/lib/machine_learning/mocks.ts @@ -7,7 +7,7 @@ import { MlPluginSetup } from '../../../../ml/server'; import { elasticsearchServiceMock } from '../../../../../../src/core/server/mocks'; -const createMockClient = () => elasticsearchServiceMock.createClusterClient(); +const createMockClient = () => elasticsearchServiceMock.createLegacyClusterClient(); const createMockMlSystemProvider = () => jest.fn(() => ({ mlCapabilities: jest.fn(), diff --git a/x-pack/plugins/upgrade_assistant/server/lib/es_deprecation_logging_apis.test.ts b/x-pack/plugins/upgrade_assistant/server/lib/es_deprecation_logging_apis.test.ts index 4ce21f1b311e8..b0dec299b2b12 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/es_deprecation_logging_apis.test.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/es_deprecation_logging_apis.test.ts @@ -12,7 +12,7 @@ import { describe('getDeprecationLoggingStatus', () => { it('calls cluster.getSettings', async () => { - const dataClient = elasticsearchServiceMock.createScopedClusterClient(); + const dataClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); await getDeprecationLoggingStatus(dataClient); expect(dataClient.callAsCurrentUser).toHaveBeenCalledWith('cluster.getSettings', { includeDefaults: true, @@ -23,7 +23,7 @@ describe('getDeprecationLoggingStatus', () => { describe('setDeprecationLogging', () => { describe('isEnabled = true', () => { it('calls cluster.putSettings with logger.deprecation = WARN', async () => { - const dataClient = elasticsearchServiceMock.createScopedClusterClient(); + const dataClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); await setDeprecationLogging(dataClient, true); expect(dataClient.callAsCurrentUser).toHaveBeenCalledWith('cluster.putSettings', { body: { transient: { 'logger.deprecation': 'WARN' } }, @@ -33,7 +33,7 @@ describe('setDeprecationLogging', () => { describe('isEnabled = false', () => { it('calls cluster.putSettings with logger.deprecation = ERROR', async () => { - const dataClient = elasticsearchServiceMock.createScopedClusterClient(); + const dataClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); await setDeprecationLogging(dataClient, false); expect(dataClient.callAsCurrentUser).toHaveBeenCalledWith('cluster.putSettings', { body: { transient: { 'logger.deprecation': 'ERROR' } }, diff --git a/x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.test.ts b/x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.test.ts index 89571a4a18231..2a4fa5cd48ded 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.test.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.test.ts @@ -14,7 +14,7 @@ import fakeDeprecations from './__fixtures__/fake_deprecations.json'; describe('getUpgradeAssistantStatus', () => { let deprecationsResponse: DeprecationAPIResponse; - const dataClient = elasticsearchServiceMock.createScopedClusterClient(); + const dataClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); (dataClient.callAsCurrentUser as jest.Mock).mockImplementation(async (api, { path, index }) => { if (path === '/_migration/deprecations') { return deprecationsResponse; diff --git a/x-pack/plugins/upgrade_assistant/server/lib/telemetry/usage_collector.test.ts b/x-pack/plugins/upgrade_assistant/server/lib/telemetry/usage_collector.test.ts index 7188241e10f9a..e14056439ca6b 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/telemetry/usage_collector.test.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/telemetry/usage_collector.test.ts @@ -21,7 +21,7 @@ describe('Upgrade Assistant Usage Collector', () => { let clusterClient: ILegacyClusterClient; beforeEach(() => { - clusterClient = elasticsearchServiceMock.createClusterClient(); + clusterClient = elasticsearchServiceMock.createLegacyClusterClient(); (clusterClient.callAsInternalUser as jest.Mock).mockResolvedValue({ persistent: {}, transient: { diff --git a/x-pack/plugins/upgrade_assistant/server/routes/__mocks__/routes.mock.ts b/x-pack/plugins/upgrade_assistant/server/routes/__mocks__/routes.mock.ts index 861ef2d3968dc..2df770c3ce45c 100644 --- a/x-pack/plugins/upgrade_assistant/server/routes/__mocks__/routes.mock.ts +++ b/x-pack/plugins/upgrade_assistant/server/routes/__mocks__/routes.mock.ts @@ -13,7 +13,7 @@ export const routeHandlerContextMock = ({ core: { elasticsearch: { legacy: { - client: elasticsearchServiceMock.createScopedClusterClient(), + client: elasticsearchServiceMock.createLegacyScopedClusterClient(), }, }, savedObjects: { client: savedObjectsClientMock.create() }, diff --git a/x-pack/plugins/uptime/server/lib/requests/__tests__/get_monitor_status.test.ts b/x-pack/plugins/uptime/server/lib/requests/__tests__/get_monitor_status.test.ts index 17bbb051b1ab1..2a1417b49dca4 100644 --- a/x-pack/plugins/uptime/server/lib/requests/__tests__/get_monitor_status.test.ts +++ b/x-pack/plugins/uptime/server/lib/requests/__tests__/get_monitor_status.test.ts @@ -51,7 +51,7 @@ type MockCallES = (method: any, params: any) => Promise; const setupMock = ( criteria: MultiPageCriteria[] ): [MockCallES, jest.Mocked>] => { - const esMock = elasticsearchServiceMock.createScopedClusterClient(); + const esMock = elasticsearchServiceMock.createLegacyScopedClusterClient(); criteria.forEach(({ after_key, bucketCriteria }) => { const mockResponse = { From ab853039530778d40882faa5c8b0826fc862eca0 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Tue, 30 Jun 2020 23:15:35 +0200 Subject: [PATCH 2/5] move legacy client mocks to legacy folder --- .../elasticsearch_service.mock.ts | 105 ++++-------------- src/core/server/elasticsearch/legacy/mocks.ts | 97 ++++++++++++++++ 2 files changed, 117 insertions(+), 85 deletions(-) create mode 100644 src/core/server/elasticsearch/legacy/mocks.ts diff --git a/src/core/server/elasticsearch/elasticsearch_service.mock.ts b/src/core/server/elasticsearch/elasticsearch_service.mock.ts index cdbe358bf8b5f..f524781de4c7e 100644 --- a/src/core/server/elasticsearch/elasticsearch_service.mock.ts +++ b/src/core/server/elasticsearch/elasticsearch_service.mock.ts @@ -18,37 +18,14 @@ */ import { BehaviorSubject } from 'rxjs'; -import { Client } from 'elasticsearch'; -import { - ILegacyClusterClient, - ILegacyCustomClusterClient, - ILegacyScopedClusterClient, -} from './legacy'; +import { ILegacyClusterClient, ILegacyCustomClusterClient } from './legacy'; +import { legacyClientMock } from './legacy/mocks'; import { ElasticsearchConfig } from './elasticsearch_config'; import { ElasticsearchService } from './elasticsearch_service'; import { InternalElasticsearchServiceSetup, ElasticsearchStatusMeta } from './types'; import { NodesVersionCompatibility } from './version_check/ensure_es_version'; import { ServiceStatus, ServiceStatusLevels } from '../status'; -const createScopedClusterClientMock = (): jest.Mocked => ({ - callAsInternalUser: jest.fn(), - callAsCurrentUser: jest.fn(), -}); - -const createCustomClusterClientMock = (): jest.Mocked => ({ - ...createClusterClientMock(), - close: jest.fn(), -}); - -function createClusterClientMock() { - const client: jest.Mocked = { - callAsInternalUser: jest.fn(), - asScoped: jest.fn(), - }; - client.asScoped.mockReturnValue(createScopedClusterClientMock()); - return client; -} - interface MockedElasticSearchServiceSetup { legacy: { createClient: jest.Mock; @@ -60,11 +37,13 @@ const createSetupContractMock = () => { const setupContract: MockedElasticSearchServiceSetup = { legacy: { createClient: jest.fn(), - client: createClusterClientMock(), + client: legacyClientMock.createClusterClient(), }, }; - setupContract.legacy.createClient.mockReturnValue(createCustomClusterClientMock()); - setupContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock()); + setupContract.legacy.createClient.mockReturnValue(legacyClientMock.createCustomClusterClient()); + setupContract.legacy.client.asScoped.mockReturnValue( + legacyClientMock.createScopedClusterClient() + ); return setupContract; }; @@ -74,11 +53,14 @@ const createStartContractMock = () => { const startContract: MockedElasticSearchServiceStart = { legacy: { createClient: jest.fn(), - client: createClusterClientMock(), + client: legacyClientMock.createClusterClient(), }, }; - startContract.legacy.createClient.mockReturnValue(createCustomClusterClientMock()); - startContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock()); + startContract.legacy.createClient.mockReturnValue(legacyClientMock.createCustomClusterClient()); + startContract.legacy.client.asScoped.mockReturnValue( + legacyClientMock.createScopedClusterClient() + ); + return startContract; }; @@ -104,7 +86,9 @@ const createInternalSetupContractMock = () => { ...createSetupContractMock().legacy, }, }; - setupContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock()); + setupContract.legacy.client.asScoped.mockReturnValue( + legacyClientMock.createScopedClusterClient() + ); return setupContract; }; @@ -121,62 +105,13 @@ const createMock = () => { return mocked; }; -const createElasticsearchClientMock = () => { - const mocked: jest.Mocked = { - cat: {} as any, - cluster: {} as any, - indices: {} as any, - ingest: {} as any, - nodes: {} as any, - snapshot: {} as any, - tasks: {} as any, - bulk: jest.fn(), - clearScroll: jest.fn(), - count: jest.fn(), - create: jest.fn(), - delete: jest.fn(), - deleteByQuery: jest.fn(), - deleteScript: jest.fn(), - deleteTemplate: jest.fn(), - exists: jest.fn(), - explain: jest.fn(), - fieldStats: jest.fn(), - get: jest.fn(), - getScript: jest.fn(), - getSource: jest.fn(), - getTemplate: jest.fn(), - index: jest.fn(), - info: jest.fn(), - mget: jest.fn(), - msearch: jest.fn(), - msearchTemplate: jest.fn(), - mtermvectors: jest.fn(), - ping: jest.fn(), - putScript: jest.fn(), - putTemplate: jest.fn(), - reindex: jest.fn(), - reindexRethrottle: jest.fn(), - renderSearchTemplate: jest.fn(), - scroll: jest.fn(), - search: jest.fn(), - searchShards: jest.fn(), - searchTemplate: jest.fn(), - suggest: jest.fn(), - termvectors: jest.fn(), - update: jest.fn(), - updateByQuery: jest.fn(), - close: jest.fn(), - }; - return mocked; -}; - export const elasticsearchServiceMock = { create: createMock, createInternalSetup: createInternalSetupContractMock, createSetup: createSetupContractMock, createStart: createStartContractMock, - createLegacyClusterClient: createClusterClientMock, - createLegacyCustomClusterClient: createCustomClusterClientMock, - createLegacyScopedClusterClient: createScopedClusterClientMock, - createLegacyElasticsearchClient: createElasticsearchClientMock, + createLegacyClusterClient: legacyClientMock.createClusterClient, + createLegacyCustomClusterClient: legacyClientMock.createCustomClusterClient, + createLegacyScopedClusterClient: legacyClientMock.createScopedClusterClient, + createLegacyElasticsearchClient: legacyClientMock.createElasticsearchClient, }; diff --git a/src/core/server/elasticsearch/legacy/mocks.ts b/src/core/server/elasticsearch/legacy/mocks.ts new file mode 100644 index 0000000000000..7714e7032940a --- /dev/null +++ b/src/core/server/elasticsearch/legacy/mocks.ts @@ -0,0 +1,97 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Client } from 'elasticsearch'; +import { ILegacyScopedClusterClient } from './scoped_cluster_client'; +import { ILegacyClusterClient, ILegacyCustomClusterClient } from './cluster_client'; + +const createScopedClusterClientMock = (): jest.Mocked => ({ + callAsInternalUser: jest.fn(), + callAsCurrentUser: jest.fn(), +}); + +const createCustomClusterClientMock = (): jest.Mocked => ({ + ...createClusterClientMock(), + close: jest.fn(), +}); + +function createClusterClientMock() { + const client: jest.Mocked = { + callAsInternalUser: jest.fn(), + asScoped: jest.fn(), + }; + client.asScoped.mockReturnValue(createScopedClusterClientMock()); + return client; +} + +const createElasticsearchClientMock = () => { + const mocked: jest.Mocked = { + cat: {} as any, + cluster: {} as any, + indices: {} as any, + ingest: {} as any, + nodes: {} as any, + snapshot: {} as any, + tasks: {} as any, + bulk: jest.fn(), + clearScroll: jest.fn(), + count: jest.fn(), + create: jest.fn(), + delete: jest.fn(), + deleteByQuery: jest.fn(), + deleteScript: jest.fn(), + deleteTemplate: jest.fn(), + exists: jest.fn(), + explain: jest.fn(), + fieldStats: jest.fn(), + get: jest.fn(), + getScript: jest.fn(), + getSource: jest.fn(), + getTemplate: jest.fn(), + index: jest.fn(), + info: jest.fn(), + mget: jest.fn(), + msearch: jest.fn(), + msearchTemplate: jest.fn(), + mtermvectors: jest.fn(), + ping: jest.fn(), + putScript: jest.fn(), + putTemplate: jest.fn(), + reindex: jest.fn(), + reindexRethrottle: jest.fn(), + renderSearchTemplate: jest.fn(), + scroll: jest.fn(), + search: jest.fn(), + searchShards: jest.fn(), + searchTemplate: jest.fn(), + suggest: jest.fn(), + termvectors: jest.fn(), + update: jest.fn(), + updateByQuery: jest.fn(), + close: jest.fn(), + }; + return mocked; +}; + +export const legacyClientMock = { + createScopedClusterClient: createScopedClusterClientMock, + createCustomClusterClient: createCustomClusterClientMock, + createClusterClient: createClusterClientMock, + createElasticsearchClient: createElasticsearchClientMock, +}; From 704dd00caacc543cabbd3e3cd87a9318e74e7eae Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Wed, 1 Jul 2020 14:57:23 +0200 Subject: [PATCH 3/5] fix usages --- .../server/elasticsearch/elasticsearch_service.test.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/server/elasticsearch/elasticsearch_service.test.ts b/src/core/server/elasticsearch/elasticsearch_service.test.ts index 2e210be5c09d1..99d12b8662577 100644 --- a/src/core/server/elasticsearch/elasticsearch_service.test.ts +++ b/src/core/server/elasticsearch/elasticsearch_service.test.ts @@ -31,7 +31,6 @@ import { httpServiceMock } from '../http/http_service.mock'; import { ElasticsearchConfig } from './elasticsearch_config'; import { ElasticsearchService } from './elasticsearch_service'; import { elasticsearchServiceMock } from './elasticsearch_service.mock'; -import { elasticsearchClientMock } from './client/mocks'; import { duration } from 'moment'; const delay = async (durationMs: number) => @@ -76,7 +75,7 @@ describe('#setup', () => { }); it('returns elasticsearch client as a part of the contract', async () => { - const mockClusterClientInstance = elasticsearchServiceMock.createClusterClient(); + const mockClusterClientInstance = elasticsearchServiceMock.createLegacyClusterClient(); MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance); const setupContract = await elasticsearchService.setup(deps); @@ -210,7 +209,7 @@ describe('#setup', () => { }); it('esNodeVersionCompatibility$ only starts polling when subscribed to', async (done) => { - const clusterClientInstance = elasticsearchServiceMock.createClusterClient(); + const clusterClientInstance = elasticsearchServiceMock.createLegacyClusterClient(); MockClusterClient.mockImplementationOnce(() => clusterClientInstance); clusterClientInstance.callAsInternalUser.mockRejectedValue(new Error()); @@ -226,7 +225,7 @@ describe('#setup', () => { }); it('esNodeVersionCompatibility$ stops polling when unsubscribed from', async (done) => { - const mockClusterClientInstance = elasticsearchServiceMock.createClusterClient(); + const mockClusterClientInstance = elasticsearchServiceMock.createLegacyClusterClient(); MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance); mockClusterClientInstance.callAsInternalUser.mockRejectedValue(new Error()); @@ -256,7 +255,7 @@ describe('#stop', () => { it('stops pollEsNodeVersions even if there are active subscriptions', async (done) => { expect.assertions(2); - const mockClusterClientInstance = elasticsearchServiceMock.createCustomClusterClient(); + const mockClusterClientInstance = elasticsearchServiceMock.createLegacyCustomClusterClient(); MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance); From abcc825478f47925f6ede82112a6bfc5d7e97462 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Mon, 6 Jul 2020 08:30:57 +0200 Subject: [PATCH 4/5] adapt new usages --- .../endpoint/routes/artifacts/download_exception_list.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/artifacts/download_exception_list.test.ts b/x-pack/plugins/security_solution/server/endpoint/routes/artifacts/download_exception_list.test.ts index 540976134d8ae..863a1d5037756 100644 --- a/x-pack/plugins/security_solution/server/endpoint/routes/artifacts/download_exception_list.test.ts +++ b/x-pack/plugins/security_solution/server/endpoint/routes/artifacts/download_exception_list.test.ts @@ -85,8 +85,8 @@ describe('test alerts route', () => { let ingestSavedObjectClient: jest.Mocked; beforeEach(() => { - mockClusterClient = elasticsearchServiceMock.createClusterClient(); - mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); + mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient(); + mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); mockSavedObjectClient = savedObjectsClientMock.create(); mockResponse = httpServerMock.createResponseFactory(); mockClusterClient.asScoped.mockReturnValue(mockScopedClient); From 299fe9f37b1c893b9812562ad8cf3aa61eb0b444 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Tue, 7 Jul 2020 11:55:35 +0200 Subject: [PATCH 5/5] adapt new usages --- x-pack/plugins/global_search/server/services/context.mock.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/global_search/server/services/context.mock.ts b/x-pack/plugins/global_search/server/services/context.mock.ts index 50c6da109f8dd..7c72686529c15 100644 --- a/x-pack/plugins/global_search/server/services/context.mock.ts +++ b/x-pack/plugins/global_search/server/services/context.mock.ts @@ -20,7 +20,7 @@ const createContextMock = () => { }, elasticsearch: { legacy: { - client: elasticsearchServiceMock.createScopedClusterClient(), + client: elasticsearchServiceMock.createLegacyScopedClusterClient(), }, }, uiSettings: {