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,297 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module TCellAgent
|
4
|
-
module Policies
|
5
|
-
|
6
|
-
describe ResponseCodesSensor do
|
7
|
-
context "#initialize" do
|
8
|
-
context "default sensor" do
|
9
|
-
it "should have properties set to defaults" do
|
10
|
-
sensor = ResponseCodesSensor.new
|
11
|
-
expect(sensor.enabled).to eq(false)
|
12
|
-
expect(sensor.series_400_enabled).to eq(false)
|
13
|
-
expect(sensor.series_500_enabled).to eq(false)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "setting enabled on sensor" do
|
18
|
-
it "should have properties set to defaults" do
|
19
|
-
sensor = ResponseCodesSensor.new({"enabled" => true})
|
20
|
-
expect(sensor.enabled).to eq(true)
|
21
|
-
expect(sensor.series_400_enabled).to eq(false)
|
22
|
-
expect(sensor.series_500_enabled).to eq(false)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "setting series_400_enabled on sensor" do
|
27
|
-
it "should have properties set to defaults" do
|
28
|
-
sensor = ResponseCodesSensor.new({"series_400_enabled" => true})
|
29
|
-
expect(sensor.enabled).to eq(false)
|
30
|
-
expect(sensor.series_400_enabled).to eq(true)
|
31
|
-
expect(sensor.series_500_enabled).to eq(false)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "setting series_500_enabled on sensor" do
|
36
|
-
it "should have properties set to defaults" do
|
37
|
-
sensor = ResponseCodesSensor.new({"series_500_enabled" => true})
|
38
|
-
expect(sensor.enabled).to eq(false)
|
39
|
-
expect(sensor.series_400_enabled).to eq(false)
|
40
|
-
expect(sensor.series_500_enabled).to eq(true)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "setting excluded_route_ids on sensor" do
|
45
|
-
it "should have excluded_route_ids" do
|
46
|
-
sensor = ResponseCodesSensor.new({"exclude_routes" => ["excluded_route_id"]})
|
47
|
-
expect(sensor.enabled).to eq(false)
|
48
|
-
expect(sensor.series_400_enabled).to eq(false)
|
49
|
-
expect(sensor.series_500_enabled).to eq(false)
|
50
|
-
expect(sensor.excluded_route_ids).to eq({"excluded_route_id" => true})
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "#check" do
|
56
|
-
context "with disabled sensor" do
|
57
|
-
it "should not send event" do
|
58
|
-
sensor = ResponseCodesSensor.new({"enabled" => false})
|
59
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
60
|
-
meta.remote_address = "remote_address"
|
61
|
-
meta.method = "get"
|
62
|
-
meta.location = "location"
|
63
|
-
meta.route_id = "route_id"
|
64
|
-
meta.session_id = "session_id"
|
65
|
-
meta.user_id = "user_id"
|
66
|
-
meta.transaction_id = "transaction_id"
|
67
|
-
|
68
|
-
expect(TCellAgent::AppSensor::Sensor).to_not receive(:send_event)
|
69
|
-
sensor.check(meta, 200)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "with enabled sensor" do
|
74
|
-
context "with 200 response code" do
|
75
|
-
before(:each) do
|
76
|
-
@sensor = ResponseCodesSensor.new({"enabled" => true})
|
77
|
-
|
78
|
-
@meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
79
|
-
@meta.remote_address = "remote_address"
|
80
|
-
@meta.method = "get"
|
81
|
-
@meta.location = "location"
|
82
|
-
@meta.route_id = "route_id"
|
83
|
-
@meta.session_id = "session_id"
|
84
|
-
@meta.user_id = "user_id"
|
85
|
-
@meta.transaction_id = "transaction_id"
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should not send an event" do
|
89
|
-
expect(TCellAgent::AppSensor::Sensor).to_not receive(:send_event)
|
90
|
-
@sensor.check(@meta, 200)
|
91
|
-
end
|
92
|
-
|
93
|
-
context "no excluded routes" do
|
94
|
-
it "should not send an event" do
|
95
|
-
@sensor.excluded_route_ids = {}
|
96
|
-
|
97
|
-
expect(TCellAgent::AppSensor::Sensor).to_not receive(:send_event)
|
98
|
-
@sensor.check(@meta, 200)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context "has excluded routes" do
|
103
|
-
context "route id matches" do
|
104
|
-
it "should not send an event" do
|
105
|
-
@sensor.excluded_route_ids = {"route_id" => true}
|
106
|
-
|
107
|
-
expect(TCellAgent::AppSensor::Sensor).to_not receive(:send_event)
|
108
|
-
@sensor.check(@meta, 200)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
context "route id does not match" do
|
112
|
-
it "should not send an event" do
|
113
|
-
@sensor.excluded_route_ids = {"unmatching_route_id" => true}
|
114
|
-
|
115
|
-
expect(TCellAgent::AppSensor::Sensor).to_not receive(:send_event)
|
116
|
-
@sensor.check(@meta, 200)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "with 300 response code" do
|
123
|
-
it "should not send an event" do
|
124
|
-
sensor = ResponseCodesSensor.new({"enabled" => true})
|
125
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
126
|
-
meta.remote_address = "remote_address"
|
127
|
-
meta.method = "get"
|
128
|
-
meta.location = "location"
|
129
|
-
meta.route_id = "route_id"
|
130
|
-
meta.session_id = "session_id"
|
131
|
-
meta.user_id = "user_id"
|
132
|
-
meta.transaction_id = "transaction_id"
|
133
|
-
|
134
|
-
expect(TCellAgent::AppSensor::Sensor).to_not receive(:send_event)
|
135
|
-
sensor.check(meta, 300)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context "with disabled series_400_enabled" do
|
140
|
-
context "with 400 response code" do
|
141
|
-
it "should not send an event" do
|
142
|
-
sensor = ResponseCodesSensor.new({
|
143
|
-
"enabled" => true,
|
144
|
-
"series_400_enabled" => false
|
145
|
-
})
|
146
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
147
|
-
meta.remote_address = "remote_address"
|
148
|
-
meta.method = "get"
|
149
|
-
meta.location = "location"
|
150
|
-
meta.route_id = "route_id"
|
151
|
-
meta.session_id = "session_id"
|
152
|
-
meta.user_id = "user_id"
|
153
|
-
meta.transaction_id = "transaction_id"
|
154
|
-
|
155
|
-
expect(TCellAgent::AppSensor::Sensor).to_not receive(:send_event)
|
156
|
-
sensor.check(meta, 400)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context "with enabled series_400_enabled and full uri" do
|
162
|
-
context "with 400 response code" do
|
163
|
-
before(:each) do
|
164
|
-
@sensor = ResponseCodesSensor.new({
|
165
|
-
"enabled" => true,
|
166
|
-
"series_400_enabled" => true,
|
167
|
-
"collect_full_uri" => true
|
168
|
-
})
|
169
|
-
@meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
170
|
-
@meta.remote_address = "remote_address"
|
171
|
-
@meta.method = "get"
|
172
|
-
@meta.location = "location"
|
173
|
-
@meta.route_id = "route_id"
|
174
|
-
@meta.session_id = "session_id"
|
175
|
-
@meta.user_id = "user_id"
|
176
|
-
@meta.transaction_id = "transaction_id"
|
177
|
-
end
|
178
|
-
|
179
|
-
it "should send an event" do
|
180
|
-
expect(TCellAgent::AppSensor::Sensor).to receive(:send_event).with(
|
181
|
-
@meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[4], nil, {code: 400} , nil, nil, true
|
182
|
-
)
|
183
|
-
@sensor.check(@meta, 400)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
|
189
|
-
context "with enabled series_400_enabled" do
|
190
|
-
context "with 400 response code" do
|
191
|
-
before(:each) do
|
192
|
-
@sensor = ResponseCodesSensor.new({
|
193
|
-
"enabled" => true,
|
194
|
-
"series_400_enabled" => true
|
195
|
-
})
|
196
|
-
@meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
197
|
-
@meta.remote_address = "remote_address"
|
198
|
-
@meta.method = "get"
|
199
|
-
@meta.location = "location"
|
200
|
-
@meta.route_id = "route_id"
|
201
|
-
@meta.session_id = "session_id"
|
202
|
-
@meta.user_id = "user_id"
|
203
|
-
@meta.transaction_id = "transaction_id"
|
204
|
-
end
|
205
|
-
|
206
|
-
it "should send an event" do
|
207
|
-
expect(TCellAgent::AppSensor::Sensor).to receive(:send_event).with(
|
208
|
-
@meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[4], nil, {code: 400} , nil, nil, false
|
209
|
-
)
|
210
|
-
@sensor.check(@meta, 400)
|
211
|
-
end
|
212
|
-
|
213
|
-
context "no excluded routes" do
|
214
|
-
it "should send an event" do
|
215
|
-
@sensor.excluded_route_ids = {}
|
216
|
-
|
217
|
-
expect(TCellAgent::AppSensor::Sensor).to receive(:send_event).with(
|
218
|
-
@meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[4], nil, {code: 400} , nil, nil, false
|
219
|
-
)
|
220
|
-
@sensor.check(@meta, 400)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context "has excluded routes" do
|
225
|
-
context "route id matches" do
|
226
|
-
it "should not send an event" do
|
227
|
-
@sensor.excluded_route_ids = {"route_id" => true}
|
228
|
-
|
229
|
-
expect(TCellAgent::AppSensor::Sensor).to_not receive(:send_event)
|
230
|
-
@sensor.check(@meta, 400)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
context "route id does not match" do
|
234
|
-
it "should send an event" do
|
235
|
-
@sensor.excluded_route_ids = {"unmatching_route_id" => true}
|
236
|
-
|
237
|
-
expect(TCellAgent::AppSensor::Sensor).to receive(:send_event).with(
|
238
|
-
@meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[4], nil, {code: 400} , nil, nil, false
|
239
|
-
)
|
240
|
-
@sensor.check(@meta, 400)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context "with disabled series_500_enabled" do
|
248
|
-
context "with 500 response code" do
|
249
|
-
it "should not send an event" do
|
250
|
-
sensor = ResponseCodesSensor.new({
|
251
|
-
"enabled" => true,
|
252
|
-
"series_500_enabled" => false
|
253
|
-
})
|
254
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
255
|
-
meta.remote_address = "remote_address"
|
256
|
-
meta.method = "get"
|
257
|
-
meta.location = "location"
|
258
|
-
meta.route_id = "route_id"
|
259
|
-
meta.session_id = "session_id"
|
260
|
-
meta.user_id = "user_id"
|
261
|
-
meta.transaction_id = "transaction_id"
|
262
|
-
|
263
|
-
expect(TCellAgent::AppSensor::Sensor).to_not receive(:send_event)
|
264
|
-
sensor.check(meta, 500)
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
context "with enabled series_500_enabled" do
|
270
|
-
context "with 500 response code" do
|
271
|
-
it "should send an event" do
|
272
|
-
sensor = ResponseCodesSensor.new({
|
273
|
-
"enabled" => true,
|
274
|
-
"series_500_enabled" => true
|
275
|
-
})
|
276
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
277
|
-
meta.remote_address = "remote_address"
|
278
|
-
meta.method = "get"
|
279
|
-
meta.location = "location"
|
280
|
-
meta.route_id = "route_id"
|
281
|
-
meta.session_id = "session_id"
|
282
|
-
meta.user_id = "user_id"
|
283
|
-
meta.transaction_id = "transaction_id"
|
284
|
-
|
285
|
-
expect(TCellAgent::AppSensor::Sensor).to receive(:send_event).with(
|
286
|
-
meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[500], nil, {code: 500} , nil, nil, false
|
287
|
-
)
|
288
|
-
sensor.check(meta, 500)
|
289
|
-
end
|
290
|
-
end
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
end
|
297
|
-
end
|
@@ -1,241 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module TCellAgent
|
4
|
-
module Policies
|
5
|
-
|
6
|
-
describe ResponseSizeSensor do
|
7
|
-
context "#initialize" do
|
8
|
-
context "default sensor" do
|
9
|
-
it "should have properties set to defaults" do
|
10
|
-
sensor = ResponseSizeSensor.new
|
11
|
-
expect(sensor.enabled).to eq(false)
|
12
|
-
expect(sensor.limit).to eq(2097152)
|
13
|
-
expect(sensor.excluded_route_ids).to eq({})
|
14
|
-
expect(sensor.dp_code).to eq(ResponseSizeSensor::DP_UNUSUAL_RESPONSE_SIZE)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "setting enabled on sensor" do
|
19
|
-
it "should have properties set to defaults" do
|
20
|
-
sensor = ResponseSizeSensor.new({"enabled" => true})
|
21
|
-
expect(sensor.enabled).to eq(true)
|
22
|
-
expect(sensor.limit).to eq(2097152)
|
23
|
-
expect(sensor.excluded_route_ids).to eq({})
|
24
|
-
expect(sensor.dp_code).to eq(ResponseSizeSensor::DP_UNUSUAL_RESPONSE_SIZE)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "setting limit on sensor" do
|
29
|
-
it "should have properties set to defaults" do
|
30
|
-
sensor = ResponseSizeSensor.new({"limit" => 1})
|
31
|
-
expect(sensor.enabled).to eq(false)
|
32
|
-
expect(sensor.limit).to eq(1)
|
33
|
-
expect(sensor.excluded_route_ids).to eq({})
|
34
|
-
expect(sensor.dp_code).to eq(ResponseSizeSensor::DP_UNUSUAL_RESPONSE_SIZE)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "setting excluded routes on sensor" do
|
39
|
-
it "should have properties set to defaults" do
|
40
|
-
sensor = ResponseSizeSensor.new({"exclude_routes" => ["1", "10", "20"]})
|
41
|
-
expect(sensor.enabled).to eq(false)
|
42
|
-
expect(sensor.limit).to eq(2097152)
|
43
|
-
expect(sensor.excluded_route_ids).to eq({"1"=>true, "10"=>true, "20"=>true})
|
44
|
-
expect(sensor.dp_code).to eq(ResponseSizeSensor::DP_UNUSUAL_RESPONSE_SIZE)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "#check" do
|
50
|
-
context "with disabled sensor" do
|
51
|
-
it "should not send event" do
|
52
|
-
sensor = ResponseSizeSensor.new({"enabled" => false})
|
53
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
54
|
-
meta.remote_address = "remote_address"
|
55
|
-
meta.method = "get"
|
56
|
-
meta.location = "location"
|
57
|
-
meta.route_id = "route_id"
|
58
|
-
meta.session_id = "session_id"
|
59
|
-
meta.user_id = "user_id"
|
60
|
-
meta.transaction_id = "transaction_id"
|
61
|
-
meta.response_content_bytes_len = 1024
|
62
|
-
|
63
|
-
expect(TCellAgent).to_not receive(:send_event)
|
64
|
-
sensor.check(meta)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "with enabled sensor" do
|
69
|
-
context "size is zero" do
|
70
|
-
it "should not send event" do
|
71
|
-
sensor = ResponseSizeSensor.new({
|
72
|
-
"enabled" => true,
|
73
|
-
"limit" => 2048,
|
74
|
-
"exclude_routes" => []
|
75
|
-
})
|
76
|
-
|
77
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
78
|
-
meta.remote_address = "remote_address"
|
79
|
-
meta.method = "get"
|
80
|
-
meta.location = "location"
|
81
|
-
meta.route_id = "route_id"
|
82
|
-
meta.session_id = "session_id"
|
83
|
-
meta.user_id = "user_id"
|
84
|
-
meta.transaction_id = "transaction_id"
|
85
|
-
meta.response_content_bytes_len = 0
|
86
|
-
|
87
|
-
expect(TCellAgent).to_not receive(:send_event)
|
88
|
-
sensor.check(meta)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context "size is too small" do
|
93
|
-
context "by half a KiB" do
|
94
|
-
it "should not send event" do
|
95
|
-
sensor = ResponseSizeSensor.new({
|
96
|
-
"enabled" => true,
|
97
|
-
"limit" => 1,
|
98
|
-
"exclude_routes" => []
|
99
|
-
})
|
100
|
-
|
101
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
102
|
-
meta.remote_address = "remote_address"
|
103
|
-
meta.method = "get"
|
104
|
-
meta.location = "location"
|
105
|
-
meta.route_id = "route_id"
|
106
|
-
meta.session_id = "session_id"
|
107
|
-
meta.user_id = "user_id"
|
108
|
-
meta.transaction_id = "transaction_id"
|
109
|
-
meta.response_content_bytes_len = 512
|
110
|
-
|
111
|
-
expect(TCellAgent).to_not receive(:send_event)
|
112
|
-
sensor.check(meta)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context "size is ok" do
|
118
|
-
it "should not send event" do
|
119
|
-
sensor = ResponseSizeSensor.new({
|
120
|
-
"enabled" => true,
|
121
|
-
"limit" => 2048,
|
122
|
-
"exclude_routes" => []
|
123
|
-
})
|
124
|
-
|
125
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
126
|
-
meta.remote_address = "remote_address"
|
127
|
-
meta.method = "get"
|
128
|
-
meta.location = "location"
|
129
|
-
meta.route_id = "route_id"
|
130
|
-
meta.session_id = "session_id"
|
131
|
-
meta.user_id = "user_id"
|
132
|
-
meta.transaction_id = "transaction_id"
|
133
|
-
meta.response_content_bytes_len = 1024
|
134
|
-
|
135
|
-
expect(TCellAgent).to_not receive(:send_event)
|
136
|
-
sensor.check(meta)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context "size is too big" do
|
141
|
-
context "by half a KiB" do
|
142
|
-
it "should not send event" do
|
143
|
-
sensor = ResponseSizeSensor.new({
|
144
|
-
"enabled" => true,
|
145
|
-
"limit" => 1,
|
146
|
-
"exclude_routes" => []
|
147
|
-
})
|
148
|
-
|
149
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
150
|
-
meta.remote_address = "remote_address"
|
151
|
-
meta.method = "get"
|
152
|
-
meta.location = "location"
|
153
|
-
meta.route_id = "excluded_route_id"
|
154
|
-
meta.session_id = "session_id"
|
155
|
-
meta.user_id = "user_id"
|
156
|
-
meta.transaction_id = "transaction_id"
|
157
|
-
meta.response_content_bytes_len = 1024 + 512
|
158
|
-
|
159
|
-
expect(TCellAgent).to receive(:send_event).with(
|
160
|
-
{"event_type"=>"as",
|
161
|
-
"dp"=>"rspsz",
|
162
|
-
"remote_addr"=>"remote_address",
|
163
|
-
"m"=>"get",
|
164
|
-
"meta"=>{"sz"=>1536},
|
165
|
-
"rid"=>"excluded_route_id"}
|
166
|
-
)
|
167
|
-
sensor.check(meta)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
context "route_id is excluded" do
|
172
|
-
it "should not send event" do
|
173
|
-
sensor = ResponseSizeSensor.new({
|
174
|
-
"enabled" => true,
|
175
|
-
"limit" => 1024,
|
176
|
-
"exclude_routes" => ["excluded_route_id"]
|
177
|
-
})
|
178
|
-
|
179
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
180
|
-
meta.remote_address = "remote_address"
|
181
|
-
meta.method = "get"
|
182
|
-
meta.location = "location"
|
183
|
-
meta.route_id = "excluded_route_id"
|
184
|
-
meta.session_id = "session_id"
|
185
|
-
meta.user_id = "user_id"
|
186
|
-
meta.transaction_id = "transaction_id"
|
187
|
-
meta.response_content_bytes_len = 2048
|
188
|
-
|
189
|
-
expect(TCellAgent).to_not receive(:send_event)
|
190
|
-
sensor.check(meta)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
context "route is not excluded" do
|
195
|
-
it "should send event" do
|
196
|
-
sensor = ResponseSizeSensor.new({
|
197
|
-
"enabled" => true,
|
198
|
-
"limit" => 1,
|
199
|
-
"exclude_routes" => []
|
200
|
-
})
|
201
|
-
|
202
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
203
|
-
meta.remote_address = "remote_address"
|
204
|
-
meta.method = "get"
|
205
|
-
meta.location = "location"
|
206
|
-
meta.route_id = "excluded_route_id"
|
207
|
-
meta.session_id = "session_id"
|
208
|
-
meta.user_id = "user_id"
|
209
|
-
meta.transaction_id = "transaction_id"
|
210
|
-
meta.response_content_bytes_len = 2048
|
211
|
-
|
212
|
-
expect(TCellAgent).to receive(:send_event).with(
|
213
|
-
{"event_type"=>"as",
|
214
|
-
"dp"=>"rspsz",
|
215
|
-
"remote_addr"=>"remote_address",
|
216
|
-
"m"=>"get",
|
217
|
-
"meta"=>{"sz"=>2048},
|
218
|
-
"rid"=>"excluded_route_id"}
|
219
|
-
)
|
220
|
-
sensor.check(meta)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
context "#get_content_length" do
|
229
|
-
it "should return the response size" do
|
230
|
-
sensor = ResponseSizeSensor.new({"enabled" => false})
|
231
|
-
meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
232
|
-
meta.request_content_bytes_len = 1024
|
233
|
-
meta.response_content_bytes_len = 2048
|
234
|
-
|
235
|
-
expect(sensor.get_content_length(meta)).to eq(2048)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
end
|
241
|
-
end
|