Skip to content

Commit 2b445a2

Browse files
committed
Integration tests to run with credentials anebled and SSL configs.
1 parent 8bf045f commit 2b445a2

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

spec/filters/integration/elasticsearch_esql_spec.rb

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
describe LogStash::Filters::Elasticsearch, integration: true do
88

9+
ELASTIC_SECURITY_ENABLED = ENV['ELASTIC_SECURITY_ENABLED'].eql? 'true'
910
SECURE_INTEGRATION = ENV['SECURE_INTEGRATION'].eql? 'true'
1011
ES_HOSTS = ["http#{SECURE_INTEGRATION ? 's' : nil}://#{ESHelper.get_host_port}"]
12+
CA_PATH = File.expand_path('../fixtures/test_certs/ca.crt', File.dirname(__FILE__))
1113

1214
let(:plugin) { described_class.new(config) }
1315
let(:es_index) { "es-filter-plugin-esql-integration-#{rand(1000)}" }
@@ -21,25 +23,49 @@
2123
{ "message" => "odd test message", "type" => "t" }
2224
]
2325
end
24-
let(:config) do
26+
27+
let(:base_config) do
2528
{
29+
"query_type" => "esql",
2630
"hosts" => ES_HOSTS,
27-
"query_type" => "esql"
31+
"ssl_enabled" => SECURE_INTEGRATION
2832
}
2933
end
34+
35+
let(:credentials) do
36+
if SECURE_INTEGRATION
37+
{ 'user' => 'tests', 'password' => 'Tests123' }
38+
else
39+
{ 'user' => 'elastic', 'password' => ENV['ELASTIC_PASSWORD'] }
40+
end
41+
end
42+
43+
let(:config) do
44+
config = ELASTIC_SECURITY_ENABLED ? base_config.merge(credentials) : base_config
45+
config = { 'ssl_certificate_authorities' => CA_PATH }.merge(config) if SECURE_INTEGRATION
46+
config
47+
end
48+
3049
let(:event) { LogStash::Event.new({}) }
31-
let(:es_client) do
32-
Elasticsearch::Client.new(hosts: ES_HOSTS)
50+
51+
def es_client
52+
@es_client ||= begin
53+
user = SECURE_INTEGRATION ? 'tests' : 'elastic'
54+
password = SECURE_INTEGRATION ? 'Tests123' : ENV['ELASTIC_PASSWORD']
55+
56+
es_client_config = { hosts: ES_HOSTS }
57+
es_client_config = es_client_config.merge({ user: user, password: password }) if ELASTIC_SECURITY_ENABLED || SECURE_INTEGRATION
58+
es_client_config = es_client_config.merge({ transport_options: { ssl: { ca_path: CA_PATH, verify: false }}}) if SECURE_INTEGRATION
59+
60+
Elasticsearch::Client.new(es_client_config)
61+
end
3362
end
3463

3564
before(:all) do
3665
is_ls_with_esql_supported_client = Gem::Version.create(LOGSTASH_VERSION) >= Gem::Version.create(LogStash::Filters::Elasticsearch::LS_ESQL_SUPPORT_VERSION)
66+
# Skip tests if an ES version doesn't support ES|QL
3767
skip "LS version does not have ES client which supports ES|QL" unless is_ls_with_esql_supported_client
3868

39-
# Skip tests if an ES version doesn't support ES||QL
40-
es_client = SECURE_INTEGRATION ?
41-
Elasticsearch::Client.new(hosts: ES_HOSTS, user: 'tests', password: 'Tests123') :
42-
Elasticsearch::Client.new(hosts: ES_HOSTS)
4369
es_version_info = es_client.info["version"]
4470
es_gem_version = Gem::Version.create(es_version_info["number"])
4571
skip "ES version does not support ES|QL" if es_gem_version.nil? || es_gem_version < Gem::Version.create(LogStash::Filters::Elasticsearch::ES_ESQL_SUPPORT_VERSION)

0 commit comments

Comments
 (0)