elasticsearch 8.18.0 → 9.0.0

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.
@@ -1,148 +0,0 @@
1
- # Licensed to Elasticsearch B.V. under one or more contributor
2
- # license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright
4
- # ownership. Elasticsearch B.V. licenses this file to you under
5
- # the Apache License, Version 2.0 (the "License"); you may
6
- # not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing,
12
- # software distributed under the License is distributed on an
13
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- # KIND, either express or implied. See the License for the
15
- # specific language governing permissions and limitations
16
- # under the License.
17
-
18
- require 'spec_helper'
19
- require 'webmock/rspec'
20
-
21
- describe 'Elasticsearch: Validation' do
22
- let(:host) { 'http://localhost:9200' }
23
- let(:count_request_stub) do
24
- stub_request(:get, "#{host}/_count")
25
- .to_return(status: status, body: nil, headers: headers)
26
- end
27
- let(:status) { 200 }
28
- let(:body) { nil }
29
- let(:headers) { {} }
30
- let(:client) { Elasticsearch::Client.new }
31
-
32
- context 'When Elasticsearch replies with status 401' do
33
- let(:status) { 401 }
34
-
35
- it 'Verifies the request but shows a warning' do
36
- stderr = $stderr
37
- fake_stderr = StringIO.new
38
- $stderr = fake_stderr
39
- expect(client.instance_variable_get('@verified')).to be false
40
- count_request_stub
41
- expect do
42
- client.count
43
- end.to raise_error Elastic::Transport::Transport::Errors::Unauthorized
44
- expect(client.instance_variable_get('@verified')).to be true
45
-
46
- fake_stderr.rewind
47
- expect(fake_stderr.string).to eq("#{Elasticsearch::SECURITY_PRIVILEGES_VALIDATION_WARNING}\n")
48
- ensure
49
- $stderr = stderr
50
- end
51
- end
52
-
53
- context 'When Elasticsearch replies with status 403' do
54
- let(:status) { 403 }
55
-
56
- it 'Verifies the request but shows a warning' do
57
- stderr = $stderr
58
- fake_stderr = StringIO.new
59
- $stderr = fake_stderr
60
-
61
- expect(client.instance_variable_get('@verified')).to be false
62
- count_request_stub
63
- expect do
64
- client.count
65
- end.to raise_error Elastic::Transport::Transport::Errors::Forbidden
66
- expect(client.instance_variable_get('@verified')).to be true
67
-
68
- fake_stderr.rewind
69
- expect(fake_stderr.string).to eq("#{Elasticsearch::SECURITY_PRIVILEGES_VALIDATION_WARNING}\n")
70
- ensure
71
- $stderr = stderr
72
- end
73
- end
74
-
75
- context 'When Elasticsearch replies with status 413' do
76
- let(:status) { 413 }
77
-
78
- it 'Verifies the request and shows a warning' do
79
- stderr = $stderr
80
- fake_stderr = StringIO.new
81
- $stderr = fake_stderr
82
-
83
- expect(client.instance_variable_get('@verified')).to be false
84
- count_request_stub
85
- expect do
86
- client.count
87
- end.to raise_error Elastic::Transport::Transport::Errors::RequestEntityTooLarge
88
- expect(client.instance_variable_get('@verified')).to be true
89
-
90
- fake_stderr.rewind
91
- expect(fake_stderr.string.delete("\n"))
92
- .to eq(Elasticsearch::SECURITY_PRIVILEGES_VALIDATION_WARNING)
93
- ensure
94
- $stderr = stderr
95
- end
96
- end
97
-
98
- context 'When Elasticsearch replies with status 503' do
99
- let(:status) { 503 }
100
- let(:body) { {}.to_json }
101
-
102
- it 'Does not verify the request and shows a warning' do
103
- stderr = $stderr
104
- fake_stderr = StringIO.new
105
- $stderr = fake_stderr
106
-
107
- expect(client.instance_variable_get('@verified')).to be false
108
- count_request_stub
109
- expect do
110
- client.count
111
- end.to raise_error Elastic::Transport::Transport::Errors::ServiceUnavailable
112
- expect(client.instance_variable_get('@verified')).to be false
113
-
114
- fake_stderr.rewind
115
- expect(fake_stderr.string)
116
- .to eq(
117
- <<~MSG
118
- The client is unable to verify that the server is \
119
- Elasticsearch. Some functionality may not be compatible \
120
- if the server is running an unsupported product.
121
- MSG
122
- )
123
- ensure
124
- $stderr = stderr
125
- end
126
- end
127
-
128
- context 'When the header is present' do
129
- let(:headers) { { 'X-Elastic-Product' => 'Elasticsearch' } }
130
-
131
- it 'Makes requests and passes validation' do
132
- expect(client.instance_variable_get('@verified')).to be false
133
- count_request_stub
134
- client.count
135
- expect(client.instance_variable_get('@verified')).to be true
136
- end
137
- end
138
-
139
- context 'When the header is not present' do
140
- it 'Fails validation' do
141
- expect(client.instance_variable_get('@verified')).to be false
142
- stub_request(:get, "#{host}/_cluster/health")
143
- .to_return(status: status, body: nil, headers: {})
144
- expect { client.cluster.health }.to raise_error Elasticsearch::UnsupportedProductError, Elasticsearch::NOT_ELASTICSEARCH_WARNING
145
- expect(client.instance_variable_get('@verified')).to be false
146
- end
147
- end
148
- end
@@ -1,55 +0,0 @@
1
- # Licensed to Elasticsearch B.V. under one or more contributor
2
- # license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright
4
- # ownership. Elasticsearch B.V. licenses this file to you under
5
- # the Apache License, Version 2.0 (the "License"); you may
6
- # not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing,
12
- # software distributed under the License is distributed on an
13
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- # KIND, either express or implied. See the License for the
15
- # specific language governing permissions and limitations
16
- # under the License.
17
- require 'spec_helper'
18
- require 'ostruct'
19
-
20
- describe Elasticsearch::Client do
21
- context 'when a header is set on an endpoint request' do
22
- let(:client) { described_class.new }
23
- let(:headers) { { 'user-agent' => 'my ruby app' } }
24
-
25
- it 'performs the request with the header' do
26
- allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
27
- expect { client.search(headers: headers) }.not_to raise_error
28
- expect(client).to have_received(:perform_request)
29
- .with('GET', '_search', {}, nil, headers, { endpoint: 'search' })
30
- end
31
- end
32
-
33
- context 'when a header is set on an endpoint request and on initialization' do
34
- let!(:client) do
35
- described_class.new(
36
- host: 'http://localhost:9200',
37
- transport_options: { headers: instance_headers }
38
- ).tap do |client|
39
- client.instance_variable_set('@verified', true)
40
- end
41
- end
42
- let(:instance_headers) { { set_in_instantiation: 'header value' } }
43
- let(:param_headers) { { 'user-agent' => 'My Ruby Tests', 'set-on-method-call' => 'header value' } }
44
-
45
- it 'performs the request with the header' do
46
- expected_headers = client.transport.connections.connections.first.connection.headers.merge(param_headers)
47
-
48
- expect_any_instance_of(Faraday::Connection)
49
- .to receive(:run_request)
50
- .with(:get, 'http://localhost:9200/_search', nil, expected_headers) { OpenStruct.new(body: '') }
51
-
52
- client.search(headers: param_headers)
53
- end
54
- end
55
- end
@@ -1,48 +0,0 @@
1
- # Licensed to Elasticsearch B.V. under one or more contributor
2
- # license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright
4
- # ownership. Elasticsearch B.V. licenses this file to you under
5
- # the Apache License, Version 2.0 (the "License"); you may
6
- # not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing,
12
- # software distributed under the License is distributed on an
13
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- # KIND, either express or implied. See the License for the
15
- # specific language governing permissions and limitations
16
- # under the License.
17
- require 'spec_helper'
18
- require 'ostruct'
19
-
20
- describe Elasticsearch::Client do
21
- let(:transport) { client.instance_variable_get('@transport') }
22
- let(:client) { described_class.new.tap { |cl| cl.instance_variable_set('@verified', true) } }
23
-
24
- before do
25
- allow(transport).to receive(:perform_request) { OpenStruct.new(body: '') }
26
- end
27
-
28
- context 'when x-opaque-id is set' do
29
- it 'uses x-opaque-id on a request' do
30
- client.search(opaque_id: '12345')
31
- expect(transport).to have_received(:perform_request)
32
- .with('GET', '_search', {}, nil, { 'X-Opaque-Id' => '12345' }, {:endpoint=>"search"})
33
- end
34
- end
35
-
36
- context 'when an x-opaque-id prefix is set on initialization' do
37
- let(:prefix) { 'elastic_cloud' }
38
- let(:client) do
39
- described_class.new(opaque_id_prefix: prefix).tap { |cl| cl.instance_variable_set('@verified', true) }
40
- end
41
-
42
- it 'uses x-opaque-id on a request' do
43
- expect { client.search(opaque_id: '12345') }.not_to raise_error
44
- expect(transport).to have_received(:perform_request)
45
- .with('GET', '_search', {}, nil, { 'X-Opaque-Id' => 'elastic_cloud12345' }, {:endpoint=>"search"})
46
- end
47
- end
48
- end
@@ -1,69 +0,0 @@
1
- # Licensed to Elasticsearch B.V. under one or more contributor
2
- # license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright
4
- # ownership. Elasticsearch B.V. licenses this file to you under
5
- # the Apache License, Version 2.0 (the "License"); you may
6
- # not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing,
12
- # software distributed under the License is distributed on an
13
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- # KIND, either express or implied. See the License for the
15
- # specific language governing permissions and limitations
16
- # under the License.
17
- require 'spec_helper'
18
-
19
- describe Elasticsearch::Client do
20
- let(:user_agent) {
21
- "elasticsearch-ruby/#{Elasticsearch::VERSION}; elastic-transport-ruby/#{Elastic::Transport::VERSION}; RUBY_VERSION: #{RUBY_VERSION}; #{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
22
- }
23
-
24
- context 'when no user-agent is set on initialization' do
25
- let(:client) { described_class.new }
26
-
27
- it 'has the expected header' do
28
- expect(client.transport.options[:transport_options][:headers][:user_agent]).to eq user_agent
29
- end
30
- end
31
-
32
- context 'when a header is specified on initialization' do
33
- let(:client) do
34
- described_class.new(
35
- transport_options: { headers: { 'X-Test-Header' => 'Test' } }
36
- )
37
- end
38
-
39
- it 'has the expected header' do
40
- expect(client.transport.options[:transport_options][:headers][:user_agent]).to eq user_agent
41
- expect(client.transport.options[:transport_options][:headers]['X-Test-Header']).to eq 'Test'
42
- end
43
- end
44
-
45
- context 'when other transport_options are specified on initialization' do
46
- let(:client) do
47
- described_class.new(
48
- transport_options: { params: { format: 'yaml' } }
49
- )
50
- end
51
-
52
- it 'has the expected header' do
53
- expect(client.transport.options[:transport_options][:headers][:user_agent]).to eq user_agent
54
- expect(client.transport.options[:transport_options][:params][:format]).to eq 'yaml'
55
- end
56
- end
57
-
58
- context 'when :user_agent is specified on initialization' do
59
- let(:client) do
60
- described_class.new(
61
- transport_options: { headers: { user_agent: 'TestApp' } }
62
- )
63
- end
64
-
65
- it 'has the expected header' do
66
- expect(client.transport.options[:transport_options][:headers][:user_agent]).to eq 'TestApp'
67
- end
68
- end
69
- end
@@ -1,33 +0,0 @@
1
- # Licensed to Elasticsearch B.V. under one or more contributor
2
- # license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright
4
- # ownership. Elasticsearch B.V. licenses this file to you under
5
- # the Apache License, Version 2.0 (the "License"); you may
6
- # not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing,
12
- # software distributed under the License is distributed on an
13
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- # KIND, either express or implied. See the License for the
15
- # specific language governing permissions and limitations
16
- # under the License.
17
-
18
- require 'spec_helper'
19
-
20
- describe 'Elasticsearch: wrapper gem' do
21
- it 'requires all neccessary subgems' do
22
- expect(defined? Elasticsearch::Client)
23
- expect(defined? Elasticsearch::API)
24
- end
25
-
26
- it 'mixes the API into the client' do
27
- client = Elasticsearch::Client.new
28
-
29
- expect(client).to respond_to(:search)
30
- expect(client).to respond_to(:cluster)
31
- expect(client).to respond_to(:indices)
32
- end
33
- end