elasticsearch-transport 7.9.0 → 7.11.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.
@@ -0,0 +1,214 @@
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' do
112
+ require 'net/http/persistent'
113
+ expect(headers['x-elastic-client-meta']).to match(regexp)
114
+ meta = "#{meta_header},np=#{Net::HTTP::Persistent::VERSION}"
115
+ expect(headers).to include('x-elastic-client-meta' => meta)
116
+ end
117
+ end
118
+
119
+ context 'using httpclient' do
120
+ let(:adapter) { :httpclient }
121
+
122
+ it 'sets adapter in the meta header' do
123
+ require 'httpclient'
124
+ expect(headers['x-elastic-client-meta']).to match(regexp)
125
+ meta = "#{meta_header},hc=#{HTTPClient::VERSION}"
126
+ expect(headers).to include('x-elastic-client-meta' => meta)
127
+ end
128
+ end
129
+
130
+ context 'using typhoeus' do
131
+ let(:adapter) { :typhoeus }
132
+
133
+ it 'sets adapter in the meta header' do
134
+ require 'typhoeus'
135
+ expect(headers['x-elastic-client-meta']).to match(regexp)
136
+ meta = "#{meta_header},ty=#{Typhoeus::VERSION}"
137
+ expect(headers).to include('x-elastic-client-meta' => meta)
138
+ end
139
+ end
140
+
141
+ unless defined?(JRUBY_VERSION)
142
+ let(:adapter) { :patron }
143
+
144
+ context 'using patron' do
145
+ it 'sets adapter in the meta header' do
146
+ require 'patron'
147
+ expect(headers['x-elastic-client-meta']).to match(regexp)
148
+ meta = "#{meta_header},pt=#{Patron::VERSION}"
149
+ expect(headers).to include('x-elastic-client-meta' => meta)
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ if defined?(JRUBY_VERSION)
156
+ context 'when using manticore' do
157
+ let(:client) do
158
+ Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore)
159
+ end
160
+ let(:subject) { client.transport.connections.first.connection.instance_variable_get("@options")[:headers]}
161
+
162
+ it 'sets manticore in the metaheader' do
163
+ expect(subject['x-elastic-client-meta']).to match(regexp)
164
+ expect(subject['x-elastic-client-meta']).to match(/mc=[0-9.]+/)
165
+ end
166
+ end
167
+ else
168
+ context 'when using curb' do
169
+ let(:client) do
170
+ Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Curb)
171
+ end
172
+
173
+ it 'sets curb in the metaheader' do
174
+ expect(subject['x-elastic-client-meta']).to match(regexp)
175
+ expect(subject['x-elastic-client-meta']).to match(/cl=[0-9.]+/)
176
+ end
177
+ end
178
+ end
179
+
180
+ context 'when using custom transport implementation' do
181
+ class MyTransport
182
+ include Elasticsearch::Transport::Transport::Base
183
+ def initialize(args); end
184
+ end
185
+ let(:client) { Elasticsearch::Client.new(transport_class: MyTransport) }
186
+ let(:subject){ client.instance_variable_get("@arguments")[:transport_options][:headers] }
187
+ let(:meta_header) do
188
+ if jruby?
189
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
190
+ else
191
+ "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION}"
192
+ end
193
+ end
194
+
195
+ it 'doesnae set any info about the implementation in the metaheader' do
196
+ expect(subject['x-elastic-client-meta']).to match(regexp)
197
+ expect(subject).to include('x-elastic-client-meta' => meta_header)
198
+ end
199
+ end
200
+
201
+ context 'when using a different service version' do
202
+ before do
203
+ stub_const("Elastic::META_HEADER_SERVICE_VERSION", [:ent, '8.0.0'])
204
+ end
205
+
206
+ let(:client) { Elasticsearch::Client.new }
207
+
208
+ it 'sets the service version in the metaheader' do
209
+ expect(subject['x-elastic-client-meta']).to match(regexp)
210
+ expect(subject['x-elastic-client-meta']).to start_with('ent=8.0.0')
211
+ end
212
+ end
213
+ end
214
+ end
@@ -57,6 +57,11 @@ class Elasticsearch::Transport::Transport::Connections::ConnectionTest < Minites
57
57
  assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
58
58
  end
59
59
 
60
+ should "return right full url with path when path starts with /" do
61
+ c = Connection.new :host => { :protocol => 'http', :host => 'localhost', :port => '9200', :path => '/foo' }
62
+ assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('/_search', {:foo => 'bar'})
63
+ end
64
+
60
65
  should "have a string representation" do
61
66
  c = Connection.new :host => 'x'
62
67
  assert_match /host: x/, c.to_s
@@ -56,7 +56,7 @@ else
56
56
 
57
57
  should "set body for GET request" do
58
58
  @transport.connections.first.connection.expects(:get).
59
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
59
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
60
60
  :headers => {"Content-Type" => "application/json",
61
61
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
62
62
  @transport.perform_request 'GET', '/', {}, '{"foo":"bar"}'
@@ -64,7 +64,7 @@ else
64
64
 
65
65
  should "set body for PUT request" do
66
66
  @transport.connections.first.connection.expects(:put).
67
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
67
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
68
68
  :headers => {"Content-Type" => "application/json",
69
69
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
70
70
  @transport.perform_request 'PUT', '/', {}, {:foo => 'bar'}
@@ -72,7 +72,7 @@ else
72
72
 
73
73
  should "serialize the request body" do
74
74
  @transport.connections.first.connection.expects(:post).
75
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
75
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
76
76
  :headers => {"Content-Type" => "application/json",
77
77
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
78
78
  @transport.perform_request 'POST', '/', {}, {'foo' => 'bar'}
@@ -80,7 +80,7 @@ else
80
80
 
81
81
  should "set custom headers for PUT request" do
82
82
  @transport.connections.first.connection.expects(:put).
83
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
83
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
84
84
  :headers => {"Content-Type" => "application/json",
85
85
  "User-Agent" => @transport.send(:user_agent_header)}})
86
86
  .returns(stub_everything)
@@ -89,7 +89,7 @@ else
89
89
 
90
90
  should "not serialize a String request body" do
91
91
  @transport.connections.first.connection.expects(:post).
92
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
92
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
93
93
  :headers => {"Content-Type" => "application/json",
94
94
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
95
95
  @transport.serializer.expects(:dump).never
@@ -103,7 +103,7 @@ else
103
103
 
104
104
  transport = Manticore.new :hosts => [ { :host => 'localhost', :port => 8080 } ], :options => options
105
105
 
106
- transport.connections.first.connection.stub("http://localhost:8080//", :body => "\"\"", :headers => {"Content-Type" => "application/x-ndjson",
106
+ transport.connections.first.connection.stub("http://localhost:8080/", :body => "\"\"", :headers => {"Content-Type" => "application/x-ndjson",
107
107
  "User-Agent" => @transport.send(:user_agent_header)}, :code => 200 )
108
108
 
109
109
  response = transport.perform_request 'GET', '/', {}
@@ -124,15 +124,15 @@ else
124
124
  end
125
125
 
126
126
  should "handle HTTP methods" do
127
- @transport.connections.first.connection.expects(:delete).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
127
+ @transport.connections.first.connection.expects(:delete).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
128
128
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
129
- @transport.connections.first.connection.expects(:head).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
129
+ @transport.connections.first.connection.expects(:head).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
130
130
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
131
- @transport.connections.first.connection.expects(:get).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
131
+ @transport.connections.first.connection.expects(:get).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
132
132
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
133
- @transport.connections.first.connection.expects(:put).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
133
+ @transport.connections.first.connection.expects(:put).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
134
134
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
135
- @transport.connections.first.connection.expects(:post).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
135
+ @transport.connections.first.connection.expects(:post).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
136
136
  "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
137
137
 
138
138
  %w| HEAD GET PUT POST DELETE |.each { |method| @transport.perform_request method, '/' }
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.9.0
4
+ version: 7.11.0
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-08-18 00:00:00.000000000 Z
11
+ date: 2021-02-10 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: []
@@ -391,6 +391,7 @@ files:
391
391
  - spec/elasticsearch/connections/selector_spec.rb
392
392
  - spec/elasticsearch/transport/base_spec.rb
393
393
  - spec/elasticsearch/transport/client_spec.rb
394
+ - spec/elasticsearch/transport/meta_header_spec.rb
394
395
  - spec/elasticsearch/transport/sniffer_spec.rb
395
396
  - spec/spec_helper.rb
396
397
  - test/integration/transport_test.rb
@@ -427,7 +428,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
427
428
  - !ruby/object:Gem::Version
428
429
  version: '0'
429
430
  requirements: []
430
- rubygems_version: 3.1.2
431
+ rubygems_version: 3.1.4
431
432
  signing_key:
432
433
  specification_version: 4
433
434
  summary: Ruby client for Elasticsearch.
@@ -436,6 +437,7 @@ test_files:
436
437
  - spec/elasticsearch/connections/selector_spec.rb
437
438
  - spec/elasticsearch/transport/base_spec.rb
438
439
  - spec/elasticsearch/transport/client_spec.rb
440
+ - spec/elasticsearch/transport/meta_header_spec.rb
439
441
  - spec/elasticsearch/transport/sniffer_spec.rb
440
442
  - spec/spec_helper.rb
441
443
  - test/integration/transport_test.rb