tcell_agent 0.4.0 → 1.0.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 (199) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -22
  3. data/bin/tcell_agent +127 -132
  4. data/lib/tcell_agent/agent/event_processor.rb +23 -22
  5. data/lib/tcell_agent/agent/fork_pipe_manager.rb +7 -7
  6. data/lib/tcell_agent/agent/policy_manager.rb +20 -15
  7. data/lib/tcell_agent/agent/policy_types.rb +5 -11
  8. data/lib/tcell_agent/agent/static_agent.rb +5 -1
  9. data/lib/tcell_agent/agent.rb +6 -4
  10. data/lib/tcell_agent/api.rb +7 -9
  11. data/lib/tcell_agent/appsensor/meta_data.rb +11 -4
  12. data/lib/tcell_agent/authlogic.rb +3 -3
  13. data/lib/tcell_agent/cmdi.rb +6 -4
  14. data/lib/tcell_agent/config/unknown_options.rb +3 -1
  15. data/lib/tcell_agent/configuration.rb +47 -49
  16. data/lib/tcell_agent/devise.rb +2 -2
  17. data/lib/tcell_agent/hooks/login_fraud.rb +58 -29
  18. data/lib/tcell_agent/instrumentation.rb +11 -10
  19. data/lib/tcell_agent/logger.rb +2 -2
  20. data/lib/tcell_agent/patches/meta_data.rb +9 -13
  21. data/lib/tcell_agent/patches.rb +7 -10
  22. data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -5
  23. data/lib/tcell_agent/policies/content_security_policy.rb +6 -12
  24. data/lib/tcell_agent/policies/dataloss_policy.rb +2 -2
  25. data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
  26. data/lib/tcell_agent/policies/policy.rb +0 -2
  27. data/lib/tcell_agent/policies/rust_policies.rb +90 -0
  28. data/lib/tcell_agent/policies/secure_headers_policy.rb +2 -2
  29. data/lib/tcell_agent/rails/auth/authlogic.rb +42 -24
  30. data/lib/tcell_agent/rails/auth/devise.rb +44 -23
  31. data/lib/tcell_agent/rails/auth/doorkeeper.rb +33 -15
  32. data/lib/tcell_agent/rails/better_ip.rb +1 -1
  33. data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
  34. data/lib/tcell_agent/rails/dlp/process_request.rb +1 -1
  35. data/lib/tcell_agent/rails/dlp.rb +6 -6
  36. data/lib/tcell_agent/rails/dlp_handler.rb +1 -1
  37. data/lib/tcell_agent/rails/js_agent_insert.rb +1 -1
  38. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +1 -1
  39. data/lib/tcell_agent/rails/middleware/context_middleware.rb +3 -2
  40. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +10 -9
  41. data/lib/tcell_agent/rails/routes/grape.rb +6 -6
  42. data/lib/tcell_agent/rails/routes.rb +8 -11
  43. data/lib/tcell_agent/rust/libtcellagent-0.11.1.dylib +0 -0
  44. data/lib/tcell_agent/rust/{libtcellagent-0.6.1.so → libtcellagent-0.11.1.so} +0 -0
  45. data/lib/tcell_agent/rust/models.rb +16 -0
  46. data/lib/tcell_agent/rust/tcellagent-0.11.1.dll +0 -0
  47. data/lib/tcell_agent/rust/whisperer.rb +119 -48
  48. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +17 -20
  49. data/lib/tcell_agent/sensor_events/command_injection.rb +50 -5
  50. data/lib/tcell_agent/sensor_events/login_fraud.rb +34 -18
  51. data/lib/tcell_agent/sensor_events/patches.rb +21 -0
  52. data/lib/tcell_agent/sensor_events/server_agent.rb +3 -3
  53. data/lib/tcell_agent/sensor_events/util/utils.rb +4 -3
  54. data/lib/tcell_agent/servers/puma.rb +2 -2
  55. data/lib/tcell_agent/servers/unicorn.rb +1 -1
  56. data/lib/tcell_agent/utils/passwords.rb +28 -0
  57. data/lib/tcell_agent/version.rb +1 -1
  58. data/lib/tcell_agent.rb +1 -5
  59. data/spec/apps/rails-3.2/config/tcell_agent.config +15 -0
  60. data/spec/apps/rails-3.2/log/development.log +0 -0
  61. data/spec/apps/rails-3.2/log/test.log +12 -0
  62. data/spec/apps/rails-4.1/log/test.log +0 -0
  63. data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +46 -45
  64. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +276 -164
  65. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +44 -47
  66. data/spec/lib/tcell_agent/api/api_spec.rb +16 -16
  67. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +131 -116
  68. data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +55 -51
  69. data/spec/lib/tcell_agent/cmdi_spec.rb +413 -436
  70. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +145 -128
  71. data/spec/lib/tcell_agent/configuration_spec.rb +165 -169
  72. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +144 -153
  73. data/spec/lib/tcell_agent/instrumentation_spec.rb +84 -85
  74. data/spec/lib/tcell_agent/patches_spec.rb +70 -111
  75. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +313 -244
  76. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +28 -28
  77. data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +643 -513
  78. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +55 -102
  79. data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +111 -134
  80. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +141 -146
  81. data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +8 -8
  82. data/spec/lib/tcell_agent/policies/login_policy_spec.rb +15 -17
  83. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +231 -559
  84. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +27 -27
  85. data/spec/lib/tcell_agent/rails/better_ip_spec.rb +30 -34
  86. data/spec/lib/tcell_agent/rails/logger_spec.rb +50 -49
  87. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +182 -199
  88. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +110 -84
  89. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +107 -85
  90. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +68 -40
  91. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +81 -67
  92. data/spec/lib/tcell_agent/rails/responses_spec.rb +33 -37
  93. data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +116 -121
  94. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +25 -28
  95. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +87 -85
  96. data/spec/lib/tcell_agent/rails_spec.rb +1 -6
  97. data/spec/lib/tcell_agent/rust/models_spec.rb +112 -0
  98. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +502 -179
  99. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +44 -33
  100. data/spec/lib/tcell_agent/sensor_events/dlp_spec.rb +4 -4
  101. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +183 -169
  102. data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +25 -25
  103. data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +17 -20
  104. data/spec/lib/tcell_agent/utils/params_spec.rb +28 -28
  105. data/spec/lib/tcell_agent/utils/passwords_spec.rb +143 -0
  106. data/spec/lib/tcell_agent/utils/strings_spec.rb +35 -35
  107. data/spec/lib/tcell_agent_spec.rb +8 -8
  108. data/spec/spec_helper.rb +4 -4
  109. data/spec/support/middleware_helper.rb +10 -10
  110. data/spec/support/static_agent_overrides.rb +16 -12
  111. data/tcell_agent.gemspec +17 -33
  112. metadata +43 -198
  113. data/LICENSE_libinjection +0 -32
  114. data/Readme.txt +0 -7
  115. data/ext/libinjection/extconf.rb +0 -3
  116. data/ext/libinjection/libinjection.h +0 -65
  117. data/ext/libinjection/libinjection_html5.c +0 -847
  118. data/ext/libinjection/libinjection_html5.h +0 -54
  119. data/ext/libinjection/libinjection_sqli.c +0 -2317
  120. data/ext/libinjection/libinjection_sqli.h +0 -295
  121. data/ext/libinjection/libinjection_sqli_data.h +0 -9004
  122. data/ext/libinjection/libinjection_wrap.c +0 -3525
  123. data/ext/libinjection/libinjection_xss.c +0 -531
  124. data/ext/libinjection/libinjection_xss.h +0 -21
  125. data/lib/tcell_agent/appsensor/injections_matcher.rb +0 -155
  126. data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +0 -49
  127. data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +0 -67
  128. data/lib/tcell_agent/appsensor/rules/baserules.json +0 -467
  129. data/lib/tcell_agent/patches/block_rule.rb +0 -93
  130. data/lib/tcell_agent/patches/sensors_matcher.rb +0 -31
  131. data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +0 -23
  132. data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +0 -23
  133. data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +0 -117
  134. data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +0 -26
  135. data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +0 -22
  136. data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +0 -34
  137. data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +0 -34
  138. data/lib/tcell_agent/policies/appsensor_policy.rb +0 -49
  139. data/lib/tcell_agent/policies/command_injection_policy.rb +0 -196
  140. data/lib/tcell_agent/policies/honeytokens_policy.rb +0 -69
  141. data/lib/tcell_agent/policies/patches_policy.rb +0 -84
  142. data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
  143. data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
  144. data/spec/apps/rails-3.2/Gemfile +0 -25
  145. data/spec/apps/rails-3.2/Gemfile.lock +0 -126
  146. data/spec/apps/rails-3.2/Rakefile +0 -7
  147. data/spec/apps/rails-3.2/app/assets/images/rails.png +0 -0
  148. data/spec/apps/rails-3.2/app/assets/javascripts/application.js +0 -15
  149. data/spec/apps/rails-3.2/app/assets/stylesheets/application.css +0 -13
  150. data/spec/apps/rails-3.2/app/controllers/application_controller.rb +0 -3
  151. data/spec/apps/rails-3.2/app/controllers/t_cell_app_controller.rb +0 -5
  152. data/spec/apps/rails-3.2/app/helpers/application_helper.rb +0 -2
  153. data/spec/apps/rails-3.2/app/views/layouts/application.html.erb +0 -14
  154. data/spec/apps/rails-3.2/app/views/t_cell_app/index.html.erb +0 -1
  155. data/spec/apps/rails-3.2/config/application.rb +0 -63
  156. data/spec/apps/rails-3.2/config/boot.rb +0 -6
  157. data/spec/apps/rails-3.2/config/environment.rb +0 -5
  158. data/spec/apps/rails-3.2/config/environments/test.rb +0 -37
  159. data/spec/apps/rails-3.2/config/routes.rb +0 -11
  160. data/spec/apps/rails-3.2/config.ru +0 -4
  161. data/spec/apps/rails-4.1/Gemfile +0 -7
  162. data/spec/apps/rails-4.1/Gemfile.lock +0 -114
  163. data/spec/apps/rails-4.1/Rakefile +0 -6
  164. data/spec/apps/rails-4.1/app/assets/javascripts/application.js +0 -16
  165. data/spec/apps/rails-4.1/app/assets/stylesheets/application.css +0 -15
  166. data/spec/apps/rails-4.1/app/controllers/application_controller.rb +0 -5
  167. data/spec/apps/rails-4.1/app/controllers/t_cell_app_controller.rb +0 -5
  168. data/spec/apps/rails-4.1/app/helpers/application_helper.rb +0 -2
  169. data/spec/apps/rails-4.1/app/views/layouts/application.html.erb +0 -14
  170. data/spec/apps/rails-4.1/app/views/t_cell_app/index.html.erb +0 -1
  171. data/spec/apps/rails-4.1/config/application.rb +0 -24
  172. data/spec/apps/rails-4.1/config/boot.rb +0 -4
  173. data/spec/apps/rails-4.1/config/environment.rb +0 -5
  174. data/spec/apps/rails-4.1/config/environments/test.rb +0 -41
  175. data/spec/apps/rails-4.1/config/initializers/assets.rb +0 -8
  176. data/spec/apps/rails-4.1/config/initializers/backtrace_silencers.rb +0 -7
  177. data/spec/apps/rails-4.1/config/initializers/cookies_serializer.rb +0 -3
  178. data/spec/apps/rails-4.1/config/initializers/filter_parameter_logging.rb +0 -4
  179. data/spec/apps/rails-4.1/config/initializers/inflections.rb +0 -16
  180. data/spec/apps/rails-4.1/config/initializers/mime_types.rb +0 -4
  181. data/spec/apps/rails-4.1/config/initializers/session_store.rb +0 -3
  182. data/spec/apps/rails-4.1/config/initializers/wrap_parameters.rb +0 -14
  183. data/spec/apps/rails-4.1/config/locales/en.yml +0 -23
  184. data/spec/apps/rails-4.1/config/routes.rb +0 -12
  185. data/spec/apps/rails-4.1/config/secrets.yml +0 -22
  186. data/spec/apps/rails-4.1/config.ru +0 -4
  187. data/spec/controllers/application_controller.rb +0 -12
  188. data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +0 -522
  189. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -23
  190. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +0 -159
  191. data/spec/lib/tcell_agent/patches/block_rule_spec.rb +0 -458
  192. data/spec/lib/tcell_agent/patches/sensors_matcher_spec.rb +0 -35
  193. data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +0 -139
  194. data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +0 -139
  195. data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +0 -167
  196. data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +0 -139
  197. data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +0 -246
  198. data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +0 -882
  199. data/spec/lib/tcell_agent/policies/honeytokens_policy_spec.rb +0 -22
@@ -5,19 +5,18 @@ module TCellAgent
5
5
  end
6
6
  end
7
7
 
8
-
9
8
  module TCellAgent
10
9
  module Instrumentation
11
10
  describe Instrumentation do
12
- context "Body - SessionId Filters" do
13
- it "Tests Redaction and Events in Body" do
11
+ context 'Body - SessionId Filters' do
12
+ it 'Tests Redaction and Events in Body' do
14
13
  action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
15
14
  action.body_redact = true
16
15
  action.action_id = 5
17
16
  policy_json_two = {
18
- "policy_id"=>"x1a1",
19
- "data"=>{
20
- "session_id_protections"=>{"body"=>["redact"], "log"=>["event"]}
17
+ 'policy_id' => 'x1a1',
18
+ 'data' => {
19
+ 'session_id_protections' => { 'body' => ['redact'], 'log' => ['event'] }
21
20
  }
22
21
  }
23
22
  session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
@@ -26,23 +25,23 @@ module TCellAgent
26
25
  TCellAgent.set_thread_agent(mock_agent)
27
26
 
28
27
  context = TCellData.new
29
- context.session_id = "tim123123my"
28
+ context.session_id = 'tim123123my'
30
29
 
31
- body = "this is about tim123123my 3123123."
30
+ body = 'this is about tim123123my 3123123.'
32
31
  TCellAgent.empty_event_queue
33
32
  context.filter_body!(body)
34
- expect(body).to eq("this is about [redacted] 3123123.")
33
+ expect(body).to eq('this is about [redacted] 3123123.')
35
34
  expect(TCellAgent.event_queue.length).to eq(1)
36
35
  TCellAgent.set_thread_agent(nil)
37
36
  end
38
- it "Tests Events in Body" do
37
+ it 'Tests Events in Body' do
39
38
  action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
40
39
  action.body_redact = true
41
40
  action.action_id = 5
42
41
  policy_json_two = {
43
- "policy_id"=>"x1a1",
44
- "data"=>{
45
- "session_id_protections"=>{"body"=>["event"], "log"=>["redact"]}
42
+ 'policy_id' => 'x1a1',
43
+ 'data' => {
44
+ 'session_id_protections' => { 'body' => ['event'], 'log' => ['redact'] }
46
45
  }
47
46
  }
48
47
  session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
@@ -51,25 +50,25 @@ module TCellAgent
51
50
  TCellAgent.set_thread_agent(mock_agent)
52
51
 
53
52
  context = TCellData.new
54
- context.session_id = "tim123123my"
53
+ context.session_id = 'tim123123my'
55
54
 
56
- body = "this is about tim123123my 3123123."
55
+ body = 'this is about tim123123my 3123123.'
57
56
  TCellAgent.empty_event_queue
58
57
  context.filter_body!(body)
59
- expect(body).to eq("this is about tim123123my 3123123.")
58
+ expect(body).to eq('this is about tim123123my 3123123.')
60
59
  expect(TCellAgent.event_queue.length).to eq(1)
61
60
  TCellAgent.set_thread_agent(nil)
62
61
  end
63
62
  end
64
- context "Log - SessionId Filters" do
65
- it "Tests Redaction and Events in Body" do
63
+ context 'Log - SessionId Filters' do
64
+ it 'Tests Redaction and Events in Body' do
66
65
  action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
67
66
  action.body_redact = true
68
67
  action.action_id = 5
69
68
  policy_json_two = {
70
- "policy_id"=>"x1a1",
71
- "data"=>{
72
- "session_id_protections"=>{"body"=>["redact"], "log"=>["redact"]}
69
+ 'policy_id' => 'x1a1',
70
+ 'data' => {
71
+ 'session_id_protections' => { 'body' => ['redact'], 'log' => ['redact'] }
73
72
  }
74
73
  }
75
74
  session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
@@ -78,23 +77,23 @@ module TCellAgent
78
77
  TCellAgent.set_thread_agent(mock_agent)
79
78
 
80
79
  context = TCellData.new
81
- context.session_id = "tim123123my"
80
+ context.session_id = 'tim123123my'
82
81
 
83
- body = "this is about tim123123my 3123123."
82
+ body = 'this is about tim123123my 3123123.'
84
83
  TCellAgent.empty_event_queue
85
84
  context.filter_log(body)
86
- expect(body).to eq("this is about [redacted] 3123123.")
85
+ expect(body).to eq('this is about [redacted] 3123123.')
87
86
  expect(TCellAgent.event_queue.length).to eq(1)
88
87
  TCellAgent.set_thread_agent(nil)
89
88
  end
90
- it "Tests Events Only" do
89
+ it 'Tests Events Only' do
91
90
  action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
92
91
  action.body_redact = true
93
92
  action.action_id = 5
94
93
  policy_json_two = {
95
- "policy_id"=>"x1a1",
96
- "data"=>{
97
- "session_id_protections"=>{"body"=>["redact"], "log"=>["event"]}
94
+ 'policy_id' => 'x1a1',
95
+ 'data' => {
96
+ 'session_id_protections' => { 'body' => ['redact'], 'log' => ['event'] }
98
97
  }
99
98
  }
100
99
  session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
@@ -103,101 +102,101 @@ module TCellAgent
103
102
  TCellAgent.set_thread_agent(mock_agent)
104
103
 
105
104
  context = TCellData.new
106
- context.session_id = "tim123123my"
105
+ context.session_id = 'tim123123my'
107
106
 
108
- body = "this is about tim123123my 3123123."
107
+ body = 'this is about tim123123my 3123123.'
109
108
  TCellAgent.empty_event_queue
110
109
  context.filter_log(body)
111
- expect(body).to eq("this is about tim123123my 3123123.")
110
+ expect(body).to eq('this is about tim123123my 3123123.')
112
111
  expect(TCellAgent.event_queue.length).to eq(1)
113
112
  TCellAgent.set_thread_agent(nil)
114
113
  end
115
114
  end
116
- context "Body - Database Filters" do
117
- it "Tests Redaction and Events in Body" do
115
+ context 'Body - Database Filters' do
116
+ it 'Tests Redaction and Events in Body' do
118
117
  action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
119
118
  action.body_redact = true
120
119
  action.action_id = 5
121
120
  context = TCellData.new
122
- context.add_response_db_filter("timmy", action, "don", "sam", "tim", "fred")
123
- context.add_response_db_filter("timmy23", action, "don", "sam", "tim", "fred")
124
- context.add_response_db_filter("3123123", action, "don", "sam", "tim", "fred")
125
- context.add_response_db_filter("tim123my", action, "don", "sam", "tim", "fred")
126
- context.add_response_db_filter("timmy1", action, "don", "sam", "tim", "fred")
127
- context.add_response_db_filter("tim123123my", action, "don", "sam", "tim", "fred")
128
- context.add_response_db_filter("ti21312mmy", action, "don", "sam", "tim", "fred")
129
- context.add_response_db_filter("ti123123mmy", action, "don", "sam", "tim", "fred")
130
- context.add_response_db_filter(10233234, action, "don", "sam", "tim", "fred")
131
- context.add_response_db_filter(true, action, "don", "sam", "tim", "fred")
132
- body = "this is about timmy1 3123123."
121
+ context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
122
+ context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
123
+ context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
124
+ context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
125
+ context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
126
+ context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
127
+ context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
128
+ context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
129
+ context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
130
+ context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
131
+ body = 'this is about timmy1 3123123.'
133
132
  TCellAgent.empty_event_queue
134
133
  context.filter_body!(body)
135
- expect(body).to eq("this is about [redacted] [redacted].")
134
+ expect(body).to eq('this is about [redacted] [redacted].')
136
135
  expect(TCellAgent.event_queue.length).to eq(2)
137
136
  end
138
- it "Tests Event Only Match in Body" do
137
+ it 'Tests Event Only Match in Body' do
139
138
  action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
140
139
  action.body_event = true
141
140
  action.action_id = 5
142
141
  context = TCellData.new
143
- context.add_response_db_filter("timmy", action, "don", "sam", "tim", "fred")
144
- context.add_response_db_filter("timmy23", action, "don", "sam", "tim", "fred")
145
- context.add_response_db_filter("3123123", action, "don", "sam", "tim", "fred")
146
- context.add_response_db_filter("tim123my", action, "don", "sam", "tim", "fred")
147
- context.add_response_db_filter("timmy1", action, "don", "sam", "tim", "fred")
148
- context.add_response_db_filter("tim123123my", action, "don", "sam", "tim", "fred")
149
- context.add_response_db_filter("ti21312mmy", action, "don", "sam", "tim", "fred")
150
- context.add_response_db_filter("ti123123mmy", action, "don", "sam", "tim", "fred")
151
- context.add_response_db_filter(10233234, action, "don", "sam", "tim", "fred")
152
- context.add_response_db_filter(true, action, "don", "sam", "tim", "fred")
153
- body = "this is about timmy1 3123123."
142
+ context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
143
+ context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
144
+ context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
145
+ context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
146
+ context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
147
+ context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
148
+ context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
149
+ context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
150
+ context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
151
+ context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
152
+ body = 'this is about timmy1 3123123.'
154
153
  TCellAgent.empty_event_queue
155
154
  context.filter_body!(body)
156
- expect(body).to eq("this is about timmy1 3123123.")
155
+ expect(body).to eq('this is about timmy1 3123123.')
157
156
  expect(TCellAgent.event_queue.length).to eq(3) # timmy, timmy1, 3123123
158
157
  end
159
158
  end
160
- context "Log - Database Filters" do
161
- it "Tests Redaction and Events" do
159
+ context 'Log - Database Filters' do
160
+ it 'Tests Redaction and Events' do
162
161
  action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
163
162
  action.log_redact = true
164
163
  action.action_id = 5
165
164
  context = TCellData.new
166
- context.add_response_db_filter("timmy", action, "don", "sam", "tim", "fred")
167
- context.add_response_db_filter("timmy23", action, "don", "sam", "tim", "fred")
168
- context.add_response_db_filter("3123123", action, "don", "sam", "tim", "fred")
169
- context.add_response_db_filter("tim123my", action, "don", "sam", "tim", "fred")
170
- context.add_response_db_filter("timmy1", action, "don", "sam", "tim", "fred")
171
- context.add_response_db_filter("tim123123my", action, "don", "sam", "tim", "fred")
172
- context.add_response_db_filter("ti21312mmy", action, "don", "sam", "tim", "fred")
173
- context.add_response_db_filter("ti123123mmy", action, "don", "sam", "tim", "fred")
174
- context.add_response_db_filter(10233234, action, "don", "sam", "tim", "fred")
175
- context.add_response_db_filter(true, action, "don", "sam", "tim", "fred")
176
- body = "this is about timmy1 3123123."
165
+ context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
166
+ context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
167
+ context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
168
+ context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
169
+ context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
170
+ context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
171
+ context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
172
+ context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
173
+ context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
174
+ context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
175
+ body = 'this is about timmy1 3123123.'
177
176
  TCellAgent.empty_event_queue
178
177
  context.filter_log(body)
179
- expect(body).to eq("this is about [redacted] [redacted].")
178
+ expect(body).to eq('this is about [redacted] [redacted].')
180
179
  expect(TCellAgent.event_queue.length).to eq(2)
181
180
  end
182
- it "Tests Report-Only and Events" do
181
+ it 'Tests Report-Only and Events' do
183
182
  action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
184
183
  action.log_event = true
185
184
  action.action_id = 5
186
185
  context = TCellData.new
187
- context.add_response_db_filter("timmy", action, "don", "sam", "tim", "fred")
188
- context.add_response_db_filter("timmy23", action, "don", "sam", "tim", "fred")
189
- context.add_response_db_filter("3123123", action, "don", "sam", "tim", "fred")
190
- context.add_response_db_filter("tim123my", action, "don", "sam", "tim", "fred")
191
- context.add_response_db_filter("timmy1", action, "don", "sam", "tim", "fred")
192
- context.add_response_db_filter("tim123123my", action, "don", "sam", "tim", "fred")
193
- context.add_response_db_filter("ti21312mmy", action, "don", "sam", "tim", "fred")
194
- context.add_response_db_filter("ti123123mmy", action, "don", "sam", "tim", "fred")
195
- context.add_response_db_filter(10233234, action, "don", "sam", "tim", "fred")
196
- context.add_response_db_filter(true, action, "don", "sam", "tim", "fred")
197
- body = "this is about timmy1 3123123."
186
+ context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
187
+ context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
188
+ context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
189
+ context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
190
+ context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
191
+ context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
192
+ context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
193
+ context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
194
+ context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
195
+ context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
196
+ body = 'this is about timmy1 3123123.'
198
197
  TCellAgent.empty_event_queue
199
198
  context.filter_log(body)
200
- expect(body).to eq("this is about timmy1 3123123.")
199
+ expect(body).to eq('this is about timmy1 3123123.')
201
200
  expect(TCellAgent.event_queue.length).to eq(3) # timmy, timmy1, 3123123
202
201
  end
203
202
  end
@@ -2,160 +2,119 @@ require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
4
  module Instrumentation
5
-
6
- describe ".block?" do
7
-
8
- context "with an unexpected error" do
9
- it "should return nil" do
10
- request = double("request")
11
- expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::Patches).and_raise(Exception.new("UNEXPECTED"))
5
+ describe '.block?' do
6
+ context 'with an unexpected error' do
7
+ it 'should return false' do
8
+ request = double('request')
9
+ expect(TCellAgent).to receive(:policy).with(
10
+ TCellAgent::PolicyTypes::Rust
11
+ ).and_raise(StandardError.new('UNEXPECTED'))
12
12
  expect(TCellAgent::Patches::MetaData).to_not receive(:build)
13
13
 
14
- expect(Patches.block?(request)).to eq(nil)
14
+ expect(Patches.block?(request)).to eq(false)
15
15
  end
16
16
  end
17
17
 
18
- context "with an empty patches policy" do
19
- it "should return nil" do
20
- request = double("request")
18
+ context 'with an empty patches policy' do
19
+ it 'should return false' do
20
+ request = double('request')
21
21
  expect(TCellAgent).to receive(:policy).and_return(nil)
22
22
  expect(TCellAgent::Patches::MetaData).to_not receive(:build)
23
23
 
24
- expect(Patches.block?(request)).to eq(nil)
24
+ expect(Patches.block?(request)).to eq(false)
25
25
  end
26
26
  end
27
27
 
28
- context "with a disabled patches policy" do
29
- it "should return nil" do
30
- request = double("request")
31
- patches = TCellAgent::Policies::PatchesPolicy.from_json({
32
- "policy_id" => "policy_id",
33
- "version" => 1,
34
- "data" => {}
35
- })
36
- expect(patches.enabled).to eq(false)
37
-
38
- expect(TCellAgent).to receive(:policy).and_return(patches)
28
+ context 'with a disabled patches policy' do
29
+ it 'should return false' do
30
+ request = double('request')
31
+ rust_policies = TCellAgent::Policies::RustPolicies.new
32
+ expect(rust_policies.patches_enabled).to eq(false)
33
+
34
+ expect(TCellAgent).to receive(:policy).and_return(rust_policies)
39
35
  expect(TCellAgent::Patches::MetaData).to_not receive(:build)
40
36
 
41
- expect(Patches.block?(request)).to eq(nil)
37
+ expect(Patches.block?(request)).to eq(false)
42
38
  end
43
39
  end
44
40
 
45
- context "with a patches policy that does not apply" do
46
- it "should return nil" do
47
- request = double("request")
48
- meta_data = double("meta_data")
49
- patches = TCellAgent::Policies::PatchesPolicy.from_json({
50
- "policy_id" => "policy_id",
51
- "version" => 1,
52
- "data" => {"blocked_ips" => [{"ip" => "1.1.1.1"}]}
53
- })
54
- expect(patches.enabled).to eq(true)
55
-
56
- expect(TCellAgent).to receive(:policy).and_return(patches)
41
+ context 'with a patches policy that does not apply' do
42
+ it 'should return false' do
43
+ request = double('request')
44
+ meta_data = double('meta_data')
45
+ rust_policies = TCellAgent::Policies::RustPolicies.new
46
+ tcell_context = TCellAgent::Instrumentation::TCellData.new
47
+
48
+ expect(TCellAgent).to receive(:policy).and_return(rust_policies)
49
+ expect(rust_policies).to receive(:patches_enabled).and_return(true)
50
+ expect(rust_policies).to receive(:block_request?).and_return(false)
51
+ expect(request).to receive(:env).and_return(
52
+ {
53
+ TCellAgent::Instrumentation::TCELL_ID => tcell_context
54
+ }
55
+ )
57
56
  expect(TCellAgent::Patches::MetaData).to receive(:build).and_return(
58
57
  meta_data
59
58
  )
60
- expect(meta_data).to receive(:remote_address).and_return("2.2.2.2")
61
59
 
62
- expect(Patches.block?(request)).to eq(nil)
60
+ expect(Patches.block?(request)).to eq(false)
61
+ expect(tcell_context.patches_blocking_triggered).to eq(false)
63
62
  end
64
63
  end
65
64
 
66
-
67
- context "with a patches policy that applies" do
68
- it "should return a response" do
69
- request = double("request")
70
- meta_data = double("meta_data")
65
+ context 'with a patches policy that applies' do
66
+ it 'should return a response' do
67
+ request = double('request')
68
+ meta_data = double('meta_data')
71
69
  tcell_context = TCellAgent::Instrumentation::TCellData.new
72
- patches = TCellAgent::Policies::PatchesPolicy.from_json({
73
- "policy_id" => "policy_id",
74
- "version" => 1,
75
- "data" => {"blocked_ips" => [{"ip" => "1.1.1.1"}]}
76
- })
77
- expect(patches.enabled).to eq(true)
78
- expect(tcell_context.ip_blocking_triggered).to eq(false)
79
-
80
- expect(TCellAgent).to receive(:policy).and_return(patches)
70
+ rust_policies = TCellAgent::Policies::RustPolicies.new
71
+ expect(tcell_context.patches_blocking_triggered).to eq(false)
72
+
73
+ expect(TCellAgent).to receive(:policy).and_return(rust_policies)
74
+ expect(rust_policies).to receive(:patches_enabled).and_return(true)
75
+ expect(rust_policies).to receive(:block_request?).and_return(true)
81
76
  expect(TCellAgent::Patches::MetaData).to receive(:build).and_return(
82
77
  meta_data
83
78
  )
84
- expect(meta_data).to receive(:remote_address).and_return("1.1.1.1")
85
- expect(request).to receive(:env).and_return({TCellAgent::Instrumentation::TCELL_ID => tcell_context})
79
+ expect(request).to receive(:env).and_return({ TCellAgent::Instrumentation::TCELL_ID => tcell_context })
86
80
 
87
- expect(Patches.block?(request)).to eq(403)
81
+ expect(Patches.block?(request)).to eq(true)
88
82
 
89
- expect(tcell_context.ip_blocking_triggered).to eq(true)
83
+ expect(tcell_context.patches_blocking_triggered).to eq(true)
90
84
  end
91
85
 
92
86
  context "and that's complex" do
93
- it "should return a response" do
94
- request = double("request")
87
+ it 'should return a response' do
88
+ request = double('request')
95
89
  meta_data = TCellAgent::Patches::MetaData.new(
96
- "get",
97
- "2.3.4.5",
98
- "route_id",
99
- "session_id",
100
- "user_id",
101
- "transaction_id")
102
- meta_data.get_dict = {"paramater" => "<script>"}
103
- tcell_context = TCellAgent::Instrumentation::TCellData.new
104
- patches = TCellAgent::Policies::PatchesPolicy.from_json({
105
- "policy_id" => "policy_id",
106
- "version" => 1,
107
- "data" => {
108
- "blocked_ips" => [{"ip" => "8.8.8.8"}],
109
- "block_rules" => [
110
- {"ips" => ["8.8.8.8"]},
111
- {
112
- "ips" => ["2.3.4.5"],
113
- "sensor_matches" => {
114
- "xss" => {"patterns" => ["1", "2", "3", "4", "5", "6", "7", "8"]}
115
- }
116
- }
117
- ]
118
- }
119
- })
120
- expect(patches.enabled).to eq(true)
121
- expect(tcell_context.ip_blocking_triggered).to eq(false)
122
-
123
- expect(TCellAgent).to receive(:policy).and_return(patches)
124
- expect(TCellAgent::Patches::MetaData).to receive(:build).and_return(
125
- meta_data
90
+ 'get',
91
+ '2.3.4.5',
92
+ 'route_id',
93
+ 'session_id',
94
+ 'user_id',
95
+ 'transaction_id',
96
+ 'http://test.com/'
126
97
  )
127
- expect(request).to receive(:env).and_return({TCellAgent::Instrumentation::TCELL_ID => tcell_context})
98
+ meta_data.get_dict = { 'paramater' => '<script>' }
99
+ tcell_context = TCellAgent::Instrumentation::TCellData.new
100
+ rust_policies = TCellAgent::Policies::RustPolicies.new
128
101
 
129
- expect(Patches.block?(request)).to eq(403)
102
+ expect(tcell_context.patches_blocking_triggered).to eq(false)
130
103
 
131
- expect(tcell_context.ip_blocking_triggered).to eq(true)
132
- end
133
- end
134
-
135
- context "with an unexpected error" do
136
- it "should return nil" do
137
- request = double("request")
138
- meta_data = double("meta_data")
139
- patches = TCellAgent::Policies::PatchesPolicy.from_json({
140
- "policy_id" => "policy_id",
141
- "version" => 1,
142
- "data" => {"blocked_ips" => [{"ip" => "1.1.1.1"}]}
143
- })
144
- expect(patches.enabled).to eq(true)
145
-
146
- expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::Patches).and_return(patches)
104
+ expect(TCellAgent).to receive(:policy).and_return(rust_policies)
105
+ expect(rust_policies).to receive(:patches_enabled).and_return(true)
106
+ expect(rust_policies).to receive(:block_request?).and_return(true)
147
107
  expect(TCellAgent::Patches::MetaData).to receive(:build).and_return(
148
108
  meta_data
149
109
  )
150
- expect(meta_data).to receive(:remote_address).and_raise(Exception.new("UNEXPECTED"))
151
- expect(request).to_not receive(:env)
110
+ expect(request).to receive(:env).and_return({ TCellAgent::Instrumentation::TCELL_ID => tcell_context })
111
+
112
+ expect(Patches.block?(request)).to eq(true)
152
113
 
153
- expect(Patches.block?(request)).to eq(nil)
114
+ expect(tcell_context.patches_blocking_triggered).to eq(true)
154
115
  end
155
116
  end
156
117
  end
157
-
158
118
  end
159
-
160
119
  end
161
120
  end