elasticsearch 7.13.3 → 7.14.0.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dd904fe3389952a5434f9bdd54e43b085d686146620423f1f55e5e1cfcea9cc
4
- data.tar.gz: 8456c08f65bde635e6238f01f6227d4688003c1083ac69c6b45029ba031d7679
3
+ metadata.gz: 2e005cdbfff8d8486e0cf54d74a9c68173235bd00ea1c42371438ba76433d78b
4
+ data.tar.gz: 50bd687f7cea41c62e5d53672e438467cb522890a707efe68b228521cf0dd170
5
5
  SHA512:
6
- metadata.gz: cc9635e7f85dddfec58ea02f18f31a586f0e671abbbfb19038564c976097d982bad0f1777b94798a1f4baca88213d7ac03ca27dc162792903eed1724f3f62289
7
- data.tar.gz: c4aeeeb547a5e678ff1421b0fbcdc521662d6606afc359f6e813cf38278b274be320e2b912d09b7e722f2a46f8518fbe0a741748f2f9ff10c8a407b703e11d2b
6
+ metadata.gz: 2f1641346dca4764402a543fdd86976804137b5bcadb696b306c3bb3683ba3b03f3605e56beaf14c310f72220c52874e973f18980867f83b4244464890f4fcbf
7
+ data.tar.gz: 02b2e651a97e7f5ffa3ca5548cf56e0e8a3c281728dd8b2ff94f8172f4db36f639860b6b3662d67ded42ec41369152e36cbb38885cf3a349bef5b90f76f704b5
data/README.md CHANGED
@@ -86,6 +86,10 @@ Please refer to the specific library documentation for details:
86
86
  [[README]](https://github.com/elasticsearch/elasticsearch-ruby/blob/master/elasticsearch-api/README.md)
87
87
  [[Documentation]](http://rubydoc.info/gems/elasticsearch-api/file/README.markdown)
88
88
 
89
+ ## Development
90
+
91
+ You can run `rake -T` to check the test tasks. Use `COVERAGE=true` before running a test task to check the coverage with Simplecov.
92
+
89
93
  ## License
90
94
 
91
95
  This software is licensed under the [Apache 2 license](./LICENSE).
data/Rakefile CHANGED
@@ -15,40 +15,35 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- require "bundler/gem_tasks"
18
+ require 'bundler/gem_tasks'
19
19
 
20
- desc "Run unit tests"
21
- task :test => 'test:unit'
20
+ task(:default) { system 'rake --tasks' }
21
+
22
+ desc 'Run unit tests'
23
+ task test: 'test:spec'
22
24
 
23
25
  # ----- Test tasks ------------------------------------------------------------
26
+ require 'rspec/core/rake_task'
24
27
 
25
- require 'rake/testtask'
26
28
  namespace :test do
27
- desc "Wait for Elasticsearch to be in a green state"
29
+ desc 'Wait for Elasticsearch to be in a green state'
28
30
  task :wait_for_green do
29
31
  sh '../scripts/wait-cluster.sh'
30
32
  end
31
33
 
32
- Rake::TestTask.new(:unit) do |test|
33
- test.libs << 'lib' << 'test'
34
- test.test_files = FileList["test/unit/**/*_test.rb"]
35
- test.verbose = false
36
- test.warning = false
34
+ RSpec::Core::RakeTask.new(:integration) do |t|
35
+ t.pattern = 'spec/integration/**{,/*/**}/*_spec.rb'
37
36
  end
38
37
 
39
- Rake::TestTask.new(:integration) do |test|
40
- test.deps = [ :wait_for_green ]
41
- test.libs << 'lib' << 'test'
42
- test.test_files = FileList["test/integration/**/*_test.rb"]
43
- test.verbose = false
44
- test.warning = false
38
+ RSpec::Core::RakeTask.new(:unit) do |t|
39
+ t.pattern = 'spec/unit/**{,/*/**}/*_spec.rb'
45
40
  end
46
41
 
47
- Rake::TestTask.new(:all) do |test|
48
- test.libs << 'lib' << 'test'
49
- test.test_files = FileList["test/unit/**/*_test.rb", "test/integration/**/*_test.rb"]
42
+ desc 'Run unit and integration tests'
43
+ task :all do
44
+ Rake::Task['test:unit'].invoke
45
+ Rake::Task['test:integration'].invoke
50
46
  end
51
-
52
47
  end
53
48
 
54
49
  # ----- Documentation tasks ---------------------------------------------------
@@ -45,31 +45,19 @@ Gem::Specification.new do |s|
45
45
 
46
46
  s.required_ruby_version = '>= 2.4'
47
47
 
48
- s.add_dependency 'elasticsearch-transport', '7.13.3'
49
- s.add_dependency 'elasticsearch-api', '7.13.3'
48
+ s.add_dependency 'elasticsearch-transport', '7.14.0.pre'
49
+ s.add_dependency 'elasticsearch-api', '7.14.0.pre'
50
50
 
51
51
  s.add_development_dependency 'bundler'
52
-
53
- s.add_development_dependency 'rake', '~> 13'
54
-
55
- s.add_development_dependency 'elasticsearch-extensions'
56
-
57
- s.add_development_dependency 'ansi'
58
- s.add_development_dependency 'shoulda-context'
59
- s.add_development_dependency 'mocha'
60
- s.add_development_dependency 'yard'
52
+ s.add_development_dependency 'byebug' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
61
53
  s.add_development_dependency 'pry'
62
-
63
-
64
- s.add_development_dependency 'minitest'
65
- s.add_development_dependency 'minitest-reporters'
66
- s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
54
+ s.add_development_dependency 'rake', '~> 13'
67
55
  s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
68
- s.add_development_dependency 'simplecov', '~> 0.17', '< 0.18'
69
- s.add_development_dependency 'simplecov-rcov'
70
- s.add_development_dependency 'cane'
71
-
72
- s.add_development_dependency 'test-unit', '~> 2'
56
+ s.add_development_dependency 'rspec'
57
+ s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
58
+ s.add_development_dependency 'simplecov'
59
+ s.add_development_dependency 'webmock'
60
+ s.add_development_dependency 'yard'
73
61
 
74
62
  s.description = <<-DESC.gsub(/^ /, '')
75
63
  Ruby integrations for Elasticsearch (client, API, etc.)
data/lib/elasticsearch.rb CHANGED
@@ -15,18 +15,91 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- require "elasticsearch/version"
19
-
18
+ require 'elasticsearch/version'
20
19
  require 'elasticsearch/transport'
21
20
  require 'elasticsearch/api'
22
21
 
23
22
  module Elasticsearch
24
- module Transport
25
- class Client
26
- include Elasticsearch::API
23
+ SECURITY_PRIVILEGES_VALIDATION_WARNING = 'The client is unable to verify that the server is Elasticsearch due to security privileges on the server side.'.freeze
24
+ NOT_ELASTICSEARCH_WARNING = 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.'.freeze
25
+ YOU_KNOW_FOR_SEARCH = 'You know, for Search'.freeze
26
+
27
+ class Client
28
+ include Elasticsearch::API
29
+ attr_accessor :transport
30
+
31
+ # See Elasticsearch::Transport::Client for initializer parameters
32
+ def initialize(arguments = {}, &block)
33
+ @verified = false
34
+ @transport = Elasticsearch::Transport::Client.new(arguments, &block)
35
+ end
36
+
37
+ def method_missing(name, *args, &block)
38
+ if name == :perform_request
39
+ verify_elasticsearch unless @verified
40
+ @transport.perform_request(*args, &block)
41
+ else
42
+ super
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def verify_elasticsearch
49
+ begin
50
+ response = elasticsearch_validation_request
51
+ rescue Elasticsearch::Transport::Transport::Errors::Unauthorized,
52
+ Elasticsearch::Transport::Transport::Errors::Forbidden
53
+ @verified = true
54
+ warn(SECURITY_PRIVILEGES_VALIDATION_WARNING)
55
+ return
56
+ end
57
+
58
+ body = if response.headers['content-type'] == 'application/yaml'
59
+ require 'yaml'
60
+ YAML.load(response.body)
61
+ else
62
+ response.body
63
+ end
64
+ version = body.dig('version', 'number')
65
+ verify_with_version_or_header(body, version, response.headers)
66
+ end
67
+
68
+ def verify_with_version_or_header(body, version, headers)
69
+ raise Elasticsearch::NotElasticsearchError if version.nil? || version < '6.0.0'
70
+
71
+ if version == '7.x-SNAPSHOT' || Gem::Version.new(version) >= Gem::Version.new('7.14-SNAPSHOT')
72
+ raise Elasticsearch::NotElasticsearchError unless headers['x-elastic-product'] == 'Elasticsearch'
73
+
74
+ @verified = true
75
+ elsif Gem::Version.new(version) > Gem::Version.new('6.0.0') &&
76
+ Gem::Version.new(version) < Gem::Version.new('7.0.0')
77
+ raise Elasticsearch::NotElasticsearchError unless
78
+ body['tagline'] == YOU_KNOW_FOR_SEARCH
79
+
80
+ @verified = true
81
+ elsif Gem::Version.new(version) >= Gem::Version.new('7.0.0') &&
82
+ Gem::Version.new(version) < Gem::Version.new('7.14-SNAPSHOT')
83
+ raise Elasticsearch::NotElasticsearchError unless
84
+ body['tagline'] == YOU_KNOW_FOR_SEARCH &&
85
+ body.dig('version', 'build_flavor') == 'default'
86
+
87
+ @verified = true
88
+ end
89
+ end
90
+
91
+ def elasticsearch_validation_request
92
+ @transport.perform_request('GET', '/')
93
+ end
94
+ end
95
+
96
+ class NotElasticsearchError < StandardError
97
+ def initialize
98
+ super(NOT_ELASTICSEARCH_WARNING)
27
99
  end
28
100
  end
29
101
  end
102
+
30
103
  module Elastic
31
104
  # If the version is X.X.X.pre/alpha/beta, use X.X.Xp for the meta-header:
32
105
  def self.client_meta_version
@@ -16,5 +16,5 @@
16
16
  # under the License.
17
17
 
18
18
  module Elasticsearch
19
- VERSION = '7.13.3'.freeze
19
+ VERSION = '7.14.0.pre'.freeze
20
20
  end
@@ -0,0 +1,57 @@
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 'logger'
19
+
20
+ context 'Elasticsearch client' do
21
+ let(:logger) { Logger.new($stderr) }
22
+
23
+ let(:client) do
24
+ Elasticsearch::Client.new(
25
+ host: ELASTICSEARCH_URL,
26
+ logger: logger
27
+ )
28
+ end
29
+
30
+ context 'Integrates with elasticsearch API' do
31
+ it 'should perform the API methods' do
32
+ expect do
33
+ # Index a document
34
+ client.index(index: 'test-index', id: '1', body: { title: 'Test' })
35
+
36
+ # Refresh the index
37
+ client.indices.refresh(index: 'test-index')
38
+
39
+ # Search
40
+ response = client.search(index: 'test-index', body: { query: { match: { title: 'test' } } })
41
+
42
+ expect(response['hits']['total']['value']).to eq 1
43
+ expect(response['hits']['hits'][0]['_source']['title']).to eq 'Test'
44
+
45
+ # Delete the index
46
+ client.indices.delete(index: 'test-index')
47
+ end.not_to raise_error
48
+ end
49
+ end
50
+
51
+ context 'Reports the right meta header' do
52
+ it 'Reports es service name and gem version' do
53
+ headers = client.transport.transport.connections.first.connection.headers
54
+ expect(headers['x-elastic-client-meta']).to match Elastic.client_meta_version
55
+ end
56
+ end
57
+ end
@@ -14,30 +14,17 @@
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 'test_helper'
19
-
20
- module Elasticsearch
21
- module Test
22
- class WrapperGemTest < Minitest::Test
23
-
24
- context "Wrapper gem" do
25
-
26
- should "require all neccessary subgems" do
27
- assert defined? Elasticsearch::Client
28
- assert defined? Elasticsearch::API
29
- end
30
-
31
- should "mix the API into the client" do
32
- client = Elasticsearch::Client.new
33
-
34
- assert_respond_to client, :search
35
- assert_respond_to client, :cluster
36
- assert_respond_to client, :indices
37
- end
38
-
39
- end
40
-
41
- end
17
+ require 'spec_helper'
18
+ require 'logger'
19
+
20
+ describe 'Elasticsearch validation integration' do
21
+ it 'Validates for Elasticsearch > 7.14' do
22
+ client = Elasticsearch::Client.new(
23
+ host: ELASTICSEARCH_URL,
24
+ logger: Logger.new($stderr)
25
+ )
26
+ expect(client.instance_variable_get('@verified')).to be false
27
+ client.count
28
+ expect(client.instance_variable_get('@verified')).to be true
42
29
  end
43
30
  end
@@ -0,0 +1,26 @@
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 'elasticsearch'
19
+ require 'rspec'
20
+
21
+ ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
22
+ raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
23
+
24
+ RSpec.configure do |config|
25
+ config.formatter = :documentation
26
+ end
@@ -0,0 +1,386 @@
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(:verify_request_stub) do
24
+ stub_request(:get, host)
25
+ .to_return(status: status, body: body, headers: headers)
26
+ end
27
+ let(:count_request_stub) do
28
+ stub_request(:post, "#{host}/_count")
29
+ .to_return(status: 200, body: nil, headers: {})
30
+ end
31
+ let(:status) { 200 }
32
+ let(:body) { {}.to_json }
33
+ let(:client) { Elasticsearch::Client.new }
34
+ let(:headers) do
35
+ { 'content-type' => 'json' }
36
+ end
37
+
38
+ def error_requests_and_expectations
39
+ expect { client.count }.to raise_error Elasticsearch::NotElasticsearchError
40
+ assert_requested :get, host
41
+ assert_not_requested :post, "#{host}/_count"
42
+ expect { client.cluster.health }.to raise_error Elasticsearch::NotElasticsearchError
43
+ expect(client.instance_variable_get('@verified')).to be false
44
+ expect { client.cluster.health }.to raise_error Elasticsearch::NotElasticsearchError
45
+ end
46
+
47
+ def valid_requests_and_expectations
48
+ expect(client.instance_variable_get('@verified')).to be false
49
+ assert_not_requested :get, host
50
+
51
+ client.count
52
+ expect(client.instance_variable_get('@verified'))
53
+ assert_requested :get, host
54
+ assert_requested :post, "#{host}/_count"
55
+ end
56
+
57
+ context 'When Elasticsearch replies with status 401' do
58
+ let(:status) { 401 }
59
+ let(:body) { {}.to_json }
60
+
61
+ it 'Verifies the request but shows a warning' do
62
+ stderr = $stderr
63
+ fake_stderr = StringIO.new
64
+ $stderr = fake_stderr
65
+
66
+ verify_request_stub
67
+ count_request_stub
68
+
69
+ valid_requests_and_expectations
70
+
71
+ fake_stderr.rewind
72
+ expect(fake_stderr.string).to eq("#{Elasticsearch::SECURITY_PRIVILEGES_VALIDATION_WARNING}\n")
73
+ ensure
74
+ $stderr = stderr
75
+ end
76
+ end
77
+
78
+ context 'When Elasticsearch replies with status 403' do
79
+ let(:status) { 403 }
80
+ let(:body) { {}.to_json }
81
+
82
+ it 'Verifies the request but shows a warning' do
83
+ stderr = $stderr
84
+ fake_stderr = StringIO.new
85
+ $stderr = fake_stderr
86
+
87
+ verify_request_stub
88
+ count_request_stub
89
+
90
+ valid_requests_and_expectations
91
+
92
+ fake_stderr.rewind
93
+ expect(fake_stderr.string).to eq("#{Elasticsearch::SECURITY_PRIVILEGES_VALIDATION_WARNING}\n")
94
+ ensure
95
+ $stderr = stderr
96
+ end
97
+ end
98
+
99
+ context 'When the Elasticsearch version is >= 7.14' do
100
+ context 'With a valid Elasticsearch response' do
101
+ let(:body) { { 'version' => { 'number' => '7.14.0' } }.to_json }
102
+ let(:headers) do
103
+ {
104
+ 'X-Elastic-Product' => 'Elasticsearch',
105
+ 'content-type' => 'json'
106
+ }
107
+ end
108
+ it 'Makes requests and passes validation' do
109
+ verify_request_stub
110
+ count_request_stub
111
+
112
+ valid_requests_and_expectations
113
+ end
114
+ end
115
+
116
+ context 'When the header is not present' do
117
+ it 'Fails validation' do
118
+ verify_request_stub
119
+
120
+ expect(client.instance_variable_get('@verified')).to be false
121
+ assert_not_requested :get, host
122
+
123
+ error_requests_and_expectations
124
+ end
125
+ end
126
+ end
127
+
128
+ context 'When the Elasticsearch version is >= 7.14-SNAPSHOT' do
129
+ context 'With a valid Elasticsearch response' do
130
+ let(:body) { { 'version' => { 'number' => '7.14-SNAPSHOT' } }.to_json }
131
+ let(:headers) do
132
+ {
133
+ 'X-Elastic-Product' => 'Elasticsearch',
134
+ 'content-type' => 'json'
135
+ }
136
+ end
137
+ it 'Makes requests and passes validation' do
138
+ verify_request_stub
139
+ count_request_stub
140
+
141
+ valid_requests_and_expectations
142
+ end
143
+ end
144
+
145
+ context 'When the header is not present' do
146
+ it 'Fails validation' do
147
+ verify_request_stub
148
+
149
+ expect(client.instance_variable_get('@verified')).to be false
150
+ assert_not_requested :get, host
151
+
152
+ error_requests_and_expectations
153
+ end
154
+ end
155
+ end
156
+
157
+ context 'When the Elasticsearch version is >= 7.15-SNAPSHOT' do
158
+ context 'With a valid Elasticsearch response' do
159
+ let(:body) { { 'version' => { 'number' => '7.15-SNAPSHOT' } }.to_json }
160
+ let(:headers) do
161
+ {
162
+ 'X-Elastic-Product' => 'Elasticsearch',
163
+ 'content-type' => 'json'
164
+ }
165
+ end
166
+ it 'Makes requests and passes validation' do
167
+ verify_request_stub
168
+ count_request_stub
169
+
170
+ valid_requests_and_expectations
171
+ end
172
+ end
173
+
174
+ context 'When the header is not present' do
175
+ it 'Fails validation' do
176
+ verify_request_stub
177
+
178
+ expect(client.instance_variable_get('@verified')).to be false
179
+ assert_not_requested :get, host
180
+
181
+ error_requests_and_expectations
182
+ end
183
+ end
184
+ end
185
+
186
+ context 'When the version is 7.x-SNAPSHOT' do
187
+ let(:body) { { 'version' => { 'number' => '7.x-SNAPSHOT' } }.to_json }
188
+
189
+ context 'When the header is not present' do
190
+ it 'Fails validation' do
191
+ verify_request_stub
192
+ count_request_stub
193
+
194
+ error_requests_and_expectations
195
+ end
196
+ end
197
+
198
+ context 'With a valid Elasticsearch response' do
199
+ let(:headers) do
200
+ {
201
+ 'X-Elastic-Product' => 'Elasticsearch',
202
+ 'content-type' => 'json'
203
+ }
204
+ end
205
+
206
+ it 'Makes requests and passes validation' do
207
+ verify_request_stub
208
+ count_request_stub
209
+
210
+ valid_requests_and_expectations
211
+ end
212
+ end
213
+ end
214
+
215
+ context 'When Elasticsearch version is 7.4.0' do
216
+ context 'When tagline is not present' do
217
+ let(:body) { { 'version' => { 'number' => '7.4.0', 'build_flavor' => 'default' } }.to_json }
218
+
219
+ it 'Fails validation' do
220
+ verify_request_stub
221
+ count_request_stub
222
+
223
+ error_requests_and_expectations
224
+ end
225
+ end
226
+
227
+ context 'When build flavor is not present' do
228
+ let(:body) do
229
+ {
230
+ 'version' => {
231
+ 'number' => '7.4.0'
232
+ },
233
+ 'tagline' => Elasticsearch::YOU_KNOW_FOR_SEARCH
234
+ }.to_json
235
+ end
236
+
237
+ it 'Fails validation' do
238
+ verify_request_stub
239
+ count_request_stub
240
+
241
+ error_requests_and_expectations
242
+ end
243
+ end
244
+
245
+ context 'With a valid Elasticsearch response' do
246
+ let(:body) do
247
+ {
248
+ 'version' => {
249
+ 'number' => '7.4.0',
250
+ 'build_flavor' => 'default'
251
+ },
252
+ 'tagline' => Elasticsearch::YOU_KNOW_FOR_SEARCH
253
+ }.to_json
254
+ end
255
+
256
+ it 'Makes requests and passes validation' do
257
+ verify_request_stub
258
+ count_request_stub
259
+
260
+ valid_requests_and_expectations
261
+ end
262
+ end
263
+ end
264
+
265
+ context 'When Elasticsearch version is < 6.0.0' do
266
+ let(:body) { { 'version' => { 'number' => '5.0.0' } }.to_json }
267
+
268
+ it 'Raises an exception and client doesnae work' do
269
+ verify_request_stub
270
+ error_requests_and_expectations
271
+ end
272
+ end
273
+
274
+ context 'When there is no version data' do
275
+ let(:body) { {}.to_json }
276
+ it 'Raises an exception and client doesnae work' do
277
+ verify_request_stub
278
+ error_requests_and_expectations
279
+ end
280
+ end
281
+
282
+ context 'When Elasticsearch version is between 6.0.0 and 7.0.0' do
283
+ context 'With an Elasticsearch valid response' do
284
+ let(:body) do
285
+ {
286
+ 'version' => {
287
+ 'number' => '6.8.10'
288
+ },
289
+ 'tagline' => Elasticsearch::YOU_KNOW_FOR_SEARCH
290
+ }.to_json
291
+ end
292
+
293
+ it 'Makes requests and passes validation' do
294
+ verify_request_stub
295
+ count_request_stub
296
+
297
+ valid_requests_and_expectations
298
+ end
299
+ end
300
+
301
+ context 'With no tagline' do
302
+ let(:body) do
303
+ { 'version' => { 'number' => '6.8.10' } }.to_json
304
+ end
305
+
306
+ it 'Fails validation' do
307
+ verify_request_stub
308
+ count_request_stub
309
+
310
+ error_requests_and_expectations
311
+ end
312
+ end
313
+ end
314
+
315
+ context 'When Elasticsearch version is between 7.0.0 and 7.14.0' do
316
+ context 'With a valid Elasticsearch response' do
317
+ let(:body) do
318
+ {
319
+ 'version' => {
320
+ 'number' => '7.10.0',
321
+ 'build_flavor' => 'default'
322
+ },
323
+ 'tagline' => Elasticsearch::YOU_KNOW_FOR_SEARCH
324
+ }.to_json
325
+ end
326
+
327
+ it 'Makes requests and passes validation' do
328
+ verify_request_stub
329
+ count_request_stub
330
+
331
+ valid_requests_and_expectations
332
+ end
333
+ end
334
+
335
+ context 'When the tagline is not present' do
336
+ let(:body) do
337
+ {
338
+ 'version' => {
339
+ 'number' => '7.10.0',
340
+ 'build_flavor' => 'default'
341
+ }
342
+ }.to_json
343
+ end
344
+
345
+ it 'Fails validation' do
346
+ verify_request_stub
347
+ count_request_stub
348
+
349
+ error_requests_and_expectations
350
+ end
351
+ end
352
+
353
+ context 'When the build_flavor is not present' do
354
+ let(:body) do
355
+ {
356
+ 'version' => {
357
+ 'number' => '7.10.0'
358
+ },
359
+ 'tagline' => Elasticsearch::YOU_KNOW_FOR_SEARCH
360
+ }.to_json
361
+ end
362
+
363
+ it 'Fails validation' do
364
+ verify_request_stub
365
+ count_request_stub
366
+
367
+ error_requests_and_expectations
368
+ end
369
+ end
370
+ end
371
+
372
+ context 'When doing a yaml content-type request' do
373
+ let(:client) do
374
+ Elasticsearch::Client.new(transport_options: {headers: { accept: 'application/yaml', content_type: 'application/yaml' }})
375
+ end
376
+
377
+ let(:headers) { { 'content-type' => 'application/yaml', 'X-Elastic-Product' => 'Elasticsearch' } }
378
+ let(:body) { "---\nversion:\n number: \"7.14.0-SNAPSHOT\"\n" }
379
+
380
+ it 'validates' do
381
+ verify_request_stub
382
+ count_request_stub
383
+ valid_requests_and_expectations
384
+ end
385
+ end
386
+ end
@@ -0,0 +1,39 @@
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 'elasticsearch'
18
+ require 'webmock/rspec'
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
+
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
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.13.3
4
+ version: 7.14.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-12 00:00:00.000000000 Z
11
+ date: 2021-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch-transport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 7.13.3
19
+ version: 7.14.0.pre
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 7.13.3
26
+ version: 7.14.0.pre
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: elasticsearch-api
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 7.13.3
33
+ version: 7.14.0.pre
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 7.13.3
40
+ version: 7.14.0.pre
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,49 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '13'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '13'
69
- - !ruby/object:Gem::Dependency
70
- name: elasticsearch-extensions
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: ansi
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: shoulda-context
56
+ name: byebug
99
57
  requirement: !ruby/object:Gem::Requirement
100
58
  requirements:
101
59
  - - ">="
@@ -109,21 +67,7 @@ dependencies:
109
67
  - !ruby/object:Gem::Version
110
68
  version: '0'
111
69
  - !ruby/object:Gem::Dependency
112
- name: mocha
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: yard
70
+ name: pry
127
71
  requirement: !ruby/object:Gem::Requirement
128
72
  requirements:
129
73
  - - ">="
@@ -137,21 +81,21 @@ dependencies:
137
81
  - !ruby/object:Gem::Version
138
82
  version: '0'
139
83
  - !ruby/object:Gem::Dependency
140
- name: pry
84
+ name: rake
141
85
  requirement: !ruby/object:Gem::Requirement
142
86
  requirements:
143
- - - ">="
87
+ - - "~>"
144
88
  - !ruby/object:Gem::Version
145
- version: '0'
89
+ version: '13'
146
90
  type: :development
147
91
  prerelease: false
148
92
  version_requirements: !ruby/object:Gem::Requirement
149
93
  requirements:
150
- - - ">="
94
+ - - "~>"
151
95
  - !ruby/object:Gem::Version
152
- version: '0'
96
+ version: '13'
153
97
  - !ruby/object:Gem::Dependency
154
- name: minitest
98
+ name: require-prof
155
99
  requirement: !ruby/object:Gem::Requirement
156
100
  requirements:
157
101
  - - ">="
@@ -165,7 +109,7 @@ dependencies:
165
109
  - !ruby/object:Gem::Version
166
110
  version: '0'
167
111
  - !ruby/object:Gem::Dependency
168
- name: minitest-reporters
112
+ name: rspec
169
113
  requirement: !ruby/object:Gem::Requirement
170
114
  requirements:
171
115
  - - ">="
@@ -193,7 +137,7 @@ dependencies:
193
137
  - !ruby/object:Gem::Version
194
138
  version: '0'
195
139
  - !ruby/object:Gem::Dependency
196
- name: require-prof
140
+ name: simplecov
197
141
  requirement: !ruby/object:Gem::Requirement
198
142
  requirements:
199
143
  - - ">="
@@ -207,27 +151,7 @@ dependencies:
207
151
  - !ruby/object:Gem::Version
208
152
  version: '0'
209
153
  - !ruby/object:Gem::Dependency
210
- name: simplecov
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: '0.17'
216
- - - "<"
217
- - !ruby/object:Gem::Version
218
- version: '0.18'
219
- type: :development
220
- prerelease: false
221
- version_requirements: !ruby/object:Gem::Requirement
222
- requirements:
223
- - - "~>"
224
- - !ruby/object:Gem::Version
225
- version: '0.17'
226
- - - "<"
227
- - !ruby/object:Gem::Version
228
- version: '0.18'
229
- - !ruby/object:Gem::Dependency
230
- name: simplecov-rcov
154
+ name: webmock
231
155
  requirement: !ruby/object:Gem::Requirement
232
156
  requirements:
233
157
  - - ">="
@@ -241,7 +165,7 @@ dependencies:
241
165
  - !ruby/object:Gem::Version
242
166
  version: '0'
243
167
  - !ruby/object:Gem::Dependency
244
- name: cane
168
+ name: yard
245
169
  requirement: !ruby/object:Gem::Requirement
246
170
  requirements:
247
171
  - - ">="
@@ -254,20 +178,6 @@ dependencies:
254
178
  - - ">="
255
179
  - !ruby/object:Gem::Version
256
180
  version: '0'
257
- - !ruby/object:Gem::Dependency
258
- name: test-unit
259
- requirement: !ruby/object:Gem::Requirement
260
- requirements:
261
- - - "~>"
262
- - !ruby/object:Gem::Version
263
- version: '2'
264
- type: :development
265
- prerelease: false
266
- version_requirements: !ruby/object:Gem::Requirement
267
- requirements:
268
- - - "~>"
269
- - !ruby/object:Gem::Version
270
- version: '2'
271
181
  description: 'Ruby integrations for Elasticsearch (client, API, etc.)
272
182
 
273
183
  '
@@ -290,9 +200,11 @@ files:
290
200
  - lib/elasticsearch-ruby.rb
291
201
  - lib/elasticsearch.rb
292
202
  - lib/elasticsearch/version.rb
293
- - test/integration/client_integration_test.rb
294
- - test/test_helper.rb
295
- - test/unit/wrapper_gem_test.rb
203
+ - spec/integration/client_integration_spec.rb
204
+ - spec/integration/validation_integration_spec.rb
205
+ - spec/spec_helper.rb
206
+ - spec/unit/elasticsearch_product_validation_spec.rb
207
+ - spec/unit/wrapper_gem_spec.rb
296
208
  homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/7.x/index.html
297
209
  licenses:
298
210
  - Apache-2.0
@@ -313,15 +225,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
313
225
  version: '2.4'
314
226
  required_rubygems_version: !ruby/object:Gem::Requirement
315
227
  requirements:
316
- - - ">="
228
+ - - ">"
317
229
  - !ruby/object:Gem::Version
318
- version: '0'
230
+ version: 1.3.1
319
231
  requirements: []
320
232
  rubygems_version: 3.2.15
321
233
  signing_key:
322
234
  specification_version: 4
323
235
  summary: Ruby integrations for Elasticsearch
324
236
  test_files:
325
- - test/integration/client_integration_test.rb
326
- - test/test_helper.rb
327
- - test/unit/wrapper_gem_test.rb
237
+ - spec/integration/client_integration_spec.rb
238
+ - spec/integration/validation_integration_spec.rb
239
+ - spec/spec_helper.rb
240
+ - spec/unit/elasticsearch_product_validation_spec.rb
241
+ - spec/unit/wrapper_gem_spec.rb
@@ -1,80 +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 'test_helper'
19
- require 'logger'
20
-
21
- module Elasticsearch
22
- module Test
23
- class ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
24
- startup do
25
- Elasticsearch::Extensions::Test::Cluster.start(number_of_nodes: 2) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 2)
26
- end
27
-
28
- shutdown do
29
- Elasticsearch::Extensions::Test::Cluster.stop(number_of_nodes: 2) if ENV['SERVER'] and Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 2)
30
- end
31
-
32
- context "Elasticsearch client" do
33
- setup do
34
- system "curl -X DELETE http://#{TEST_HOST}:#{TEST_PORT}/_all > /dev/null 2>&1"
35
-
36
- @logger = Logger.new(STDERR)
37
- @logger.formatter = proc do |severity, datetime, progname, msg|
38
- color = case severity
39
- when /INFO/ then :green
40
- when /ERROR|WARN|FATAL/ then :red
41
- when /DEBUG/ then :cyan
42
- else :white
43
- end
44
- ANSI.ansi(severity[0] + ' ', color, :faint) + ANSI.ansi(msg, :white, :faint) + "\n"
45
- end
46
-
47
- @client = Elasticsearch::Client.new host: "#{TEST_HOST}:#{TEST_PORT}", logger: (ENV['QUIET'] ? nil : @logger)
48
- end
49
-
50
- should "perform the API methods" do
51
- assert_nothing_raised do
52
- # Index a document
53
- #
54
- @client.index index: 'test-index', type: 'test-type', id: '1', body: { title: 'Test' }
55
-
56
- # Refresh the index
57
- #
58
- @client.indices.refresh index: 'test-index'
59
-
60
- # Search
61
- #
62
- response = @client.search index: 'test-index', body: { query: { match: { title: 'test' } } }
63
-
64
- assert_equal 1, response['hits']['total']['value']
65
- assert_equal 'Test', response['hits']['hits'][0]['_source']['title']
66
-
67
- # Delete the index
68
- #
69
- @client.indices.delete index: 'test-index'
70
- end
71
- end
72
-
73
- should 'report the right meta header' do
74
- headers = @client.transport.connections.first.connection.headers
75
- assert_match /^es=#{Elasticsearch::VERSION}/, headers['x-elastic-client-meta']
76
- end
77
- end
78
- end
79
- end
80
- end
data/test/test_helper.rb DELETED
@@ -1,115 +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
- ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS']
19
- hosts.split(',').map do |host|
20
- /(http\:\/\/)?(\S+)/.match(host)[2]
21
- end
22
- end.freeze
23
-
24
- TEST_HOST, TEST_PORT = ELASTICSEARCH_HOSTS.first.split(':') if ELASTICSEARCH_HOSTS
25
-
26
- RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
27
- JRUBY = defined?(JRUBY_VERSION)
28
-
29
- if RUBY_1_8 and not ENV['BUNDLE_GEMFILE']
30
- require 'rubygems'
31
- gem 'test-unit'
32
- end
33
-
34
- if ENV['COVERAGE'] && ENV['CI'].nil? && !RUBY_1_8
35
- require 'simplecov'
36
- SimpleCov.start { add_filter "/test|test_/" }
37
- end
38
-
39
- if ENV['CI'] && !RUBY_1_8
40
- require 'simplecov'
41
- require 'simplecov-rcov'
42
- SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
43
- SimpleCov.start { add_filter "/test|test_" }
44
- end
45
-
46
- # Register `at_exit` handler for integration tests shutdown.
47
- # MUST be called before requiring `test/unit`.
48
- if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
49
- at_exit { Elasticsearch::Test::IntegrationTestCase.__run_at_exit_hooks }
50
- end
51
-
52
- require 'test/unit' if RUBY_1_8
53
-
54
- require 'minitest/autorun'
55
- require 'minitest/reporters'
56
- require 'shoulda/context'
57
- require 'mocha/minitest'
58
-
59
- require 'require-prof' if ENV["REQUIRE_PROF"]
60
- require 'elasticsearch'
61
- RequireProf.print_timing_infos if ENV["REQUIRE_PROF"]
62
-
63
- if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
64
- require 'elasticsearch/extensions/test/cluster'
65
- require 'elasticsearch/extensions/test/startup_shutdown'
66
- require 'elasticsearch/extensions/test/profiling' unless JRUBY
67
- end
68
-
69
- Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
70
-
71
- module Minitest
72
- module Assertions
73
- def assert_nothing_raised(*args)
74
- begin
75
- line = __LINE__
76
- yield
77
- rescue RuntimeError => e
78
- raise MiniTest::Assertion, "Exception raised:\n<#{e.class}>", e.backtrace
79
- end
80
- true
81
- end
82
-
83
- def assert_not_nil(object, msg=nil)
84
- msg = message(msg) { "<#{object.inspect}> expected to not be nil" }
85
- assert !object.nil?, msg
86
- end
87
-
88
- def assert_block(*msgs)
89
- assert yield, *msgs
90
- end
91
-
92
- alias :assert_raise :assert_raises
93
- end
94
- end
95
-
96
- module Elasticsearch
97
- module Test
98
- class IntegrationTestCase < ::Minitest::Test
99
- extend Elasticsearch::Extensions::Test::StartupShutdown
100
-
101
- shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
102
- context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8
103
- end if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
104
- end
105
-
106
- module Test
107
- class ProfilingTest < ::Minitest::Test
108
- extend Elasticsearch::Extensions::Test::StartupShutdown
109
- extend Elasticsearch::Extensions::Test::Profiling
110
-
111
- shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
112
- context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8
113
- end unless RUBY_1_8 || JRUBY
114
- end
115
- end