diff --git a/src/core/server/elasticsearch/elasticsearch_service.mock.ts b/src/core/server/elasticsearch/elasticsearch_service.mock.ts index ce0a2fb8dd84..465c8c92fbdd 100644 --- a/src/core/server/elasticsearch/elasticsearch_service.mock.ts +++ b/src/core/server/elasticsearch/elasticsearch_service.mock.ts @@ -183,8 +183,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 c42ff956f2a5..e50f7cc7f74c 100644 --- a/src/core/server/elasticsearch/elasticsearch_service.test.ts +++ b/src/core/server/elasticsearch/elasticsearch_service.test.ts @@ -59,7 +59,7 @@ let coreContext: CoreContext; const logger = loggingSystemMock.create(); let mockClusterClientInstance: ReturnType; -let mockLegacyClusterClientInstance: ReturnType; +let mockLegacyClusterClientInstance: ReturnType; beforeEach(() => { env = Env.createDefault(getEnvOptions()); @@ -70,7 +70,7 @@ beforeEach(() => { MockLegacyClusterClient.mockClear(); MockClusterClient.mockClear(); - mockLegacyClusterClientInstance = elasticsearchServiceMock.createCustomClusterClient(); + mockLegacyClusterClientInstance = elasticsearchServiceMock.createLegacyCustomClusterClient(); MockLegacyClusterClient.mockImplementation(() => mockLegacyClusterClientInstance); mockClusterClientInstance = elasticsearchClientMock.createCustomClusterClient(); MockClusterClient.mockImplementation(() => mockClusterClientInstance); 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 6f9b4b96eae9..f7ebd18b9c48 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 4491942951c5..73d8e79069ce 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 69fab828e63d..807d75cd0d70 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 1763d275c6fb..87aa571ce6b8 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 c94a7aba46cf..84f79d53f218 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 7d86d4fde7e6..548495866ec2 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 b3f41e03ebdc..ce782dbd631a 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 c1918feb7f4e..c2cff83f85f0 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 feec1ee9ba00..ee6f0a301e9f 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 3fd7e12ed8a0..a78e47446fef 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 bf549c18da30..6e8327e15154 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 7ac981968083..3eee1978d4f1 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 d28e95834ca0..406d5661c091 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 d1e3cf89e94d..bd2ad10c4013 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 24e469c9ec9b..910f9e69ea80 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 9669c98e1349..c20ba0a1ec7a 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 0cdd452d459d..631a6f9ab213 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 3b77ea324817..300447096af9 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 4157f0598b3d..56d44e6628a8 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 7c71348bb8ca..1b574e6e44c1 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 95de8ca9d00e..22d10d1cec34 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 e6949269e3fc..c221ecd3f1e2 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 c00374efd59b..f04506eb0159 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 d787e76628d6..aea5994e3ba3 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 fd014e1a7cb8..fec03c5d04b0 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 e9af806b36f0..851ecf8107ad 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 ba0f23a3393a..f83331d84e43 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 8ad04672fdfa..e8cf37330aff 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 4d0ab1c96474..f67e0863086b 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 65a3d1bf1650..364a5b737f2c 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 }; 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 0ce7eae932fe..c102af76805b 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 64af6fc85727..a7b958ee02de 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 f77469552d98..40065e757e99 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 2889cf78aff8..33c52688ce8e 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 afb67dc3bbfc..a506cc6306c5 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 ada6a1c8d2dc..399f79f44744 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 49123fe9c74d..d9062bcfa2ef 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 5dbe8682c542..66e8086d49c6 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 bec60fa149bc..8f115f11329d 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 c7ff2a1e68b0..24de2af5e970 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 34961dbe2767..aec0310129f6 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 8070b3371fcb..ee1d550bbe24 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 e0df59ebe7a0..9af7268a57f9 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 ed3d1bbd0fca..8f61d2a122f0 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 721c020c7431..21c7fc134043 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 24af9917186b..addfae4ed16c 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 f6ae2c584a34..310b9e7136a0 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 545095a6a0c1..8ea30315c6a8 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 0578f795f4a4..8d4524e06c49 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 7289eb6dea16..c45dd5bd8a28 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 f044022d6db6..e9b692e4731a 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 4ce21f1b311e..b0dec299b2b1 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 89571a4a1823..2a4fa5cd48de 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 7188241e10f9..e14056439ca6 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 861ef2d3968d..2df770c3ce45 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 17bbb051b1ab..2a1417b49dca 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 = {