Skip to content

Commit

Permalink
Handle old rack-test
Browse files Browse the repository at this point in the history
Prior to 0.7 an argument is lacking to generate multipart requests
without uploading a file.
  • Loading branch information
lloeki committed Oct 11, 2022
1 parent 2990268 commit 052644c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
32 changes: 17 additions & 15 deletions spec/datadog/appsec/contrib/rack/integration_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,25 @@
it_behaves_like 'a trace with AppSec events'
end

context 'with an event-triggering request in multipart/form-data body' do
let(:params) { Rack::Test::Utils.build_multipart({ q: '1 OR 1;' }, true, true) }
let(:headers) { { 'CONTENT_TYPE' => "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}" } }

let(:middlewares) do
[
Datadog::Tracing::Contrib::Rack::TraceMiddleware,
Datadog::AppSec::Contrib::Rack::RequestMiddleware,
Datadog::AppSec::Contrib::Rack::RequestBodyMiddleware,
]
end
unless Gem.loaded_specs['rack-test'].version.to_s < '0.7'
context 'with an event-triggering request in multipart/form-data body' do
let(:params) { Rack::Test::Utils.build_multipart({ q: '1 OR 1;' }, true, true) }
let(:headers) { { 'CONTENT_TYPE' => "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}" } }

let(:middlewares) do
[
Datadog::Tracing::Contrib::Rack::TraceMiddleware,
Datadog::AppSec::Contrib::Rack::RequestMiddleware,
Datadog::AppSec::Contrib::Rack::RequestBodyMiddleware,
]
end

it { is_expected.to be_ok }
it { is_expected.to be_ok }

it_behaves_like 'a POST 200 span'
it_behaves_like 'a trace with AppSec tags'
it_behaves_like 'a trace with AppSec events'
it_behaves_like 'a POST 200 span'
it_behaves_like 'a trace with AppSec tags'
it_behaves_like 'a trace with AppSec events'
end
end

context 'with an event-triggering request as JSON' do
Expand Down
16 changes: 9 additions & 7 deletions spec/datadog/appsec/contrib/rails/integration_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,17 @@ def success
it_behaves_like 'a trace with AppSec events'
end

context 'with an event-triggering request in multipart/form-data body' do
let(:params) { Rack::Test::Utils.build_multipart({ q: '1 OR 1;' }, true, true) }
let(:headers) { { 'CONTENT_TYPE' => "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}" } }
unless Gem.loaded_specs['rack-test'].version.to_s < '0.7'
context 'with an event-triggering request in multipart/form-data body' do
let(:params) { Rack::Test::Utils.build_multipart({ q: '1 OR 1;' }, true, true) }
let(:headers) { { 'CONTENT_TYPE' => "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}" } }

it { is_expected.to be_ok }
it { is_expected.to be_ok }

it_behaves_like 'a POST 200 span'
it_behaves_like 'a trace with AppSec tags'
it_behaves_like 'a trace with AppSec events'
it_behaves_like 'a POST 200 span'
it_behaves_like 'a trace with AppSec tags'
it_behaves_like 'a trace with AppSec events'
end
end

context 'with an event-triggering request as JSON' do
Expand Down
16 changes: 9 additions & 7 deletions spec/datadog/appsec/contrib/sinatra/integration_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,17 @@
it_behaves_like 'a trace with AppSec events'
end

context 'with an event-triggering request in multipart/form-data body' do
let(:params) { Rack::Test::Utils.build_multipart({ q: '1 OR 1;' }, true, true) }
let(:headers) { { 'CONTENT_TYPE' => "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}" } }
unless Gem.loaded_specs['rack-test'].version.to_s < '0.7'
context 'with an event-triggering request in multipart/form-data body' do
let(:params) { Rack::Test::Utils.build_multipart({ q: '1 OR 1;' }, true, true) }
let(:headers) { { 'CONTENT_TYPE' => "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}" } }

it { is_expected.to be_ok }
it { is_expected.to be_ok }

it_behaves_like 'a POST 200 span'
it_behaves_like 'a trace with AppSec tags'
it_behaves_like 'a trace with AppSec events'
it_behaves_like 'a POST 200 span'
it_behaves_like 'a trace with AppSec tags'
it_behaves_like 'a trace with AppSec events'
end
end

context 'with an event-triggering request as JSON' do
Expand Down

0 comments on commit 052644c

Please sign in to comment.