elasticsearch-transport 5.0.5 → 6.8.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.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +5 -0
  3. data/README.md +88 -34
  4. data/Rakefile +14 -17
  5. data/elasticsearch-transport.gemspec +44 -63
  6. data/lib/elasticsearch/transport/client.rb +120 -61
  7. data/lib/elasticsearch/transport/redacted.rb +79 -0
  8. data/lib/elasticsearch/transport/transport/base.rb +28 -14
  9. data/lib/elasticsearch/transport/transport/connections/collection.rb +4 -0
  10. data/lib/elasticsearch/transport/transport/connections/connection.rb +5 -1
  11. data/lib/elasticsearch/transport/transport/connections/selector.rb +4 -0
  12. data/lib/elasticsearch/transport/transport/errors.rb +4 -0
  13. data/lib/elasticsearch/transport/transport/http/curb.rb +7 -2
  14. data/lib/elasticsearch/transport/transport/http/faraday.rb +11 -8
  15. data/lib/elasticsearch/transport/transport/http/manticore.rb +6 -1
  16. data/lib/elasticsearch/transport/transport/response.rb +4 -0
  17. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +4 -0
  18. data/lib/elasticsearch/transport/transport/sniffer.rb +31 -3
  19. data/lib/elasticsearch/transport/version.rb +5 -1
  20. data/lib/elasticsearch/transport.rb +5 -0
  21. data/lib/elasticsearch-transport.rb +4 -0
  22. data/spec/elasticsearch/transport/base_spec.rb +260 -0
  23. data/spec/elasticsearch/transport/client_spec.rb +1025 -0
  24. data/spec/elasticsearch/transport/sniffer_spec.rb +269 -0
  25. data/spec/spec_helper.rb +65 -0
  26. data/test/integration/transport_test.rb +9 -5
  27. data/test/profile/client_benchmark_test.rb +23 -25
  28. data/test/test_helper.rb +10 -0
  29. data/test/unit/connection_collection_test.rb +4 -0
  30. data/test/unit/connection_selector_test.rb +4 -0
  31. data/test/unit/connection_test.rb +4 -0
  32. data/test/unit/response_test.rb +5 -1
  33. data/test/unit/serializer_test.rb +4 -0
  34. data/test/unit/transport_base_test.rb +21 -1
  35. data/test/unit/transport_curb_test.rb +12 -0
  36. data/test/unit/transport_faraday_test.rb +16 -0
  37. data/test/unit/transport_manticore_test.rb +11 -0
  38. metadata +82 -84
  39. data/test/integration/client_test.rb +0 -237
  40. data/test/unit/client_test.rb +0 -366
  41. data/test/unit/sniffer_test.rb +0 -179
@@ -0,0 +1,260 @@
1
+ # Licensed to Elasticsearch B.V under one or more agreements.
2
+ # Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
+ # See the LICENSE file in the project root for more information
4
+
5
+ # Licensed to Elasticsearch B.V. under one or more contributor
6
+ # license agreements. See the NOTICE file distributed with
7
+ # this work for additional information regarding copyright
8
+ # ownership. Elasticsearch B.V. licenses this file to you under
9
+ # the Apache License, Version 2.0 (the "License"); you may
10
+ # not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing,
16
+ # software distributed under the License is distributed on an
17
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18
+ # KIND, either express or implied. See the License for the
19
+ # specific language governing permissions and limitations
20
+ # under the License.
21
+
22
+ require 'spec_helper'
23
+
24
+ describe Elasticsearch::Transport::Transport::Base do
25
+ context 'when a host is printed in a logged message' do
26
+ shared_examples_for 'a redacted string' do
27
+ let(:client) do
28
+ Elasticsearch::Transport::Client.new(arguments)
29
+ end
30
+
31
+ let(:logger) do
32
+ double('logger', error?: true, error: '')
33
+ end
34
+
35
+ it 'does not include the password in the logged string' do
36
+ expect(logger).not_to receive(:error).with(/secret_password/)
37
+
38
+ expect {
39
+ client.cluster.stats
40
+ }.to raise_exception(Faraday::ConnectionFailed)
41
+ end
42
+
43
+ it 'replaces the password with the string \'REDACTED\'' do
44
+ expect(logger).to receive(:error).with(/REDACTED/)
45
+ expect {
46
+ client.cluster.stats
47
+ }.to raise_exception(Faraday::ConnectionFailed)
48
+ end
49
+ end
50
+
51
+ context 'when the user and password are provided as separate arguments' do
52
+ let(:arguments) do
53
+ { hosts: 'fake',
54
+ logger: logger,
55
+ password: 'secret_password',
56
+ user: 'test' }
57
+ end
58
+
59
+ it_behaves_like 'a redacted string'
60
+ end
61
+
62
+ context 'when the user and password are provided in the string URI' do
63
+ let(:arguments) do
64
+ { hosts: 'https://test:secret_password@fake_local_elasticsearch',
65
+ logger: logger }
66
+ end
67
+
68
+ it_behaves_like 'a redacted string'
69
+ end
70
+
71
+ context 'when the user and password are provided in the URI object' do
72
+ let(:arguments) do
73
+ { hosts: URI.parse('https://test:secret_password@fake_local_elasticsearch'),
74
+ logger: logger }
75
+ end
76
+
77
+ it_behaves_like 'a redacted string'
78
+ end
79
+ end
80
+
81
+ context 'when reload_on_failure is true and and hosts are unreachable' do
82
+
83
+ let(:client) do
84
+ Elasticsearch::Transport::Client.new(arguments)
85
+ end
86
+
87
+ let(:arguments) do
88
+ {
89
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
90
+ reload_on_failure: true,
91
+ sniffer_timeout: 5
92
+ }
93
+ end
94
+
95
+ it 'raises an exception' do
96
+ expect {
97
+ client.info
98
+ }.to raise_exception(Faraday::ConnectionFailed)
99
+ end
100
+ end
101
+
102
+ context 'when the client has `retry_on_failure` set to an integer' do
103
+
104
+ let(:client) do
105
+ Elasticsearch::Transport::Client.new(arguments)
106
+ end
107
+
108
+ let(:arguments) do
109
+ {
110
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
111
+ retry_on_failure: 2
112
+ }
113
+ end
114
+
115
+ context 'when `perform_request` is called without a `retry_on_failure` option value' do
116
+
117
+ before do
118
+ expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original
119
+ end
120
+
121
+ it 'uses the client `retry_on_failure` value' do
122
+ expect {
123
+ client.transport.perform_request('GET', '/info')
124
+ }.to raise_exception(Faraday::ConnectionFailed)
125
+ end
126
+ end
127
+
128
+ context 'when `perform_request` is called with a `retry_on_failure` option value' do
129
+
130
+ before do
131
+ expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
132
+ end
133
+
134
+ it 'uses the option `retry_on_failure` value' do
135
+ expect {
136
+ client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
137
+ }.to raise_exception(Faraday::ConnectionFailed)
138
+ end
139
+ end
140
+ end
141
+
142
+ context 'when the client has `retry_on_failure` set to true' do
143
+
144
+ let(:client) do
145
+ Elasticsearch::Transport::Client.new(arguments)
146
+ end
147
+
148
+ let(:arguments) do
149
+ {
150
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
151
+ retry_on_failure: true
152
+ }
153
+ end
154
+
155
+ context 'when `perform_request` is called without a `retry_on_failure` option value' do
156
+
157
+ before do
158
+ expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original
159
+ end
160
+
161
+ it 'uses the default `MAX_RETRIES` value' do
162
+ expect {
163
+ client.transport.perform_request('GET', '/info')
164
+ }.to raise_exception(Faraday::ConnectionFailed)
165
+ end
166
+ end
167
+
168
+ context 'when `perform_request` is called with a `retry_on_failure` option value' do
169
+
170
+ before do
171
+ expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
172
+ end
173
+
174
+ it 'uses the option `retry_on_failure` value' do
175
+ expect {
176
+ client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
177
+ }.to raise_exception(Faraday::ConnectionFailed)
178
+ end
179
+ end
180
+ end
181
+
182
+ context 'when the client has `retry_on_failure` set to false' do
183
+
184
+ let(:client) do
185
+ Elasticsearch::Transport::Client.new(arguments)
186
+ end
187
+
188
+ let(:arguments) do
189
+ {
190
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
191
+ retry_on_failure: false
192
+ }
193
+ end
194
+
195
+ context 'when `perform_request` is called without a `retry_on_failure` option value' do
196
+
197
+ before do
198
+ expect(client.transport).to receive(:get_connection).once.and_call_original
199
+ end
200
+
201
+ it 'does not retry' do
202
+ expect {
203
+ client.transport.perform_request('GET', '/info')
204
+ }.to raise_exception(Faraday::ConnectionFailed)
205
+ end
206
+ end
207
+
208
+ context 'when `perform_request` is called with a `retry_on_failure` option value' do
209
+
210
+ before do
211
+ expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
212
+ end
213
+
214
+ it 'uses the option `retry_on_failure` value' do
215
+ expect {
216
+ client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
217
+ }.to raise_exception(Faraday::ConnectionFailed)
218
+ end
219
+ end
220
+ end
221
+
222
+ context 'when the client has no `retry_on_failure` set' do
223
+
224
+ let(:client) do
225
+ Elasticsearch::Transport::Client.new(arguments)
226
+ end
227
+
228
+ let(:arguments) do
229
+ {
230
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
231
+ }
232
+ end
233
+
234
+ context 'when `perform_request` is called without a `retry_on_failure` option value' do
235
+
236
+ before do
237
+ expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
238
+ end
239
+
240
+ it 'does not retry' do
241
+ expect {
242
+ client.transport.perform_request('GET', '/info')
243
+ }.to raise_exception(Faraday::ConnectionFailed)
244
+ end
245
+ end
246
+
247
+ context 'when `perform_request` is called with a `retry_on_failure` option value' do
248
+
249
+ before do
250
+ expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
251
+ end
252
+
253
+ it 'uses the option `retry_on_failure` value' do
254
+ expect {
255
+ client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
256
+ }.to raise_exception(Faraday::ConnectionFailed)
257
+ end
258
+ end
259
+ end
260
+ end