tcell_agent 0.2.29 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/Readme.txt +7 -0
  3. data/bin/tcell_agent +9 -0
  4. data/lib/tcell_agent/agent/policy_manager.rb +3 -0
  5. data/lib/tcell_agent/agent/policy_types.rb +4 -1
  6. data/lib/tcell_agent/appsensor/injections_matcher.rb +20 -0
  7. data/lib/tcell_agent/appsensor/injections_reporter.rb +15 -56
  8. data/lib/tcell_agent/appsensor/meta_data.rb +56 -2
  9. data/lib/tcell_agent/appsensor/rules/baserules.json +371 -138
  10. data/lib/tcell_agent/cmdi.rb +113 -0
  11. data/lib/tcell_agent/config/unknown_options.rb +2 -0
  12. data/lib/tcell_agent/configuration.rb +30 -16
  13. data/lib/tcell_agent/hooks/login_fraud.rb +79 -0
  14. data/lib/tcell_agent/instrumentation.rb +6 -11
  15. data/lib/tcell_agent/patches/meta_data.rb +14 -11
  16. data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +5 -9
  17. data/lib/tcell_agent/policies/appsensor_policy.rb +22 -206
  18. data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -2
  19. data/lib/tcell_agent/policies/command_injection_policy.rb +196 -0
  20. data/lib/tcell_agent/policies/content_security_policy.rb +3 -2
  21. data/lib/tcell_agent/policies/dataloss_policy.rb +3 -1
  22. data/lib/tcell_agent/policies/honeytokens_policy.rb +3 -1
  23. data/lib/tcell_agent/policies/http_redirect_policy.rb +51 -37
  24. data/lib/tcell_agent/policies/http_tx_policy.rb +5 -1
  25. data/lib/tcell_agent/policies/login_fraud_policy.rb +6 -1
  26. data/lib/tcell_agent/policies/patches_policy.rb +3 -1
  27. data/lib/tcell_agent/policies/policy.rb +10 -0
  28. data/lib/tcell_agent/policies/secure_headers_policy.rb +5 -2
  29. data/lib/tcell_agent/rails/auth/devise.rb +12 -23
  30. data/lib/tcell_agent/rails/csrf_exception.rb +1 -1
  31. data/lib/tcell_agent/rails/dlp.rb +50 -54
  32. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +0 -1
  33. data/lib/tcell_agent/rails/middleware/context_middleware.rb +0 -1
  34. data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
  35. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +7 -10
  36. data/lib/tcell_agent/rails/on_start.rb +0 -1
  37. data/lib/tcell_agent/rails/tcell_body_proxy.rb +4 -4
  38. data/lib/tcell_agent/rails.rb +0 -2
  39. data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
  40. data/lib/tcell_agent/rust/libtcellagent-0.6.1.so +0 -0
  41. data/lib/tcell_agent/rust/models.rb +61 -0
  42. data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
  43. data/lib/tcell_agent/rust/whisperer.rb +112 -0
  44. data/lib/tcell_agent/sensor_events/appsensor_event.rb +25 -21
  45. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +31 -24
  46. data/lib/tcell_agent/sensor_events/command_injection.rb +58 -0
  47. data/lib/tcell_agent/sensor_events/discovery.rb +1 -1
  48. data/lib/tcell_agent/sensor_events/login_fraud.rb +3 -13
  49. data/lib/tcell_agent/sensor_events/sensor.rb +81 -77
  50. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +8 -0
  51. data/lib/tcell_agent/start_background_thread.rb +12 -3
  52. data/lib/tcell_agent/utils/io.rb +4 -1
  53. data/lib/tcell_agent/utils/params.rb +1 -0
  54. data/lib/tcell_agent/version.rb +1 -1
  55. data/lib/tcell_agent.rb +0 -1
  56. data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +27 -9
  57. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +143 -193
  58. data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +67 -0
  59. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -10
  60. data/spec/lib/tcell_agent/cmdi_spec.rb +748 -0
  61. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +8 -0
  62. data/spec/lib/tcell_agent/configuration_spec.rb +138 -6
  63. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +357 -0
  64. data/spec/lib/tcell_agent/patches/block_rule_spec.rb +70 -87
  65. data/spec/lib/tcell_agent/patches_spec.rb +9 -4
  66. data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +186 -9
  67. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +309 -484
  68. data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +736 -0
  69. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +222 -41
  70. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +56 -32
  71. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +161 -85
  72. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +40 -72
  73. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +267 -0
  74. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +20 -15
  75. data/spec/spec_helper.rb +0 -9
  76. data/tcell_agent.gemspec +8 -3
  77. metadata +40 -39
  78. data/lib/tcell_agent/appsensor/sensor.rb +0 -52
  79. data/lib/tcell_agent/policies/appsensor/database_sensor.rb +0 -56
  80. data/lib/tcell_agent/policies/appsensor/misc_sensor.rb +0 -59
  81. data/lib/tcell_agent/policies/appsensor/payloads_policy.rb +0 -150
  82. data/lib/tcell_agent/policies/appsensor/request_size_sensor.rb +0 -25
  83. data/lib/tcell_agent/policies/appsensor/response_codes_sensor.rb +0 -73
  84. data/lib/tcell_agent/policies/appsensor/response_size_sensor.rb +0 -25
  85. data/lib/tcell_agent/policies/appsensor/size_sensor.rb +0 -71
  86. data/lib/tcell_agent/policies/appsensor/user_agent_sensor.rb +0 -47
  87. data/lib/tcell_agent/rails/auth/hooks.rb +0 -79
  88. data/lib/tcell_agent/sensor_events/util/redirect_utils.rb +0 -22
  89. data/spec/lib/tcell_agent/policies/appsensor/database_sensor_spec.rb +0 -165
  90. data/spec/lib/tcell_agent/policies/appsensor/misc_sensor_spec.rb +0 -429
  91. data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_apply_spec.rb +0 -466
  92. data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_from_json_spec.rb +0 -890
  93. data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_log_spec.rb +0 -417
  94. data/spec/lib/tcell_agent/policies/appsensor/request_size_sensor_spec.rb +0 -236
  95. data/spec/lib/tcell_agent/policies/appsensor/response_codes_sensor_spec.rb +0 -297
  96. data/spec/lib/tcell_agent/policies/appsensor/response_size_sensor_spec.rb +0 -241
  97. data/spec/lib/tcell_agent/policies/appsensor/user_agent_sensor_spec.rb +0 -172
  98. data/spec/lib/tcell_agent/rails/auth/hooks_spec.rb +0 -246
  99. data/spec/lib/tcell_agent/sensor_events/util/redirect_utils_spec.rb +0 -25
  100. data/spec/support/resources/baserules.json +0 -155
@@ -1,417 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
- module Policies
5
-
6
- describe AppSensorPolicy do
7
-
8
- describe "#log" do
9
- before(:each) do
10
- @meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
11
- @meta.remote_address = "remote_address"
12
- @meta.method = "get"
13
- @meta.location = "location"
14
- @meta.route_id = "route_id"
15
- @meta.session_id = "session_id"
16
- @meta.user_id = "user_id"
17
- @meta.transaction_id = "transaction_id"
18
- end
19
-
20
- context "with log_payloads disabled" do
21
- it "should not log" do
22
- policy = PayloadsPolicy.from_json({
23
- "payloads" => {
24
- "log_payloads" => false
25
- }
26
- })
27
-
28
- expect(TCellAgent).to_not receive(:configuration)
29
- expect(TCellAgent).to_not receive(:appfirewall_payloads_logger)
30
-
31
- policy.log(
32
- "xss",
33
- @meta,
34
- TCellAgent::Utils::Params::GET_PARAM,
35
- "password",
36
- "alert()",
37
- {"l" => "query"},
38
- "pattern"
39
- )
40
- end
41
- end
42
-
43
- context "with log_payloads enabled" do
44
- context "with no blacklist" do
45
- context "with no whitelist" do
46
- it "should log the value" do
47
- policy = PayloadsPolicy.from_json({
48
- "payloads" => {
49
- "log_payloads" => true
50
- }
51
- })
52
- configuration = double("configuration", "enabled" => true)
53
- appfirewall_payloads_logger = double("appfirewall_payloads_logger")
54
-
55
- expect(TCellAgent).to receive(:configuration).and_return(configuration).exactly(3).times
56
- expect(configuration).to receive(:appfirewall_payloads_logger).and_return(
57
- appfirewall_payloads_logger
58
- ).exactly(2).times
59
- expect_any_instance_of(TCellAgent::SensorEvents::TCellAppSensorEvent).to receive(
60
- :post_process
61
- )
62
- expect(appfirewall_payloads_logger).to receive(:info).with({
63
- "event_type" => "as",
64
- "dp" => "xss",
65
- "param" => "password",
66
- "remote_addr" => "remote_address",
67
- "m" => "get",
68
- "pattern" => "pattern",
69
- "meta" => {"l" => "query"},
70
- "rid" => "route_id"
71
- }.to_json)
72
-
73
- policy.log(
74
- "xss",
75
- @meta,
76
- TCellAgent::Utils::Params::GET_PARAM,
77
- "password",
78
- "alert()",
79
- {"l" => "query"},
80
- "pattern"
81
- )
82
- end
83
- end
84
-
85
- context "with a whitelist" do
86
- context "that does not specify locations for the param" do
87
- it "should not log" do
88
- policy = PayloadsPolicy.from_json({
89
- "payloads" => {
90
- "log_payloads" => true,
91
- "log_whitelist" => {
92
- "username" => ["*"]
93
- }
94
- }
95
- })
96
-
97
- expect(TCellAgent).to_not receive(:configuration)
98
-
99
- policy.log(
100
- "xss",
101
- @meta,
102
- TCellAgent::Utils::Params::GET_PARAM,
103
- "password",
104
- "alert()",
105
- {"l" => "query"},
106
- "pattern"
107
- )
108
- end
109
- end
110
-
111
- context "that specifies locations for the param" do
112
- context "param location does not match specified location do" do
113
- it "should not log" do
114
- policy = PayloadsPolicy.from_json({
115
- "payloads" => {
116
- "log_payloads" => true,
117
- "log_whitelist" => {
118
- "username" => ["*"],
119
- "password" => ["cookie"]
120
- }
121
- }
122
- })
123
-
124
- expect(TCellAgent).to_not receive(:configuration)
125
-
126
- policy.log(
127
- "xss",
128
- @meta,
129
- TCellAgent::Utils::Params::GET_PARAM,
130
- "password",
131
- "alert()",
132
- {"l" => "query"},
133
- "pattern"
134
- )
135
- end
136
- end
137
-
138
- context "param location matches the specified location in the whitelist" do
139
- it "should log the value" do
140
- policy = PayloadsPolicy.from_json({
141
- "payloads" => {
142
- "log_payloads" => true,
143
- "log_whitelist" => {
144
- "username" => ["*"],
145
- "PASSWORD" => ["form"]
146
- }
147
- }
148
- })
149
- configuration = double("configuration", "enabled" => true)
150
- appfirewall_payloads_logger = double("appfirewall_payloads_logger")
151
-
152
- expect(TCellAgent).to receive(:configuration).and_return(configuration).exactly(3).times
153
- expect(configuration).to receive(:appfirewall_payloads_logger).and_return(
154
- appfirewall_payloads_logger
155
- ).exactly(2).times
156
- expect_any_instance_of(TCellAgent::SensorEvents::TCellAppSensorEvent).to receive(
157
- :post_process
158
- )
159
- expect(appfirewall_payloads_logger).to receive(:info).with({
160
- "event_type" => "as",
161
- "dp" => "xss",
162
- "param" => "password",
163
- "remote_addr" => "remote_address",
164
- "m" => "get",
165
- "pattern" => "pattern",
166
- "meta" => {"l" => "query"},
167
- "rid" => "route_id",
168
- }.to_json)
169
-
170
- policy.log(
171
- "xss",
172
- @meta,
173
- TCellAgent::Utils::Params::GET_PARAM,
174
- "password",
175
- "alert()",
176
- {"l" => "query"},
177
- "pattern"
178
- )
179
- end
180
- end
181
- end
182
- end
183
- end
184
-
185
- context "with a blacklist" do
186
- context "that does not specify locations for the param" do
187
- context "with no whitelist" do
188
- it "should log the value" do
189
- policy = PayloadsPolicy.from_json({
190
- "payloads" => {
191
- "log_payloads" => true,
192
- "log_blacklist" => {
193
- "username" => ["*"]
194
- }
195
- }
196
- })
197
- configuration = double("configuration", "enabled" => true)
198
- appfirewall_payloads_logger = double("appfirewall_payloads_logger")
199
-
200
- expect(TCellAgent).to receive(:configuration).and_return(configuration).exactly(3).times
201
- expect(configuration).to receive(:appfirewall_payloads_logger).and_return(
202
- appfirewall_payloads_logger
203
- ).exactly(2).times
204
- expect_any_instance_of(TCellAgent::SensorEvents::TCellAppSensorEvent).to receive(
205
- :post_process
206
- )
207
- expect(appfirewall_payloads_logger).to receive(:info).with({
208
- "event_type" => "as",
209
- "dp" => "xss",
210
- "param" => "password",
211
- "remote_addr" => "remote_address",
212
- "m" => "get",
213
- "pattern" => "pattern",
214
- "meta" => {"l" => "query"},
215
- "rid" => "route_id"
216
- }.to_json)
217
-
218
- policy.log(
219
- "xss",
220
- @meta,
221
- TCellAgent::Utils::Params::GET_PARAM,
222
- "password",
223
- "alert()",
224
- {"l" => "query"},
225
- "pattern"
226
- )
227
- end
228
- end
229
-
230
- context "with a whitelist" do
231
- context "that does not specify locations for the param" do
232
- it "should not log" do
233
- policy = PayloadsPolicy.from_json({
234
- "payloads" => {
235
- "log_payloads" => true,
236
- "log_blacklist" => {
237
- "username" => ["*"]
238
- },
239
- "log_whitelist" => {
240
- "username" => ["*"]
241
- }
242
- }
243
- })
244
-
245
- expect(TCellAgent).to_not receive(:configuration)
246
-
247
- policy.log(
248
- "xss",
249
- @meta,
250
- TCellAgent::Utils::Params::GET_PARAM,
251
- "password",
252
- "alert()",
253
- {"l" => "query"},
254
- "pattern"
255
- )
256
- end
257
- end
258
-
259
- context "that specifies locations for the param" do
260
- context "param location does not match specified location" do
261
- it "should not log" do
262
- policy = PayloadsPolicy.from_json({
263
- "payloads" => {
264
- "log_payloads" => true,
265
- "log_blacklist" => {
266
- "username" => ["*"],
267
- },
268
- "log_whitelist" => {
269
- "password" => ["cookie"]
270
- }
271
- }
272
- })
273
-
274
- expect(TCellAgent).to_not receive(:configuration)
275
-
276
- policy.log(
277
- "xss",
278
- @meta,
279
- TCellAgent::Utils::Params::GET_PARAM,
280
- "password",
281
- "alert()",
282
- {"l" => "query"},
283
- "pattern"
284
- )
285
- end
286
- end
287
-
288
- context "param location matches the specified location" do
289
- it "should log the value" do
290
- policy = PayloadsPolicy.from_json({
291
- "payloads" => {
292
- "log_payloads" => true,
293
- "log_blacklist" => {
294
- "username" => ["*"],
295
- },
296
- "log_whitelist" => {
297
- "PASSWORD" => ["form"]
298
- }
299
- },
300
- "uri_options" => {"collect_full_uri" => true}
301
- })
302
- configuration = double("configuration", "enabled" => true)
303
- appfirewall_payloads_logger = double("appfirewall_payloads_logger")
304
-
305
- expect(TCellAgent).to receive(:configuration).and_return(configuration).exactly(3).times
306
- expect(configuration).to receive(:appfirewall_payloads_logger).and_return(
307
- appfirewall_payloads_logger
308
- ).exactly(2).times
309
- expect_any_instance_of(TCellAgent::SensorEvents::TCellAppSensorEvent).to receive(
310
- :post_process
311
- )
312
- expect(appfirewall_payloads_logger).to receive(:info).with({
313
- "event_type" => "as",
314
- "dp" => "xss",
315
- "param" => "password",
316
- "remote_addr" => "remote_address",
317
- "m" => "get",
318
- "pattern" => "pattern",
319
- "meta" => {"l" => "query"},
320
- "rid" => "route_id",
321
- "full_uri" => "location"
322
- }.to_json)
323
-
324
- policy.log(
325
- "xss",
326
- @meta,
327
- TCellAgent::Utils::Params::GET_PARAM,
328
- "password",
329
- "alert()",
330
- {"l" => "query"},
331
- "pattern"
332
- )
333
- end
334
- end
335
- end
336
- end
337
- end
338
-
339
- context "that specifies locations for the param" do
340
- context "param location does not match specified location" do
341
- it "should log the value" do
342
- policy = PayloadsPolicy.from_json({
343
- "payloads" => {
344
- "log_payloads" => true,
345
- "log_blacklist" => {
346
- "password" => ["cookie"],
347
- }
348
- },
349
- "uri_options" => {"collect_full_uri" => false}
350
- })
351
- configuration = double("configuration", "enabled" => true)
352
- appfirewall_payloads_logger = double("appfirewall_payloads_logger")
353
-
354
- expect(TCellAgent).to receive(:configuration).and_return(configuration).exactly(3).times
355
- expect(configuration).to receive(:appfirewall_payloads_logger).and_return(
356
- appfirewall_payloads_logger
357
- ).exactly(2).times
358
- expect_any_instance_of(TCellAgent::SensorEvents::TCellAppSensorEvent).to receive(
359
- :post_process
360
- )
361
- expect(appfirewall_payloads_logger).to receive(:info).with({
362
- "event_type" => "as",
363
- "dp" => "xss",
364
- "param" => "password",
365
- "remote_addr" => "remote_address",
366
- "m" => "get",
367
- "pattern" => "pattern",
368
- "meta" => {"l" => "query"},
369
- "rid" => "route_id"
370
- }.to_json)
371
-
372
- policy.log(
373
- "xss",
374
- @meta,
375
- TCellAgent::Utils::Params::GET_PARAM,
376
- "password",
377
- "alert()",
378
- {"l" => "query"},
379
- "pattern"
380
- )
381
- end
382
- end
383
-
384
- context "param location matches the specified location" do
385
- it "should not log" do
386
- policy = PayloadsPolicy.from_json({
387
- "payloads" => {
388
- "log_payloads" => true,
389
- "log_blacklist" => {
390
- "password" => ["form"],
391
- }
392
- }
393
- })
394
-
395
- expect(TCellAgent).to_not receive(:configuration)
396
-
397
- policy.log(
398
- "xss",
399
- @meta,
400
- TCellAgent::Utils::Params::GET_PARAM,
401
- "password",
402
- "alert()",
403
- {"l" => "query"},
404
- "pattern"
405
- )
406
- end
407
- end
408
- end
409
- end
410
- end
411
-
412
- end
413
-
414
- end
415
-
416
- end
417
- end
@@ -1,236 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
- module Policies
5
-
6
- describe RequestSizeSensor do
7
- context "#initialize" do
8
- context "default sensor" do
9
- it "should have properties set to defaults" do
10
- sensor = RequestSizeSensor.new
11
- expect(sensor.enabled).to eq(false)
12
- expect(sensor.limit).to eq(524288)
13
- expect(sensor.excluded_route_ids).to eq({})
14
- expect(sensor.dp_code).to eq(RequestSizeSensor::DP_UNUSUAL_REQUEST_SIZE)
15
- end
16
- end
17
-
18
- context "setting enabled on sensor" do
19
- it "should have properties set to defaults" do
20
- sensor = RequestSizeSensor.new({"enabled" => true})
21
- expect(sensor.enabled).to eq(true)
22
- expect(sensor.limit).to eq(524288)
23
- expect(sensor.excluded_route_ids).to eq({})
24
- expect(sensor.dp_code).to eq(RequestSizeSensor::DP_UNUSUAL_REQUEST_SIZE)
25
- end
26
- end
27
-
28
- context "setting limit on sensor" do
29
- it "should have properties set to defaults" do
30
- sensor = RequestSizeSensor.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(RequestSizeSensor::DP_UNUSUAL_REQUEST_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 = RequestSizeSensor.new({"exclude_routes" => ["1", "10", "20"]})
41
- expect(sensor.enabled).to eq(false)
42
- expect(sensor.limit).to eq(524288)
43
- expect(sensor.excluded_route_ids).to eq({"1"=>true, "10"=>true, "20"=>true})
44
- expect(sensor.dp_code).to eq(RequestSizeSensor::DP_UNUSUAL_REQUEST_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 = RequestSizeSensor.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.request_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 = RequestSizeSensor.new({
72
- "enabled" => true,
73
- "limit" => 1,
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.request_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 = RequestSizeSensor.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.request_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 = RequestSizeSensor.new({
120
- "enabled" => true,
121
- "limit" => 1,
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.request_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 = RequestSizeSensor.new({
144
- "enabled" => true,
145
- "limit" => 1,
146
- "exclude_routes" => ["excluded_route_id"]
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.request_content_bytes_len = 1024 + 512
158
-
159
- expect(TCellAgent).to_not receive(:send_event)
160
- sensor.check(meta)
161
- end
162
- end
163
-
164
- context "route_id is excluded" do
165
- it "should not send event" do
166
- sensor = RequestSizeSensor.new({
167
- "enabled" => true,
168
- "limit" => 1,
169
- "exclude_routes" => ["excluded_route_id"]
170
- })
171
-
172
- meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
173
- meta.remote_address = "remote_address"
174
- meta.method = "get"
175
- meta.location = "location"
176
- meta.route_id = "excluded_route_id"
177
- meta.session_id = "session_id"
178
- meta.user_id = "user_id"
179
- meta.transaction_id = "transaction_id"
180
- meta.request_content_bytes_len = 2048
181
-
182
- expect(TCellAgent).to_not receive(:send_event)
183
- sensor.check(meta)
184
- end
185
- end
186
-
187
- context "route is not excluded" do
188
- it "should send event" do
189
- sensor = RequestSizeSensor.new({
190
- "enabled" => true,
191
- "limit" => 1,
192
- "exclude_routes" => []
193
- })
194
-
195
- meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
196
- meta.remote_address = "remote_address"
197
- meta.method = "get"
198
- meta.location = "location"
199
- meta.route_id = "excluded_route_id"
200
- meta.session_id = "session_id"
201
- meta.user_id = "user_id"
202
- meta.transaction_id = "transaction_id"
203
- meta.request_content_bytes_len = 2048
204
-
205
- expect(TCellAgent).to receive(:send_event).with(
206
- {
207
- "event_type" => "as",
208
- "dp" => RequestSizeSensor::DP_UNUSUAL_REQUEST_SIZE,
209
- "remote_addr" => "remote_address",
210
- "m" => "get",
211
- "meta" => {"sz" => 2048},
212
- "rid" => "excluded_route_id"
213
- }
214
- )
215
- sensor.check(meta)
216
- end
217
- end
218
- end
219
-
220
- end
221
- end
222
-
223
- context "#get_content_length" do
224
- it "should return the request size" do
225
- sensor = RequestSizeSensor.new({"enabled" => false})
226
- meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
227
- meta.request_content_bytes_len = 1024
228
- meta.response_content_bytes_len = 2048
229
-
230
- expect(sensor.get_content_length(meta)).to eq(1024)
231
- end
232
- end
233
- end
234
-
235
- end
236
- end