|
6 | 6 |
|
7 | 7 | describe LogStash::Filters::Elasticsearch, integration: true do |
8 | 8 |
|
| 9 | + ELASTIC_SECURITY_ENABLED = ENV['ELASTIC_SECURITY_ENABLED'].eql? 'true' |
9 | 10 | SECURE_INTEGRATION = ENV['SECURE_INTEGRATION'].eql? 'true' |
10 | 11 | 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__)) |
11 | 13 |
|
12 | 14 | let(:plugin) { described_class.new(config) } |
13 | 15 | let(:es_index) { "es-filter-plugin-esql-integration-#{rand(1000)}" } |
|
21 | 23 | { "message" => "odd test message", "type" => "t" } |
22 | 24 | ] |
23 | 25 | end |
24 | | - let(:config) do |
| 26 | + |
| 27 | + let(:base_config) do |
25 | 28 | { |
| 29 | + "query_type" => "esql", |
26 | 30 | "hosts" => ES_HOSTS, |
27 | | - "query_type" => "esql" |
| 31 | + "ssl_enabled" => SECURE_INTEGRATION |
28 | 32 | } |
29 | 33 | 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 | + |
30 | 49 | 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 |
33 | 62 | end |
34 | 63 |
|
35 | 64 | before(:all) do |
36 | 65 | 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 |
37 | 67 | skip "LS version does not have ES client which supports ES|QL" unless is_ls_with_esql_supported_client |
38 | 68 |
|
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) |
43 | 69 | es_version_info = es_client.info["version"] |
44 | 70 | es_gem_version = Gem::Version.create(es_version_info["number"]) |
45 | 71 | 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