Skip to content

Commit c1ccb4d

Browse files
Handle security config for ES8
1 parent bb6fbe8 commit c1ccb4d

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

Rakefile

+10-8
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ def admin_client
3838

3939
if test_suite == 'security'
4040
transport_options.merge!(:ssl => { verify: false,
41-
ca_path: CERT_DIR })
41+
ca_path: defined?(CERT_DIR) ? CERT_DIR : nil
42+
}.compact)
4243

4344
password = ENV['ELASTIC_PASSWORD']
4445
user = ENV['ELASTIC_USER'] || 'elastic'
45-
url = "https://#{user}:#{password}@#{host}:#{port}"
46+
url = "https://#{user}:#{password}@#{host || 'localhost'}:#{port || 9200}"
4647
else
4748
url = "http://#{host || 'localhost'}:#{port || 9200}"
4849
end
50+
ENV['ELASTICSEARCH_URL'] ||= url
4951
Elasticsearch::Client.new(host: url, transport_options: transport_options)
5052
end
5153
end
@@ -140,7 +142,7 @@ namespace :test do
140142
end
141143

142144
desc "Run all tests in all subprojects"
143-
task all: :wait_for_green do
145+
task all: :wait_for_green_or_yellow do
144146
subprojects.each do |project|
145147
puts '-'*80
146148
sh "cd #{project} && " +
@@ -151,20 +153,20 @@ namespace :test do
151153
end
152154
end
153155

154-
desc "Wait for elasticsearch cluster to be in green state"
155-
task :wait_for_green do
156+
desc "Wait for elasticsearch cluster to be in green or yellow state"
157+
task :wait_for_green_or_yellow do
156158
require 'elasticsearch'
157159

158160
ready = nil
159161
5.times do |i|
160162
begin
161-
puts "Attempting to wait for green status: #{i + 1}"
162-
if admin_client.cluster.health(wait_for_status: 'green', timeout: '50s')
163+
puts "Attempting to wait for green or yellow status: #{i + 1}"
164+
if admin_client.cluster.health(wait_for_status: 'yellow', timeout: '50s')
163165
ready = true
164166
break
165167
end
166168
rescue Elastic::Transport::Transport::Errors::RequestTimeout => ex
167-
puts "Couldn't confirm green status.\n#{ex.inspect}."
169+
puts "Couldn't confirm green or yellow status.\n#{ex.inspect}."
168170
rescue Faraday::ConnectionFailed => ex
169171
puts "Couldn't connect to Elasticsearch.\n#{ex.inspect}."
170172
sleep(30)

elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ class ::DummyIndexingModelForRecreate
591591

592592
context 'when the index is not found' do
593593
let(:logger) { nil }
594-
let(:client) { Elasticsearch::Client.new(logger: logger) }
594+
let(:client) { Elasticsearch::Client.new(logger: logger, transport_options: { ssl: { verify: false } }) }
595595

596596
before do
597597
expect(DummyIndexingModelForRecreate).to receive(:client).at_most(3).times.and_return(client)

elasticsearch-model/spec/spec_helper.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
4646
Elasticsearch::Model.client = Elasticsearch::Client.new(
4747
host: ELASTICSEARCH_URL,
48-
tracer: (ENV['QUIET'] ? nil : tracer)
48+
tracer: (ENV['QUIET'] ? nil : tracer),
49+
transport_options: { :ssl => { verify: false } }
4950
)
5051
puts "Elasticsearch Version: #{Elasticsearch::Model.client.info['version']}"
5152

elasticsearch-persistence/spec/spec_helper.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
#
3737
# @since 6.0.0
3838
DEFAULT_CLIENT = Elasticsearch::Client.new(host: ELASTICSEARCH_URL,
39-
tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR)))
39+
tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR)),
40+
transport_options: { :ssl => { verify: false } })
4041

4142
class MyTestRepository
4243
include Elasticsearch::Persistence::Repository

elasticsearch-rails/spec/spec_helper.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
tracer = ::Logger.new(STDERR)
3737
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
3838
Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL,
39-
tracer: (ENV['QUIET'] ? nil : tracer)
39+
tracer: (ENV['QUIET'] ? nil : tracer),
40+
transport_options: { :ssl => { verify: false } }
4041
puts "Elasticsearch Version: #{Elasticsearch::Model.client.info['version']}"
4142

4243
unless ActiveRecord::Base.connected?

0 commit comments

Comments
 (0)