elasticsearch 7.17.11 → 8.0.0.pre1
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.
- checksums.yaml +4 -4
- data/Gemfile +4 -10
- data/README.md +70 -31
- data/bin/elastic_ruby_console +2 -5
- data/elasticsearch.gemspec +14 -14
- data/lib/elasticsearch/version.rb +1 -1
- data/lib/elasticsearch.rb +97 -33
- data/spec/integration/client_integration_spec.rb +10 -4
- data/spec/spec_helper.rb +8 -3
- data/spec/unit/api_key_spec.rb +101 -0
- data/spec/unit/cloud_credentials_spec.rb +167 -0
- data/spec/unit/custom_transport_implementation_spec.rb +43 -0
- data/spec/unit/elasticsearch_product_validation_spec.rb +17 -233
- data/spec/unit/headers_spec.rb +55 -0
- data/spec/unit/opaque_id_spec.rb +48 -0
- data/spec/unit/wrapper_gem_spec.rb +4 -10
- metadata +31 -25
- data/spec/integration/characters_escaping_spec.rb +0 -97
- data/spec/integration/validation_integration_spec.rb +0 -30
- /data/{LICENSE → LICENSE.txt} +0 -0
@@ -0,0 +1,167 @@
|
|
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::Client do
|
21
|
+
context 'when cloud credentials are provided' do
|
22
|
+
let(:client) do
|
23
|
+
described_class.new(
|
24
|
+
cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
|
25
|
+
user: 'elastic',
|
26
|
+
password: 'changeme'
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:hosts) do
|
31
|
+
client.transport.hosts
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'extracts the cloud credentials' do
|
35
|
+
expect(hosts[0][:host]).to eq('abcd.localhost')
|
36
|
+
expect(hosts[0][:protocol]).to eq('https')
|
37
|
+
expect(hosts[0][:user]).to eq('elastic')
|
38
|
+
expect(hosts[0][:password]).to eq('changeme')
|
39
|
+
expect(hosts[0][:port]).to eq(443)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'creates the correct full url' do
|
43
|
+
expect(
|
44
|
+
client.transport.__full_url(client.transport.hosts[0])
|
45
|
+
).to eq('https://elastic:changeme@abcd.localhost:443')
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when a port is specified' do
|
49
|
+
let(:client) do
|
50
|
+
described_class.new(cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elastic', password: 'changeme', port: 9250)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'sets the specified port along with the cloud credentials' do
|
54
|
+
expect(hosts[0][:host]).to eq('abcd.localhost')
|
55
|
+
expect(hosts[0][:protocol]).to eq('https')
|
56
|
+
expect(hosts[0][:user]).to eq('elastic')
|
57
|
+
expect(hosts[0][:password]).to eq('changeme')
|
58
|
+
expect(hosts[0][:port]).to eq(9250)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'creates the correct full url' do
|
62
|
+
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9250')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when the cluster has alternate names' do
|
67
|
+
let(:client) do
|
68
|
+
described_class.new(
|
69
|
+
cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==',
|
70
|
+
user: 'elasticfantastic',
|
71
|
+
password: 'tobechanged'
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:hosts) do
|
76
|
+
client.transport.hosts
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'extracts the cloud credentials' do
|
80
|
+
expect(hosts[0][:host]).to eq('abcd.localhost')
|
81
|
+
expect(hosts[0][:protocol]).to eq('https')
|
82
|
+
expect(hosts[0][:user]).to eq('elasticfantastic')
|
83
|
+
expect(hosts[0][:password]).to eq('tobechanged')
|
84
|
+
expect(hosts[0][:port]).to eq(443)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'creates the correct full url' do
|
88
|
+
expect(
|
89
|
+
client.transport.__full_url(client.transport.hosts[0])
|
90
|
+
).to eq('https://elasticfantastic:tobechanged@abcd.localhost:443')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when decoded cloud id has a trailing dollar sign' do
|
95
|
+
let(:client) do
|
96
|
+
described_class.new(
|
97
|
+
cloud_id: 'a_cluster:bG9jYWxob3N0JGFiY2Qk',
|
98
|
+
user: 'elasticfantastic',
|
99
|
+
password: 'changeme'
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
let(:hosts) do
|
104
|
+
client.transport.hosts
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'extracts the cloud credentials' do
|
108
|
+
expect(hosts[0][:host]).to eq('abcd.localhost')
|
109
|
+
expect(hosts[0][:protocol]).to eq('https')
|
110
|
+
expect(hosts[0][:user]).to eq('elasticfantastic')
|
111
|
+
expect(hosts[0][:password]).to eq('changeme')
|
112
|
+
expect(hosts[0][:port]).to eq(443)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'creates the correct full url' do
|
116
|
+
expect(
|
117
|
+
client.transport.__full_url(client.transport.hosts[0])
|
118
|
+
).to eq('https://elasticfantastic:changeme@abcd.localhost:443')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'when the cloud host provides a port' do
|
123
|
+
let(:client) do
|
124
|
+
described_class.new(
|
125
|
+
cloud_id: 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk',
|
126
|
+
user: 'elastic',
|
127
|
+
password: 'changeme'
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:hosts) do
|
132
|
+
client.transport.hosts
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'creates the correct full url' do
|
136
|
+
expect(hosts[0][:host]).to eq('elastic_id.elastic_server')
|
137
|
+
expect(hosts[0][:protocol]).to eq('https')
|
138
|
+
expect(hosts[0][:user]).to eq('elastic')
|
139
|
+
expect(hosts[0][:password]).to eq('changeme')
|
140
|
+
expect(hosts[0][:port]).to eq(9243)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when the cloud host provides a port and the port is also specified' do
|
145
|
+
let(:client) do
|
146
|
+
described_class.new(
|
147
|
+
cloud_id: 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk',
|
148
|
+
user: 'elastic',
|
149
|
+
password: 'changeme',
|
150
|
+
port: 9200
|
151
|
+
)
|
152
|
+
end
|
153
|
+
|
154
|
+
let(:hosts) do
|
155
|
+
client.transport.hosts
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'creates the correct full url' do
|
159
|
+
expect(hosts[0][:host]).to eq('elastic_id.elastic_server')
|
160
|
+
expect(hosts[0][:protocol]).to eq('https')
|
161
|
+
expect(hosts[0][:user]).to eq('elastic')
|
162
|
+
expect(hosts[0][:password]).to eq('changeme')
|
163
|
+
expect(hosts[0][:port]).to eq(9243)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
context 'when using custom transport implementation' do
|
21
|
+
class MyTransport
|
22
|
+
include Elastic::Transport::Transport::Base
|
23
|
+
def initialize(args); end
|
24
|
+
end
|
25
|
+
let(:client) { Elasticsearch::Client.new(transport_class: MyTransport) }
|
26
|
+
let(:arguments) { client.instance_variable_get('@transport').instance_variable_get('@arguments') }
|
27
|
+
let(:subject) do
|
28
|
+
arguments[:transport_options][:headers]
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:meta_header) do
|
32
|
+
if jruby?
|
33
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
|
34
|
+
else
|
35
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elastic::Transport::VERSION}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'doesnae set any info about the implementation in the metaheader' do
|
40
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -25,20 +25,20 @@ describe 'Elasticsearch: Validation' do
|
|
25
25
|
.to_return(status: status, body: body, headers: headers)
|
26
26
|
end
|
27
27
|
let(:count_request_stub) do
|
28
|
-
stub_request(:
|
28
|
+
stub_request(:post, "#{host}/_count")
|
29
29
|
.to_return(status: 200, body: nil, headers: {})
|
30
30
|
end
|
31
31
|
let(:status) { 200 }
|
32
32
|
let(:body) { {}.to_json }
|
33
33
|
let(:client) { Elasticsearch::Client.new }
|
34
34
|
let(:headers) do
|
35
|
-
{ 'content-type' => 'json' }
|
35
|
+
{ 'content-type' => 'application/json' }
|
36
36
|
end
|
37
37
|
|
38
38
|
def error_requests_and_expectations(message = Elasticsearch::NOT_ELASTICSEARCH_WARNING)
|
39
39
|
expect { client.count }.to raise_error Elasticsearch::UnsupportedProductError, message
|
40
40
|
assert_requested :get, host
|
41
|
-
assert_not_requested :
|
41
|
+
assert_not_requested :post, "#{host}/_count"
|
42
42
|
expect { client.cluster.health }.to raise_error Elasticsearch::UnsupportedProductError, message
|
43
43
|
expect(client.instance_variable_get('@verified')).to be false
|
44
44
|
expect { client.cluster.health }.to raise_error Elasticsearch::UnsupportedProductError, message
|
@@ -51,7 +51,7 @@ describe 'Elasticsearch: Validation' do
|
|
51
51
|
client.count
|
52
52
|
expect(client.instance_variable_get('@verified'))
|
53
53
|
assert_requested :get, host
|
54
|
-
assert_requested :
|
54
|
+
assert_requested :post, "#{host}/_count"
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'When Elasticsearch replies with status 401' do
|
@@ -96,30 +96,9 @@ describe 'Elasticsearch: Validation' do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
context 'When Elasticsearch
|
100
|
-
let(:status) { 413 }
|
101
|
-
let(:body) { {}.to_json }
|
102
|
-
|
103
|
-
it 'Verifies the request but shows a warning' do
|
104
|
-
stderr = $stderr
|
105
|
-
fake_stderr = StringIO.new
|
106
|
-
$stderr = fake_stderr
|
107
|
-
|
108
|
-
verify_request_stub
|
109
|
-
count_request_stub
|
110
|
-
|
111
|
-
valid_requests_and_expectations
|
112
|
-
|
113
|
-
fake_stderr.rewind
|
114
|
-
expect(fake_stderr.string).to eq("#{Elasticsearch::SECURITY_PRIVILEGES_VALIDATION_WARNING}\n")
|
115
|
-
ensure
|
116
|
-
$stderr = stderr
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'When the Elasticsearch version is >= 7.14' do
|
99
|
+
context 'When the Elasticsearch version is >= 8.0.0' do
|
121
100
|
context 'With a valid Elasticsearch response' do
|
122
|
-
let(:body) { { 'version' => { 'number' => '
|
101
|
+
let(:body) { { 'version' => { 'number' => '8.0.0' } }.to_json }
|
123
102
|
let(:headers) do
|
124
103
|
{
|
125
104
|
'X-Elastic-Product' => 'Elasticsearch',
|
@@ -147,9 +126,9 @@ describe 'Elasticsearch: Validation' do
|
|
147
126
|
end
|
148
127
|
end
|
149
128
|
|
150
|
-
context 'When the Elasticsearch version is >=
|
129
|
+
context 'When the Elasticsearch version is >= 8.1.0' do
|
151
130
|
context 'With a valid Elasticsearch response' do
|
152
|
-
let(:body) { { 'version' => { 'number' => '
|
131
|
+
let(:body) { { 'version' => { 'number' => '8.1.0' } }.to_json }
|
153
132
|
let(:headers) do
|
154
133
|
{
|
155
134
|
'X-Elastic-Product' => 'Elasticsearch',
|
@@ -177,15 +156,17 @@ describe 'Elasticsearch: Validation' do
|
|
177
156
|
end
|
178
157
|
end
|
179
158
|
|
180
|
-
|
159
|
+
|
160
|
+
context 'When the Elasticsearch version is 8.0.0.pre' do
|
181
161
|
context 'With a valid Elasticsearch response' do
|
182
|
-
let(:body) { { 'version' => { 'number' => '
|
162
|
+
let(:body) { { 'version' => { 'number' => '8.0.0.pre' } }.to_json }
|
183
163
|
let(:headers) do
|
184
164
|
{
|
185
165
|
'X-Elastic-Product' => 'Elasticsearch',
|
186
166
|
'content-type' => 'json'
|
187
167
|
}
|
188
168
|
end
|
169
|
+
|
189
170
|
it 'Makes requests and passes validation' do
|
190
171
|
verify_request_stub
|
191
172
|
count_request_stub
|
@@ -206,8 +187,8 @@ describe 'Elasticsearch: Validation' do
|
|
206
187
|
end
|
207
188
|
end
|
208
189
|
|
209
|
-
context 'When the version is
|
210
|
-
let(:body) { { 'version' => { 'number' => '
|
190
|
+
context 'When the version is 8.0.0-SNAPSHOT' do
|
191
|
+
let(:body) { { 'version' => { 'number' => '8.0.0-SNAPSHOT' } }.to_json }
|
211
192
|
|
212
193
|
context 'When the header is not present' do
|
213
194
|
it 'Fails validation' do
|
@@ -235,77 +216,8 @@ describe 'Elasticsearch: Validation' do
|
|
235
216
|
end
|
236
217
|
end
|
237
218
|
|
238
|
-
context 'When Elasticsearch version is
|
239
|
-
|
240
|
-
let(:body) { { 'version' => { 'number' => '7.4.0', 'build_flavor' => 'default' } }.to_json }
|
241
|
-
|
242
|
-
it 'Fails validation' do
|
243
|
-
verify_request_stub
|
244
|
-
count_request_stub
|
245
|
-
|
246
|
-
error_requests_and_expectations
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
context 'When build flavor is not present' do
|
251
|
-
let(:body) do
|
252
|
-
{
|
253
|
-
'version' => {
|
254
|
-
'number' => '7.4.0'
|
255
|
-
},
|
256
|
-
'tagline' => Elasticsearch::YOU_KNOW_FOR_SEARCH
|
257
|
-
}.to_json
|
258
|
-
end
|
259
|
-
|
260
|
-
it 'Fails validation' do
|
261
|
-
verify_request_stub
|
262
|
-
count_request_stub
|
263
|
-
|
264
|
-
error_requests_and_expectations(Elasticsearch::NOT_SUPPORTED_ELASTICSEARCH_WARNING)
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
context 'When the tagline is different' do
|
269
|
-
let(:body) do
|
270
|
-
{
|
271
|
-
'version' => {
|
272
|
-
'number' => '7.4.0',
|
273
|
-
'build_flavor' => 'default'
|
274
|
-
},
|
275
|
-
'tagline' => 'You Know, for other stuff'
|
276
|
-
}.to_json
|
277
|
-
end
|
278
|
-
|
279
|
-
it 'Fails validation' do
|
280
|
-
verify_request_stub
|
281
|
-
count_request_stub
|
282
|
-
|
283
|
-
error_requests_and_expectations
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
context 'With a valid Elasticsearch response' do
|
288
|
-
let(:body) do
|
289
|
-
{
|
290
|
-
'version' => {
|
291
|
-
'number' => '7.4.0',
|
292
|
-
'build_flavor' => 'default'
|
293
|
-
},
|
294
|
-
'tagline' => 'You Know, for Search'
|
295
|
-
}.to_json
|
296
|
-
end
|
297
|
-
|
298
|
-
it 'Makes requests and passes validation' do
|
299
|
-
verify_request_stub
|
300
|
-
count_request_stub
|
301
|
-
|
302
|
-
valid_requests_and_expectations
|
303
|
-
end
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
context 'When Elasticsearch version is < 6.0.0' do
|
308
|
-
let(:body) { { 'version' => { 'number' => '5.0.0' } }.to_json }
|
219
|
+
context 'When Elasticsearch version is < 8.0.0' do
|
220
|
+
let(:body) { { 'version' => { 'number' => '7.16.0' } }.to_json }
|
309
221
|
|
310
222
|
it 'Raises an exception and client doesnae work' do
|
311
223
|
verify_request_stub
|
@@ -321,141 +233,13 @@ describe 'Elasticsearch: Validation' do
|
|
321
233
|
end
|
322
234
|
end
|
323
235
|
|
324
|
-
context 'When Elasticsearch version is between 6.0.0 and 7.0.0' do
|
325
|
-
context 'With an Elasticsearch valid response' do
|
326
|
-
let(:body) do
|
327
|
-
{
|
328
|
-
'version' => {
|
329
|
-
'number' => '6.8.10'
|
330
|
-
},
|
331
|
-
'tagline' => 'You Know, for Search'
|
332
|
-
}.to_json
|
333
|
-
end
|
334
|
-
|
335
|
-
it 'Makes requests and passes validation' do
|
336
|
-
verify_request_stub
|
337
|
-
count_request_stub
|
338
|
-
|
339
|
-
valid_requests_and_expectations
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
context 'With no tagline' do
|
344
|
-
let(:body) do
|
345
|
-
{ 'version' => { 'number' => '6.8.10' } }.to_json
|
346
|
-
end
|
347
|
-
|
348
|
-
it 'Fails validation' do
|
349
|
-
verify_request_stub
|
350
|
-
count_request_stub
|
351
|
-
|
352
|
-
error_requests_and_expectations
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
context 'When the tagline is different' do
|
357
|
-
let(:body) do
|
358
|
-
{
|
359
|
-
'version' => {
|
360
|
-
'number' => '6.8.10',
|
361
|
-
'build_flavor' => 'default'
|
362
|
-
},
|
363
|
-
'tagline' => 'You Know, for Stuff'
|
364
|
-
}.to_json
|
365
|
-
end
|
366
|
-
|
367
|
-
it 'Fails validation' do
|
368
|
-
verify_request_stub
|
369
|
-
count_request_stub
|
370
|
-
|
371
|
-
error_requests_and_expectations
|
372
|
-
end
|
373
|
-
end
|
374
|
-
end
|
375
|
-
|
376
|
-
context 'When Elasticsearch version is between 7.0.0 and 7.14.0' do
|
377
|
-
context 'With a valid Elasticsearch response' do
|
378
|
-
let(:body) do
|
379
|
-
{
|
380
|
-
'version' => {
|
381
|
-
'number' => '7.10.0',
|
382
|
-
'build_flavor' => 'default'
|
383
|
-
},
|
384
|
-
'tagline' => 'You Know, for Search'
|
385
|
-
}.to_json
|
386
|
-
end
|
387
|
-
|
388
|
-
it 'Makes requests and passes validation' do
|
389
|
-
verify_request_stub
|
390
|
-
count_request_stub
|
391
|
-
|
392
|
-
valid_requests_and_expectations
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
context 'When the tagline is not present' do
|
397
|
-
let(:body) do
|
398
|
-
{
|
399
|
-
'version' => {
|
400
|
-
'number' => '7.10.0',
|
401
|
-
'build_flavor' => 'default'
|
402
|
-
}
|
403
|
-
}.to_json
|
404
|
-
end
|
405
|
-
|
406
|
-
it 'Fails validation' do
|
407
|
-
verify_request_stub
|
408
|
-
count_request_stub
|
409
|
-
|
410
|
-
error_requests_and_expectations
|
411
|
-
end
|
412
|
-
end
|
413
|
-
|
414
|
-
context 'When the tagline is different' do
|
415
|
-
let(:body) do
|
416
|
-
{
|
417
|
-
'version' => {
|
418
|
-
'number' => '7.10.0',
|
419
|
-
'build_flavor' => 'default'
|
420
|
-
},
|
421
|
-
'tagline' => 'You Know, for other stuff'
|
422
|
-
}.to_json
|
423
|
-
end
|
424
|
-
|
425
|
-
it 'Fails validation' do
|
426
|
-
verify_request_stub
|
427
|
-
count_request_stub
|
428
|
-
|
429
|
-
error_requests_and_expectations
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
context 'When the build_flavor is not present' do
|
434
|
-
let(:body) do
|
435
|
-
{
|
436
|
-
'version' => {
|
437
|
-
'number' => '7.10.0'
|
438
|
-
},
|
439
|
-
'tagline' => 'You Know, for Search'
|
440
|
-
}.to_json
|
441
|
-
end
|
442
|
-
|
443
|
-
it 'Fails validation' do
|
444
|
-
verify_request_stub
|
445
|
-
count_request_stub
|
446
|
-
|
447
|
-
error_requests_and_expectations(Elasticsearch::NOT_SUPPORTED_ELASTICSEARCH_WARNING)
|
448
|
-
end
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
236
|
context 'When doing a yaml content-type request' do
|
453
237
|
let(:client) do
|
454
238
|
Elasticsearch::Client.new(transport_options: {headers: { accept: 'application/yaml', content_type: 'application/yaml' }})
|
455
239
|
end
|
456
240
|
|
457
241
|
let(:headers) { { 'content-type' => 'application/yaml', 'X-Elastic-Product' => 'Elasticsearch' } }
|
458
|
-
let(:body) { "---\nversion:\n number: \"
|
242
|
+
let(:body) { "---\nversion:\n number: \"8.0.0-SNAPSHOT\"\n" }
|
459
243
|
|
460
244
|
it 'validates' do
|
461
245
|
verify_request_stub
|
@@ -0,0 +1,55 @@
|
|
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)
|
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
|
@@ -0,0 +1,48 @@
|
|
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' })
|
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' })
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -14,13 +14,13 @@
|
|
14
14
|
# KIND, either express or implied. See the License for the
|
15
15
|
# specific language governing permissions and limitations
|
16
16
|
# under the License.
|
17
|
-
|
18
|
-
require '
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
19
|
|
20
20
|
describe 'Elasticsearch: wrapper gem' do
|
21
21
|
it 'requires all neccessary subgems' do
|
22
|
-
expect(defined?
|
23
|
-
expect(defined?
|
22
|
+
expect(defined? Elasticsearch::Client)
|
23
|
+
expect(defined? Elasticsearch::API)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'mixes the API into the client' do
|
@@ -30,10 +30,4 @@ describe 'Elasticsearch: wrapper gem' do
|
|
30
30
|
expect(client).to respond_to(:cluster)
|
31
31
|
expect(client).to respond_to(:indices)
|
32
32
|
end
|
33
|
-
|
34
|
-
it 'can access the client transport' do
|
35
|
-
client = Elasticsearch::Client.new
|
36
|
-
expect(client.transport).to be_a(Elasticsearch::Transport::Client)
|
37
|
-
expect(client.transport.transport).to be_a(Elasticsearch::Transport::Transport::HTTP::Faraday)
|
38
|
-
end
|
39
33
|
end
|