tcell_agent 0.2.29 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.txt +7 -0
- data/bin/tcell_agent +9 -0
- data/lib/tcell_agent/agent/policy_manager.rb +3 -0
- data/lib/tcell_agent/agent/policy_types.rb +4 -1
- data/lib/tcell_agent/appsensor/injections_matcher.rb +20 -0
- data/lib/tcell_agent/appsensor/injections_reporter.rb +15 -56
- data/lib/tcell_agent/appsensor/meta_data.rb +56 -2
- data/lib/tcell_agent/appsensor/rules/baserules.json +371 -138
- data/lib/tcell_agent/cmdi.rb +113 -0
- data/lib/tcell_agent/config/unknown_options.rb +2 -0
- data/lib/tcell_agent/configuration.rb +30 -16
- data/lib/tcell_agent/hooks/login_fraud.rb +79 -0
- data/lib/tcell_agent/instrumentation.rb +6 -11
- data/lib/tcell_agent/patches/meta_data.rb +14 -11
- data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +5 -9
- data/lib/tcell_agent/policies/appsensor_policy.rb +22 -206
- data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -2
- data/lib/tcell_agent/policies/command_injection_policy.rb +196 -0
- data/lib/tcell_agent/policies/content_security_policy.rb +3 -2
- data/lib/tcell_agent/policies/dataloss_policy.rb +3 -1
- data/lib/tcell_agent/policies/honeytokens_policy.rb +3 -1
- data/lib/tcell_agent/policies/http_redirect_policy.rb +51 -37
- data/lib/tcell_agent/policies/http_tx_policy.rb +5 -1
- data/lib/tcell_agent/policies/login_fraud_policy.rb +6 -1
- data/lib/tcell_agent/policies/patches_policy.rb +3 -1
- data/lib/tcell_agent/policies/policy.rb +10 -0
- data/lib/tcell_agent/policies/secure_headers_policy.rb +5 -2
- data/lib/tcell_agent/rails/auth/devise.rb +12 -23
- data/lib/tcell_agent/rails/csrf_exception.rb +1 -1
- data/lib/tcell_agent/rails/dlp.rb +50 -54
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +0 -1
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +0 -1
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +7 -10
- data/lib/tcell_agent/rails/on_start.rb +0 -1
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +4 -4
- data/lib/tcell_agent/rails.rb +0 -2
- data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
- data/lib/tcell_agent/rust/libtcellagent-0.6.1.so +0 -0
- data/lib/tcell_agent/rust/models.rb +61 -0
- data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +112 -0
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +25 -21
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +31 -24
- data/lib/tcell_agent/sensor_events/command_injection.rb +58 -0
- data/lib/tcell_agent/sensor_events/discovery.rb +1 -1
- data/lib/tcell_agent/sensor_events/login_fraud.rb +3 -13
- data/lib/tcell_agent/sensor_events/sensor.rb +81 -77
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +8 -0
- data/lib/tcell_agent/start_background_thread.rb +12 -3
- data/lib/tcell_agent/utils/io.rb +4 -1
- data/lib/tcell_agent/utils/params.rb +1 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/lib/tcell_agent.rb +0 -1
- data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +27 -9
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +143 -193
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +67 -0
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -10
- data/spec/lib/tcell_agent/cmdi_spec.rb +748 -0
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +8 -0
- data/spec/lib/tcell_agent/configuration_spec.rb +138 -6
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +357 -0
- data/spec/lib/tcell_agent/patches/block_rule_spec.rb +70 -87
- data/spec/lib/tcell_agent/patches_spec.rb +9 -4
- data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +186 -9
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +309 -484
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +736 -0
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +222 -41
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +56 -32
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +161 -85
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +40 -72
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +267 -0
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +20 -15
- data/spec/spec_helper.rb +0 -9
- data/tcell_agent.gemspec +8 -3
- metadata +40 -39
- data/lib/tcell_agent/appsensor/sensor.rb +0 -52
- data/lib/tcell_agent/policies/appsensor/database_sensor.rb +0 -56
- data/lib/tcell_agent/policies/appsensor/misc_sensor.rb +0 -59
- data/lib/tcell_agent/policies/appsensor/payloads_policy.rb +0 -150
- data/lib/tcell_agent/policies/appsensor/request_size_sensor.rb +0 -25
- data/lib/tcell_agent/policies/appsensor/response_codes_sensor.rb +0 -73
- data/lib/tcell_agent/policies/appsensor/response_size_sensor.rb +0 -25
- data/lib/tcell_agent/policies/appsensor/size_sensor.rb +0 -71
- data/lib/tcell_agent/policies/appsensor/user_agent_sensor.rb +0 -47
- data/lib/tcell_agent/rails/auth/hooks.rb +0 -79
- data/lib/tcell_agent/sensor_events/util/redirect_utils.rb +0 -22
- data/spec/lib/tcell_agent/policies/appsensor/database_sensor_spec.rb +0 -165
- data/spec/lib/tcell_agent/policies/appsensor/misc_sensor_spec.rb +0 -429
- data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_apply_spec.rb +0 -466
- data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_from_json_spec.rb +0 -890
- data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_log_spec.rb +0 -417
- data/spec/lib/tcell_agent/policies/appsensor/request_size_sensor_spec.rb +0 -236
- data/spec/lib/tcell_agent/policies/appsensor/response_codes_sensor_spec.rb +0 -297
- data/spec/lib/tcell_agent/policies/appsensor/response_size_sensor_spec.rb +0 -241
- data/spec/lib/tcell_agent/policies/appsensor/user_agent_sensor_spec.rb +0 -172
- data/spec/lib/tcell_agent/rails/auth/hooks_spec.rb +0 -246
- data/spec/lib/tcell_agent/sensor_events/util/redirect_utils_spec.rb +0 -25
- data/spec/support/resources/baserules.json +0 -155
@@ -1,165 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module TCellAgent
|
4
|
-
module Policies
|
5
|
-
|
6
|
-
describe DatabaseSensor do
|
7
|
-
|
8
|
-
context "#initialize" do
|
9
|
-
context "default sensor" do
|
10
|
-
it "should have properties set to defaults" do
|
11
|
-
sensor = DatabaseSensor.new
|
12
|
-
expect(sensor.enabled).to eq(false)
|
13
|
-
expect(sensor.max_rows).to eq(1001)
|
14
|
-
expect(sensor.excluded_route_ids).to eq({})
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "setting enabled on sensor" do
|
19
|
-
it "should have properties set to defaults" do
|
20
|
-
sensor = DatabaseSensor.new({"enabled" => true})
|
21
|
-
expect(sensor.enabled).to eq(true)
|
22
|
-
expect(sensor.max_rows).to eq(1001)
|
23
|
-
expect(sensor.excluded_route_ids).to eq({})
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "setting max_rows on sensor" do
|
28
|
-
it "should have properties set to defaults" do
|
29
|
-
sensor = DatabaseSensor.new({"large_result" => {"limit" => 1}})
|
30
|
-
expect(sensor.enabled).to eq(false)
|
31
|
-
expect(sensor.max_rows).to eq(1)
|
32
|
-
expect(sensor.excluded_route_ids).to eq({})
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "setting excluded routes on sensor" do
|
37
|
-
it "should have properties set to defaults" do
|
38
|
-
sensor = DatabaseSensor.new({"exclude_routes" => ["1", "10", "20"]})
|
39
|
-
expect(sensor.enabled).to eq(false)
|
40
|
-
expect(sensor.max_rows).to eq(1001)
|
41
|
-
expect(sensor.excluded_route_ids).to eq({"1"=>true, "10"=>true, "20"=>true})
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "#check" do
|
47
|
-
context "with disabled sensor" do
|
48
|
-
it "should not send event" do
|
49
|
-
sensor = DatabaseSensor.new({"enabled" => false})
|
50
|
-
|
51
|
-
expect(TCellAgent).to_not receive(:send_event)
|
52
|
-
sensor.check({}, 10)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "with enabled sensor" do
|
57
|
-
context "records is less than limit" do
|
58
|
-
it "should not send event" do
|
59
|
-
sensor = DatabaseSensor.new({
|
60
|
-
"enabled" => true,
|
61
|
-
"large_result" => { "limit" => 10},
|
62
|
-
"exclude_routes" => []
|
63
|
-
})
|
64
|
-
|
65
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
66
|
-
|
67
|
-
expect(TCellAgent).to_not receive(:send_event)
|
68
|
-
sensor.check(tcell_data, 1)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "records are more than limit" do
|
73
|
-
it "should send event" do
|
74
|
-
sensor = DatabaseSensor.new({
|
75
|
-
"enabled" => true,
|
76
|
-
"large_result" => { "limit" => 10},
|
77
|
-
"exclude_routes" => []
|
78
|
-
})
|
79
|
-
|
80
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
81
|
-
tcell_data.ip_address = "ip_address"
|
82
|
-
tcell_data.request_method = "get"
|
83
|
-
tcell_data.uri = "location"
|
84
|
-
tcell_data.route_id = "route_id"
|
85
|
-
tcell_data.session_id = "session_id"
|
86
|
-
tcell_data.user_id = "user_id"
|
87
|
-
tcell_data.transaction_id = "transaction_id"
|
88
|
-
|
89
|
-
expect(TCellAgent).to receive(:send_event).with(
|
90
|
-
{
|
91
|
-
"event_type" => "as",
|
92
|
-
"dp" => DatabaseSensor::DP_CODE,
|
93
|
-
"remote_addr" => "ip_address",
|
94
|
-
"rid" => "route_id",
|
95
|
-
"m" => "get",
|
96
|
-
"meta" => {"rows" => 11}
|
97
|
-
}
|
98
|
-
)
|
99
|
-
sensor.check(tcell_data, 11)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context "records are more than limit" do
|
104
|
-
context "route_id is excluded" do
|
105
|
-
it "should not send event" do
|
106
|
-
sensor = DatabaseSensor.new({
|
107
|
-
"enabled" => true,
|
108
|
-
"large_result" => { "limit" => 10},
|
109
|
-
"exclude_routes" => ["route_id"]
|
110
|
-
})
|
111
|
-
|
112
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
113
|
-
tcell_data.ip_address = "ip_address"
|
114
|
-
tcell_data.request_method = "get"
|
115
|
-
tcell_data.uri = "location"
|
116
|
-
tcell_data.route_id = "route_id"
|
117
|
-
tcell_data.session_id = "session_id"
|
118
|
-
tcell_data.user_id = "user_id"
|
119
|
-
tcell_data.transaction_id = "transaction_id"
|
120
|
-
|
121
|
-
expect(TCellAgent).to_not receive(:send_event)
|
122
|
-
|
123
|
-
sensor.check(tcell_data, 11)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context "route is not excluded" do
|
128
|
-
it "should send event" do
|
129
|
-
sensor = DatabaseSensor.new({
|
130
|
-
"enabled" => true,
|
131
|
-
"large_result" => { "limit" => 10},
|
132
|
-
"exclude_routes" => ["nonmatching_route_id"]
|
133
|
-
})
|
134
|
-
|
135
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
136
|
-
tcell_data.ip_address = "ip_address"
|
137
|
-
tcell_data.request_method = "get"
|
138
|
-
tcell_data.uri = "location"
|
139
|
-
tcell_data.route_id = "route_id"
|
140
|
-
tcell_data.session_id = "session_id"
|
141
|
-
tcell_data.user_id = "user_id"
|
142
|
-
tcell_data.transaction_id = "transaction_id"
|
143
|
-
|
144
|
-
expect(TCellAgent).to receive(:send_event).with(
|
145
|
-
{
|
146
|
-
"event_type" => "as",
|
147
|
-
"dp" => DatabaseSensor::DP_CODE,
|
148
|
-
"remote_addr" => "ip_address",
|
149
|
-
"rid" => "route_id",
|
150
|
-
"m" => "get",
|
151
|
-
"meta" => {"rows" => 11}
|
152
|
-
}
|
153
|
-
)
|
154
|
-
sensor.check(tcell_data, 11)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
165
|
-
end
|
@@ -1,429 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
module TCellAgent
|
5
|
-
module Policies
|
6
|
-
|
7
|
-
class FakeInvalidAuthenticityToken < StandardError
|
8
|
-
end
|
9
|
-
|
10
|
-
class FakeStatementInvalid < StandardError
|
11
|
-
end
|
12
|
-
|
13
|
-
describe MiscSensor do
|
14
|
-
context "#initialize" do
|
15
|
-
context "default sensor" do
|
16
|
-
it "should have properties set to defaults" do
|
17
|
-
sensor = MiscSensor.new
|
18
|
-
expect(sensor.enabled).to eq(false)
|
19
|
-
expect(sensor.csrf_exception_enabled).to eq(false)
|
20
|
-
expect(sensor.sql_exception_enabled).to eq(false)
|
21
|
-
expect(sensor.excluded_route_ids).to eq({})
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "setting enabled on sensor" do
|
26
|
-
it "should have enabled set" do
|
27
|
-
sensor = MiscSensor.new({"enabled" => true})
|
28
|
-
expect(sensor.enabled).to eq(true)
|
29
|
-
expect(sensor.csrf_exception_enabled).to eq(false)
|
30
|
-
expect(sensor.sql_exception_enabled).to eq(false)
|
31
|
-
expect(sensor.excluded_route_ids).to eq({})
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "setting csrf_exception_enabled on sensor" do
|
36
|
-
it "should csrf_exception_enabled set" do
|
37
|
-
sensor = MiscSensor.new({"csrf_exception_enabled" => true})
|
38
|
-
expect(sensor.enabled).to eq(false)
|
39
|
-
expect(sensor.csrf_exception_enabled).to eq(true)
|
40
|
-
expect(sensor.sql_exception_enabled).to eq(false)
|
41
|
-
expect(sensor.excluded_route_ids).to eq({})
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "setting sql_exception_enabled on sensor" do
|
46
|
-
it "should sql_exception_enabled set" do
|
47
|
-
sensor = MiscSensor.new({"sql_exception_enabled" => true})
|
48
|
-
expect(sensor.enabled).to eq(false)
|
49
|
-
expect(sensor.csrf_exception_enabled).to eq(false)
|
50
|
-
expect(sensor.sql_exception_enabled).to eq(true)
|
51
|
-
expect(sensor.excluded_route_ids).to eq({})
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "setting excluded_route_ids on sensor" do
|
56
|
-
it "should excluded_route_ids set" do
|
57
|
-
sensor = MiscSensor.new({"sql_exception_enabled" => true, "exclude_routes" => ["route_id"]})
|
58
|
-
expect(sensor.enabled).to eq(false)
|
59
|
-
expect(sensor.csrf_exception_enabled).to eq(false)
|
60
|
-
expect(sensor.sql_exception_enabled).to eq(true)
|
61
|
-
expect(sensor.excluded_route_ids).to eq({"route_id" => true})
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#csrf_rejected" do
|
67
|
-
before(:each) do
|
68
|
-
@exception_class = FakeInvalidAuthenticityToken
|
69
|
-
end
|
70
|
-
|
71
|
-
context "with disabled sensor" do
|
72
|
-
context "with disabled csrf_exception_enabled sensor" do
|
73
|
-
it "should not send event" do
|
74
|
-
sensor = MiscSensor.new({"enabled" => false, "csrf_exception_enabled" => false})
|
75
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
76
|
-
|
77
|
-
expect(TCellAgent).to_not receive(:send_event)
|
78
|
-
|
79
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "with enabled csrf_exception_enabled" do
|
84
|
-
it "should not send event" do
|
85
|
-
sensor = MiscSensor.new({"enabled" => false, "csrf_exception_enabled" => true})
|
86
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
87
|
-
|
88
|
-
expect(TCellAgent).to_not receive(:send_event)
|
89
|
-
|
90
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
91
|
-
end
|
92
|
-
|
93
|
-
context "with nil tcell-data" do
|
94
|
-
it "should not send event" do
|
95
|
-
sensor = MiscSensor.new({"enabled" => false, "csrf_exception_enabled" => true})
|
96
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
97
|
-
|
98
|
-
expect(TCellAgent).to_not receive(:send_event)
|
99
|
-
|
100
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context "with enabled sensor" do
|
107
|
-
context "with disabled csrf_exception_enabled sensor" do
|
108
|
-
it "should not send event" do
|
109
|
-
sensor = MiscSensor.new({"enabled" => true, "csrf_exception_enabled" => false})
|
110
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
111
|
-
|
112
|
-
expect(TCellAgent).to_not receive(:send_event)
|
113
|
-
|
114
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
115
|
-
end
|
116
|
-
|
117
|
-
context "no excluded routes" do
|
118
|
-
it "should not send an event" do
|
119
|
-
sensor = MiscSensor.new({
|
120
|
-
"enabled" => true,
|
121
|
-
"csrf_exception_enabled" => false,
|
122
|
-
"exclude_routes" => []
|
123
|
-
})
|
124
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
125
|
-
tcell_data.route_id = "route_id"
|
126
|
-
|
127
|
-
expect(TCellAgent).to_not receive(:send_event)
|
128
|
-
|
129
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "has excluded routes" do
|
134
|
-
context "route id matches" do
|
135
|
-
it "should not send an event" do
|
136
|
-
sensor = MiscSensor.new({
|
137
|
-
"enabled" => true,
|
138
|
-
"csrf_exception_enabled" => false,
|
139
|
-
"exclude_routes" => []
|
140
|
-
})
|
141
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
142
|
-
tcell_data.route_id = "route_id"
|
143
|
-
|
144
|
-
expect(TCellAgent).to_not receive(:send_event)
|
145
|
-
|
146
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context "route id does not match" do
|
151
|
-
it "should not send an event" do
|
152
|
-
sensor = MiscSensor.new({
|
153
|
-
"enabled" => true,
|
154
|
-
"csrf_exception_enabled" => false,
|
155
|
-
"exclude_routes" => ["nonmatching"]
|
156
|
-
})
|
157
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
158
|
-
tcell_data.route_id = "route_id"
|
159
|
-
|
160
|
-
expect(TCellAgent).to_not receive(:send_event)
|
161
|
-
|
162
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context "with enabled csrf_exception_enabled" do
|
169
|
-
it "should send event" do
|
170
|
-
sensor = MiscSensor.new({"enabled" => true, "csrf_exception_enabled" => true})
|
171
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
172
|
-
|
173
|
-
expect(TCellAgent).to receive(:send_event).with({
|
174
|
-
"event_type"=>"as",
|
175
|
-
"dp"=>"excsrf",
|
176
|
-
"param"=>"TCellAgent::Policies::FakeInvalidAuthenticityToken"
|
177
|
-
})
|
178
|
-
|
179
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
180
|
-
end
|
181
|
-
|
182
|
-
context "no excluded routes" do
|
183
|
-
it "should send an event" do
|
184
|
-
sensor = MiscSensor.new({
|
185
|
-
"enabled" => true,
|
186
|
-
"csrf_exception_enabled" => true,
|
187
|
-
"exclude_routes" => []
|
188
|
-
})
|
189
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
190
|
-
tcell_data.route_id = "route_id"
|
191
|
-
|
192
|
-
expect(TCellAgent).to receive(:send_event).with({
|
193
|
-
"event_type"=>"as",
|
194
|
-
"dp"=>"excsrf",
|
195
|
-
"param"=>"TCellAgent::Policies::FakeInvalidAuthenticityToken",
|
196
|
-
"rid"=>"route_id"
|
197
|
-
})
|
198
|
-
|
199
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context "has excluded routes" do
|
204
|
-
context "route id matches" do
|
205
|
-
it "should not send an event" do
|
206
|
-
sensor = MiscSensor.new({
|
207
|
-
"enabled" => true,
|
208
|
-
"csrf_exception_enabled" => true,
|
209
|
-
"exclude_routes" => ["route_id"]
|
210
|
-
})
|
211
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
212
|
-
tcell_data.route_id = "route_id"
|
213
|
-
|
214
|
-
expect(TCellAgent).to_not receive(:send_event)
|
215
|
-
|
216
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
context "route id does not match" do
|
221
|
-
it "should send an event" do
|
222
|
-
sensor = MiscSensor.new({
|
223
|
-
"enabled" => true,
|
224
|
-
"csrf_exception_enabled" => true,
|
225
|
-
"exclude_routes" => ["nonmatching"]
|
226
|
-
})
|
227
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
228
|
-
tcell_data.route_id = "route_id"
|
229
|
-
|
230
|
-
expect(TCellAgent).to receive(:send_event).with({
|
231
|
-
"event_type"=>"as",
|
232
|
-
"dp"=>"excsrf",
|
233
|
-
"param"=>"TCellAgent::Policies::FakeInvalidAuthenticityToken",
|
234
|
-
"rid"=>"route_id"
|
235
|
-
})
|
236
|
-
|
237
|
-
sensor.csrf_rejected(tcell_data, @exception_class)
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
describe "#sql_exception_enabled" do
|
247
|
-
before(:each) do
|
248
|
-
@exception = FakeStatementInvalid.new
|
249
|
-
end
|
250
|
-
|
251
|
-
context "with disabled sensor" do
|
252
|
-
context "with disabled sql_exception_enabled sensor" do
|
253
|
-
it "should not send event" do
|
254
|
-
sensor = MiscSensor.new({"enabled" => false, "sql_exception_enabled" => false})
|
255
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
256
|
-
|
257
|
-
expect(TCellAgent).to_not receive(:send_event)
|
258
|
-
|
259
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context "with enabled sql_exception_enabled" do
|
264
|
-
it "should not send event" do
|
265
|
-
sensor = MiscSensor.new({"enabled" => false, "sql_exception_enabled" => true})
|
266
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
267
|
-
|
268
|
-
expect(TCellAgent).to_not receive(:send_event)
|
269
|
-
|
270
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
271
|
-
end
|
272
|
-
|
273
|
-
context "with nil tcell-data" do
|
274
|
-
it "should not send event" do
|
275
|
-
sensor = MiscSensor.new({"enabled" => false, "sql_exception_enabled" => true})
|
276
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
277
|
-
|
278
|
-
expect(TCellAgent).to_not receive(:send_event)
|
279
|
-
|
280
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
context "with enabled sensor" do
|
287
|
-
context "with disabled sql_exception_enabled sensor" do
|
288
|
-
it "should not send event" do
|
289
|
-
sensor = MiscSensor.new({"enabled" => true, "sql_exception_enabled" => false})
|
290
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
291
|
-
|
292
|
-
expect(TCellAgent).to_not receive(:send_event)
|
293
|
-
|
294
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
295
|
-
end
|
296
|
-
|
297
|
-
context "no excluded routes" do
|
298
|
-
it "should not send an event" do
|
299
|
-
sensor = MiscSensor.new({
|
300
|
-
"enabled" => true,
|
301
|
-
"sql_exception_enabled" => false,
|
302
|
-
"exclude_routes" => []
|
303
|
-
})
|
304
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
305
|
-
tcell_data.route_id = "route_id"
|
306
|
-
|
307
|
-
expect(TCellAgent).to_not receive(:send_event)
|
308
|
-
|
309
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
context "has excluded routes" do
|
314
|
-
context "route id matches" do
|
315
|
-
it "should not send an event" do
|
316
|
-
sensor = MiscSensor.new({
|
317
|
-
"enabled" => true,
|
318
|
-
"sql_exception_enabled" => false,
|
319
|
-
"exclude_routes" => []
|
320
|
-
})
|
321
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
322
|
-
tcell_data.route_id = "route_id"
|
323
|
-
|
324
|
-
expect(TCellAgent).to_not receive(:send_event)
|
325
|
-
|
326
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
context "route id does not match" do
|
331
|
-
it "should not send an event" do
|
332
|
-
sensor = MiscSensor.new({
|
333
|
-
"enabled" => true,
|
334
|
-
"sql_exception_enabled" => false,
|
335
|
-
"exclude_routes" => ["nonmatching"]
|
336
|
-
})
|
337
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
338
|
-
tcell_data.route_id = "route_id"
|
339
|
-
|
340
|
-
expect(TCellAgent).to_not receive(:send_event)
|
341
|
-
|
342
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
context "with enabled sql_exception_enabled" do
|
349
|
-
it "should send event" do
|
350
|
-
sensor = MiscSensor.new({"enabled" => true, "sql_exception_enabled" => true})
|
351
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
352
|
-
|
353
|
-
expect(TCellAgent).to receive(:send_event).with({
|
354
|
-
"event_type"=>"as",
|
355
|
-
"dp"=>"exsql",
|
356
|
-
"param"=>"TCellAgent::Policies::FakeStatementInvalid"
|
357
|
-
})
|
358
|
-
|
359
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
360
|
-
end
|
361
|
-
|
362
|
-
context "no excluded routes" do
|
363
|
-
it "should send an event" do
|
364
|
-
sensor = MiscSensor.new({
|
365
|
-
"enabled" => true,
|
366
|
-
"sql_exception_enabled" => true,
|
367
|
-
"exclude_routes" => []
|
368
|
-
})
|
369
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
370
|
-
tcell_data.route_id = "route_id"
|
371
|
-
|
372
|
-
expect(TCellAgent).to receive(:send_event).with({
|
373
|
-
"event_type"=>"as",
|
374
|
-
"dp"=>"exsql",
|
375
|
-
"param"=>"TCellAgent::Policies::FakeStatementInvalid",
|
376
|
-
"rid"=>"route_id"
|
377
|
-
})
|
378
|
-
|
379
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
context "has excluded routes" do
|
384
|
-
context "route id matches" do
|
385
|
-
it "should not send an event" do
|
386
|
-
sensor = MiscSensor.new({
|
387
|
-
"enabled" => true,
|
388
|
-
"sql_exception_enabled" => true,
|
389
|
-
"exclude_routes" => ["route_id"]
|
390
|
-
})
|
391
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
392
|
-
tcell_data.route_id = "route_id"
|
393
|
-
|
394
|
-
expect(TCellAgent).to_not receive(:send_event)
|
395
|
-
|
396
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
397
|
-
end
|
398
|
-
end
|
399
|
-
|
400
|
-
context "route id does not match" do
|
401
|
-
it "should send an event" do
|
402
|
-
sensor = MiscSensor.new({
|
403
|
-
"enabled" => true,
|
404
|
-
"sql_exception_enabled" => true,
|
405
|
-
"exclude_routes" => ["nonmatching"]
|
406
|
-
})
|
407
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
408
|
-
tcell_data.route_id = "route_id"
|
409
|
-
|
410
|
-
expect(TCellAgent).to receive(:send_event).with({
|
411
|
-
"event_type"=>"as",
|
412
|
-
"dp"=>"exsql",
|
413
|
-
"param"=>"TCellAgent::Policies::FakeStatementInvalid",
|
414
|
-
"rid"=>"route_id"
|
415
|
-
})
|
416
|
-
|
417
|
-
sensor.sql_exception_detected(tcell_data, @exception)
|
418
|
-
end
|
419
|
-
end
|
420
|
-
end
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
end
|
425
|
-
|
426
|
-
end
|
427
|
-
|
428
|
-
end
|
429
|
-
end
|