From a3d2d026bdc2396cb00773169e25860f8afb1d9c Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 14 Nov 2024 13:10:37 -0500 Subject: [PATCH] Fixed unit tests on Logstash 8.x Unit tests were failing due to a new requirement to include the `rackup` gem. This commit includes the version of `rackup` prior to the Fiber based rework, as that was causing test failures. This commit also ensures that the request body is rewound before being read in tests. --- CHANGELOG.md | 3 +++ logstash-output-http.gemspec | 5 ++++- spec/outputs/http_spec.rb | 11 +++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a481956..9aea5c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 5.7.1 + - Added new development `rackup` dependency to fix tests + ## 5.7.0 - Added new `ssl_enabled` setting for enabling/disabling the SSL configurations [#144](https://github.com/logstash-plugins/logstash-output-http/pull/144) diff --git a/logstash-output-http.gemspec b/logstash-output-http.gemspec index eec6861..7c308cb 100644 --- a/logstash-output-http.gemspec +++ b/logstash-output-http.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'logstash-output-http' - s.version = '5.7.0' + s.version = '5.7.1' s.licenses = ['Apache License (2.0)'] s.summary = "Sends events to a generic HTTP or HTTPS endpoint" s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program" @@ -25,4 +25,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'logstash-devutils' s.add_development_dependency 'sinatra' s.add_development_dependency 'webrick' + + # Pin to avoid using new Fiber-based implementation that breaks tests here + s.add_development_dependency 'rackup', "< 2.1.0" end diff --git a/spec/outputs/http_spec.rb b/spec/outputs/http_spec.rb index 323fef4..fff075b 100644 --- a/spec/outputs/http_spec.rb +++ b/spec/outputs/http_spec.rb @@ -255,7 +255,7 @@ end let(:last_request) { TestApp.last_request } - let(:body) { last_request.body.read } + let(:body) { read_last_request_body(last_request) } let(:content_type) { last_request.env["CONTENT_TYPE"] } it "should receive the request" do @@ -458,7 +458,7 @@ after { subject.close } let(:last_request) { TestApp.last_request } - let(:last_request_body) { last_request.body.read } + let(:last_request_body) { read_last_request_body(last_request) } let(:event) { LogStash::Event.new("message" => "hello!") } @@ -530,3 +530,10 @@ end if tls_version_enabled_by_default?('TLSv1.3') && JOpenSSL::VERSION > '0.12' # due WEBrick uses OpenSSL end + +# Pre-emptively rewind the retrieval of `last_request.body` - for form based endpoints, the body +# is placed in params, and body is empty, requiring a `rewind` for the body to be available for comparison +def read_last_request_body(last_request) + last_request.body.rewind + last_request.body.read +end \ No newline at end of file