Skip to content

Commit 20eefbc

Browse files
committed
rebase fixes
1 parent d40321d commit 20eefbc

File tree

5 files changed

+28
-172
lines changed

5 files changed

+28
-172
lines changed

src/core/server/audit_trail/audit_trail_service.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,10 @@ describe('AuditTrailService', () => {
7575
const { asScoped } = auditTrail.start();
7676
const kibanaRequest = httpServerMock.createKibanaRequest();
7777
const auditor = asScoped(kibanaRequest);
78-
const message = {
79-
type: 'foo',
80-
message: 'bar',
81-
};
82-
auditor.add(() => message);
78+
const eventDecorator = jest.fn();
79+
auditor.add(eventDecorator);
8380

84-
expect(addEventMock).toHaveBeenLastCalledWith(message);
81+
expect(addEventMock).toHaveBeenLastCalledWith(eventDecorator);
8582
});
8683

8784
describe('return the same auditor instance for the same KibanaRequest', () => {

src/core/server/elasticsearch/elasticsearch_service.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ describe('#setup', () => {
113113
expect(MockLegacyClusterClient).toHaveBeenCalledWith(
114114
expect.objectContaining(customConfig),
115115
expect.objectContaining({ context: ['elasticsearch', 'some-custom-type'] }),
116-
expect.any(Function),
117116
expect.any(Function)
118117
);
119118
});

src/core/server/elasticsearch/legacy/cluster_client.test.ts

Lines changed: 24 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727

2828
import { errors } from 'elasticsearch';
2929
import { get } from 'lodash';
30-
import { auditTrailServiceMock } from '../../audit_trail/audit_trail_service.mock';
3130
import { Logger } from '../../logging';
3231
import { loggingSystemMock } from '../../logging/logging_system.mock';
3332
import { httpServerMock } from '../../http/http_server.mocks';
@@ -43,11 +42,7 @@ test('#constructor creates client with parsed config', () => {
4342
const mockEsConfig = { apiVersion: 'es-version' } as any;
4443
const mockLogger = logger.get();
4544

46-
const clusterClient = new LegacyClusterClient(
47-
mockEsConfig,
48-
mockLogger,
49-
auditTrailServiceMock.createAuditorFactory
50-
);
45+
const clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger);
5146
expect(clusterClient).toBeDefined();
5247

5348
expect(mockParseElasticsearchClientConfig).toHaveBeenCalledTimes(1);
@@ -73,11 +68,7 @@ describe('#callAsInternalUser', () => {
7368
};
7469
MockClient.mockImplementation(() => mockEsClientInstance);
7570

76-
clusterClient = new LegacyClusterClient(
77-
{ apiVersion: 'es-version' } as any,
78-
logger.get(),
79-
auditTrailServiceMock.createAuditorFactory
80-
);
71+
clusterClient = new LegacyClusterClient({ apiVersion: 'es-version' } as any, logger.get());
8172
});
8273

8374
test('fails if cluster client is closed', async () => {
@@ -246,11 +237,7 @@ describe('#asScoped', () => {
246237
requestHeadersWhitelist: ['one', 'two'],
247238
} as any;
248239

249-
clusterClient = new LegacyClusterClient(
250-
mockEsConfig,
251-
mockLogger,
252-
auditTrailServiceMock.createAuditorFactory
253-
);
240+
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger);
254241
jest.clearAllMocks();
255242
});
256243

@@ -285,11 +272,7 @@ describe('#asScoped', () => {
285272

286273
test('properly configures `ignoreCertAndKey` for various configurations', () => {
287274
// Config without SSL.
288-
clusterClient = new LegacyClusterClient(
289-
mockEsConfig,
290-
mockLogger,
291-
auditTrailServiceMock.createAuditorFactory
292-
);
275+
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger);
293276

294277
mockParseElasticsearchClientConfig.mockClear();
295278
clusterClient.asScoped(httpServerMock.createRawRequest({ headers: { one: '1' } }));
@@ -302,11 +285,7 @@ describe('#asScoped', () => {
302285

303286
// Config ssl.alwaysPresentCertificate === false
304287
mockEsConfig = { ...mockEsConfig, ssl: { alwaysPresentCertificate: false } } as any;
305-
clusterClient = new LegacyClusterClient(
306-
mockEsConfig,
307-
mockLogger,
308-
auditTrailServiceMock.createAuditorFactory
309-
);
288+
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger);
310289

311290
mockParseElasticsearchClientConfig.mockClear();
312291
clusterClient.asScoped(httpServerMock.createRawRequest({ headers: { one: '1' } }));
@@ -319,11 +298,7 @@ describe('#asScoped', () => {
319298

320299
// Config ssl.alwaysPresentCertificate === true
321300
mockEsConfig = { ...mockEsConfig, ssl: { alwaysPresentCertificate: true } } as any;
322-
clusterClient = new LegacyClusterClient(
323-
mockEsConfig,
324-
mockLogger,
325-
auditTrailServiceMock.createAuditorFactory
326-
);
301+
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger);
327302

328303
mockParseElasticsearchClientConfig.mockClear();
329304
clusterClient.asScoped(httpServerMock.createRawRequest({ headers: { one: '1' } }));
@@ -344,8 +319,7 @@ describe('#asScoped', () => {
344319
expect(MockScopedClusterClient).toHaveBeenCalledWith(
345320
expect.any(Function),
346321
expect.any(Function),
347-
{ one: '1', two: '2' },
348-
expect.any(Object)
322+
{ one: '1', two: '2' }
349323
);
350324
});
351325

@@ -358,8 +332,7 @@ describe('#asScoped', () => {
358332
expect(MockScopedClusterClient).toHaveBeenCalledWith(
359333
expect.any(Function),
360334
expect.any(Function),
361-
{ 'x-opaque-id': 'alpha' },
362-
expect.any(Object)
335+
{ 'x-opaque-id': 'alpha' }
363336
);
364337
});
365338

@@ -381,142 +354,75 @@ describe('#asScoped', () => {
381354
});
382355

383356
test('does not fail when scope to not defined request', async () => {
384-
clusterClient = new LegacyClusterClient(
385-
mockEsConfig,
386-
mockLogger,
387-
auditTrailServiceMock.createAuditorFactory
388-
);
357+
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger);
389358
clusterClient.asScoped();
390359
expect(MockScopedClusterClient).toHaveBeenCalledTimes(1);
391360
expect(MockScopedClusterClient).toHaveBeenCalledWith(
392361
expect.any(Function),
393362
expect.any(Function),
394-
{},
395-
undefined
363+
{}
396364
);
397365
});
398366

399367
test('does not fail when scope to a request without headers', async () => {
400-
clusterClient = new LegacyClusterClient(
401-
mockEsConfig,
402-
mockLogger,
403-
auditTrailServiceMock.createAuditorFactory
404-
);
368+
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger);
405369
clusterClient.asScoped({} as any);
406370
expect(MockScopedClusterClient).toHaveBeenCalledTimes(1);
407371
expect(MockScopedClusterClient).toHaveBeenCalledWith(
408372
expect.any(Function),
409373
expect.any(Function),
410-
{},
411-
undefined
374+
{}
412375
);
413376
});
414377

415378
test('calls getAuthHeaders and filters results for a real request', async () => {
416-
clusterClient = new LegacyClusterClient(
417-
mockEsConfig,
418-
mockLogger,
419-
auditTrailServiceMock.createAuditorFactory,
420-
() => ({
421-
one: '1',
422-
three: '3',
423-
})
424-
);
379+
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger, () => ({
380+
one: '1',
381+
three: '3',
382+
}));
425383
clusterClient.asScoped(httpServerMock.createRawRequest({ headers: { two: '2' } }));
426384
expect(MockScopedClusterClient).toHaveBeenCalledTimes(1);
427385
expect(MockScopedClusterClient).toHaveBeenCalledWith(
428386
expect.any(Function),
429387
expect.any(Function),
430-
{ one: '1', two: '2' },
431-
expect.any(Object)
388+
{ one: '1', two: '2' }
432389
);
433390
});
434391

435392
test('getAuthHeaders results rewrite extends a request headers', async () => {
436-
clusterClient = new LegacyClusterClient(
437-
mockEsConfig,
438-
mockLogger,
439-
auditTrailServiceMock.createAuditorFactory,
440-
() => ({ one: 'foo' })
441-
);
393+
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger, () => ({ one: 'foo' }));
442394
clusterClient.asScoped(httpServerMock.createRawRequest({ headers: { one: '1', two: '2' } }));
443395
expect(MockScopedClusterClient).toHaveBeenCalledTimes(1);
444396
expect(MockScopedClusterClient).toHaveBeenCalledWith(
445397
expect.any(Function),
446398
expect.any(Function),
447-
{ one: 'foo', two: '2' },
448-
expect.any(Object)
399+
{ one: 'foo', two: '2' }
449400
);
450401
});
451402

452403
test("doesn't call getAuthHeaders for a fake request", async () => {
453-
clusterClient = new LegacyClusterClient(
454-
mockEsConfig,
455-
mockLogger,
456-
auditTrailServiceMock.createAuditorFactory,
457-
() => ({})
458-
);
404+
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger, () => ({}));
459405
clusterClient.asScoped({ headers: { one: 'foo' } });
460406

461407
expect(MockScopedClusterClient).toHaveBeenCalledTimes(1);
462408
expect(MockScopedClusterClient).toHaveBeenCalledWith(
463409
expect.any(Function),
464410
expect.any(Function),
465-
{ one: 'foo' },
466-
undefined
411+
{ one: 'foo' }
467412
);
468413
});
469414

470415
test('filters a fake request headers', async () => {
471-
clusterClient = new LegacyClusterClient(
472-
mockEsConfig,
473-
mockLogger,
474-
auditTrailServiceMock.createAuditorFactory
475-
);
416+
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger);
476417
clusterClient.asScoped({ headers: { one: '1', two: '2', three: '3' } });
477418

478419
expect(MockScopedClusterClient).toHaveBeenCalledTimes(1);
479420
expect(MockScopedClusterClient).toHaveBeenCalledWith(
480421
expect.any(Function),
481422
expect.any(Function),
482-
{ one: '1', two: '2' },
483-
undefined
423+
{ one: '1', two: '2' }
484424
);
485425
});
486-
487-
describe('Auditor', () => {
488-
it('creates Auditor for KibanaRequest', async () => {
489-
const auditor = auditTrailServiceMock.createAuditor();
490-
const auditorFactory = auditTrailServiceMock.createAuditorFactory();
491-
auditorFactory.asScoped.mockReturnValue(auditor);
492-
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger, () => auditorFactory);
493-
clusterClient.asScoped(httpServerMock.createKibanaRequest());
494-
495-
expect(MockScopedClusterClient).toHaveBeenCalledTimes(1);
496-
expect(MockScopedClusterClient).toHaveBeenCalledWith(
497-
expect.any(Function),
498-
expect.any(Function),
499-
expect.objectContaining({ 'x-opaque-id': expect.any(String) }),
500-
auditor
501-
);
502-
});
503-
504-
it("doesn't create Auditor for a fake request", async () => {
505-
const getAuthHeaders = jest.fn();
506-
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger, getAuthHeaders);
507-
clusterClient.asScoped({ headers: { one: '1', two: '2', three: '3' } });
508-
509-
expect(getAuthHeaders).not.toHaveBeenCalled();
510-
});
511-
512-
it("doesn't create Auditor when no request passed", async () => {
513-
const getAuthHeaders = jest.fn();
514-
clusterClient = new LegacyClusterClient(mockEsConfig, mockLogger, getAuthHeaders);
515-
clusterClient.asScoped();
516-
517-
expect(getAuthHeaders).not.toHaveBeenCalled();
518-
});
519-
});
520426
});
521427

522428
describe('#close', () => {
@@ -534,8 +440,7 @@ describe('#close', () => {
534440

535441
clusterClient = new LegacyClusterClient(
536442
{ apiVersion: 'es-version', requestHeadersWhitelist: [] } as any,
537-
logger.get(),
538-
auditTrailServiceMock.createAuditorFactory
443+
logger.get()
539444
);
540445
});
541446

src/core/server/elasticsearch/legacy/cluster_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Client } from 'elasticsearch';
2020
import { get } from 'lodash';
2121

2222
import { LegacyElasticsearchErrorHelpers } from './errors';
23-
import { GetAuthHeaders, KibanaRequest, isKibanaRequest, isRealRequest } from '../../http';
23+
import { GetAuthHeaders, isKibanaRequest, isRealRequest } from '../../http';
2424
import { filterHeaders, ensureRawRequest } from '../../http/router';
2525
import { Logger } from '../../logging';
2626
import { ScopeableRequest } from '../types';

src/core/server/elasticsearch/legacy/scoped_cluster_client.test.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
import { LegacyScopedClusterClient } from './scoped_cluster_client';
21-
import { auditTrailServiceMock } from '../../audit_trail/audit_trail_service.mock';
2221

2322
let internalAPICaller: jest.Mock;
2423
let scopedAPICaller: jest.Mock;
@@ -84,28 +83,6 @@ describe('#callAsInternalUser', () => {
8483

8584
expect(scopedAPICaller).not.toHaveBeenCalled();
8685
});
87-
88-
describe('Auditor', () => {
89-
it('does not fail when no auditor provided', () => {
90-
const clusterClientWithoutAuditor = new LegacyScopedClusterClient(jest.fn(), jest.fn());
91-
expect(() => clusterClientWithoutAuditor.callAsInternalUser('endpoint')).not.toThrow();
92-
});
93-
it('creates an audit record if auditor provided', () => {
94-
const auditor = auditTrailServiceMock.createAuditor();
95-
const clusterClientWithoutAuditor = new LegacyScopedClusterClient(
96-
jest.fn(),
97-
jest.fn(),
98-
{},
99-
auditor
100-
);
101-
clusterClientWithoutAuditor.callAsInternalUser('endpoint');
102-
expect(auditor.add).toHaveBeenCalledTimes(1);
103-
expect(auditor.add).toHaveBeenLastCalledWith({
104-
message: 'endpoint',
105-
type: 'elasticsearch.call.internalUser',
106-
});
107-
});
108-
});
10986
});
11087

11188
describe('#callAsCurrentUser', () => {
@@ -229,26 +206,4 @@ describe('#callAsCurrentUser', () => {
229206

230207
expect(internalAPICaller).not.toHaveBeenCalled();
231208
});
232-
233-
describe('Auditor', () => {
234-
it('does not fail when no auditor provided', () => {
235-
const clusterClientWithoutAuditor = new LegacyScopedClusterClient(jest.fn(), jest.fn());
236-
expect(() => clusterClientWithoutAuditor.callAsCurrentUser('endpoint')).not.toThrow();
237-
});
238-
it('creates an audit record if auditor provided', () => {
239-
const auditor = auditTrailServiceMock.createAuditor();
240-
const clusterClientWithoutAuditor = new LegacyScopedClusterClient(
241-
jest.fn(),
242-
jest.fn(),
243-
{},
244-
auditor
245-
);
246-
clusterClientWithoutAuditor.callAsCurrentUser('endpoint');
247-
expect(auditor.add).toHaveBeenCalledTimes(1);
248-
expect(auditor.add).toHaveBeenLastCalledWith({
249-
message: 'endpoint',
250-
type: 'elasticsearch.call.currentUser',
251-
});
252-
});
253-
});
254209
});

0 commit comments

Comments
 (0)