|
65 | 65 | processor.finalize
|
66 | 66 | end
|
67 | 67 |
|
68 |
| - it 'calls waf with correct arguments when querying using .where' do |
69 |
| - expected_db_statement = if PlatformHelpers.jruby? |
70 |
| - 'SELECT "users".* FROM "users" WHERE "users"."name" = ?' |
71 |
| - else |
72 |
| - 'SELECT "users".* FROM "users" WHERE "users"."name" = $1' |
73 |
| - end |
74 |
| - |
75 |
| - expect(Datadog::AppSec.active_context).to( |
76 |
| - receive(:run_rasp).with( |
77 |
| - Datadog::AppSec::Ext::RASP_SQLI, |
78 |
| - {}, |
79 |
| - { |
80 |
| - 'server.db.statement' => expected_db_statement, |
81 |
| - 'server.db.system' => 'postgresql' |
82 |
| - }, |
83 |
| - Datadog.configuration.appsec.waf_timeout |
84 |
| - ).and_call_original |
85 |
| - ) |
86 |
| - |
87 |
| - User.where(name: 'Bob').to_a |
88 |
| - end |
| 68 | + context 'when RASP is disabled' do |
| 69 | + before do |
| 70 | + allow(Datadog::AppSec).to receive(:rasp_enabled?).and_return(false) |
| 71 | + end |
89 | 72 |
|
90 |
| - it 'calls waf with correct arguments when querying using .find_by_sql' do |
91 |
| - expect(Datadog::AppSec.active_context).to( |
92 |
| - receive(:run_rasp).with( |
93 |
| - Datadog::AppSec::Ext::RASP_SQLI, |
94 |
| - {}, |
95 |
| - { |
96 |
| - 'server.db.statement' => "SELECT * FROM users WHERE name = 'Bob'", |
97 |
| - 'server.db.system' => 'postgresql' |
98 |
| - }, |
99 |
| - Datadog.configuration.appsec.waf_timeout |
100 |
| - ).and_call_original |
101 |
| - ) |
102 |
| - |
103 |
| - User.find_by_sql("SELECT * FROM users WHERE name = 'Bob'").to_a |
| 73 | + it 'does not call waf when querying using .where' do |
| 74 | + expect(Datadog::AppSec.active_context).not_to receive(:run_rasp) |
| 75 | + |
| 76 | + User.where(name: 'Bob').to_a |
| 77 | + end |
| 78 | + |
| 79 | + it 'does not call waf when querying using .find_by_sql' do |
| 80 | + expect(Datadog::AppSec.active_context).not_to receive(:run_rasp) |
| 81 | + |
| 82 | + User.find_by_sql("SELECT * FROM users WHERE name = 'Bob'").to_a |
| 83 | + end |
104 | 84 | end
|
105 | 85 |
|
106 |
| - it 'adds an event to processor context if waf result is a match' do |
107 |
| - result = Datadog::AppSec::SecurityEngine::Result::Match.new( |
108 |
| - events: [], actions: {}, derivatives: {}, timeout: false, duration_ns: 0, duration_ext_ns: 0 |
109 |
| - ) |
| 86 | + context 'when RASP is enabled' do |
| 87 | + before do |
| 88 | + allow(Datadog::AppSec).to receive(:rasp_enabled?).and_return(true) |
| 89 | + end |
| 90 | + |
| 91 | + it 'calls waf with correct arguments when querying using .where' do |
| 92 | + expected_db_statement = if PlatformHelpers.jruby? |
| 93 | + 'SELECT "users".* FROM "users" WHERE "users"."name" = ?' |
| 94 | + else |
| 95 | + 'SELECT "users".* FROM "users" WHERE "users"."name" = $1' |
| 96 | + end |
| 97 | + |
| 98 | + expect(Datadog::AppSec.active_context).to( |
| 99 | + receive(:run_rasp).with( |
| 100 | + Datadog::AppSec::Ext::RASP_SQLI, |
| 101 | + {}, |
| 102 | + { |
| 103 | + 'server.db.statement' => expected_db_statement, |
| 104 | + 'server.db.system' => 'postgresql' |
| 105 | + }, |
| 106 | + Datadog.configuration.appsec.waf_timeout |
| 107 | + ).and_call_original |
| 108 | + ) |
| 109 | + |
| 110 | + User.where(name: 'Bob').to_a |
| 111 | + end |
110 | 112 |
|
111 |
| - expect(Datadog::AppSec.active_context).to receive(:run_rasp).and_return(result) |
112 |
| - expect(Datadog::AppSec.active_context.events).to receive(:<<).and_call_original |
| 113 | + it 'calls waf with correct arguments when querying using .find_by_sql' do |
| 114 | + expect(Datadog::AppSec.active_context).to( |
| 115 | + receive(:run_rasp).with( |
| 116 | + Datadog::AppSec::Ext::RASP_SQLI, |
| 117 | + {}, |
| 118 | + { |
| 119 | + 'server.db.statement' => "SELECT * FROM users WHERE name = 'Bob'", |
| 120 | + 'server.db.system' => 'postgresql' |
| 121 | + }, |
| 122 | + Datadog.configuration.appsec.waf_timeout |
| 123 | + ).and_call_original |
| 124 | + ) |
| 125 | + |
| 126 | + User.find_by_sql("SELECT * FROM users WHERE name = 'Bob'").to_a |
| 127 | + end |
113 | 128 |
|
114 |
| - User.where(name: 'Bob').to_a |
| 129 | + it 'adds an event to processor context if waf result is a match' do |
| 130 | + result = Datadog::AppSec::SecurityEngine::Result::Match.new( |
| 131 | + events: [], actions: {}, derivatives: {}, timeout: false, duration_ns: 0, duration_ext_ns: 0 |
| 132 | + ) |
| 133 | + |
| 134 | + expect(Datadog::AppSec.active_context).to receive(:run_rasp).and_return(result) |
| 135 | + expect(Datadog::AppSec.active_context.events).to receive(:<<).and_call_original |
| 136 | + |
| 137 | + User.where(name: 'Bob').to_a |
| 138 | + end |
115 | 139 | end
|
116 | 140 | end
|
0 commit comments