elasticsearch-transport 7.10.0 → 7.11.2

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.
@@ -0,0 +1,265 @@
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::Transport::Client do
21
+ context 'meta-header' do
22
+ let(:subject) { client.transport.connections.first.connection.headers }
23
+ let(:client) { described_class.new }
24
+ let(:regexp) { /^[a-z]{1,}=[a-z0-9.\-]{1,}(?:,[a-z]{1,}=[a-z0-9._\-]+)*$/ }
25
+ let(:adapter) { :net_http }
26
+ let(:adapter_code) { "nh=#{defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}" }
27
+ let(:meta_header) do
28
+ if jruby?
29
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
30
+ else
31
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
32
+ end
33
+ end
34
+
35
+ context 'client_meta_version' do
36
+ let(:version) { ['7.1.0-alpha', '7.11.0.pre.1', '8.0.0-beta', '8.0.0.beta.2']}
37
+
38
+ it 'converts the version to X.X.Xp' do
39
+ expect(client.send(:client_meta_version, '7.0.0-alpha')).to eq('7.0.0p')
40
+ expect(client.send(:client_meta_version, '7.11.0.pre.1')).to eq('7.11.0p')
41
+ expect(client.send(:client_meta_version, '8.1.0-beta')).to eq('8.1.0p')
42
+ expect(client.send(:client_meta_version, '8.0.0.beta.2')).to eq('8.0.0p')
43
+ expect(client.send(:client_meta_version, '12.16.4.pre')).to eq('12.16.4p')
44
+ end
45
+ end
46
+
47
+ # We are testing this method in the previous block, so now using it inside the test to make the
48
+ # Elasticsearch version in the meta header string dynamic
49
+ def meta_version
50
+ client.send(:client_meta_version, Elasticsearch::VERSION)
51
+ end
52
+
53
+ context 'single use of meta header' do
54
+ let(:client) do
55
+ described_class.new(adapter: adapter).tap do |klient|
56
+ allow(klient).to receive(:__build_connections)
57
+ end
58
+ end
59
+
60
+ it 'x-elastic-client-header value matches regexp' do
61
+ expect(subject['x-elastic-client-meta']).to match(regexp)
62
+ expect(subject).to include('x-elastic-client-meta' => meta_header)
63
+ end
64
+ end
65
+
66
+ context 'when using user-agent headers' do
67
+ let(:client) do
68
+ transport_options = { headers: { user_agent: 'My Ruby App' } }
69
+ described_class.new(transport_options: transport_options, adapter: adapter).tap do |klient|
70
+ allow(klient).to receive(:__build_connections)
71
+ end
72
+ end
73
+
74
+ it 'is friendly to previously set headers' do
75
+ expect(subject).to include(user_agent: 'My Ruby App')
76
+ expect(subject['x-elastic-client-meta']).to match(regexp)
77
+ expect(subject).to include('x-elastic-client-meta' => meta_header)
78
+ end
79
+ end
80
+
81
+ context 'when using API Key' do
82
+ let(:client) do
83
+ described_class.new(api_key: 'an_api_key', adapter: adapter)
84
+ end
85
+
86
+ let(:authorization_header) do
87
+ client.transport.connections.first.connection.headers['Authorization']
88
+ end
89
+
90
+ it 'adds the ApiKey header to the connection' do
91
+ expect(authorization_header).to eq('ApiKey an_api_key')
92
+ expect(subject['x-elastic-client-meta']).to match(regexp)
93
+ expect(subject).to include('x-elastic-client-meta' => meta_header)
94
+ end
95
+ end
96
+
97
+ context 'adapters' do
98
+ let(:meta_header) do
99
+ if jruby?
100
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION}"
101
+ else
102
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION}"
103
+ end
104
+ end
105
+ let(:client) { described_class.new(adapter: adapter) }
106
+ let(:headers) { client.transport.connections.first.connection.headers }
107
+
108
+ context 'using net/http/persistent' do
109
+ let(:adapter) { :net_http_persistent }
110
+
111
+ it 'sets adapter in the meta header version to 0 when not loaded' do
112
+ fork {
113
+ expect(headers['x-elastic-client-meta']).to match(regexp)
114
+ meta = "#{meta_header},np=0"
115
+ expect(headers).to include('x-elastic-client-meta' => meta)
116
+ }
117
+ end unless jruby?
118
+
119
+ it 'sets adapter in the meta header' do
120
+ require 'net/http/persistent'
121
+ expect(headers['x-elastic-client-meta']).to match(regexp)
122
+ meta = "#{meta_header},np=#{Net::HTTP::Persistent::VERSION}"
123
+ expect(headers).to include('x-elastic-client-meta' => meta)
124
+ end
125
+ end
126
+
127
+ context 'using httpclient' do
128
+ let(:adapter) { :httpclient }
129
+
130
+ it 'sets adapter in the meta header version to 0 when not loaded' do
131
+ fork {
132
+ expect(headers['x-elastic-client-meta']).to match(regexp)
133
+ meta = "#{meta_header},hc=0"
134
+ expect(headers).to include('x-elastic-client-meta' => meta)
135
+ }
136
+ end unless jruby?
137
+
138
+ it 'sets adapter in the meta header' do
139
+ require 'httpclient'
140
+ expect(headers['x-elastic-client-meta']).to match(regexp)
141
+ meta = "#{meta_header},hc=#{HTTPClient::VERSION}"
142
+ expect(headers).to include('x-elastic-client-meta' => meta)
143
+ end
144
+ end
145
+
146
+ context 'using typhoeus' do
147
+ let(:adapter) { :typhoeus }
148
+
149
+ it 'sets adapter in the meta header version to 0 when not loaded' do
150
+ fork {
151
+ expect(headers['x-elastic-client-meta']).to match(regexp)
152
+ meta = "#{meta_header},ty=0"
153
+ expect(headers).to include('x-elastic-client-meta' => meta)
154
+ }
155
+ end unless jruby?
156
+
157
+ it 'sets adapter in the meta header' do
158
+ require 'typhoeus'
159
+ expect(headers['x-elastic-client-meta']).to match(regexp)
160
+ meta = "#{meta_header},ty=#{Typhoeus::VERSION}"
161
+ expect(headers).to include('x-elastic-client-meta' => meta)
162
+ end
163
+ end
164
+
165
+ unless jruby?
166
+ let(:adapter) { :patron }
167
+
168
+ context 'using patron without requiring it' do
169
+ it 'sets adapter in the meta header version to 0 when not loaded' do
170
+ fork {
171
+ expect(headers['x-elastic-client-meta']).to match(regexp)
172
+ meta = "#{meta_header},pt=0"
173
+ expect(headers).to include('x-elastic-client-meta' => meta)
174
+ }
175
+ end
176
+ end
177
+
178
+ context 'using patron' do
179
+ it 'sets adapter in the meta header' do
180
+ require 'patron'
181
+ expect(headers['x-elastic-client-meta']).to match(regexp)
182
+ meta = "#{meta_header},pt=#{Patron::VERSION}"
183
+ expect(headers).to include('x-elastic-client-meta' => meta)
184
+ end
185
+ end
186
+ end
187
+
188
+ context 'using other' do
189
+ let(:adapter) { :some_other_adapter }
190
+
191
+ it 'sets adapter in the meta header without requiring' do
192
+ Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
193
+ expect(headers['x-elastic-client-meta']).to match(regexp)
194
+ expect(headers).to include('x-elastic-client-meta' => meta_header)
195
+ end
196
+
197
+ it 'sets adapter in the meta header' do
198
+ require 'net/http/persistent'
199
+ Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
200
+ expect(headers['x-elastic-client-meta']).to match(regexp)
201
+ expect(headers).to include('x-elastic-client-meta' => meta_header)
202
+ end
203
+ end
204
+ end
205
+
206
+ if defined?(JRUBY_VERSION)
207
+ context 'when using manticore' do
208
+ let(:client) do
209
+ Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore)
210
+ end
211
+ let(:subject) { client.transport.connections.first.connection.instance_variable_get("@options")[:headers]}
212
+
213
+ it 'sets manticore in the metaheader' do
214
+ expect(subject['x-elastic-client-meta']).to match(regexp)
215
+ expect(subject['x-elastic-client-meta']).to match(/mc=[0-9.]+/)
216
+ end
217
+ end
218
+ else
219
+ context 'when using curb' do
220
+ let(:client) do
221
+ Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Curb)
222
+ end
223
+
224
+ it 'sets curb in the metaheader' do
225
+ expect(subject['x-elastic-client-meta']).to match(regexp)
226
+ expect(subject['x-elastic-client-meta']).to match(/cl=[0-9.]+/)
227
+ end
228
+ end
229
+ end
230
+
231
+ context 'when using custom transport implementation' do
232
+ class MyTransport
233
+ include Elasticsearch::Transport::Transport::Base
234
+ def initialize(args); end
235
+ end
236
+ let(:client) { Elasticsearch::Client.new(transport_class: MyTransport) }
237
+ let(:subject){ client.instance_variable_get("@arguments")[:transport_options][:headers] }
238
+ let(:meta_header) do
239
+ if jruby?
240
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
241
+ else
242
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION}"
243
+ end
244
+ end
245
+
246
+ it 'doesnae set any info about the implementation in the metaheader' do
247
+ expect(subject['x-elastic-client-meta']).to match(regexp)
248
+ expect(subject).to include('x-elastic-client-meta' => meta_header)
249
+ end
250
+ end
251
+
252
+ context 'when using a different service version' do
253
+ before do
254
+ stub_const("Elastic::META_HEADER_SERVICE_VERSION", [:ent, '8.0.0'])
255
+ end
256
+
257
+ let(:client) { Elasticsearch::Client.new }
258
+
259
+ it 'sets the service version in the metaheader' do
260
+ expect(subject['x-elastic-client-meta']).to match(regexp)
261
+ expect(subject['x-elastic-client-meta']).to start_with('ent=8.0.0')
262
+ end
263
+ end
264
+ end
265
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.10.0
4
+ version: 7.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -355,7 +355,7 @@ dependencies:
355
355
  description: 'Ruby client for Elasticsearch. See the `elasticsearch` gem for full
356
356
  integration.
357
357
 
358
- '
358
+ '
359
359
  email:
360
360
  - karel.minarik@elasticsearch.org
361
361
  executables: []
@@ -373,6 +373,7 @@ files:
373
373
  - lib/elasticsearch-transport.rb
374
374
  - lib/elasticsearch/transport.rb
375
375
  - lib/elasticsearch/transport/client.rb
376
+ - lib/elasticsearch/transport/meta_header.rb
376
377
  - lib/elasticsearch/transport/redacted.rb
377
378
  - lib/elasticsearch/transport/transport/base.rb
378
379
  - lib/elasticsearch/transport/transport/connections/collection.rb
@@ -391,6 +392,7 @@ files:
391
392
  - spec/elasticsearch/connections/selector_spec.rb
392
393
  - spec/elasticsearch/transport/base_spec.rb
393
394
  - spec/elasticsearch/transport/client_spec.rb
395
+ - spec/elasticsearch/transport/meta_header_spec.rb
394
396
  - spec/elasticsearch/transport/sniffer_spec.rb
395
397
  - spec/spec_helper.rb
396
398
  - test/integration/transport_test.rb
@@ -427,7 +429,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
427
429
  - !ruby/object:Gem::Version
428
430
  version: '0'
429
431
  requirements: []
430
- rubygems_version: 3.1.2
432
+ rubygems_version: 3.1.4
431
433
  signing_key:
432
434
  specification_version: 4
433
435
  summary: Ruby client for Elasticsearch.
@@ -436,6 +438,7 @@ test_files:
436
438
  - spec/elasticsearch/connections/selector_spec.rb
437
439
  - spec/elasticsearch/transport/base_spec.rb
438
440
  - spec/elasticsearch/transport/client_spec.rb
441
+ - spec/elasticsearch/transport/meta_header_spec.rb
439
442
  - spec/elasticsearch/transport/sniffer_spec.rb
440
443
  - spec/spec_helper.rb
441
444
  - test/integration/transport_test.rb