@@ -27,7 +27,6 @@ import {
2727
2828import { errors } from 'elasticsearch' ;
2929import { get } from 'lodash' ;
30- import { auditTrailServiceMock } from '../../audit_trail/audit_trail_service.mock' ;
3130import { Logger } from '../../logging' ;
3231import { loggingSystemMock } from '../../logging/logging_system.mock' ;
3332import { 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
522428describe ( '#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
0 commit comments