Skip to content

Commit

Permalink
[GEM] Handle 413 responses for product check
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Jan 25, 2022
1 parent 480433e commit 77bc88f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion elasticsearch/lib/elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def verify_elasticsearch
begin
response = elasticsearch_validation_request
rescue Elasticsearch::Transport::Transport::Errors::Unauthorized,
Elasticsearch::Transport::Transport::Errors::Forbidden
Elasticsearch::Transport::Transport::Errors::Forbidden,
Elasticsearch::Transport::Transport::Errors::RequestEntityTooLarge
@verified = true
warn(SECURITY_PRIVILEGES_VALIDATION_WARNING)
return
Expand Down
21 changes: 21 additions & 0 deletions elasticsearch/spec/unit/elasticsearch_product_validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ def valid_requests_and_expectations
end
end

context 'When Elasticsearch replies with status 403' do
let(:status) { 413 }
let(:body) { {}.to_json }

it 'Verifies the request but shows a warning' do
stderr = $stderr
fake_stderr = StringIO.new
$stderr = fake_stderr

verify_request_stub
count_request_stub

valid_requests_and_expectations

fake_stderr.rewind
expect(fake_stderr.string).to eq("#{Elasticsearch::SECURITY_PRIVILEGES_VALIDATION_WARNING}\n")
ensure
$stderr = stderr
end
end

context 'When the Elasticsearch version is >= 7.14' do
context 'With a valid Elasticsearch response' do
let(:body) { { 'version' => { 'number' => '7.14.0' } }.to_json }
Expand Down

0 comments on commit 77bc88f

Please sign in to comment.