tcell_agent 1.1.3 → 1.1.4

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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/bin/tcell_agent +10 -2
  3. data/lib/tcell_agent.rb +3 -3
  4. data/lib/tcell_agent/agent.rb +42 -52
  5. data/lib/tcell_agent/agent/event_processor.rb +129 -162
  6. data/lib/tcell_agent/agent/fork_pipe_manager.rb +57 -62
  7. data/lib/tcell_agent/agent/policy_manager.rb +83 -104
  8. data/lib/tcell_agent/agent/policy_types.rb +24 -29
  9. data/lib/tcell_agent/agent/route_manager.rb +36 -46
  10. data/lib/tcell_agent/agent/static_agent.rb +19 -21
  11. data/lib/tcell_agent/api.rb +23 -28
  12. data/lib/tcell_agent/appsensor/injections_reporter.rb +7 -11
  13. data/lib/tcell_agent/authlogic.rb +7 -7
  14. data/lib/tcell_agent/cmdi.rb +22 -23
  15. data/lib/tcell_agent/config/unknown_options.rb +71 -69
  16. data/lib/tcell_agent/configuration.rb +187 -191
  17. data/lib/tcell_agent/devise.rb +13 -15
  18. data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
  19. data/lib/tcell_agent/instrumentation.rb +120 -124
  20. data/lib/tcell_agent/logger.rb +29 -45
  21. data/lib/tcell_agent/patches.rb +5 -5
  22. data/lib/tcell_agent/policies/dataloss_policy.rb +263 -288
  23. data/lib/tcell_agent/policies/http_redirect_policy.rb +25 -37
  24. data/lib/tcell_agent/policies/http_tx_policy.rb +48 -52
  25. data/lib/tcell_agent/policies/login_fraud_policy.rb +15 -20
  26. data/lib/tcell_agent/policies/policy.rb +0 -2
  27. data/lib/tcell_agent/policies/rust_policies.rb +24 -29
  28. data/lib/tcell_agent/rails.rb +2 -3
  29. data/lib/tcell_agent/rails/auth/authlogic.rb +2 -2
  30. data/lib/tcell_agent/rails/auth/devise.rb +2 -2
  31. data/lib/tcell_agent/rails/auth/doorkeeper.rb +2 -2
  32. data/lib/tcell_agent/rails/better_ip.rb +12 -16
  33. data/lib/tcell_agent/rails/csrf_exception.rb +4 -7
  34. data/lib/tcell_agent/rails/dlp.rb +208 -107
  35. data/lib/tcell_agent/rails/dlp/process_request.rb +37 -47
  36. data/lib/tcell_agent/rails/dlp_handler.rb +9 -11
  37. data/lib/tcell_agent/rails/js_agent_insert.rb +11 -14
  38. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +8 -7
  39. data/lib/tcell_agent/rails/middleware/context_middleware.rb +4 -5
  40. data/lib/tcell_agent/rails/middleware/global_middleware.rb +5 -8
  41. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +24 -27
  42. data/lib/tcell_agent/rails/on_start.rb +5 -5
  43. data/lib/tcell_agent/rails/responses.rb +7 -9
  44. data/lib/tcell_agent/rails/routes.rb +62 -81
  45. data/lib/tcell_agent/rails/routes/grape.rb +25 -30
  46. data/lib/tcell_agent/rails/routes/route_id.rb +9 -14
  47. data/lib/tcell_agent/rails/settings_reporter.rb +44 -33
  48. data/lib/tcell_agent/rails/tcell_body_proxy.rb +15 -18
  49. data/lib/tcell_agent/routes/table.rb +31 -33
  50. data/lib/tcell_agent/rust/{libtcellagent-1.3.0.dylib → libtcellagent-1.3.1.dylib} +0 -0
  51. data/lib/tcell_agent/rust/{libtcellagent-1.3.0.so → libtcellagent-1.3.1.so} +0 -0
  52. data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.0.so → libtcellagent-alpine-1.3.1.so} +0 -0
  53. data/lib/tcell_agent/rust/models.rb +32 -37
  54. data/lib/tcell_agent/rust/tcellagent-1.3.1.dll +0 -0
  55. data/lib/tcell_agent/rust/whisperer.rb +101 -104
  56. data/lib/tcell_agent/sensor_events/app_config.rb +7 -7
  57. data/lib/tcell_agent/sensor_events/appsensor_event.rb +26 -27
  58. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +20 -88
  59. data/lib/tcell_agent/sensor_events/command_injection.rb +52 -80
  60. data/lib/tcell_agent/sensor_events/discovery.rb +27 -27
  61. data/lib/tcell_agent/sensor_events/dlp.rb +50 -56
  62. data/lib/tcell_agent/sensor_events/honeytokens.rb +9 -9
  63. data/lib/tcell_agent/sensor_events/metrics.rb +20 -21
  64. data/lib/tcell_agent/sensor_events/patches.rb +10 -12
  65. data/lib/tcell_agent/sensor_events/sensor.rb +32 -36
  66. data/lib/tcell_agent/sensor_events/server_agent.rb +130 -127
  67. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +60 -80
  68. data/lib/tcell_agent/sensor_events/util/utils.rb +3 -5
  69. data/lib/tcell_agent/servers/passenger.rb +5 -9
  70. data/lib/tcell_agent/servers/puma.rb +18 -27
  71. data/lib/tcell_agent/servers/rails_server.rb +5 -9
  72. data/lib/tcell_agent/servers/thin.rb +2 -4
  73. data/lib/tcell_agent/servers/unicorn.rb +18 -27
  74. data/lib/tcell_agent/servers/webrick.rb +2 -4
  75. data/lib/tcell_agent/settings_reporter.rb +126 -0
  76. data/lib/tcell_agent/sinatra.rb +24 -26
  77. data/lib/tcell_agent/start_background_thread.rb +21 -142
  78. data/lib/tcell_agent/system_info.rb +4 -3
  79. data/lib/tcell_agent/tcell_context.rb +150 -0
  80. data/lib/tcell_agent/userinfo.rb +3 -3
  81. data/lib/tcell_agent/utils/io.rb +19 -24
  82. data/lib/tcell_agent/utils/params.rb +9 -15
  83. data/lib/tcell_agent/utils/queue_with_timeout.rb +26 -32
  84. data/lib/tcell_agent/utils/strings.rb +4 -6
  85. data/lib/tcell_agent/version.rb +1 -1
  86. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +5 -5
  87. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +7 -7
  88. data/spec/lib/tcell_agent/cmdi_spec.rb +21 -21
  89. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +29 -24
  90. data/spec/lib/tcell_agent/instrumentation_spec.rb +4 -4
  91. data/spec/lib/tcell_agent/patches_spec.rb +8 -8
  92. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +23 -23
  93. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +2 -2
  94. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +69 -0
  95. data/spec/lib/tcell_agent/rails/dlp_spec.rb +1039 -0
  96. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +271 -0
  97. data/spec/lib/tcell_agent/rails/logger_spec.rb +5 -5
  98. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +3 -3
  99. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +4 -4
  100. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +5 -5
  101. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +1 -1
  102. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +11 -8
  103. data/spec/lib/tcell_agent/rails/responses_spec.rb +2 -2
  104. data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +2 -2
  105. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +1 -1
  106. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +4 -4
  107. data/spec/lib/tcell_agent/rust/models_spec.rb +83 -75
  108. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +14 -14
  109. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +19 -70
  110. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +1 -1
  111. data/spec/lib/tcell_agent/settings_reporter_spec.rb +162 -0
  112. data/spec/lib/tcell_agent/tcell_context_spec.rb +154 -0
  113. data/spec/spec_helper.rb +5 -0
  114. metadata +18 -10
  115. data/lib/tcell_agent/appsensor/meta_data.rb +0 -132
  116. data/lib/tcell_agent/patches/meta_data.rb +0 -59
  117. data/lib/tcell_agent/rust/tcellagent-1.3.0.dll +0 -0
  118. data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +0 -71
@@ -7,7 +7,7 @@ module TCellAgent
7
7
  context 'with nil status code' do
8
8
  context 'with empty headers' do
9
9
  it 'should return false' do
10
- expect(Rails.empty_content?(nil, {})).to eq(false)
10
+ expect(Rails.empty_content?(nil, {})).to eq(nil)
11
11
  end
12
12
  end
13
13
 
@@ -52,7 +52,7 @@ module TCellAgent
52
52
  context 'that contains content' do
53
53
  context 'with empty headers' do
54
54
  it 'should return false' do
55
- expect(Rails.empty_content?(200, {})).to eq(false)
55
+ expect(Rails.empty_content?(200, {})).to eq(nil)
56
56
  end
57
57
  end
58
58
 
@@ -197,14 +197,14 @@ module TCellAgent
197
197
  describe '.instrument_grape_api' do
198
198
  context 'with nil routes' do
199
199
  it 'should not send any events' do
200
- expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
200
+ expect(TCellAgent::SensorEvents::Util).to_not receive(:calculate_route_id)
201
201
  TCellAgent::Instrumentation.instrument_grape_api('/api', nil)
202
202
  end
203
203
  end
204
204
 
205
205
  context 'with empty routes' do
206
206
  it 'should not send any events' do
207
- expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
207
+ expect(TCellAgent::SensorEvents::Util).to_not receive(:calculate_route_id)
208
208
  TCellAgent::Instrumentation.instrument_grape_api('/api', [])
209
209
  end
210
210
  end
@@ -44,7 +44,7 @@ module TCellAgent
44
44
  RouteId.update_context({ TCELL_CONTEXT_KEY => tcell_context }, { :id => 1 }, route)
45
45
 
46
46
  expect(tcell_context.route_id).to eq(
47
- TCellAgent::SensorEvents::Util.calculateRouteId('GET', '/some/regular/path')
47
+ TCellAgent::SensorEvents::Util.calculate_route_id('GET', '/some/regular/path')
48
48
  )
49
49
  expect(tcell_context.grape_mount_endpoint).to eq(nil)
50
50
  expect(tcell_context.path_parameters).to eq({ :id => 1 })
@@ -21,7 +21,7 @@ module TCellAgent
21
21
 
22
22
  expect(TCellAgent).to receive(:configuration).and_return(configuration).twice
23
23
  expect(TCellAgent::Instrumentation).to_not receive(:instrument_grape_api)
24
- expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
24
+ expect(TCellAgent::SensorEvents::Util).to_not receive(:calculate_route_id)
25
25
 
26
26
  Rails.instrument_route(nil)
27
27
  end
@@ -69,7 +69,7 @@ module TCellAgent
69
69
 
70
70
  expect(TCellAgent).to receive(:configuration).and_return(configuration).twice
71
71
  expect(route).to receive(:verb).and_return('GET|POST')
72
- expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
72
+ expect(TCellAgent::SensorEvents::Util).to_not receive(:calculate_route_id)
73
73
  expect(TCellAgent::Instrumentation).to receive(:instrument_grape_api).with(
74
74
  '/grape', ['/api/grape/route']
75
75
  )
@@ -123,7 +123,7 @@ module TCellAgent
123
123
  expect(TCellAgent::Instrumentation).to receive(:instrument_grape_api).with(
124
124
  '/grape', ['/api/grape/route']
125
125
  )
126
- expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
126
+ expect(TCellAgent::SensorEvents::Util).to_not receive(:calculate_route_id)
127
127
 
128
128
  Rails.instrument_route(route)
129
129
  end
@@ -173,7 +173,7 @@ module TCellAgent
173
173
  expect(TCellAgent::Instrumentation).to receive(:instrument_grape_api).with(
174
174
  '/grape', ['/api/grape/route']
175
175
  )
176
- expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
176
+ expect(TCellAgent::SensorEvents::Util).to_not receive(:calculate_route_id)
177
177
 
178
178
  Rails.instrument_route(route)
179
179
  end
@@ -5,7 +5,7 @@ module TCellAgent
5
5
  module Rust
6
6
  describe '.create_request_response' do
7
7
  it 'should create request response' do
8
- appsensor_meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new(
8
+ meta_data = TCellAgent::MetaData.new(
9
9
  'GET',
10
10
  '192.168.1.1',
11
11
  '12345',
@@ -14,66 +14,70 @@ module TCellAgent
14
14
  'transaction_id',
15
15
  'http://192.168.1.1/some/path?xss_param=<script>'
16
16
  )
17
- appsensor_meta.response_code = 200
18
- appsensor_meta.user_agent = 'Mozilla'
19
- appsensor_meta.path = '/some/path'
20
- appsensor_meta.request_content_bytes_len = 1024
21
- appsensor_meta.response_content_bytes_len = 2048
22
- appsensor_meta.get_dict = { 'user' => { 'xss_param' => '<script>' } }
23
- appsensor_meta.sql_exceptions = [{ 'exception_name' => 'OperationalError', 'exception_payload' => 'Developer Error' }]
24
- appsensor_meta.csrf_exception_name = 'ActionController::InvalidAuthenticityToken'
25
- appsensor_meta.path_parameters = { 'xss_param' => '<script>' }
26
- appsensor_meta.post_dict = TCellAgent::Utils::Params.flatten({ 'already_flattened' => { 'xss_param' => '<script>' } })
27
- appsensor_meta.body_dict = TCellAgent::Utils::Params.flatten({ 'already_flattened' => { 'xss_param' => '<script>' } })
28
- appsensor_meta.cookie_dict = { 'xss_param' => '<script>' }
29
- appsensor_meta.set_headers_dict({ 'HTTP_XSS_PARAM' => '<script>' })
17
+ meta_data.response_code = 200
18
+ meta_data.user_agent = 'Mozilla'
19
+ meta_data.path = '/some/path'
20
+ meta_data.request_content_bytes_len = 1024
21
+ meta_data.response_content_bytes_len = 2048
22
+ meta_data.get_dict = { 'user' => { 'xss_param' => '<script>' } }
23
+ meta_data.sql_exceptions = [{ 'exception_name' => 'OperationalError', 'exception_payload' => 'Developer Error' }]
24
+ meta_data.csrf_exception_name = 'ActionController::InvalidAuthenticityToken'
25
+ meta_data.path_parameters = { 'xss_param' => '<script>' }
26
+ meta_data.post_dict = { 'xss_param' => '<script>' }
27
+ meta_data.cookie_dict = { 'xss_param' => '<script>' }
28
+ meta_data.headers_dict = { 'HTTP_XSS_PARAM' => '<script>' }
30
29
 
31
- result = Models.create_request_response(appsensor_meta)
30
+ json_body = { 'xss_param' => '<script>' }.to_json
31
+ meta_data.set_body_dict(json_body.bytesize, 'application/json', json_body)
32
32
 
33
- expect(result).to eq({
34
- 'method' => 'GET',
35
- 'status_code' => 200,
36
- 'route_id' => '12345',
37
- 'path' => '/some/path',
38
- 'query_params' => [
39
- { 'name' => 'xss_param', 'value' => '<script>' }
40
- ],
41
- 'post_params' => [
42
- { 'name' => 'xss_param', 'value' => '<script>' },
43
- { 'name' => 'xss_param', 'value' => '<script>' }
44
- ],
45
- 'headers' => [
46
- { 'name' => 'xss-param', 'value' => '<script>' }
47
- ],
48
- 'cookies' => [
49
- { 'name' => 'xss_param', 'value' => '<script>' }
50
- ],
51
- 'path_params' => [
52
- { 'name' => 'xss_param', 'value' => '<script>' }
53
- ],
54
- 'remote_address' => '192.168.1.1',
55
- 'full_uri' => 'http://192.168.1.1/some/path?xss_param=<script>',
56
- 'session_id' => 'session_id',
57
- 'user_id' => 'user_id',
58
- 'user_agent' => 'Mozilla',
59
- 'request_bytes_length' => 1024,
60
- 'response_bytes_length' => 2048,
61
- 'csrf_exception' => {
62
- 'exception_name' => 'ActionController::InvalidAuthenticityToken'
63
- },
64
- 'sql_exceptions' => [
65
- {
66
- 'exception_name' => 'OperationalError',
67
- 'exception_payload' => 'Developer Error'
68
- }
69
- ]
70
- })
33
+ result = Models.create_request_response(meta_data)
34
+
35
+ expect(result).to eq(
36
+ {
37
+ 'method' => 'GET',
38
+ 'status_code' => 200,
39
+ 'route_id' => '12345',
40
+ 'path' => '/some/path',
41
+ 'query_params' => [
42
+ { 'name' => 'xss_param', 'value' => '<script>' }
43
+ ],
44
+ 'post_params' => [
45
+ { 'name' => 'xss_param', 'value' => '<script>' },
46
+ { 'name' => 'xss_param', 'value' => '<script>' }
47
+ ],
48
+ 'headers' => [
49
+ { 'name' => 'xss-param', 'value' => '<script>' }
50
+ ],
51
+ 'cookies' => [
52
+ { 'name' => 'xss_param', 'value' => '<script>' }
53
+ ],
54
+ 'path_params' => [
55
+ { 'name' => 'xss_param', 'value' => '<script>' }
56
+ ],
57
+ 'remote_address' => '192.168.1.1',
58
+ 'full_uri' => 'http://192.168.1.1/some/path?xss_param=<script>',
59
+ 'session_id' => 'session_id',
60
+ 'user_id' => 'user_id',
61
+ 'user_agent' => 'Mozilla',
62
+ 'request_bytes_length' => 1024,
63
+ 'response_bytes_length' => 2048,
64
+ 'csrf_exception' => {
65
+ 'exception_name' => 'ActionController::InvalidAuthenticityToken'
66
+ },
67
+ 'sql_exceptions' => [
68
+ {
69
+ 'exception_name' => 'OperationalError',
70
+ 'exception_payload' => 'Developer Error'
71
+ }
72
+ ]
73
+ }
74
+ )
71
75
  end
72
76
  end
73
77
 
74
78
  describe '.create_patches_request' do
75
79
  it 'should create patches request' do
76
- appsensor_meta = TCellAgent::Patches::MetaData.new(
80
+ meta_data = TCellAgent::MetaData.new(
77
81
  'GET',
78
82
  '192.168.1.1',
79
83
  '12345',
@@ -83,29 +87,33 @@ module TCellAgent
83
87
  'http://192.168.1.1/some/path?xss_param=<script>'
84
88
  )
85
89
 
86
- appsensor_meta.path = '/some/path'
87
- appsensor_meta.request_content_bytes_len = 1024
88
- appsensor_meta.get_dict = { 'user' => { 'xss_param' => '<script>' } }
89
- appsensor_meta.post_dict = { 'user' => { 'xss_param' => '<script>' } }
90
- appsensor_meta.body_dict = { 'user' => { 'xss_param' => '<script>' } }
91
- appsensor_meta.cookie_dict = { 'xss_param' => '<script>' }
92
- appsensor_meta.set_headers_dict({ 'HTTP_XSS_PARAM' => '<script>' })
90
+ meta_data.path = '/some/path'
91
+ meta_data.request_content_bytes_len = 1024
92
+ meta_data.get_dict = { 'user' => { 'xss_param' => '<script>' } }
93
+ meta_data.post_dict = { 'user' => { 'xss_param' => '<script>' } }
94
+ meta_data.cookie_dict = { 'xss_param' => '<script>' }
95
+ meta_data.headers_dict = { 'HTTP_XSS_PARAM' => '<script>' }
93
96
 
94
- result = Models.create_patches_request(appsensor_meta)
97
+ json_body = { 'user' => { 'xss_param' => '<script>' } }.to_json
98
+ meta_data.set_body_dict(json_body.bytesize, 'application/json', json_body)
95
99
 
96
- expect(result).to eq({
97
- 'method' => 'GET',
98
- 'path' => '/some/path',
99
- 'remote_address' => '192.168.1.1',
100
- 'request_bytes_length' => 1024,
101
- 'query_params' => [{ 'name' => 'xss_param', 'value' => '<script>' }],
102
- 'post_params' => [
103
- { 'name' => 'xss_param', 'value' => '<script>' },
104
- { 'name' => 'r', 'value' => { 'xss_param' => '<script>' } }
105
- ],
106
- 'headers' => [{ 'name' => 'xss-param', 'value' => '<script>' }],
107
- 'cookies' => [{ 'name' => 'xss_param', 'value' => '<script>' }]
108
- })
100
+ result = Models.create_patches_request(meta_data)
101
+
102
+ expect(result).to eq(
103
+ {
104
+ 'method' => 'GET',
105
+ 'path' => '/some/path',
106
+ 'remote_address' => '192.168.1.1',
107
+ 'request_bytes_length' => 1024,
108
+ 'query_params' => [{ 'name' => 'xss_param', 'value' => '<script>' }],
109
+ 'post_params' => [
110
+ { 'name' => 'xss_param', 'value' => '<script>' },
111
+ { 'name' => 'xss_param', 'value' => '<script>' }
112
+ ],
113
+ 'headers' => [{ 'name' => 'xss-param', 'value' => '<script>' }],
114
+ 'cookies' => [{ 'name' => 'xss_param', 'value' => '<script>' }]
115
+ }
116
+ )
109
117
  end
110
118
  end
111
119
  end
@@ -602,7 +602,7 @@ module TCellAgent
602
602
  end
603
603
 
604
604
  it 'should return appfirewall injections' do
605
- appsensor_meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new(
605
+ meta_data = TCellAgent::MetaData.new(
606
606
  'GET',
607
607
  '192.168.1.1',
608
608
  '12345',
@@ -611,22 +611,22 @@ module TCellAgent
611
611
  'transaction_id',
612
612
  'http://192.168.1.1/some/path?xss_param=<script>'
613
613
  )
614
- appsensor_meta.path = '/some/path'
615
- appsensor_meta.request_content_bytes_len = 1024
616
- appsensor_meta.response_content_bytes_len = 2048
617
- appsensor_meta.get_dict = { 'xss_param' => '<script>' }
618
- appsensor_meta.user_agent = 'Mozilla'
619
- appsensor_meta.sql_exceptions = [
614
+ meta_data.path = '/some/path'
615
+ meta_data.request_content_bytes_len = 1024
616
+ meta_data.response_content_bytes_len = 2048
617
+ meta_data.get_dict = { 'xss_param' => '<script>' }
618
+ meta_data.user_agent = 'Mozilla'
619
+ meta_data.sql_exceptions = [
620
620
  {
621
621
  'exception_name' => 'OperationalError',
622
622
  'exception_payload' => 'Developer Error'
623
623
  }
624
624
  ]
625
- appsensor_meta.csrf_exception_name = 'ActionController::InvalidAuthenticityToken'
625
+ meta_data.csrf_exception_name = 'ActionController::InvalidAuthenticityToken'
626
626
 
627
627
  whisper = Whisperer.apply_appfirewall(
628
628
  @agent_ptr,
629
- appsensor_meta
629
+ meta_data
630
630
  )
631
631
  expect(whisper).to eq(
632
632
  {
@@ -669,7 +669,7 @@ module TCellAgent
669
669
  end
670
670
 
671
671
  it 'should return patches blocking' do
672
- appsensor_meta = TCellAgent::Patches::MetaData.new(
672
+ meta_data = TCellAgent::MetaData.new(
673
673
  'GET',
674
674
  '192.168.1.1',
675
675
  '12345',
@@ -678,12 +678,12 @@ module TCellAgent
678
678
  'transaction_id',
679
679
  'http://192.168.1.1/some/path?xss_param=<script>'
680
680
  )
681
- appsensor_meta.path = '/some/path'
682
- appsensor_meta.request_content_bytes_len = 1024
683
- appsensor_meta.get_dict = { 'xss_param' => '<script>' }
681
+ meta_data.path = '/some/path'
682
+ meta_data.request_content_bytes_len = 1024
683
+ meta_data.get_dict = { 'xss_param' => '<script>' }
684
684
  whisper = Whisperer.apply_patches(
685
685
  @agent_ptr,
686
- appsensor_meta
686
+ meta_data
687
687
  )
688
688
  expect(whisper).to eq(
689
689
  {
@@ -3,9 +3,9 @@ require 'spec_helper'
3
3
  module TCellAgent
4
4
  module SensorEvents
5
5
  describe AppSensorMetaEvent do
6
- describe '#body_params' do
6
+ describe '#post_process' do
7
7
  before(:each) do
8
- @appsensor_meta = AppSensorMetaEvent.new(
8
+ @meta_data = TCellAgent::MetaData.new(
9
9
  'get',
10
10
  'remote_address',
11
11
  'route_id',
@@ -14,80 +14,29 @@ module TCellAgent
14
14
  'transaction_id',
15
15
  'http://test.com'
16
16
  )
17
+ @appsensor_meta_event = AppSensorMetaEvent.new(@meta_data)
17
18
  end
18
19
 
19
- context 'with text/html content type' do
20
- it 'should set the body params to empty' do
21
- @appsensor_meta.set_body_dict(
22
- 67,
23
- 'text/html',
24
- {
25
- :username => 'tester',
26
- :password => 'pass'
27
- }.to_json
28
- )
20
+ context 'empty rust policies' do
21
+ it 'should not process anything' do
22
+ expect(TCellAgent).to receive(:policy).with(
23
+ TCellAgent::PolicyTypes::RUST
24
+ ).and_return(nil)
29
25
 
30
- expect(@appsensor_meta.body_dict).to eq({})
26
+ @appsensor_meta_event.post_process
31
27
  end
32
28
  end
29
+ context 'rust policies available' do
30
+ it 'should call rust policies for processing' do
31
+ rust_policies = double('rust_policies')
32
+ expect(TCellAgent).to receive(:policy).with(
33
+ TCellAgent::PolicyTypes::RUST
34
+ ).and_return(rust_policies)
35
+ expect(rust_policies).to receive(:check_appfirewall_injections).with(
36
+ @appsensor_meta_event.meta_data
37
+ )
33
38
 
34
- context 'with application/json content type' do
35
- context 'with empty request body' do
36
- it 'should set the body params to empty' do
37
- @appsensor_meta.set_body_dict(
38
- 67,
39
- 'application/json',
40
- nil
41
- )
42
-
43
- expect(@appsensor_meta.body_dict).to eq({})
44
- end
45
- end
46
-
47
- context 'with bad json in the body' do
48
- it 'should set the body params to empty' do
49
- @appsensor_meta.set_body_dict(
50
- 67,
51
- 'application/json',
52
- '{"username":"tester""password":"pass"}'
53
- )
54
-
55
- expect(@appsensor_meta.body_dict).to eq({})
56
- end
57
- end
58
-
59
- context 'with valid json in the body' do
60
- it 'should set the body params' do
61
- @appsensor_meta.set_body_dict(
62
- 67,
63
- 'application/json',
64
- {
65
- :username => 'tester',
66
- :password => 'pass'
67
- }.to_json
68
- )
69
-
70
- expect(@appsensor_meta.body_dict).to eq(
71
- {
72
- ['username'] => 'tester',
73
- ['password'] => 'pass'
74
- }
75
- )
76
- end
77
- end
78
-
79
- context 'with a json body that is too big' do
80
- it 'should set the body params to empty' do
81
- @appsensor_meta.set_body_dict(
82
- 20_000_000,
83
- 'application/json',
84
- {
85
- :username => 'tester',
86
- :password => 'pass'
87
- }.to_json
88
- )
89
- expect(@appsensor_meta.body_dict).to eq({})
90
- end
39
+ @appsensor_meta_event.post_process
91
40
  end
92
41
  end
93
42
  end
@@ -19,7 +19,7 @@ module TCellAgent
19
19
  sessions_metric = SessionsMetric.new
20
20
  sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
21
21
 
22
- expect(sessions_metric.has_sessions?).to eq(true)
22
+ expect(sessions_metric.sessions?).to eq(true)
23
23
  expect(sessions_metric).to eq(
24
24
  {
25
25
  'event_type' => 'metrics',