elasticsearch-transport 7.9.0 → 7.17.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -10
  3. data/Gemfile-faraday1.gemfile +47 -0
  4. data/README.md +23 -17
  5. data/Rakefile +47 -10
  6. data/elasticsearch-transport.gemspec +16 -18
  7. data/lib/elasticsearch/transport/client.rb +133 -56
  8. data/lib/elasticsearch/transport/meta_header.rb +135 -0
  9. data/lib/elasticsearch/transport/transport/base.rb +41 -22
  10. data/lib/elasticsearch/transport/transport/connections/collection.rb +2 -5
  11. data/lib/elasticsearch/transport/transport/connections/connection.rb +6 -4
  12. data/lib/elasticsearch/transport/transport/errors.rb +1 -0
  13. data/lib/elasticsearch/transport/transport/http/curb.rb +44 -32
  14. data/lib/elasticsearch/transport/transport/http/faraday.rb +15 -5
  15. data/lib/elasticsearch/transport/transport/http/manticore.rb +41 -29
  16. data/lib/elasticsearch/transport/transport/response.rb +1 -1
  17. data/lib/elasticsearch/transport/version.rb +1 -1
  18. data/lib/elasticsearch/transport.rb +19 -30
  19. data/spec/elasticsearch/connections/collection_spec.rb +12 -0
  20. data/spec/elasticsearch/transport/base_spec.rb +90 -33
  21. data/spec/elasticsearch/transport/client_spec.rb +569 -164
  22. data/spec/elasticsearch/transport/http/curb_spec.rb +126 -0
  23. data/spec/elasticsearch/transport/http/faraday_spec.rb +141 -0
  24. data/spec/elasticsearch/transport/http/manticore_spec.rb +161 -0
  25. data/spec/elasticsearch/transport/meta_header_spec.rb +301 -0
  26. data/spec/spec_helper.rb +13 -5
  27. data/test/integration/jruby_test.rb +43 -0
  28. data/test/integration/transport_test.rb +93 -43
  29. data/test/test_helper.rb +10 -22
  30. data/test/unit/adapters_test.rb +88 -0
  31. data/test/unit/connection_test.rb +7 -2
  32. data/test/unit/response_test.rb +1 -1
  33. data/test/unit/transport_base_test.rb +17 -8
  34. data/test/unit/transport_curb_test.rb +0 -1
  35. data/test/unit/transport_faraday_test.rb +2 -2
  36. data/test/unit/transport_manticore_test.rb +242 -155
  37. metadata +62 -84
@@ -24,10 +24,6 @@ describe Elasticsearch::Transport::Client do
24
24
  end
25
25
  end
26
26
 
27
- it 'is aliased as Elasticsearch::Client' do
28
- expect(Elasticsearch::Client.new).to be_a(described_class)
29
- end
30
-
31
27
  it 'has a default transport' do
32
28
  expect(client.transport).to be_a(Elasticsearch::Transport::Client::DEFAULT_TRANSPORT_CLASS)
33
29
  end
@@ -231,14 +227,15 @@ describe Elasticsearch::Transport::Client do
231
227
 
232
228
  describe 'adapter' do
233
229
  context 'when no adapter is specified' do
234
- let(:adapter) do
235
- client.transport.connections.all.first.connection.builder.adapter
236
- end
230
+ fork do
231
+ let(:client) { described_class.new }
232
+ let(:adapter) { client.transport.connections.all.first.connection.builder.adapter }
237
233
 
238
- it 'uses Faraday NetHttp' do
239
- expect(adapter).to eq Faraday::Adapter::NetHttp
234
+ it 'uses Faraday NetHttp' do
235
+ expect(adapter).to eq Faraday::Adapter::NetHttp
236
+ end
240
237
  end
241
- end
238
+ end unless jruby?
242
239
 
243
240
  context 'when the adapter is patron' do
244
241
  let(:adapter) do
@@ -246,13 +243,14 @@ describe Elasticsearch::Transport::Client do
246
243
  end
247
244
 
248
245
  let(:client) do
249
- described_class.new(adapter: :patron)
246
+ described_class.new(adapter: :patron, enable_meta_header: false)
250
247
  end
251
248
 
252
249
  it 'uses Faraday with the adapter' do
250
+ require 'faraday/patron'
253
251
  expect(adapter).to eq Faraday::Adapter::Patron
254
252
  end
255
- end
253
+ end unless jruby?
256
254
 
257
255
  context 'when the adapter is typhoeus' do
258
256
  let(:adapter) do
@@ -260,13 +258,15 @@ describe Elasticsearch::Transport::Client do
260
258
  end
261
259
 
262
260
  let(:client) do
263
- described_class.new(adapter: :typhoeus)
261
+ require 'faraday/typhoeus' if is_faraday_v2?
262
+
263
+ described_class.new(adapter: :typhoeus, enable_meta_header: false)
264
264
  end
265
265
 
266
266
  it 'uses Faraday with the adapter' do
267
267
  expect(adapter).to eq Faraday::Adapter::Typhoeus
268
268
  end
269
- end
269
+ end unless jruby?
270
270
 
271
271
  context 'when the adapter is specified as a string key' do
272
272
  let(:adapter) do
@@ -274,13 +274,13 @@ describe Elasticsearch::Transport::Client do
274
274
  end
275
275
 
276
276
  let(:client) do
277
- described_class.new('adapter' => :patron)
277
+ described_class.new(adapter: :patron, enable_meta_header: false)
278
278
  end
279
279
 
280
280
  it 'uses Faraday with the adapter' do
281
281
  expect(adapter).to eq Faraday::Adapter::Patron
282
282
  end
283
- end
283
+ end unless jruby?
284
284
 
285
285
  context 'when the adapter can be detected', unless: jruby? do
286
286
 
@@ -322,13 +322,17 @@ describe Elasticsearch::Transport::Client do
322
322
  it 'sets the logger' do
323
323
  expect(handlers).to include(Faraday::Response::Logger)
324
324
  end
325
- end
325
+ end unless jruby?
326
326
  end
327
327
 
328
328
  context 'when cloud credentials are provided' do
329
329
 
330
330
  let(:client) do
331
- described_class.new(cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elastic', password: 'changeme')
331
+ described_class.new(
332
+ cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
333
+ user: 'elastic',
334
+ password: 'changeme'
335
+ )
332
336
  end
333
337
 
334
338
  let(:hosts) do
@@ -340,17 +344,19 @@ describe Elasticsearch::Transport::Client do
340
344
  expect(hosts[0][:protocol]).to eq('https')
341
345
  expect(hosts[0][:user]).to eq('elastic')
342
346
  expect(hosts[0][:password]).to eq('changeme')
343
- expect(hosts[0][:port]).to eq(9243)
347
+ expect(hosts[0][:port]).to eq(443)
344
348
  end
345
349
 
346
350
  it 'creates the correct full url' do
347
- expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9243')
351
+ expect(
352
+ client.transport.__full_url(client.transport.hosts[0])
353
+ ).to eq('https://elastic:changeme@abcd.localhost:443')
348
354
  end
349
355
 
350
356
  context 'when a port is specified' do
351
357
 
352
358
  let(:client) do
353
- described_class.new(cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elastic', password: 'changeme', port: 9200 )
359
+ described_class.new(cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elastic', password: 'changeme', port: 9250)
354
360
  end
355
361
 
356
362
  it 'sets the specified port along with the cloud credentials' do
@@ -358,18 +364,22 @@ describe Elasticsearch::Transport::Client do
358
364
  expect(hosts[0][:protocol]).to eq('https')
359
365
  expect(hosts[0][:user]).to eq('elastic')
360
366
  expect(hosts[0][:password]).to eq('changeme')
361
- expect(hosts[0][:port]).to eq(9200)
367
+ expect(hosts[0][:port]).to eq(9250)
362
368
  end
363
369
 
364
370
  it 'creates the correct full url' do
365
- expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9200')
371
+ expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9250')
366
372
  end
367
373
  end
368
374
 
369
375
  context 'when the cluster has alternate names' do
370
376
 
371
377
  let(:client) do
372
- described_class.new(cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elasticfantastic', password: 'tobechanged')
378
+ described_class.new(
379
+ cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==',
380
+ user: 'elasticfantastic',
381
+ password: 'tobechanged'
382
+ )
373
383
  end
374
384
 
375
385
  let(:hosts) do
@@ -381,124 +391,334 @@ describe Elasticsearch::Transport::Client do
381
391
  expect(hosts[0][:protocol]).to eq('https')
382
392
  expect(hosts[0][:user]).to eq('elasticfantastic')
383
393
  expect(hosts[0][:password]).to eq('tobechanged')
384
- expect(hosts[0][:port]).to eq(9243)
394
+ expect(hosts[0][:port]).to eq(443)
385
395
  end
386
396
 
387
397
  it 'creates the correct full url' do
388
- expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elasticfantastic:tobechanged@abcd.localhost:9243')
398
+ expect(
399
+ client.transport.__full_url(client.transport.hosts[0])
400
+ ).to eq('https://elasticfantastic:tobechanged@abcd.localhost:443')
389
401
  end
390
-
391
402
  end
392
- end
393
403
 
394
- shared_examples_for 'a client that extracts hosts' do
404
+ context 'when decoded cloud id has a trailing dollar sign' do
405
+ let(:client) do
406
+ described_class.new(
407
+ cloud_id: 'a_cluster:bG9jYWxob3N0JGFiY2Qk',
408
+ user: 'elasticfantastic',
409
+ password: 'changeme'
410
+ )
411
+ end
395
412
 
396
- context 'when the hosts are a String' do
413
+ let(:hosts) do
414
+ client.transport.hosts
415
+ end
397
416
 
398
- let(:host) do
399
- 'myhost'
417
+ it 'extracts the cloud credentials' do
418
+ expect(hosts[0][:host]).to eq('abcd.localhost')
419
+ expect(hosts[0][:protocol]).to eq('https')
420
+ expect(hosts[0][:user]).to eq('elasticfantastic')
421
+ expect(hosts[0][:password]).to eq('changeme')
422
+ expect(hosts[0][:port]).to eq(443)
400
423
  end
401
424
 
402
- it 'extracts the host' do
403
- expect(hosts[0][:host]).to eq('myhost')
404
- expect(hosts[0][:protocol]).to eq('http')
405
- expect(hosts[0][:port]).to be(9200)
425
+ it 'creates the correct full url' do
426
+ expect(
427
+ client.transport.__full_url(client.transport.hosts[0])
428
+ ).to eq('https://elasticfantastic:changeme@abcd.localhost:443')
406
429
  end
430
+ end
407
431
 
408
- context 'when IPv6 format is used' do
432
+ context 'when the cloud host provides a port' do
433
+ let(:client) do
434
+ described_class.new(
435
+ cloud_id: 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk',
436
+ user: 'elastic',
437
+ password: 'changeme'
438
+ )
439
+ end
409
440
 
410
- around do |example|
411
- original_setting = Faraday.ignore_env_proxy
412
- Faraday.ignore_env_proxy = true
413
- example.run
414
- Faraday.ignore_env_proxy = original_setting
415
- end
441
+ let(:hosts) do
442
+ client.transport.hosts
443
+ end
416
444
 
417
- let(:host) do
418
- 'https://[2090:db8:85a3:9811::1f]:8080'
419
- end
445
+ it 'creates the correct full url' do
446
+ expect(hosts[0][:host]).to eq('elastic_id.elastic_server')
447
+ expect(hosts[0][:protocol]).to eq('https')
448
+ expect(hosts[0][:user]).to eq('elastic')
449
+ expect(hosts[0][:password]).to eq('changeme')
450
+ expect(hosts[0][:port]).to eq(9243)
451
+ end
452
+ end
420
453
 
421
- it 'extracts the host' do
422
- expect(hosts[0][:host]).to eq('[2090:db8:85a3:9811::1f]')
423
- expect(hosts[0][:scheme]).to eq('https')
424
- expect(hosts[0][:port]).to be(8080)
425
- end
454
+ context 'when the cloud host provides a port and the port is also specified' do
455
+ let(:client) do
456
+ described_class.new(
457
+ cloud_id: 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk',
458
+ user: 'elastic',
459
+ password: 'changeme',
460
+ port: 9200
461
+ )
462
+ end
426
463
 
427
- it 'creates the correct full url' do
428
- expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://[2090:db8:85a3:9811::1f]:8080')
429
- end
464
+ let(:hosts) do
465
+ client.transport.hosts
430
466
  end
431
467
 
432
- context 'when a path is specified' do
468
+ it 'creates the correct full url' do
469
+ expect(hosts[0][:host]).to eq('elastic_id.elastic_server')
470
+ expect(hosts[0][:protocol]).to eq('https')
471
+ expect(hosts[0][:user]).to eq('elastic')
472
+ expect(hosts[0][:password]).to eq('changeme')
473
+ expect(hosts[0][:port]).to eq(9243)
474
+ end
475
+ end
476
+ end
433
477
 
434
- let(:host) do
435
- 'https://myhost:8080/api'
436
- end
478
+ shared_examples_for 'a client that extracts hosts' do
437
479
 
438
- it 'extracts the host' do
439
- expect(hosts[0][:host]).to eq('myhost')
440
- expect(hosts[0][:scheme]).to eq('https')
441
- expect(hosts[0][:path]).to eq('/api')
442
- expect(hosts[0][:port]).to be(8080)
443
- end
444
- end
480
+ context 'when the host is a String' do
445
481
 
446
- context 'when a scheme is specified' do
482
+ context 'when there is a protocol specified' do
447
483
 
448
- let(:host) do
449
- 'https://myhost:8080'
450
- end
484
+ context 'when credentials are specified \'http://USERNAME:PASSWORD@myhost:8080\'' do
451
485
 
452
- it 'extracts the host' do
453
- expect(hosts[0][:host]).to eq('myhost')
454
- expect(hosts[0][:scheme]).to eq('https')
455
- expect(hosts[0][:port]).to be(8080)
486
+ let(:host) do
487
+ 'http://USERNAME:PASSWORD@myhost:8080'
488
+ end
489
+
490
+ it 'extracts the credentials' do
491
+ expect(hosts[0][:user]).to eq('USERNAME')
492
+ expect(hosts[0][:password]).to eq('PASSWORD')
493
+ end
494
+
495
+ it 'extracts the host' do
496
+ expect(hosts[0][:host]).to eq('myhost')
497
+ end
498
+
499
+ it 'extracts the port' do
500
+ expect(hosts[0][:port]).to be(8080)
501
+ end
456
502
  end
457
- end
458
503
 
459
- context 'when credentials are specified' do
504
+ context 'when there is a trailing slash \'http://myhost/\'' do
460
505
 
461
- let(:host) do
462
- 'http://USERNAME:PASSWORD@myhost:8080'
506
+ let(:host) do
507
+ 'http://myhost/'
508
+ end
509
+
510
+ it 'extracts the host' do
511
+ expect(hosts[0][:host]).to eq('myhost')
512
+ expect(hosts[0][:scheme]).to eq('http')
513
+ expect(hosts[0][:path]).to eq('')
514
+ end
515
+
516
+ it 'extracts the scheme' do
517
+ expect(hosts[0][:scheme]).to eq('http')
518
+ end
519
+
520
+ it 'extracts the path' do
521
+ expect(hosts[0][:path]).to eq('')
522
+ end
463
523
  end
464
524
 
465
- it 'extracts the host' do
466
- expect(hosts[0][:host]).to eq('myhost')
467
- expect(hosts[0][:scheme]).to eq('http')
468
- expect(hosts[0][:user]).to eq('USERNAME')
469
- expect(hosts[0][:password]).to eq('PASSWORD')
470
- expect(hosts[0][:port]).to be(8080)
525
+ context 'when there is a trailing slash with a path \'http://myhost/foo/bar/\'' do
526
+
527
+ let(:host) do
528
+ 'http://myhost/foo/bar/'
529
+ end
530
+
531
+ it 'extracts the host' do
532
+ expect(hosts[0][:host]).to eq('myhost')
533
+ expect(hosts[0][:scheme]).to eq('http')
534
+ expect(hosts[0][:path]).to eq('/foo/bar')
535
+ end
471
536
  end
472
- end
473
537
 
474
- context 'when there is a trailing slash' do
538
+ context 'when the protocol is http' do
475
539
 
476
- let(:host) do
477
- 'http://myhost/'
540
+ context 'when there is no port specified \'http://myhost\'' do
541
+
542
+ let(:host) do
543
+ 'http://myhost'
544
+ end
545
+
546
+ it 'extracts the host' do
547
+ expect(hosts[0][:host]).to eq('myhost')
548
+ end
549
+
550
+ it 'extracts the protocol' do
551
+ expect(hosts[0][:protocol]).to eq('http')
552
+ end
553
+
554
+ it 'defaults to port 9200' do
555
+ expect(hosts[0][:port]).to be(9200)
556
+ end
557
+ end
558
+
559
+ context 'when there is a port specified \'http://myhost:7101\'' do
560
+
561
+ let(:host) do
562
+ 'http://myhost:7101'
563
+ end
564
+
565
+ it 'extracts the host' do
566
+ expect(hosts[0][:host]).to eq('myhost')
567
+ end
568
+
569
+ it 'extracts the protocol' do
570
+ expect(hosts[0][:protocol]).to eq('http')
571
+ end
572
+
573
+ it 'extracts the port' do
574
+ expect(hosts[0][:port]).to be(7101)
575
+ end
576
+
577
+ context 'when there is a path specified \'http://myhost:7101/api\'' do
578
+
579
+ let(:host) do
580
+ 'http://myhost:7101/api'
581
+ end
582
+
583
+ it 'sets the path' do
584
+ expect(hosts[0][:host]).to eq('myhost')
585
+ expect(hosts[0][:protocol]).to eq('http')
586
+ expect(hosts[0][:path]).to eq('/api')
587
+ expect(hosts[0][:port]).to be(7101)
588
+ end
589
+
590
+ it 'extracts the host' do
591
+ expect(hosts[0][:host]).to eq('myhost')
592
+ end
593
+
594
+ it 'extracts the protocol' do
595
+ expect(hosts[0][:protocol]).to eq('http')
596
+ end
597
+
598
+ it 'extracts the port' do
599
+ expect(hosts[0][:port]).to be(7101)
600
+ end
601
+
602
+ it 'extracts the path' do
603
+ expect(hosts[0][:path]).to eq('/api')
604
+ end
605
+ end
606
+ end
478
607
  end
479
608
 
480
- it 'extracts the host' do
481
- expect(hosts[0][:host]).to eq('myhost')
482
- expect(hosts[0][:scheme]).to eq('http')
483
- expect(hosts[0][:path]).to eq('')
609
+ context 'when the protocol is https' do
610
+
611
+ context 'when there is no port specified \'https://myhost\'' do
612
+
613
+ let(:host) do
614
+ 'https://myhost'
615
+ end
616
+
617
+ it 'extracts the host' do
618
+ expect(hosts[0][:host]).to eq('myhost')
619
+ end
620
+
621
+ it 'extracts the protocol' do
622
+ expect(hosts[0][:protocol]).to eq('https')
623
+ end
624
+
625
+ it 'defaults to port 443' do
626
+ expect(hosts[0][:port]).to be(443)
627
+ end
628
+ end
629
+
630
+ context 'when there is a port specified \'https://myhost:7101\'' do
631
+
632
+ let(:host) do
633
+ 'https://myhost:7101'
634
+ end
635
+
636
+ it 'extracts the host' do
637
+ expect(hosts[0][:host]).to eq('myhost')
638
+ end
639
+
640
+ it 'extracts the protocol' do
641
+ expect(hosts[0][:protocol]).to eq('https')
642
+ end
643
+
644
+ it 'extracts the port' do
645
+ expect(hosts[0][:port]).to be(7101)
646
+ end
647
+
648
+ context 'when there is a path specified \'https://myhost:7101/api\'' do
649
+
650
+ let(:host) do
651
+ 'https://myhost:7101/api'
652
+ end
653
+
654
+ it 'extracts the host' do
655
+ expect(hosts[0][:host]).to eq('myhost')
656
+ end
657
+
658
+ it 'extracts the protocol' do
659
+ expect(hosts[0][:protocol]).to eq('https')
660
+ end
661
+
662
+ it 'extracts the port' do
663
+ expect(hosts[0][:port]).to be(7101)
664
+ end
665
+
666
+ it 'extracts the path' do
667
+ expect(hosts[0][:path]).to eq('/api')
668
+ end
669
+ end
670
+ end
671
+
672
+ context 'when IPv6 format is used' do
673
+
674
+ around do |example|
675
+ original_setting = Faraday.ignore_env_proxy
676
+ Faraday.ignore_env_proxy = true
677
+ example.run
678
+ Faraday.ignore_env_proxy = original_setting
679
+ end
680
+
681
+ let(:host) do
682
+ 'https://[2090:db8:85a3:9811::1f]:8080'
683
+ end
684
+
685
+ it 'extracts the host' do
686
+ expect(hosts[0][:host]).to eq('[2090:db8:85a3:9811::1f]')
687
+ end
688
+
689
+ it 'extracts the protocol' do
690
+ expect(hosts[0][:protocol]).to eq('https')
691
+ end
692
+
693
+ it 'extracts the port' do
694
+ expect(hosts[0][:port]).to be(8080)
695
+ end
696
+
697
+ it 'creates the correct full url' do
698
+ expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://[2090:db8:85a3:9811::1f]:8080')
699
+ end
700
+ end
484
701
  end
485
702
  end
486
703
 
487
- context 'when there is a trailing slash with a path' do
704
+ context 'when no protocol is specified \'myhost\'' do
488
705
 
489
706
  let(:host) do
490
- 'http://myhost/foo/bar/'
707
+ 'myhost'
491
708
  end
492
709
 
493
- it 'extracts the host' do
710
+ it 'defaults to http' do
494
711
  expect(hosts[0][:host]).to eq('myhost')
495
- expect(hosts[0][:scheme]).to eq('http')
496
- expect(hosts[0][:path]).to eq('/foo/bar')
712
+ expect(hosts[0][:protocol]).to eq('http')
713
+ end
714
+
715
+ it 'uses port 9200' do
716
+ expect(hosts[0][:port]).to be(9200)
497
717
  end
498
718
  end
499
719
  end
500
720
 
501
- context 'when the hosts are a Hash' do
721
+ context 'when the host is a Hash' do
502
722
 
503
723
  let(:host) do
504
724
  { :host => 'myhost', :scheme => 'https' }
@@ -506,7 +726,13 @@ describe Elasticsearch::Transport::Client do
506
726
 
507
727
  it 'extracts the host' do
508
728
  expect(hosts[0][:host]).to eq('myhost')
509
- expect(hosts[0][:scheme]).to eq('https')
729
+ end
730
+
731
+ it 'extracts the protocol' do
732
+ expect(hosts[0][:protocol]).to eq('https')
733
+ end
734
+
735
+ it 'extracts the port' do
510
736
  expect(hosts[0][:port]).to be(9200)
511
737
  end
512
738
 
@@ -565,7 +791,13 @@ describe Elasticsearch::Transport::Client do
565
791
 
566
792
  it 'extracts the host' do
567
793
  expect(hosts[0][:host]).to eq('myhost')
794
+ end
795
+
796
+ it 'extracts the protocol' do
568
797
  expect(hosts[0][:scheme]).to eq('https')
798
+ end
799
+
800
+ it 'converts the port to an integer' do
569
801
  expect(hosts[0][:port]).to be(443)
570
802
  end
571
803
  end
@@ -578,7 +810,13 @@ describe Elasticsearch::Transport::Client do
578
810
 
579
811
  it 'extracts the host' do
580
812
  expect(hosts[0][:host]).to eq('myhost')
813
+ end
814
+
815
+ it 'extracts the protocol' do
581
816
  expect(hosts[0][:scheme]).to eq('https')
817
+ end
818
+
819
+ it 'extracts port as an integer' do
582
820
  expect(hosts[0][:port]).to be(443)
583
821
  end
584
822
  end
@@ -592,7 +830,13 @@ describe Elasticsearch::Transport::Client do
592
830
 
593
831
  it 'extracts the host' do
594
832
  expect(hosts[0][:host]).to eq('myhost')
833
+ end
834
+
835
+ it 'extracts the protocol' do
595
836
  expect(hosts[0][:scheme]).to eq('https')
837
+ end
838
+
839
+ it 'converts the port to an integer' do
596
840
  expect(hosts[0][:port]).to be(9200)
597
841
  end
598
842
 
@@ -604,7 +848,13 @@ describe Elasticsearch::Transport::Client do
604
848
 
605
849
  it 'extracts the host' do
606
850
  expect(hosts[0][:host]).to eq('myhost')
851
+ end
852
+
853
+ it 'extracts the protocol' do
607
854
  expect(hosts[0][:scheme]).to eq('https')
855
+ end
856
+
857
+ it 'converts the port to an integer' do
608
858
  expect(hosts[0][:port]).to be(443)
609
859
  end
610
860
  end
@@ -617,7 +867,13 @@ describe Elasticsearch::Transport::Client do
617
867
 
618
868
  it 'extracts the host' do
619
869
  expect(hosts[0][:host]).to eq('myhost')
870
+ end
871
+
872
+ it 'extracts the protocol' do
620
873
  expect(hosts[0][:scheme]).to eq('https')
874
+ end
875
+
876
+ it 'extracts port as an integer' do
621
877
  expect(hosts[0][:port]).to be(443)
622
878
  end
623
879
  end
@@ -633,7 +889,13 @@ describe Elasticsearch::Transport::Client do
633
889
 
634
890
  it 'extracts the host' do
635
891
  expect(hosts[0][:host]).to eq('myhost')
892
+ end
893
+
894
+ it 'extracts the protocol' do
636
895
  expect(hosts[0][:protocol]).to eq('http')
896
+ end
897
+
898
+ it 'defaults to port 9200' do
637
899
  expect(hosts[0][:port]).to be(9200)
638
900
  end
639
901
  end
@@ -646,20 +908,13 @@ describe Elasticsearch::Transport::Client do
646
908
 
647
909
  it 'extracts the host' do
648
910
  expect(hosts[0][:host]).to eq('myhost')
649
- expect(hosts[0][:protocol]).to eq('http')
650
- expect(hosts[0][:port]).to be(9200)
651
911
  end
652
- end
653
912
 
654
- context 'when there is one host with a protocol and no port' do
655
-
656
- let(:host) do
657
- ['http://myhost']
913
+ it 'extracts the protocol' do
914
+ expect(hosts[0][:scheme]).to eq('http')
658
915
  end
659
916
 
660
- it 'extracts the host' do
661
- expect(hosts[0][:host]).to eq('myhost')
662
- expect(hosts[0][:protocol]).to eq('http')
917
+ it 'defaults to port 9200' do
663
918
  expect(hosts[0][:port]).to be(9200)
664
919
  end
665
920
  end
@@ -684,7 +939,7 @@ describe Elasticsearch::Transport::Client do
684
939
  end
685
940
  end
686
941
 
687
- context 'when there is one host with a scheme, protocol and no port' do
942
+ context 'when there is one host with a protocol and no port' do
688
943
 
689
944
  let(:host) do
690
945
  ['https://myhost']
@@ -692,12 +947,18 @@ describe Elasticsearch::Transport::Client do
692
947
 
693
948
  it 'extracts the host' do
694
949
  expect(hosts[0][:host]).to eq('myhost')
695
- expect(hosts[0][:protocol]).to eq('https')
696
- expect(hosts[0][:port]).to be(9200)
950
+ end
951
+
952
+ it 'extracts the protocol' do
953
+ expect(hosts[0][:scheme]).to eq('https')
954
+ end
955
+
956
+ it 'defaults to port 443' do
957
+ expect(hosts[0][:port]).to be(443)
697
958
  end
698
959
  end
699
960
 
700
- context 'when there is one host with a scheme, protocol, path, and no port' do
961
+ context 'when there is one host with a protocol, path, and no port' do
701
962
 
702
963
  let(:host) do
703
964
  ['http://myhost/foo/bar']
@@ -705,9 +966,18 @@ describe Elasticsearch::Transport::Client do
705
966
 
706
967
  it 'extracts the host' do
707
968
  expect(hosts[0][:host]).to eq('myhost')
708
- expect(hosts[0][:protocol]).to eq('http')
969
+ end
970
+
971
+ it 'extracts the protocol' do
972
+ expect(hosts[0][:scheme]).to eq('http')
973
+ end
974
+
975
+ it 'defaults to port 9200' do
709
976
  expect(hosts[0][:port]).to be(9200)
710
- expect(hosts[0][:path]).to eq("/foo/bar")
977
+ end
978
+
979
+ it 'extracts the path' do
980
+ expect(hosts[0][:path]).to eq('/foo/bar')
711
981
  end
712
982
  end
713
983
 
@@ -717,7 +987,7 @@ describe Elasticsearch::Transport::Client do
717
987
  ['host1', 'host2']
718
988
  end
719
989
 
720
- it 'extracts the host' do
990
+ it 'extracts the hosts' do
721
991
  expect(hosts[0][:host]).to eq('host1')
722
992
  expect(hosts[0][:protocol]).to eq('http')
723
993
  expect(hosts[0][:port]).to be(9200)
@@ -733,7 +1003,7 @@ describe Elasticsearch::Transport::Client do
733
1003
  ['host1:1000', 'host2:2000']
734
1004
  end
735
1005
 
736
- it 'extracts the host' do
1006
+ it 'extracts the hosts' do
737
1007
  expect(hosts[0][:host]).to eq('host1')
738
1008
  expect(hosts[0][:protocol]).to eq('http')
739
1009
  expect(hosts[0][:port]).to be(1000)
@@ -1146,41 +1416,69 @@ describe Elasticsearch::Transport::Client do
1146
1416
  let(:client) { described_class.new(host: hosts) }
1147
1417
 
1148
1418
  it 'doesnae raise an ArgumentError' do
1149
- expect { client.search(opaque_id: 'no_error') }.not_to raise_error
1419
+ expect { client.perform_request('GET', '_search', opaque_id: 'no_error') }.not_to raise_error
1150
1420
  end
1151
1421
 
1152
1422
  it 'uses X-Opaque-Id in the header' do
1153
1423
  allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
1154
- expect { client.search(opaque_id: 'opaque_id') }.not_to raise_error
1424
+ expect { client.perform_request('GET', '_search', {}, nil, opaque_id: 'opaque_id') }.not_to raise_error
1155
1425
  expect(client).to have_received(:perform_request)
1156
- .with('GET', '_search', { opaque_id: 'opaque_id' }, nil, {})
1426
+ .with('GET', '_search', {}, nil, { opaque_id: 'opaque_id' })
1157
1427
  end
1158
1428
  end
1159
1429
  end
1160
1430
 
1431
+ context 'when using the API Compatibility Header' do
1432
+ it 'sets the API compatibility headers' do
1433
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'true'
1434
+ client = described_class.new(host: hosts)
1435
+ headers = client.transport.connections.first.connection.headers
1436
+
1437
+ expect(headers['Content-Type']).to eq('application/vnd.elasticsearch+json; compatible-with=7')
1438
+ expect(headers['Accept']).to eq('application/vnd.elasticsearch+json; compatible-with=7')
1439
+
1440
+ ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
1441
+ end
1442
+
1443
+ it 'does not use API compatibility headers' do
1444
+ val = ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
1445
+ client = described_class.new(host: hosts)
1446
+ expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
1447
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = val
1448
+ end
1449
+
1450
+ it 'does not use API compatibility headers when it is set to unsupported values' do
1451
+ val = ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
1452
+
1453
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'test'
1454
+ client = described_class.new(host: hosts)
1455
+ expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
1456
+
1457
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'false'
1458
+ client = described_class.new(host: hosts)
1459
+ expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
1460
+
1461
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = '3'
1462
+ client = described_class.new(host: hosts)
1463
+ expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
1464
+ ENV['ELASTIC_CLIENT_APIVERSIONING'] = val
1465
+ end
1466
+ end
1467
+
1161
1468
  context 'when Elasticsearch response includes a warning header' do
1469
+ let(:logger) { double('logger', warn: '', warn?: '', info?: '', info: '', debug?: '', debug: '') }
1162
1470
  let(:client) do
1163
- Elasticsearch::Transport::Client.new(hosts: hosts)
1471
+ Elasticsearch::Transport::Client.new(hosts: hosts, logger: logger)
1164
1472
  end
1165
1473
 
1166
1474
  let(:warning) { 'Elasticsearch warning: "deprecation warning"' }
1167
1475
 
1168
1476
  it 'prints a warning' do
1169
- allow_any_instance_of(Elasticsearch::Transport::Transport::Response).to receive(:headers) do
1170
- { 'warning' => warning }
1171
- end
1172
-
1173
- begin
1174
- stderr = $stderr
1175
- fake_stderr = StringIO.new
1176
- $stderr = fake_stderr
1177
-
1178
- client.perform_request('GET', '/')
1179
- fake_stderr.rewind
1180
- expect(fake_stderr.string).to eq("warning: #{warning}\n")
1181
- ensure
1182
- $stderr = stderr
1477
+ expect_any_instance_of(Faraday::Connection).to receive(:run_request) do
1478
+ Elasticsearch::Transport::Transport::Response.new(200, {}, { 'warning' => warning })
1183
1479
  end
1480
+ client.perform_request('GET', '/')
1481
+ expect(logger).to have_received(:warn).with(warning)
1184
1482
  end
1185
1483
  end
1186
1484
 
@@ -1190,9 +1488,30 @@ describe Elasticsearch::Transport::Client do
1190
1488
 
1191
1489
  it 'performs the request with the header' do
1192
1490
  allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
1193
- expect { client.search(headers: headers) }.not_to raise_error
1491
+ expect { client.perform_request('GET', '_search', {}, nil, headers) }.not_to raise_error
1194
1492
  expect(client).to have_received(:perform_request)
1195
- .with('GET', '_search', {}, nil, headers)
1493
+ .with('GET', '_search', {}, nil, headers)
1494
+ end
1495
+ end
1496
+
1497
+ context 'when a header is set on an endpoint request and on initialization' do
1498
+ let!(:client) do
1499
+ described_class.new(
1500
+ host: hosts,
1501
+ transport_options: { headers: instance_headers }
1502
+ )
1503
+ end
1504
+ let(:instance_headers) { { set_in_instantiation: 'header value' } }
1505
+ let(:param_headers) { {'user-agent' => 'My Ruby Tests', 'set-on-method-call' => 'header value'} }
1506
+
1507
+ it 'performs the request with the header' do
1508
+ expected_headers = client.transport.connections.connections.first.connection.headers.merge(param_headers)
1509
+
1510
+ expect_any_instance_of(Faraday::Connection)
1511
+ .to receive(:run_request)
1512
+ .with(:get, "http://#{hosts[0]}/_search", nil, expected_headers) { OpenStruct.new(body: '')}
1513
+
1514
+ client.perform_request('GET', '_search', {}, nil, param_headers)
1196
1515
  end
1197
1516
  end
1198
1517
  end
@@ -1229,7 +1548,6 @@ describe Elasticsearch::Transport::Client do
1229
1548
  end
1230
1549
 
1231
1550
  context 'when a request is made' do
1232
-
1233
1551
  let!(:response) do
1234
1552
  client.perform_request('GET', '_cluster/health')
1235
1553
  end
@@ -1240,9 +1558,7 @@ describe Elasticsearch::Transport::Client do
1240
1558
  end
1241
1559
 
1242
1560
  describe '#initialize' do
1243
-
1244
1561
  context 'when options are specified' do
1245
-
1246
1562
  let(:transport_options) do
1247
1563
  { headers: { accept: 'application/yaml', content_type: 'application/yaml' } }
1248
1564
  end
@@ -1258,9 +1574,8 @@ describe Elasticsearch::Transport::Client do
1258
1574
  end
1259
1575
 
1260
1576
  context 'when a block is provided' do
1261
-
1262
1577
  let(:client) do
1263
- Elasticsearch::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
1578
+ described_class.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
1264
1579
  client.headers['Accept'] = 'application/yaml'
1265
1580
  end
1266
1581
  end
@@ -1275,8 +1590,10 @@ describe Elasticsearch::Transport::Client do
1275
1590
  end
1276
1591
 
1277
1592
  context 'when the Faraday adapter is set in the block' do
1593
+ require 'faraday/net_http_persistent' if is_faraday_v2?
1594
+
1278
1595
  let(:client) do
1279
- Elasticsearch::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
1596
+ described_class.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
1280
1597
  client.adapter(:net_http_persistent)
1281
1598
  end
1282
1599
  end
@@ -1344,6 +1661,29 @@ describe Elasticsearch::Transport::Client do
1344
1661
  end
1345
1662
  end
1346
1663
 
1664
+ context 'when retry_on_failure is true and delay_on_retry is specified' do
1665
+ context 'when a node is unreachable' do
1666
+ let(:hosts) do
1667
+ [ELASTICSEARCH_HOSTS.first, "foobar1", "foobar2"]
1668
+ end
1669
+
1670
+ let(:options) do
1671
+ { retry_on_failure: true, delay_on_retry: 3000 }
1672
+ end
1673
+
1674
+ let(:responses) do
1675
+ 5.times.collect do
1676
+ client.perform_request('GET', '_nodes/_local')
1677
+ end
1678
+ end
1679
+
1680
+ it 'retries on failure' do
1681
+ allow_any_instance_of(Object).to receive(:sleep).with(3000 / 1000)
1682
+ expect(responses.all? { true }).to be(true)
1683
+ end
1684
+ end
1685
+ end
1686
+
1347
1687
  context 'when reload_on_failure is true' do
1348
1688
 
1349
1689
  let(:hosts) do
@@ -1403,7 +1743,7 @@ describe Elasticsearch::Transport::Client do
1403
1743
  end
1404
1744
 
1405
1745
  it 'sets the Accept-Encoding header' do
1406
- expect(client.transport.connections[0].connection.headers['Accept-Encoding'])
1746
+ expect(client.transport.connections[0].connection.headers['Accept-Encoding']).to eq 'gzip'
1407
1747
  end
1408
1748
 
1409
1749
  it 'preserves the other headers' do
@@ -1412,9 +1752,10 @@ describe Elasticsearch::Transport::Client do
1412
1752
  end
1413
1753
 
1414
1754
  context 'when using the HTTPClient adapter' do
1755
+ require 'faraday/httpclient'
1415
1756
 
1416
1757
  let(:client) do
1417
- described_class.new(hosts: ELASTICSEARCH_HOSTS, compression: true, adapter: :httpclient)
1758
+ described_class.new(hosts: ELASTICSEARCH_HOSTS, compression: true, adapter: :httpclient, enable_meta_header: false)
1418
1759
  end
1419
1760
 
1420
1761
  it 'compresses the request and decompresses the response' do
@@ -1422,7 +1763,7 @@ describe Elasticsearch::Transport::Client do
1422
1763
  end
1423
1764
 
1424
1765
  it 'sets the Accept-Encoding header' do
1425
- expect(client.transport.connections[0].connection.headers['Accept-Encoding'])
1766
+ expect(client.transport.connections[0].connection.headers['Accept-Encoding']).to eq 'gzip'
1426
1767
  end
1427
1768
 
1428
1769
  it 'preserves the other headers' do
@@ -1441,7 +1782,7 @@ describe Elasticsearch::Transport::Client do
1441
1782
  end
1442
1783
 
1443
1784
  it 'sets the Accept-Encoding header' do
1444
- expect(client.transport.connections[0].connection.headers['Accept-Encoding'])
1785
+ expect(client.transport.connections[0].connection.headers['Accept-Encoding']).to eq 'gzip'
1445
1786
  end
1446
1787
 
1447
1788
  it 'preserves the other headers' do
@@ -1460,7 +1801,7 @@ describe Elasticsearch::Transport::Client do
1460
1801
  end
1461
1802
 
1462
1803
  it 'sets the Accept-Encoding header' do
1463
- expect(client.transport.connections[0].connection.headers['Accept-Encoding'])
1804
+ expect(client.transport.connections[0].connection.headers['Accept-Encoding']).to eq 'gzip'
1464
1805
  end
1465
1806
 
1466
1807
  it 'preserves the other headers' do
@@ -1479,22 +1820,23 @@ describe Elasticsearch::Transport::Client do
1479
1820
  end
1480
1821
 
1481
1822
  it 'sets the Accept-Encoding header' do
1482
- expect(client.transport.connections[0].connection.headers['Accept-Encoding'])
1823
+ expect(client.transport.connections[0].connection.headers['Accept-Encoding']).to eq 'gzip'
1483
1824
  end
1484
1825
 
1485
1826
  it 'preserves the other headers' do
1486
1827
  expect(client.transport.connections[0].connection.headers['User-Agent'])
1487
1828
  end
1488
- end
1829
+ end unless jruby?
1489
1830
  end
1490
1831
  end
1491
1832
 
1492
1833
  context 'when using Curb as the transport', unless: jruby? do
1493
-
1494
1834
  let(:client) do
1495
- described_class.new(hosts: ELASTICSEARCH_HOSTS,
1496
- compression: true,
1497
- transport_class: Elasticsearch::Transport::Transport::HTTP::Curb)
1835
+ described_class.new(
1836
+ hosts: ELASTICSEARCH_HOSTS,
1837
+ compression: true,
1838
+ transport_class: Elasticsearch::Transport::Transport::HTTP::Curb
1839
+ )
1498
1840
  end
1499
1841
 
1500
1842
  it 'compresses the request and decompresses the response' do
@@ -1502,7 +1844,7 @@ describe Elasticsearch::Transport::Client do
1502
1844
  end
1503
1845
 
1504
1846
  it 'sets the Accept-Encoding header' do
1505
- expect(client.transport.connections[0].connection.headers['Accept-Encoding'])
1847
+ expect(client.transport.connections[0].connection.headers['Accept-Encoding']).to eq 'gzip'
1506
1848
  end
1507
1849
 
1508
1850
  it 'preserves the other headers' do
@@ -1511,7 +1853,6 @@ describe Elasticsearch::Transport::Client do
1511
1853
  end
1512
1854
 
1513
1855
  context 'when using Manticore as the transport', if: jruby? do
1514
-
1515
1856
  let(:client) do
1516
1857
  described_class.new(hosts: ELASTICSEARCH_HOSTS,
1517
1858
  compression: true,
@@ -1525,9 +1866,7 @@ describe Elasticsearch::Transport::Client do
1525
1866
  end
1526
1867
 
1527
1868
  describe '#perform_request' do
1528
-
1529
1869
  context 'when a request is made' do
1530
-
1531
1870
  before do
1532
1871
  client.perform_request('DELETE', '_all')
1533
1872
  client.perform_request('DELETE', 'myindex') rescue
@@ -1550,7 +1889,6 @@ describe Elasticsearch::Transport::Client do
1550
1889
  end
1551
1890
 
1552
1891
  context 'when an invalid url is specified' do
1553
-
1554
1892
  it 'raises an exception' do
1555
1893
  expect {
1556
1894
  client.perform_request('GET', 'myindex/mydoc/1?routing=FOOBARBAZ')
@@ -1559,7 +1897,6 @@ describe Elasticsearch::Transport::Client do
1559
1897
  end
1560
1898
 
1561
1899
  context 'when the \'ignore\' parameter is specified' do
1562
-
1563
1900
  let(:response) do
1564
1901
  client.perform_request('PUT', '_foobar', ignore: 400)
1565
1902
  end
@@ -1575,7 +1912,6 @@ describe Elasticsearch::Transport::Client do
1575
1912
  end
1576
1913
 
1577
1914
  context 'when request headers are specified' do
1578
-
1579
1915
  let(:response) do
1580
1916
  client.perform_request('GET', '/', {}, nil, { 'Content-Type' => 'application/yaml' })
1581
1917
  end
@@ -1586,9 +1922,7 @@ describe Elasticsearch::Transport::Client do
1586
1922
  end
1587
1923
 
1588
1924
  describe 'selector' do
1589
-
1590
1925
  context 'when the round-robin selector is used' do
1591
-
1592
1926
  let(:nodes) do
1593
1927
  3.times.collect do
1594
1928
  client.perform_request('GET', '_nodes/_local').body['nodes'].to_a[0][1]['name']
@@ -1596,7 +1930,7 @@ describe Elasticsearch::Transport::Client do
1596
1930
  end
1597
1931
 
1598
1932
  let(:node_names) do
1599
- client.nodes.stats['nodes'].collect do |name, stats|
1933
+ client.perform_request('GET', '_nodes/stats').body('nodes').collect do |name, stats|
1600
1934
  stats['name']
1601
1935
  end
1602
1936
  end
@@ -1615,7 +1949,6 @@ describe Elasticsearch::Transport::Client do
1615
1949
  end
1616
1950
 
1617
1951
  context 'when patron is used as an adapter', unless: jruby? do
1618
-
1619
1952
  before do
1620
1953
  require 'patron'
1621
1954
  end
@@ -1670,4 +2003,76 @@ describe Elasticsearch::Transport::Client do
1670
2003
  end
1671
2004
  end
1672
2005
  end
2006
+
2007
+ context 'CA Fingerprinting' do
2008
+ context 'when setting a ca_fingerprint' do
2009
+ after do
2010
+ File.delete('./certificate.crt')
2011
+ File.delete('./certificate.key')
2012
+ end
2013
+
2014
+ let(:certificate) do
2015
+ system(
2016
+ 'openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj "/C=BE/O=Test/CN=Test"' \
2017
+ ' -keyout certificate.key -out certificate.crt',
2018
+ err: File::NULL
2019
+ )
2020
+ OpenSSL::X509::Certificate.new File.read('./certificate.crt')
2021
+ end
2022
+
2023
+ let(:client) do
2024
+ Elasticsearch::Transport::Client.new(
2025
+ host: 'https://elastic:changeme@localhost:9200',
2026
+ ca_fingerprint: OpenSSL::Digest::SHA256.hexdigest(certificate.to_der)
2027
+ )
2028
+ end
2029
+
2030
+ it 'validates CA fingerprints on perform request' do
2031
+ expect(client.transport.connections.connections.map(&:verified).uniq).to eq [false]
2032
+ allow(client.transport).to receive(:perform_request) { 'Hello' }
2033
+
2034
+ server = double('server').as_null_object
2035
+ allow(TCPSocket).to receive(:new) { server }
2036
+ socket = double('socket')
2037
+ allow(OpenSSL::SSL::SSLSocket).to receive(:new) { socket }
2038
+ allow(socket).to receive(:connect) { nil }
2039
+ allow(socket).to receive(:peer_cert_chain) { [certificate] }
2040
+
2041
+ response = client.perform_request('GET', '/')
2042
+ expect(client.transport.connections.connections.map(&:verified).uniq).to eq [true]
2043
+ expect(response).to eq 'Hello'
2044
+ end
2045
+ end
2046
+
2047
+ context 'when using an http host' do
2048
+ let(:client) do
2049
+ Elasticsearch::Transport::Client.new(
2050
+ host: 'http://elastic:changeme@localhost:9200',
2051
+ ca_fingerprint: 'test'
2052
+ )
2053
+ end
2054
+
2055
+ it 'raises an error' do
2056
+ expect do
2057
+ client.perform_request('GET', '/')
2058
+ end.to raise_exception(Elasticsearch::Transport::Transport::Error)
2059
+ end
2060
+ end
2061
+
2062
+ context 'when not setting a ca_fingerprint' do
2063
+ let(:client) do
2064
+ Elasticsearch::Transport::Client.new(
2065
+ host: 'http://elastic:changeme@localhost:9200'
2066
+ )
2067
+ end
2068
+
2069
+ it 'has unvalidated connections' do
2070
+ allow(client).to receive(:validate_ca_fingerprints) { nil }
2071
+ allow(client.transport).to receive(:perform_request) { nil }
2072
+
2073
+ client.perform_request('GET', '/')
2074
+ expect(client).to_not have_received(:validate_ca_fingerprints)
2075
+ end
2076
+ end
2077
+ end
1673
2078
  end