Skip to content

Commit 5d351a0

Browse files
committed
[GEM] Handle 413 responses for product check
1 parent 427d373 commit 5d351a0

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

elasticsearch/lib/elasticsearch.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ def verify_elasticsearch
8686
begin
8787
response = elasticsearch_validation_request
8888
rescue Elastic::Transport::Transport::Errors::Unauthorized,
89-
Elastic::Transport::Transport::Errors::Forbidden
89+
Elastic::Transport::Transport::Errors::Forbidden,
90+
Elastic::Transport::Transport::Errors::RequestEntityTooLarge
9091
@verified = true
9192
warn(SECURITY_PRIVILEGES_VALIDATION_WARNING)
9293
return
93-
rescue Elastic::Transport::Transport::Error => e
94+
rescue Elastic::Transport::Transport::Error
9495
warn(VALIDATION_WARNING)
9596
return
9697
end

elasticsearch/spec/unit/elasticsearch_product_validation_spec.rb

+4-11
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def valid_requests_and_expectations
9898
let(:status) { 413 }
9999
let(:body) { {}.to_json }
100100

101-
it 'Does not verify the request and shows a warning' do
101+
it 'Verifies the request and shows a warning' do
102102
stderr = $stderr
103103
fake_stderr = StringIO.new
104104
$stderr = fake_stderr
@@ -107,18 +107,11 @@ def valid_requests_and_expectations
107107
assert_not_requested :get, host
108108
verify_request_stub
109109
expect { client.info }.to raise_error Elastic::Transport::Transport::Errors::RequestEntityTooLarge
110-
assert_not_requested :post, "#{host}/_count"
111-
expect(client.instance_variable_get('@verified')).to be false
110+
expect(client.instance_variable_get('@verified')).to be true
112111

113112
fake_stderr.rewind
114-
expect(fake_stderr.string)
115-
.to eq(
116-
<<~MSG
117-
The client is unable to verify that the server is \
118-
Elasticsearch. Some functionality may not be compatible \
119-
if the server is running an unsupported product.
120-
MSG
121-
)
113+
expect(fake_stderr.string.delete("\n"))
114+
.to eq(Elasticsearch::SECURITY_PRIVILEGES_VALIDATION_WARNING)
122115
ensure
123116
$stderr = stderr
124117
end

0 commit comments

Comments
 (0)