rename legacy client mocks

This commit is contained in:
pgayvallet 2020-06-30 23:06:41 +02:00
parent 71a27bb886
commit e48f3ad6a4
58 changed files with 167 additions and 162 deletions

View file

@ -183,8 +183,8 @@ export const elasticsearchServiceMock = {
createInternalSetup: createInternalSetupContractMock, createInternalSetup: createInternalSetupContractMock,
createSetup: createSetupContractMock, createSetup: createSetupContractMock,
createStart: createStartContractMock, createStart: createStartContractMock,
createClusterClient: createClusterClientMock, createLegacyClusterClient: createClusterClientMock,
createCustomClusterClient: createCustomClusterClientMock, createLegacyCustomClusterClient: createCustomClusterClientMock,
createScopedClusterClient: createScopedClusterClientMock, createLegacyScopedClusterClient: createScopedClusterClientMock,
createElasticsearchClient: createElasticsearchClientMock, createLegacyElasticsearchClient: createElasticsearchClientMock,
}; };

View file

@ -59,7 +59,7 @@ let coreContext: CoreContext;
const logger = loggingSystemMock.create(); const logger = loggingSystemMock.create();
let mockClusterClientInstance: ReturnType<typeof elasticsearchClientMock.createCustomClusterClient>; let mockClusterClientInstance: ReturnType<typeof elasticsearchClientMock.createCustomClusterClient>;
let mockLegacyClusterClientInstance: ReturnType<typeof elasticsearchServiceMock.createCustomClusterClient>; let mockLegacyClusterClientInstance: ReturnType<typeof elasticsearchServiceMock.createLegacyCustomClusterClient>;
beforeEach(() => { beforeEach(() => {
env = Env.createDefault(getEnvOptions()); env = Env.createDefault(getEnvOptions());
@ -70,7 +70,7 @@ beforeEach(() => {
MockLegacyClusterClient.mockClear(); MockLegacyClusterClient.mockClear();
MockClusterClient.mockClear(); MockClusterClient.mockClear();
mockLegacyClusterClientInstance = elasticsearchServiceMock.createCustomClusterClient(); mockLegacyClusterClientInstance = elasticsearchServiceMock.createLegacyCustomClusterClient();
MockLegacyClusterClient.mockImplementation(() => mockLegacyClusterClientInstance); MockLegacyClusterClient.mockImplementation(() => mockLegacyClusterClientInstance);
mockClusterClientInstance = elasticsearchClientMock.createCustomClusterClient(); mockClusterClientInstance = elasticsearchClientMock.createCustomClusterClient();
MockClusterClient.mockImplementation(() => mockClusterClientInstance); MockClusterClient.mockImplementation(() => mockClusterClientInstance);

View file

@ -21,7 +21,7 @@ import { elasticsearchServiceMock } from '../../elasticsearch/elasticsearch_serv
export const clusterClientMock = jest.fn(); export const clusterClientMock = jest.fn();
jest.doMock('../../elasticsearch/legacy/scoped_cluster_client', () => ({ jest.doMock('../../elasticsearch/legacy/scoped_cluster_client', () => ({
LegacyScopedClusterClient: clusterClientMock.mockImplementation(function () { LegacyScopedClusterClient: clusterClientMock.mockImplementation(function () {
return elasticsearchServiceMock.createScopedClusterClient(); return elasticsearchServiceMock.createLegacyScopedClusterClient();
}), }),
})); }));
@ -31,7 +31,7 @@ jest.doMock('elasticsearch', () => {
...realES, ...realES,
// eslint-disable-next-line object-shorthand // eslint-disable-next-line object-shorthand
Client: function () { Client: function () {
return elasticsearchServiceMock.createElasticsearchClient(); return elasticsearchServiceMock.createLegacyElasticsearchClient();
}, },
}; };
}); });

View file

@ -190,7 +190,7 @@ function createCoreRequestHandlerContextMock() {
}, },
elasticsearch: { elasticsearch: {
legacy: { legacy: {
client: elasticsearchServiceMock.createScopedClusterClient(), client: elasticsearchServiceMock.createLegacyScopedClusterClient(),
}, },
}, },
uiSettings: { uiSettings: {

View file

@ -25,7 +25,7 @@ import { KibanaRequest } from 'kibana/server';
const defaultKibanaIndex = '.kibana'; const defaultKibanaIndex = '.kibana';
const savedObjectsClient = savedObjectsClientMock.create(); const savedObjectsClient = savedObjectsClientMock.create();
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const scopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
const actionExecutor = actionExecutorMock.create(); const actionExecutor = actionExecutorMock.create();
const executionEnqueuer = jest.fn(); const executionEnqueuer = jest.fn();
const request = {} as KibanaRequest; const request = {} as KibanaRequest;

View file

@ -37,7 +37,7 @@ const createServicesMock = () => {
savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>; savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>;
} }
> = { > = {
callCluster: elasticsearchServiceMock.createScopedClusterClient().callAsCurrentUser, callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
getScopedCallCluster: jest.fn(), getScopedCallCluster: jest.fn(),
savedObjectsClient: savedObjectsClientMock.create(), savedObjectsClient: savedObjectsClientMock.create(),
}; };

View file

@ -58,7 +58,7 @@ const createAlertServicesMock = () => {
alertInstanceFactory: jest alertInstanceFactory: jest
.fn<jest.Mocked<AlertInstance>, [string]>() .fn<jest.Mocked<AlertInstance>, [string]>()
.mockReturnValue(alertInstanceFactoryMock), .mockReturnValue(alertInstanceFactoryMock),
callCluster: elasticsearchServiceMock.createScopedClusterClient().callAsCurrentUser, callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
getScopedCallCluster: jest.fn(), getScopedCallCluster: jest.fn(),
savedObjectsClient: savedObjectsClientMock.create(), savedObjectsClient: savedObjectsClientMock.create(),
}; };

View file

@ -20,7 +20,7 @@ export function mockHandlerArguments(
{ {
alertsClient = alertsClientMock.create(), alertsClient = alertsClientMock.create(),
listTypes: listTypesRes = [], listTypes: listTypesRes = [],
esClient = elasticsearchServiceMock.createClusterClient(), esClient = elasticsearchServiceMock.createLegacyClusterClient(),
}: { }: {
alertsClient?: AlertsClientMock; alertsClient?: AlertsClientMock;
listTypes?: AlertType[]; listTypes?: AlertType[];

View file

@ -43,7 +43,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects); healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0]; const [, handler] = router.get.mock.calls[0];
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(Promise.resolve({})); esClient.callAsInternalUser.mockReturnValue(Promise.resolve({}));
const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']); const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']);
@ -72,7 +72,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects); healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0]; const [, handler] = router.get.mock.calls[0];
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(Promise.resolve({})); esClient.callAsInternalUser.mockReturnValue(Promise.resolve({}));
const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']); const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']);
@ -96,7 +96,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects); healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0]; const [, handler] = router.get.mock.calls[0];
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(Promise.resolve({})); esClient.callAsInternalUser.mockReturnValue(Promise.resolve({}));
const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']); const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']);
@ -120,7 +120,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects); healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0]; const [, handler] = router.get.mock.calls[0];
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(Promise.resolve({ security: {} })); esClient.callAsInternalUser.mockReturnValue(Promise.resolve({ security: {} }));
const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']); const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']);
@ -144,7 +144,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects); healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0]; const [, handler] = router.get.mock.calls[0];
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue(Promise.resolve({ security: { enabled: true } })); esClient.callAsInternalUser.mockReturnValue(Promise.resolve({ security: { enabled: true } }));
const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']); const [context, req, res] = mockHandlerArguments({ esClient }, {}, ['ok']);
@ -168,7 +168,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects); healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0]; const [, handler] = router.get.mock.calls[0];
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue( esClient.callAsInternalUser.mockReturnValue(
Promise.resolve({ security: { enabled: true, ssl: {} } }) Promise.resolve({ security: { enabled: true, ssl: {} } })
); );
@ -194,7 +194,7 @@ describe('healthRoute', () => {
healthRoute(router, licenseState, encryptedSavedObjects); healthRoute(router, licenseState, encryptedSavedObjects);
const [, handler] = router.get.mock.calls[0]; const [, handler] = router.get.mock.calls[0];
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockReturnValue( esClient.callAsInternalUser.mockReturnValue(
Promise.resolve({ security: { enabled: true, ssl: { http: { enabled: true } } } }) Promise.resolve({ security: { enabled: true, ssl: { http: { enabled: true } } } })
); );

View file

@ -15,7 +15,9 @@ import {
const mockRouteContext = ({ const mockRouteContext = ({
core: { core: {
elasticsearch: { legacy: { client: elasticsearchServiceMock.createScopedClusterClient() } }, elasticsearch: {
legacy: { client: elasticsearchServiceMock.createLegacyScopedClusterClient() },
},
}, },
} as unknown) as RequestHandlerContext; } as unknown) as RequestHandlerContext;

View file

@ -18,7 +18,7 @@ let clusterClientAdapter: IClusterClientAdapter;
beforeEach(() => { beforeEach(() => {
logger = loggingSystemMock.createLogger(); logger = loggingSystemMock.createLogger();
clusterClient = elasticsearchServiceMock.createClusterClient(); clusterClient = elasticsearchServiceMock.createLegacyClusterClient();
clusterClientAdapter = new ClusterClientAdapter({ clusterClientAdapter = new ClusterClientAdapter({
logger, logger,
clusterClientPromise: Promise.resolve(clusterClient), clusterClientPromise: Promise.resolve(clusterClient),

View file

@ -17,7 +17,7 @@ let clusterClient: EsClusterClient;
beforeEach(() => { beforeEach(() => {
logger = loggingSystemMock.createLogger(); logger = loggingSystemMock.createLogger();
clusterClient = elasticsearchServiceMock.createClusterClient(); clusterClient = elasticsearchServiceMock.createLegacyClusterClient();
}); });
describe('createEsContext', () => { describe('createEsContext', () => {

View file

@ -31,11 +31,14 @@ const flushPromises = (ms = 50) => new Promise((res) => setTimeout(res, ms));
function createCoreSetupWith(esClient: ILegacyClusterClient) { function createCoreSetupWith(esClient: ILegacyClusterClient) {
const coreSetup = coreMock.createSetup(); const coreSetup = coreMock.createSetup();
const coreStart = coreMock.createStart();
coreSetup.getStartServices.mockResolvedValue([ coreSetup.getStartServices.mockResolvedValue([
{ {
...coreMock.createStart(), ...coreStart,
elasticsearch: { legacy: { client: esClient, createClient: jest.fn() } }, elasticsearch: {
...coreStart.elasticsearch,
legacy: { client: esClient, createClient: jest.fn() },
},
}, },
{}, {},
{}, {},
@ -61,7 +64,7 @@ describe('licensing plugin', () => {
}); });
it('returns license', async () => { it('returns license', async () => {
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockResolvedValue({ esClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense(), license: buildRawLicense(),
features: {}, features: {},
@ -77,7 +80,7 @@ describe('licensing plugin', () => {
it('observable receives updated licenses', async () => { it('observable receives updated licenses', async () => {
const types: LicenseType[] = ['basic', 'gold', 'platinum']; const types: LicenseType[] = ['basic', 'gold', 'platinum'];
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockImplementation(() => esClient.callAsInternalUser.mockImplementation(() =>
Promise.resolve({ Promise.resolve({
license: buildRawLicense({ type: types.shift() }), license: buildRawLicense({ type: types.shift() }),
@ -96,7 +99,7 @@ describe('licensing plugin', () => {
}); });
it('returns a license with error when request fails', async () => { it('returns a license with error when request fails', async () => {
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockRejectedValue(new Error('test')); esClient.callAsInternalUser.mockRejectedValue(new Error('test'));
const coreSetup = createCoreSetupWith(esClient); const coreSetup = createCoreSetupWith(esClient);
@ -109,7 +112,7 @@ describe('licensing plugin', () => {
}); });
it('generate error message when x-pack plugin was not installed', async () => { 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'); const error: ElasticsearchError = new Error('reason');
error.status = 400; error.status = 400;
esClient.callAsInternalUser.mockRejectedValue(error); esClient.callAsInternalUser.mockRejectedValue(error);
@ -127,7 +130,7 @@ describe('licensing plugin', () => {
const error1 = new Error('reason-1'); const error1 = new Error('reason-1');
const error2 = new Error('reason-2'); const error2 = new Error('reason-2');
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser esClient.callAsInternalUser
.mockRejectedValueOnce(error1) .mockRejectedValueOnce(error1)
@ -145,7 +148,7 @@ describe('licensing plugin', () => {
}); });
it('fetch license immediately without subscriptions', async () => { it('fetch license immediately without subscriptions', async () => {
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockResolvedValue({ esClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense(), license: buildRawLicense(),
features: {}, features: {},
@ -161,7 +164,7 @@ describe('licensing plugin', () => {
}); });
it('logs license details without subscriptions', async () => { it('logs license details without subscriptions', async () => {
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockResolvedValue({ esClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense(), license: buildRawLicense(),
features: {}, features: {},
@ -187,7 +190,7 @@ describe('licensing plugin', () => {
it('generates signature based on fetched license content', async () => { it('generates signature based on fetched license content', async () => {
const types: LicenseType[] = ['basic', 'gold', 'basic']; const types: LicenseType[] = ['basic', 'gold', 'basic'];
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockImplementation(() => esClient.callAsInternalUser.mockImplementation(() =>
Promise.resolve({ Promise.resolve({
license: buildRawLicense({ type: types.shift() }), license: buildRawLicense({ type: types.shift() }),
@ -218,7 +221,7 @@ describe('licensing plugin', () => {
api_polling_frequency: moment.duration(50000), api_polling_frequency: moment.duration(50000),
}) })
); );
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockResolvedValue({ esClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense(), license: buildRawLicense(),
features: {}, features: {},
@ -253,7 +256,7 @@ describe('licensing plugin', () => {
}) })
); );
const esClient = elasticsearchServiceMock.createClusterClient(); const esClient = elasticsearchServiceMock.createLegacyClusterClient();
esClient.callAsInternalUser.mockResolvedValue({ esClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense(), license: buildRawLicense(),
features: {}, features: {},
@ -262,7 +265,7 @@ describe('licensing plugin', () => {
await plugin.setup(coreSetup); await plugin.setup(coreSetup);
const { createLicensePoller, license$ } = await plugin.start(); const { createLicensePoller, license$ } = await plugin.start();
const customClient = elasticsearchServiceMock.createClusterClient(); const customClient = elasticsearchServiceMock.createLegacyClusterClient();
customClient.callAsInternalUser.mockResolvedValue({ customClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense({ type: 'gold' }), license: buildRawLicense({ type: 'gold' }),
features: {}, features: {},
@ -297,7 +300,7 @@ describe('licensing plugin', () => {
await plugin.setup(coreSetup); await plugin.setup(coreSetup);
const { createLicensePoller } = await plugin.start(); const { createLicensePoller } = await plugin.start();
const customClient = elasticsearchServiceMock.createClusterClient(); const customClient = elasticsearchServiceMock.createLegacyClusterClient();
customClient.callAsInternalUser.mockResolvedValue({ customClient.callAsInternalUser.mockResolvedValue({
license: buildRawLicense({ type: 'gold' }), license: buildRawLicense({ type: 'gold' }),
features: {}, features: {},

View file

@ -49,7 +49,7 @@ const defaultMockTaskDocs = [getMockTaskInstance()];
export const getMockEs = async ( export const getMockEs = async (
mockCallWithInternal: LegacyAPICaller = getMockCallWithInternal() mockCallWithInternal: LegacyAPICaller = getMockCallWithInternal()
) => { ) => {
const client = elasticsearchServiceMock.createClusterClient(); const client = elasticsearchServiceMock.createLegacyClusterClient();
(client.callAsInternalUser as any) = mockCallWithInternal; (client.callAsInternalUser as any) = mockCallWithInternal;
return client; return client;
}; };

View file

@ -28,7 +28,7 @@ describe('ADD remote clusters', () => {
{ licenseCheckResult = { valid: true }, apiResponses = [], asserts, payload }: TestOptions { licenseCheckResult = { valid: true }, apiResponses = [], asserts, payload }: TestOptions
) => { ) => {
test(description, async () => { test(description, async () => {
const elasticsearchMock = elasticsearchServiceMock.createClusterClient(); const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient();
const mockRouteDependencies = { const mockRouteDependencies = {
router: httpServiceMock.createRouter(), router: httpServiceMock.createRouter(),
@ -40,10 +40,10 @@ describe('ADD remote clusters', () => {
}, },
}; };
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
elasticsearchServiceMock elasticsearchServiceMock
.createClusterClient() .createLegacyClusterClient()
.asScoped.mockReturnValue(mockScopedClusterClient); .asScoped.mockReturnValue(mockScopedClusterClient);
for (const apiResponse of apiResponses) { for (const apiResponse of apiResponses) {

View file

@ -30,7 +30,7 @@ describe('DELETE remote clusters', () => {
{ licenseCheckResult = { valid: true }, apiResponses = [], asserts, params }: TestOptions { licenseCheckResult = { valid: true }, apiResponses = [], asserts, params }: TestOptions
) => { ) => {
test(description, async () => { test(description, async () => {
const elasticsearchMock = elasticsearchServiceMock.createClusterClient(); const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient();
const mockRouteDependencies = { const mockRouteDependencies = {
router: httpServiceMock.createRouter(), router: httpServiceMock.createRouter(),
@ -42,10 +42,10 @@ describe('DELETE remote clusters', () => {
}, },
}; };
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
elasticsearchServiceMock elasticsearchServiceMock
.createClusterClient() .createLegacyClusterClient()
.asScoped.mockReturnValue(mockScopedClusterClient); .asScoped.mockReturnValue(mockScopedClusterClient);
for (const apiResponse of apiResponses) { for (const apiResponse of apiResponses) {

View file

@ -29,7 +29,7 @@ describe('GET remote clusters', () => {
{ licenseCheckResult = { valid: true }, apiResponses = [], asserts }: TestOptions { licenseCheckResult = { valid: true }, apiResponses = [], asserts }: TestOptions
) => { ) => {
test(description, async () => { test(description, async () => {
const elasticsearchMock = elasticsearchServiceMock.createClusterClient(); const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient();
const mockRouteDependencies = { const mockRouteDependencies = {
router: httpServiceMock.createRouter(), router: httpServiceMock.createRouter(),
@ -41,10 +41,10 @@ describe('GET remote clusters', () => {
}, },
}; };
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
elasticsearchServiceMock elasticsearchServiceMock
.createClusterClient() .createLegacyClusterClient()
.asScoped.mockReturnValue(mockScopedClusterClient); .asScoped.mockReturnValue(mockScopedClusterClient);
for (const apiResponse of apiResponses) { for (const apiResponse of apiResponses) {

View file

@ -37,7 +37,7 @@ describe('UPDATE remote clusters', () => {
}: TestOptions }: TestOptions
) => { ) => {
test(description, async () => { test(description, async () => {
const elasticsearchMock = elasticsearchServiceMock.createClusterClient(); const elasticsearchMock = elasticsearchServiceMock.createLegacyClusterClient();
const mockRouteDependencies = { const mockRouteDependencies = {
router: httpServiceMock.createRouter(), router: httpServiceMock.createRouter(),
@ -49,10 +49,10 @@ describe('UPDATE remote clusters', () => {
}, },
}; };
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
elasticsearchServiceMock elasticsearchServiceMock
.createClusterClient() .createLegacyClusterClient()
.asScoped.mockReturnValue(mockScopedClusterClient); .asScoped.mockReturnValue(mockScopedClusterClient);
for (const apiResponse of apiResponses) { for (const apiResponse of apiResponses) {

View file

@ -24,8 +24,8 @@ describe('API Keys', () => {
let mockLicense: jest.Mocked<SecurityLicense>; let mockLicense: jest.Mocked<SecurityLicense>;
beforeEach(() => { beforeEach(() => {
mockClusterClient = elasticsearchServiceMock.createClusterClient(); mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient();
mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockClusterClient.asScoped.mockReturnValue( mockClusterClient.asScoped.mockReturnValue(
(mockScopedClusterClient as unknown) as jest.Mocked<ILegacyScopedClusterClient> (mockScopedClusterClient as unknown) as jest.Mocked<ILegacyScopedClusterClient>
); );

View file

@ -45,7 +45,7 @@ function getMockOptions({
return { return {
auditLogger: securityAuditLoggerMock.create(), auditLogger: securityAuditLoggerMock.create(),
getCurrentUser: jest.fn(), getCurrentUser: jest.fn(),
clusterClient: elasticsearchServiceMock.createClusterClient(), clusterClient: elasticsearchServiceMock.createLegacyClusterClient(),
basePath: httpServiceMock.createSetupContract().basePath, basePath: httpServiceMock.createSetupContract().basePath,
license: licenseMock.create(), license: licenseMock.create(),
loggers: loggingSystemMock.create(), loggers: loggingSystemMock.create(),

View file

@ -69,7 +69,7 @@ describe('setupAuthentication()', () => {
loggingSystemMock.create().get(), loggingSystemMock.create().get(),
{ isTLSEnabled: false } { isTLSEnabled: false }
), ),
clusterClient: elasticsearchServiceMock.createClusterClient(), clusterClient: elasticsearchServiceMock.createLegacyClusterClient(),
license: licenseMock.create(), license: licenseMock.create(),
loggers: loggingSystemMock.create(), loggers: loggingSystemMock.create(),
getFeatureUsageService: jest getFeatureUsageService: jest
@ -77,7 +77,7 @@ describe('setupAuthentication()', () => {
.mockReturnValue(securityFeatureUsageServiceMock.createStartContract()), .mockReturnValue(securityFeatureUsageServiceMock.createStartContract()),
}; };
mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockSetupAuthenticationParams.clusterClient.asScoped.mockReturnValue( mockSetupAuthenticationParams.clusterClient.asScoped.mockReturnValue(
(mockScopedClusterClient as unknown) as jest.Mocked<LegacyScopedClusterClient> (mockScopedClusterClient as unknown) as jest.Mocked<LegacyScopedClusterClient>
); );

View file

@ -16,7 +16,7 @@ export type MockAuthenticationProviderOptions = ReturnType<
export function mockAuthenticationProviderOptions(options?: { name: string }) { export function mockAuthenticationProviderOptions(options?: { name: string }) {
return { return {
client: elasticsearchServiceMock.createClusterClient(), client: elasticsearchServiceMock.createLegacyClusterClient(),
logger: loggingSystemMock.create().get(), logger: loggingSystemMock.create().get(),
basePath: httpServiceMock.createBasePath(), basePath: httpServiceMock.createBasePath(),
tokens: { refresh: jest.fn(), invalidate: jest.fn() }, tokens: { refresh: jest.fn(), invalidate: jest.fn() },

View file

@ -43,7 +43,7 @@ describe('BasicAuthenticationProvider', () => {
const credentials = { username: 'user', password: 'password' }; const credentials = { username: 'user', password: 'password' };
const authorization = generateAuthorizationHeader(credentials.username, credentials.password); const authorization = generateAuthorizationHeader(credentials.username, credentials.password);
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -65,7 +65,7 @@ describe('BasicAuthenticationProvider', () => {
const authorization = generateAuthorizationHeader(credentials.username, credentials.password); const authorization = generateAuthorizationHeader(credentials.username, credentials.password);
const authenticationError = new Error('Some error'); const authenticationError = new Error('Some error');
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -147,7 +147,7 @@ describe('BasicAuthenticationProvider', () => {
const user = mockAuthenticatedUser(); const user = mockAuthenticatedUser();
const authorization = generateAuthorizationHeader('user', 'password'); const authorization = generateAuthorizationHeader('user', 'password');
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -163,7 +163,7 @@ describe('BasicAuthenticationProvider', () => {
const authorization = generateAuthorizationHeader('user', 'password'); const authorization = generateAuthorizationHeader('user', 'password');
const authenticationError = new Error('Forbidden'); const authenticationError = new Error('Forbidden');
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);

View file

@ -126,7 +126,7 @@ describe('HTTPAuthenticationProvider', () => {
]) { ]) {
const request = httpServerMock.createKibanaRequest({ headers: { authorization: header } }); const request = httpServerMock.createKibanaRequest({ headers: { authorization: header } });
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
mockOptions.client.asScoped.mockClear(); mockOptions.client.asScoped.mockClear();
@ -156,7 +156,7 @@ describe('HTTPAuthenticationProvider', () => {
]) { ]) {
const request = httpServerMock.createKibanaRequest({ headers: { authorization: header } }); const request = httpServerMock.createKibanaRequest({ headers: { authorization: header } });
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
mockOptions.client.asScoped.mockClear(); mockOptions.client.asScoped.mockClear();

View file

@ -47,7 +47,7 @@ describe('KerberosAuthenticationProvider', () => {
it('does not handle requests that can be authenticated without `Negotiate` header.', async () => { it('does not handle requests that can be authenticated without `Negotiate` header.', async () => {
const request = httpServerMock.createKibanaRequest({ headers: {} }); const request = httpServerMock.createKibanaRequest({ headers: {} });
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({}); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({});
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -61,7 +61,7 @@ describe('KerberosAuthenticationProvider', () => {
it('does not handle requests if backend does not support Kerberos.', async () => { it('does not handle requests if backend does not support Kerberos.', async () => {
const request = httpServerMock.createKibanaRequest({ headers: {} }); const request = httpServerMock.createKibanaRequest({ headers: {} });
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -82,7 +82,7 @@ describe('KerberosAuthenticationProvider', () => {
body: { error: { header: { 'WWW-Authenticate': 'Negotiate' } } }, body: { error: { header: { 'WWW-Authenticate': 'Negotiate' } } },
}) })
); );
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -101,7 +101,7 @@ describe('KerberosAuthenticationProvider', () => {
const request = httpServerMock.createKibanaRequest({ headers: {} }); const request = httpServerMock.createKibanaRequest({ headers: {} });
const failureReason = new errors.ServiceUnavailable(); const failureReason = new errors.ServiceUnavailable();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -118,7 +118,7 @@ describe('KerberosAuthenticationProvider', () => {
headers: { authorization: 'negotiate spnego' }, headers: { authorization: 'negotiate spnego' },
}); });
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
mockOptions.client.callAsInternalUser.mockResolvedValue({ mockOptions.client.callAsInternalUser.mockResolvedValue({
@ -153,7 +153,7 @@ describe('KerberosAuthenticationProvider', () => {
headers: { authorization: 'negotiate spnego' }, headers: { authorization: 'negotiate spnego' },
}); });
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
mockOptions.client.callAsInternalUser.mockResolvedValue({ mockOptions.client.callAsInternalUser.mockResolvedValue({
@ -257,7 +257,7 @@ describe('KerberosAuthenticationProvider', () => {
}); });
const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()); const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error());
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
mockOptions.client.callAsInternalUser.mockResolvedValue({ mockOptions.client.callAsInternalUser.mockResolvedValue({
@ -323,7 +323,7 @@ describe('KerberosAuthenticationProvider', () => {
const tokenPair = { accessToken: 'token', refreshToken: 'refresh-token' }; const tokenPair = { accessToken: 'token', refreshToken: 'refresh-token' };
const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()); const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error());
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
mockOptions.tokens.refresh.mockResolvedValue(null); mockOptions.tokens.refresh.mockResolvedValue(null);
@ -355,7 +355,7 @@ describe('KerberosAuthenticationProvider', () => {
}; };
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -378,7 +378,7 @@ describe('KerberosAuthenticationProvider', () => {
mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { mockOptions.client.asScoped.mockImplementation((scopeableRequest) => {
if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -386,7 +386,7 @@ describe('KerberosAuthenticationProvider', () => {
} }
if (scopeableRequest?.headers.authorization === 'Bearer newfoo') { if (scopeableRequest?.headers.authorization === 'Bearer newfoo') {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
return mockScopedClusterClient; return mockScopedClusterClient;
} }
@ -423,7 +423,7 @@ describe('KerberosAuthenticationProvider', () => {
}; };
const failureReason = new errors.InternalServerError('Token is not valid!'); const failureReason = new errors.InternalServerError('Token is not valid!');
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -450,7 +450,7 @@ describe('KerberosAuthenticationProvider', () => {
body: { error: { header: { 'WWW-Authenticate': 'Negotiate' } } }, body: { error: { header: { 'WWW-Authenticate': 'Negotiate' } } },
}) })
); );
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -475,7 +475,7 @@ describe('KerberosAuthenticationProvider', () => {
body: { error: { header: { 'WWW-Authenticate': 'Negotiate' } } }, body: { error: { header: { 'WWW-Authenticate': 'Negotiate' } } },
}) })
); );
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);

View file

@ -389,7 +389,7 @@ describe('OIDCAuthenticationProvider', () => {
}; };
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -446,7 +446,7 @@ describe('OIDCAuthenticationProvider', () => {
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const failureReason = new Error('Token is not valid!'); const failureReason = new Error('Token is not valid!');
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -466,7 +466,7 @@ describe('OIDCAuthenticationProvider', () => {
mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { mockOptions.client.asScoped.mockImplementation((scopeableRequest) => {
if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -474,7 +474,7 @@ describe('OIDCAuthenticationProvider', () => {
} }
if (scopeableRequest?.headers.authorization === 'Bearer new-access-token') { if (scopeableRequest?.headers.authorization === 'Bearer new-access-token') {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
return mockScopedClusterClient; return mockScopedClusterClient;
} }
@ -514,7 +514,7 @@ describe('OIDCAuthenticationProvider', () => {
const tokenPair = { accessToken: 'expired-token', refreshToken: 'invalid-refresh-token' }; const tokenPair = { accessToken: 'expired-token', refreshToken: 'invalid-refresh-token' };
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) 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', '&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( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -602,7 +602,7 @@ describe('OIDCAuthenticationProvider', () => {
const tokenPair = { accessToken: 'expired-token', refreshToken: 'expired-refresh-token' }; const tokenPair = { accessToken: 'expired-token', refreshToken: 'expired-refresh-token' };
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -631,7 +631,7 @@ describe('OIDCAuthenticationProvider', () => {
const tokenPair = { accessToken: 'expired-token', refreshToken: 'expired-refresh-token' }; const tokenPair = { accessToken: 'expired-token', refreshToken: 'expired-refresh-token' };
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );

View file

@ -120,7 +120,7 @@ describe('PKIAuthenticationProvider', () => {
}), }),
}); });
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); 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); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' });
@ -220,7 +220,7 @@ describe('PKIAuthenticationProvider', () => {
}); });
const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()); const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error());
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); 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 state = { accessToken: 'existing-token', peerCertificateFingerprint256: '3A:9A:C5:DD' };
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); 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 state = { accessToken: 'existing-token', peerCertificateFingerprint256: '2A:7A:C2:DD' };
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser mockScopedClusterClient.callAsCurrentUser
// In response to call with an expired token. // In response to call with an expired token.
.mockRejectedValueOnce( .mockRejectedValueOnce(
@ -436,7 +436,7 @@ describe('PKIAuthenticationProvider', () => {
}); });
const state = { accessToken: 'existing-token', peerCertificateFingerprint256: '2A:7A:C2:DD' }; const state = { accessToken: 'existing-token', peerCertificateFingerprint256: '2A:7A:C2:DD' };
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValueOnce( mockScopedClusterClient.callAsCurrentUser.mockRejectedValueOnce(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -454,7 +454,7 @@ describe('PKIAuthenticationProvider', () => {
const request = httpServerMock.createKibanaRequest({ socket: getMockSocket() }); const request = httpServerMock.createKibanaRequest({ socket: getMockSocket() });
const state = { accessToken: 'existing-token', peerCertificateFingerprint256: '2A:7A:C2:DD' }; const state = { accessToken: 'existing-token', peerCertificateFingerprint256: '2A:7A:C2:DD' };
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -480,7 +480,7 @@ describe('PKIAuthenticationProvider', () => {
}), }),
}); });
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -509,7 +509,7 @@ describe('PKIAuthenticationProvider', () => {
}); });
const failureReason = new errors.ServiceUnavailable(); const failureReason = new errors.ServiceUnavailable();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);

View file

@ -319,7 +319,7 @@ describe('SAMLAuthenticationProvider', () => {
beforeEach(() => { beforeEach(() => {
mockOptions.basePath.get.mockReturnValue(mockOptions.basePath.serverBasePath); mockOptions.basePath.get.mockReturnValue(mockOptions.basePath.serverBasePath);
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => mockScopedClusterClient.callAsCurrentUser.mockImplementation(() =>
Promise.resolve(mockAuthenticatedUser()) Promise.resolve(mockAuthenticatedUser())
); );
@ -448,7 +448,7 @@ describe('SAMLAuthenticationProvider', () => {
const authorization = 'Bearer some-valid-token'; const authorization = 'Bearer some-valid-token';
const user = mockAuthenticatedUser(); const user = mockAuthenticatedUser();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -489,7 +489,7 @@ describe('SAMLAuthenticationProvider', () => {
const authorization = `Bearer ${state.accessToken}`; const authorization = `Bearer ${state.accessToken}`;
const user = mockAuthenticatedUser(); const user = mockAuthenticatedUser();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -543,7 +543,7 @@ describe('SAMLAuthenticationProvider', () => {
}; };
const authorization = `Bearer ${state.accessToken}`; const authorization = `Bearer ${state.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => response); mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => response);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -598,7 +598,7 @@ describe('SAMLAuthenticationProvider', () => {
}; };
const authorization = `Bearer ${state.accessToken}`; const authorization = `Bearer ${state.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => response); mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => response);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -663,7 +663,7 @@ describe('SAMLAuthenticationProvider', () => {
}; };
const authorization = `Bearer ${state.accessToken}`; const authorization = `Bearer ${state.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => response); mockScopedClusterClient.callAsCurrentUser.mockImplementation(() => response);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -1061,7 +1061,7 @@ describe('SAMLAuthenticationProvider', () => {
}; };
const authorization = `Bearer ${state.accessToken}`; const authorization = `Bearer ${state.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -1088,7 +1088,7 @@ describe('SAMLAuthenticationProvider', () => {
const authorization = `Bearer ${state.accessToken}`; const authorization = `Bearer ${state.accessToken}`;
const failureReason = { statusCode: 500, message: 'Token is not valid!' }; const failureReason = { statusCode: 500, message: 'Token is not valid!' };
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -1113,7 +1113,7 @@ describe('SAMLAuthenticationProvider', () => {
mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { mockOptions.client.asScoped.mockImplementation((scopeableRequest) => {
if (scopeableRequest?.headers.authorization === `Bearer ${state.accessToken}`) { if (scopeableRequest?.headers.authorization === `Bearer ${state.accessToken}`) {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -1121,7 +1121,7 @@ describe('SAMLAuthenticationProvider', () => {
} }
if (scopeableRequest?.headers.authorization === 'Bearer new-access-token') { if (scopeableRequest?.headers.authorization === 'Bearer new-access-token') {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
return mockScopedClusterClient; return mockScopedClusterClient;
} }
@ -1165,7 +1165,7 @@ describe('SAMLAuthenticationProvider', () => {
}; };
const authorization = `Bearer ${state.accessToken}`; const authorization = `Bearer ${state.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -1199,7 +1199,7 @@ describe('SAMLAuthenticationProvider', () => {
}; };
const authorization = `Bearer ${state.accessToken}`; const authorization = `Bearer ${state.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -1231,7 +1231,7 @@ describe('SAMLAuthenticationProvider', () => {
}; };
const authorization = `Bearer ${state.accessToken}`; const authorization = `Bearer ${state.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -1263,7 +1263,7 @@ describe('SAMLAuthenticationProvider', () => {
}; };
const authorization = `Bearer ${state.accessToken}`; const authorization = `Bearer ${state.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -1304,7 +1304,7 @@ describe('SAMLAuthenticationProvider', () => {
redirect: 'https://idp-host/path/login?SAMLRequest=some%20request%20', redirect: 'https://idp-host/path/login?SAMLRequest=some%20request%20',
}); });
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );

View file

@ -49,7 +49,7 @@ describe('TokenAuthenticationProvider', () => {
const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const tokenPair = { accessToken: 'foo', refreshToken: 'bar' };
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -106,7 +106,7 @@ describe('TokenAuthenticationProvider', () => {
}); });
const authenticationError = new Error('Some error'); const authenticationError = new Error('Some error');
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -190,7 +190,7 @@ describe('TokenAuthenticationProvider', () => {
const user = mockAuthenticatedUser(); const user = mockAuthenticatedUser();
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -213,7 +213,7 @@ describe('TokenAuthenticationProvider', () => {
mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { mockOptions.client.asScoped.mockImplementation((scopeableRequest) => {
if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -221,7 +221,7 @@ describe('TokenAuthenticationProvider', () => {
} }
if (scopeableRequest?.headers.authorization === 'Bearer newfoo') { if (scopeableRequest?.headers.authorization === 'Bearer newfoo') {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user);
return mockScopedClusterClient; return mockScopedClusterClient;
} }
@ -256,7 +256,7 @@ describe('TokenAuthenticationProvider', () => {
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const authenticationError = new errors.InternalServerError('something went wrong'); const authenticationError = new errors.InternalServerError('something went wrong');
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError);
mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient);
@ -274,7 +274,7 @@ describe('TokenAuthenticationProvider', () => {
const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const tokenPair = { accessToken: 'foo', refreshToken: 'bar' };
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -300,7 +300,7 @@ describe('TokenAuthenticationProvider', () => {
const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const tokenPair = { accessToken: 'foo', refreshToken: 'bar' };
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -331,7 +331,7 @@ describe('TokenAuthenticationProvider', () => {
const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const tokenPair = { accessToken: 'foo', refreshToken: 'bar' };
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -362,7 +362,7 @@ describe('TokenAuthenticationProvider', () => {
const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const tokenPair = { accessToken: 'foo', refreshToken: 'bar' };
const authorization = `Bearer ${tokenPair.accessToken}`; const authorization = `Bearer ${tokenPair.accessToken}`;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -389,7 +389,7 @@ describe('TokenAuthenticationProvider', () => {
const authenticationError = new errors.AuthenticationException('Some error'); const authenticationError = new errors.AuthenticationException('Some error');
mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { mockOptions.client.asScoped.mockImplementation((scopeableRequest) => {
if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
); );
@ -397,7 +397,7 @@ describe('TokenAuthenticationProvider', () => {
} }
if (scopeableRequest?.headers.authorization === 'Bearer newfoo') { if (scopeableRequest?.headers.authorization === 'Bearer newfoo') {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError);
return mockScopedClusterClient; return mockScopedClusterClient;
} }

View file

@ -18,7 +18,7 @@ describe('Tokens', () => {
let tokens: Tokens; let tokens: Tokens;
let mockClusterClient: jest.Mocked<ILegacyClusterClient>; let mockClusterClient: jest.Mocked<ILegacyClusterClient>;
beforeEach(() => { beforeEach(() => {
mockClusterClient = elasticsearchServiceMock.createClusterClient(); mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient();
const tokensOptions = { const tokensOptions = {
client: mockClusterClient, client: mockClusterClient,

View file

@ -56,7 +56,7 @@ afterEach(() => {
}); });
it(`#setup returns exposed services`, () => { it(`#setup returns exposed services`, () => {
const mockClusterClient = elasticsearchServiceMock.createClusterClient(); const mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient();
const mockGetSpacesService = jest const mockGetSpacesService = jest
.fn() .fn()
.mockReturnValue({ getSpaceId: jest.fn(), namespaceToSpaceId: jest.fn() }); .mockReturnValue({ getSpaceId: jest.fn(), namespaceToSpaceId: jest.fn() });
@ -119,7 +119,7 @@ describe('#start', () => {
let licenseSubject: BehaviorSubject<SecurityLicenseFeatures>; let licenseSubject: BehaviorSubject<SecurityLicenseFeatures>;
let mockLicense: jest.Mocked<SecurityLicense>; let mockLicense: jest.Mocked<SecurityLicense>;
beforeEach(() => { beforeEach(() => {
const mockClusterClient = elasticsearchServiceMock.createClusterClient(); const mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient();
licenseSubject = new BehaviorSubject(({} as unknown) as SecurityLicenseFeatures); licenseSubject = new BehaviorSubject(({} as unknown) as SecurityLicenseFeatures);
mockLicense = licenseMock.create(); mockLicense = licenseMock.create();
@ -221,7 +221,7 @@ describe('#start', () => {
}); });
it('#stop unsubscribes from license and ES updates.', () => { 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 licenseSubject = new BehaviorSubject(({} as unknown) as SecurityLicenseFeatures);
const mockLicense = licenseMock.create(); const mockLicense = licenseMock.create();

View file

@ -21,10 +21,10 @@ const mockActions = {
const savedObjectTypes = ['foo-type', 'bar-type']; const savedObjectTypes = ['foo-type', 'bar-type'];
const createMockClusterClient = (response: any) => { const createMockClusterClient = (response: any) => {
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(response); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(response);
const mockClusterClient = elasticsearchServiceMock.createClusterClient(); const mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient();
mockClusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockClusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
return { mockClusterClient, mockScopedClusterClient }; return { mockClusterClient, mockScopedClusterClient };

View file

@ -100,7 +100,7 @@ const registerPrivilegesWithClusterTest = (
}; };
test(description, async () => { test(description, async () => {
const mockClusterClient = elasticsearchServiceMock.createClusterClient(); const mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient();
mockClusterClient.callAsInternalUser.mockImplementation(async (api) => { mockClusterClient.callAsInternalUser.mockImplementation(async (api) => {
switch (api) { switch (api) {
case 'shield.getPrivilege': { case 'shield.getPrivilege': {

View file

@ -43,7 +43,7 @@ describe('Security Plugin', () => {
protocol: 'https', protocol: 'https',
}); });
mockClusterClient = elasticsearchServiceMock.createCustomClusterClient(); mockClusterClient = elasticsearchServiceMock.createLegacyCustomClusterClient();
mockCoreSetup.elasticsearch.legacy.createClient.mockReturnValue(mockClusterClient); mockCoreSetup.elasticsearch.legacy.createClient.mockReturnValue(mockClusterClient);
mockDependencies = ({ mockDependencies = ({

View file

@ -27,7 +27,7 @@ describe('Get API keys', () => {
test(description, async () => { test(description, async () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
if (apiResponse) { if (apiResponse) {
mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse); mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse);

View file

@ -27,7 +27,7 @@ describe('Invalidate API keys', () => {
) => { ) => {
test(description, async () => { test(description, async () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
for (const apiResponse of apiResponses) { for (const apiResponse of apiResponses) {
mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(apiResponse); mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(apiResponse);

View file

@ -48,7 +48,7 @@ describe('Check API keys privileges', () => {
apiKeys.areAPIKeysEnabled() apiKeys.areAPIKeysEnabled()
); );
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
for (const apiResponse of callAsCurrentUserResponses) { for (const apiResponse of callAsCurrentUserResponses) {
mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(apiResponse); mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(apiResponse);

View file

@ -30,7 +30,7 @@ describe('DELETE role', () => {
test(description, async () => { test(description, async () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
if (apiResponse) { if (apiResponse) {
mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse); mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse);

View file

@ -33,7 +33,7 @@ describe('GET role', () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
mockRouteDefinitionParams.authz.applicationName = application; mockRouteDefinitionParams.authz.applicationName = application;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
if (apiResponse) { if (apiResponse) {
mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse); mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse);

View file

@ -33,7 +33,7 @@ describe('GET all roles', () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
mockRouteDefinitionParams.authz.applicationName = application; mockRouteDefinitionParams.authz.applicationName = application;
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
if (apiResponse) { if (apiResponse) {
mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse); mockScopedClusterClient.callAsCurrentUser.mockImplementation(apiResponse);

View file

@ -72,7 +72,7 @@ const putRoleTest = (
mockRouteDefinitionParams.authz.applicationName = application; mockRouteDefinitionParams.authz.applicationName = application;
mockRouteDefinitionParams.authz.privileges.get.mockReturnValue(privilegeMap); mockRouteDefinitionParams.authz.privileges.get.mockReturnValue(privilegeMap);
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
for (const apiResponse of apiResponses) { for (const apiResponse of apiResponses) {
mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(apiResponse); mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(apiResponse);

View file

@ -21,7 +21,7 @@ export const routeDefinitionParamsMock = {
basePath: httpServiceMock.createBasePath(), basePath: httpServiceMock.createBasePath(),
csp: httpServiceMock.createSetupContract().csp, csp: httpServiceMock.createSetupContract().csp,
logger: loggingSystemMock.create().get(), logger: loggingSystemMock.create().get(),
clusterClient: elasticsearchServiceMock.createClusterClient(), clusterClient: elasticsearchServiceMock.createLegacyClusterClient(),
config: createConfig(ConfigSchema.validate(config), loggingSystemMock.create().get(), { config: createConfig(ConfigSchema.validate(config), loggingSystemMock.create().get(), {
isTLSEnabled: false, isTLSEnabled: false,
}), }),

View file

@ -13,7 +13,7 @@ describe('DELETE role mappings', () => {
it('allows a role mapping to be deleted', async () => { it('allows a role mapping to be deleted', async () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({ acknowledged: true }); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({ acknowledged: true });

View file

@ -76,7 +76,7 @@ describe('GET role mappings feature check', () => {
test(description, async () => { test(description, async () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
mockRouteDefinitionParams.clusterClient.callAsInternalUser.mockImplementation( mockRouteDefinitionParams.clusterClient.callAsInternalUser.mockImplementation(
internalUserClusterClientImpl internalUserClusterClientImpl

View file

@ -53,7 +53,7 @@ describe('GET role mappings', () => {
it('returns all role mappings', async () => { it('returns all role mappings', async () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(mockRoleMappingResponse); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(mockRoleMappingResponse);
@ -128,7 +128,7 @@ describe('GET role mappings', () => {
it('returns role mapping by name', async () => { it('returns role mapping by name', async () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({ mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({
mapping1: { mapping1: {
@ -216,7 +216,7 @@ describe('GET role mappings', () => {
it('returns a 404 when the role mapping is not found', async () => { it('returns a 404 when the role mapping is not found', async () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(
Boom.notFound('role mapping not found!') Boom.notFound('role mapping not found!')

View file

@ -13,7 +13,7 @@ describe('POST role mappings', () => {
it('allows a role mapping to be created', async () => { it('allows a role mapping to be created', async () => {
const mockRouteDefinitionParams = routeDefinitionParamsMock.create(); const mockRouteDefinitionParams = routeDefinitionParamsMock.create();
const mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockRouteDefinitionParams.clusterClient.asScoped.mockReturnValue(mockScopedClusterClient);
mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({ created: true }); mockScopedClusterClient.callAsCurrentUser.mockResolvedValue({ created: true });

View file

@ -56,7 +56,7 @@ describe('Change password', () => {
provider: { type: 'basic', name: 'basic' }, provider: { type: 'basic', name: 'basic' },
}); });
mockScopedClusterClient = elasticsearchServiceMock.createScopedClusterClient(); mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockClusterClient = routeParamsMock.clusterClient; mockClusterClient = routeParamsMock.clusterClient;
mockClusterClient.asScoped.mockReturnValue(mockScopedClusterClient); mockClusterClient.asScoped.mockReturnValue(mockScopedClusterClient);

View file

@ -22,8 +22,8 @@ describe('test alerts route', () => {
let endpointAppContextService: EndpointAppContextService; let endpointAppContextService: EndpointAppContextService;
beforeEach(() => { beforeEach(() => {
mockClusterClient = elasticsearchServiceMock.createClusterClient(); mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient();
mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockClusterClient.asScoped.mockReturnValue(mockScopedClient); mockClusterClient.asScoped.mockReturnValue(mockScopedClient);
routerMock = httpServiceMock.createRouter(); routerMock = httpServiceMock.createRouter();

View file

@ -59,10 +59,10 @@ describe('test endpoint route', () => {
} as unknown) as SearchResponse<HostId>); } as unknown) as SearchResponse<HostId>);
beforeEach(() => { beforeEach(() => {
mockClusterClient = elasticsearchServiceMock.createClusterClient() as jest.Mocked< mockClusterClient = elasticsearchServiceMock.createLegacyClusterClient() as jest.Mocked<
ILegacyClusterClient ILegacyClusterClient
>; >;
mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockSavedObjectClient = savedObjectsClientMock.create(); mockSavedObjectClient = savedObjectsClientMock.create();
mockClusterClient.asScoped.mockReturnValue(mockScopedClient); mockClusterClient.asScoped.mockReturnValue(mockScopedClient);
routerMock = httpServiceMock.createRouter(); routerMock = httpServiceMock.createRouter();

View file

@ -29,7 +29,7 @@ describe('test find all unenrolled HostId', () => {
it('can find all hits with scroll', async () => { it('can find all hits with scroll', async () => {
const firstHostId = '1fdca33f-799f-49f4-939c-ea4383c77671'; const firstHostId = '1fdca33f-799f-49f4-939c-ea4383c77671';
const secondHostId = '2fdca33f-799f-49f4-939c-ea4383c77672'; const secondHostId = '2fdca33f-799f-49f4-939c-ea4383c77672';
mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClient.callAsCurrentUser mockScopedClient.callAsCurrentUser
.mockImplementationOnce(() => Promise.resolve(createSearchResponse(secondHostId, 'scrollId'))) .mockImplementationOnce(() => Promise.resolve(createSearchResponse(secondHostId, 'scrollId')))
.mockImplementationOnce(noUnenrolledEndpoint); .mockImplementationOnce(noUnenrolledEndpoint);
@ -46,7 +46,7 @@ describe('test find all unenrolled HostId', () => {
it('can find all unerolled endpoint host ids', async () => { it('can find all unerolled endpoint host ids', async () => {
const firstEndpointHostId = '1fdca33f-799f-49f4-939c-ea4383c77671'; const firstEndpointHostId = '1fdca33f-799f-49f4-939c-ea4383c77671';
const secondEndpointHostId = '2fdca33f-799f-49f4-939c-ea4383c77672'; const secondEndpointHostId = '2fdca33f-799f-49f4-939c-ea4383c77672';
mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClient.callAsCurrentUser mockScopedClient.callAsCurrentUser
.mockImplementationOnce(() => .mockImplementationOnce(() =>
Promise.resolve(createSearchResponse(firstEndpointHostId, 'initialScrollId')) 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 () => { it('can find unenrolled endpoint by the host id when unenrolled', async () => {
const firstEndpointHostId = '1fdca33f-799f-49f4-939c-ea4383c77671'; const firstEndpointHostId = '1fdca33f-799f-49f4-939c-ea4383c77671';
mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClient.callAsCurrentUser.mockImplementationOnce(() => mockScopedClient.callAsCurrentUser.mockImplementationOnce(() =>
Promise.resolve(createSearchResponse(firstEndpointHostId, 'initialScrollId')) 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 () => { it('find unenrolled endpoint host by the host id return undefined when no unenrolled host', async () => {
const firstHostId = '1fdca33f-799f-49f4-939c-ea4383c77671'; const firstHostId = '1fdca33f-799f-49f4-939c-ea4383c77671';
mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockScopedClient.callAsCurrentUser.mockImplementationOnce(noUnenrolledEndpoint); mockScopedClient.callAsCurrentUser.mockImplementationOnce(noUnenrolledEndpoint);
const hostId = await findUnenrolledHostByHostId(mockScopedClient, firstHostId); const hostId = await findUnenrolledHostByHostId(mockScopedClient, firstHostId);
expect(hostId).toBeFalsy(); expect(hostId).toBeFalsy();

View file

@ -32,7 +32,7 @@ describe('test policy response handler', () => {
let mockResponse: jest.Mocked<KibanaResponseFactory>; let mockResponse: jest.Mocked<KibanaResponseFactory>;
beforeEach(() => { beforeEach(() => {
mockScopedClient = elasticsearchServiceMock.createScopedClusterClient(); mockScopedClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
mockSavedObjectClient = savedObjectsClientMock.create(); mockSavedObjectClient = savedObjectsClientMock.create();
mockResponse = httpServerMock.createResponseFactory(); mockResponse = httpServerMock.createResponseFactory();
endpointAppContextService = new EndpointAppContextService(); endpointAppContextService = new EndpointAppContextService();

View file

@ -16,7 +16,7 @@ import { siemMock } from '../../../../mocks';
const createMockClients = () => ({ const createMockClients = () => ({
alertsClient: alertsClientMock.create(), alertsClient: alertsClientMock.create(),
clusterClient: elasticsearchServiceMock.createScopedClusterClient(), clusterClient: elasticsearchServiceMock.createLegacyScopedClusterClient(),
licensing: { license: licensingMock.createLicenseMock() }, licensing: { license: licensingMock.createLicenseMock() },
savedObjectsClient: savedObjectsClientMock.create(), savedObjectsClient: savedObjectsClientMock.create(),
appClient: siemMock.createClient(), appClient: siemMock.createClient(),

View file

@ -7,7 +7,7 @@
import { MlPluginSetup } from '../../../../ml/server'; import { MlPluginSetup } from '../../../../ml/server';
import { elasticsearchServiceMock } from '../../../../../../src/core/server/mocks'; import { elasticsearchServiceMock } from '../../../../../../src/core/server/mocks';
const createMockClient = () => elasticsearchServiceMock.createClusterClient(); const createMockClient = () => elasticsearchServiceMock.createLegacyClusterClient();
const createMockMlSystemProvider = () => const createMockMlSystemProvider = () =>
jest.fn(() => ({ jest.fn(() => ({
mlCapabilities: jest.fn(), mlCapabilities: jest.fn(),

View file

@ -12,7 +12,7 @@ import {
describe('getDeprecationLoggingStatus', () => { describe('getDeprecationLoggingStatus', () => {
it('calls cluster.getSettings', async () => { it('calls cluster.getSettings', async () => {
const dataClient = elasticsearchServiceMock.createScopedClusterClient(); const dataClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
await getDeprecationLoggingStatus(dataClient); await getDeprecationLoggingStatus(dataClient);
expect(dataClient.callAsCurrentUser).toHaveBeenCalledWith('cluster.getSettings', { expect(dataClient.callAsCurrentUser).toHaveBeenCalledWith('cluster.getSettings', {
includeDefaults: true, includeDefaults: true,
@ -23,7 +23,7 @@ describe('getDeprecationLoggingStatus', () => {
describe('setDeprecationLogging', () => { describe('setDeprecationLogging', () => {
describe('isEnabled = true', () => { describe('isEnabled = true', () => {
it('calls cluster.putSettings with logger.deprecation = WARN', async () => { it('calls cluster.putSettings with logger.deprecation = WARN', async () => {
const dataClient = elasticsearchServiceMock.createScopedClusterClient(); const dataClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
await setDeprecationLogging(dataClient, true); await setDeprecationLogging(dataClient, true);
expect(dataClient.callAsCurrentUser).toHaveBeenCalledWith('cluster.putSettings', { expect(dataClient.callAsCurrentUser).toHaveBeenCalledWith('cluster.putSettings', {
body: { transient: { 'logger.deprecation': 'WARN' } }, body: { transient: { 'logger.deprecation': 'WARN' } },
@ -33,7 +33,7 @@ describe('setDeprecationLogging', () => {
describe('isEnabled = false', () => { describe('isEnabled = false', () => {
it('calls cluster.putSettings with logger.deprecation = ERROR', async () => { it('calls cluster.putSettings with logger.deprecation = ERROR', async () => {
const dataClient = elasticsearchServiceMock.createScopedClusterClient(); const dataClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
await setDeprecationLogging(dataClient, false); await setDeprecationLogging(dataClient, false);
expect(dataClient.callAsCurrentUser).toHaveBeenCalledWith('cluster.putSettings', { expect(dataClient.callAsCurrentUser).toHaveBeenCalledWith('cluster.putSettings', {
body: { transient: { 'logger.deprecation': 'ERROR' } }, body: { transient: { 'logger.deprecation': 'ERROR' } },

View file

@ -14,7 +14,7 @@ import fakeDeprecations from './__fixtures__/fake_deprecations.json';
describe('getUpgradeAssistantStatus', () => { describe('getUpgradeAssistantStatus', () => {
let deprecationsResponse: DeprecationAPIResponse; let deprecationsResponse: DeprecationAPIResponse;
const dataClient = elasticsearchServiceMock.createScopedClusterClient(); const dataClient = elasticsearchServiceMock.createLegacyScopedClusterClient();
(dataClient.callAsCurrentUser as jest.Mock).mockImplementation(async (api, { path, index }) => { (dataClient.callAsCurrentUser as jest.Mock).mockImplementation(async (api, { path, index }) => {
if (path === '/_migration/deprecations') { if (path === '/_migration/deprecations') {
return deprecationsResponse; return deprecationsResponse;

View file

@ -21,7 +21,7 @@ describe('Upgrade Assistant Usage Collector', () => {
let clusterClient: ILegacyClusterClient; let clusterClient: ILegacyClusterClient;
beforeEach(() => { beforeEach(() => {
clusterClient = elasticsearchServiceMock.createClusterClient(); clusterClient = elasticsearchServiceMock.createLegacyClusterClient();
(clusterClient.callAsInternalUser as jest.Mock).mockResolvedValue({ (clusterClient.callAsInternalUser as jest.Mock).mockResolvedValue({
persistent: {}, persistent: {},
transient: { transient: {

View file

@ -13,7 +13,7 @@ export const routeHandlerContextMock = ({
core: { core: {
elasticsearch: { elasticsearch: {
legacy: { legacy: {
client: elasticsearchServiceMock.createScopedClusterClient(), client: elasticsearchServiceMock.createLegacyScopedClusterClient(),
}, },
}, },
savedObjects: { client: savedObjectsClientMock.create() }, savedObjects: { client: savedObjectsClientMock.create() },

View file

@ -51,7 +51,7 @@ type MockCallES = (method: any, params: any) => Promise<any>;
const setupMock = ( const setupMock = (
criteria: MultiPageCriteria[] criteria: MultiPageCriteria[]
): [MockCallES, jest.Mocked<Pick<LegacyScopedClusterClient, 'callAsCurrentUser'>>] => { ): [MockCallES, jest.Mocked<Pick<LegacyScopedClusterClient, 'callAsCurrentUser'>>] => {
const esMock = elasticsearchServiceMock.createScopedClusterClient(); const esMock = elasticsearchServiceMock.createLegacyScopedClusterClient();
criteria.forEach(({ after_key, bucketCriteria }) => { criteria.forEach(({ after_key, bucketCriteria }) => {
const mockResponse = { const mockResponse = {