File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed
spec/datadog/appsec/contrib Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 4
4
require 'faraday'
5
5
6
6
RSpec . describe 'AppSec Faraday integration' do
7
- let ( :waf_response_double ) { double ( match? : false ) }
8
- let ( :active_context ) { stub_const ( ' Datadog::AppSec::Context' , double ( run_rasp : waf_response_double ) ) }
7
+ let ( :context ) { instance_double ( Datadog :: AppSec :: Context , run_rasp : waf_response ) }
8
+ let ( :waf_response ) { instance_double ( Datadog ::AppSec ::SecurityEngine :: Result :: Ok , match? : false ) }
9
9
10
10
let ( :client ) do
11
11
::Faraday . new ( 'http://example.com' ) do |faraday |
21
21
c . appsec . instrument :faraday
22
22
end
23
23
24
- allow ( Datadog ::AppSec ) . to receive ( :active_context ) . and_return ( active_context )
24
+ allow ( Datadog ::AppSec ) . to receive ( :active_context ) . and_return ( context )
25
25
end
26
26
27
27
after do
41
41
end
42
42
43
43
context 'when there is no active context' do
44
- let ( :active_context ) { nil }
44
+ let ( :context ) { nil }
45
45
46
46
it 'does not call waf when making a request' do
47
47
expect ( Datadog ::AppSec . active_context ) . not_to receive ( :run_rasp )
56
56
end
57
57
58
58
it 'calls waf with correct arguments when making a request' do
59
- expect ( active_context ) . to (
59
+ expect ( Datadog :: AppSec . active_context ) . to (
60
60
receive ( :run_rasp ) . with (
61
61
Datadog ::AppSec ::Ext ::RASP_SSRF ,
62
62
{ } ,
Original file line number Diff line number Diff line change 97
97
spans . find { |s | s . name == 'rack.request' }
98
98
end
99
99
100
- context 'when RASP check was positive for http request ' do
100
+ context 'when request params contain SSRF attack ' do
101
101
before do
102
102
get ( '/ssrf' , { 'url' => '169.254.169.254' } , { 'REMOTE_ADDR' => '127.0.0.1' } )
103
103
end
104
104
105
105
it { expect ( last_response ) . to be_forbidden }
106
106
end
107
107
108
- context 'when RASP check was negative for http request ' do
108
+ context 'when request params do not contain SSRF attack ' do
109
109
before do
110
110
get ( '/ssrf' , { 'url' => 'example.com' } , { 'REMOTE_ADDR' => '127.0.0.1' } )
111
111
end
You can’t perform that action at this time.
0 commit comments