Skip to content

Commit

Permalink
Fix specs after libddwaf update to 1.18.0.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
y9v committed Nov 26, 2024
1 parent df34518 commit e21459e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/appsec/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def tag_and_keep!(scope, waf_result)
scope.trace.keep! if scope.trace

if scope.service_entry_span
scope.service_entry_span.set_tag('appsec.blocked', 'true') if waf_result.actions.include?('block_request')
scope.service_entry_span.set_tag('appsec.blocked', 'true') if waf_result.actions.key?('block_request')
scope.service_entry_span.set_tag('appsec.event', 'true')
end

Expand Down
10 changes: 7 additions & 3 deletions spec/datadog/appsec/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@
let(:with_trace) { true }
let(:with_span) { true }

let(:waf_actions) { [] }
let(:waf_actions) { {} }
let(:waf_result) do
dbl = double

Expand Down Expand Up @@ -410,7 +410,9 @@
end

context 'with block action' do
let(:waf_actions) { ['block'] }
let(:waf_actions) do
{ 'block_request' => { 'grpc_status_code' => '10', 'status_core' => '403', 'type' => 'auto' } }
end

it 'adds appsec.blocked tag to span' do
expect(scope.service_entry_span.send(:meta)['appsec.blocked']).to eq('true')
Expand Down Expand Up @@ -442,7 +444,9 @@
end

context 'with block action' do
let(:waf_actions) { ['block'] }
let(:waf_actions) do
{ 'block_request' => { 'grpc_status_code' => '10', 'status_core' => '403', 'type' => 'auto' } }
end

it 'does not add distributed tags but still add appsec span tags' do
expect(scope.trace).to be nil
Expand Down
15 changes: 10 additions & 5 deletions spec/datadog/appsec/processor/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@
it { expect(telemetry).not_to receive(:error) }
it { expect(matches).to have_attributes(count: 1) }
it { expect(events).to have_attributes(count: 1) }
it { expect(actions).to eq [[]] }
it { expect(actions).to eq [{}] }
end

context 'multiple attacks per run' do
let(:input) { input_scanner.merge(input_sqli) }

it { expect(matches).to have_attributes(count: 1) }
it { expect(events).to have_attributes(count: 2) }
it { expect(actions).to eq [[]] }
it { expect(actions).to eq [{}] }
end

context 'multiple runs' do
Expand All @@ -199,7 +199,7 @@

it { expect(matches).to have_attributes(count: 1) }
it { expect(events).to have_attributes(count: 1) }
it { expect(actions).to eq [[]] }
it { expect(actions).to eq [{}] }
end

context 'different attacks' do
Expand All @@ -215,7 +215,7 @@

it { expect(matches).to have_attributes(count: 2) }
it { expect(events).to have_attributes(count: 2) }
it { expect(actions).to eq [[], []] }
it { expect(actions).to eq [{}, {}] }
end
end

Expand All @@ -235,7 +235,12 @@

it { expect(matches).to have_attributes(count: 1) }
it { expect(events).to have_attributes(count: 1) }
it { expect(actions).to eq [['block']] }

it do
expect(actions).to(
eq([{ 'block_request' => { 'grpc_status_code' => '10', 'status_code' => '403', 'type' => 'auto' } }])
)
end
end

context 'run failed with libddwaf error result' do
Expand Down

0 comments on commit e21459e

Please sign in to comment.