tcell_agent 1.1.12 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +5 -5
  2. data/bin/tcell_agent +26 -14
  3. data/lib/tcell_agent.rb +16 -10
  4. data/lib/tcell_agent/agent.rb +78 -97
  5. data/lib/tcell_agent/agent/route_manager.rb +0 -16
  6. data/lib/tcell_agent/agent/static_agent.rb +9 -30
  7. data/lib/tcell_agent/authlogic.rb +3 -6
  8. data/lib/tcell_agent/config/unknown_options.rb +4 -8
  9. data/lib/tcell_agent/configuration.rb +38 -119
  10. data/lib/tcell_agent/devise.rb +25 -27
  11. data/lib/tcell_agent/hooks/login_fraud.rb +30 -33
  12. data/lib/tcell_agent/instrument_servers.rb +25 -0
  13. data/lib/tcell_agent/instrumentation.rb +12 -10
  14. data/lib/tcell_agent/instrumentation/cmdi.rb +19 -15
  15. data/lib/tcell_agent/instrumentation/lfi.rb +73 -0
  16. data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +25 -0
  17. data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +123 -0
  18. data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +159 -0
  19. data/lib/tcell_agent/logger.rb +50 -114
  20. data/lib/tcell_agent/patches.rb +6 -7
  21. data/lib/tcell_agent/policies/appfirewall_policy.rb +26 -0
  22. data/lib/tcell_agent/policies/command_injection_policy.rb +28 -0
  23. data/lib/tcell_agent/policies/dataloss_policy.rb +44 -44
  24. data/lib/tcell_agent/policies/headers_policy.rb +25 -0
  25. data/lib/tcell_agent/policies/http_redirect_policy.rb +13 -79
  26. data/lib/tcell_agent/policies/js_agent_policy.rb +27 -0
  27. data/lib/tcell_agent/policies/local_file_access.rb +28 -0
  28. data/lib/tcell_agent/policies/login_policy.rb +43 -0
  29. data/lib/tcell_agent/policies/patches_policy.rb +27 -0
  30. data/lib/tcell_agent/policies/policies_manager.rb +68 -0
  31. data/lib/tcell_agent/policies/policy_polling.rb +58 -0
  32. data/lib/tcell_agent/policies/policy_types.rb +14 -0
  33. data/lib/tcell_agent/policies/system_enablements.rb +27 -0
  34. data/lib/tcell_agent/rails/auth/authlogic.rb +43 -68
  35. data/lib/tcell_agent/rails/auth/devise.rb +20 -23
  36. data/lib/tcell_agent/rails/auth/doorkeeper.rb +63 -74
  37. data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
  38. data/lib/tcell_agent/rails/dlp.rb +25 -15
  39. data/lib/tcell_agent/rails/dlp_handler.rb +1 -2
  40. data/lib/tcell_agent/rails/js_agent_insert.rb +12 -13
  41. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +4 -25
  42. data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -12
  43. data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
  44. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +14 -34
  45. data/lib/tcell_agent/rails/on_start.rb +32 -31
  46. data/lib/tcell_agent/rails/routes.rb +7 -6
  47. data/lib/tcell_agent/rails/routes/grape.rb +1 -3
  48. data/lib/tcell_agent/rails/routes/route_id.rb +3 -1
  49. data/lib/tcell_agent/rails/settings_reporter.rb +23 -36
  50. data/lib/tcell_agent/rails/start_agent_after_initializers.rb +12 -0
  51. data/lib/tcell_agent/rails/tcell_body_proxy.rb +6 -4
  52. data/lib/tcell_agent/rust/agent_config.rb +49 -0
  53. data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.2.so → libtcellagent-4.14.0.dylib} +0 -0
  54. data/lib/tcell_agent/rust/libtcellagent-4.14.0.so +0 -0
  55. data/lib/tcell_agent/rust/{libtcellagent-1.3.2.so → libtcellagent-alpine-4.14.0.so} +0 -0
  56. data/lib/tcell_agent/rust/models.rb +0 -55
  57. data/lib/tcell_agent/rust/native_agent.rb +531 -0
  58. data/lib/tcell_agent/rust/native_agent_response.rb +42 -0
  59. data/lib/tcell_agent/rust/native_library.rb +68 -0
  60. data/lib/tcell_agent/rust/tcellagent-4.14.0.dll +0 -0
  61. data/lib/tcell_agent/sensor_events/agent_setting_event.rb +12 -0
  62. data/lib/tcell_agent/sensor_events/{app_config.rb → app_config_setting_event.rb} +0 -6
  63. data/lib/tcell_agent/sensor_events/dlp.rb +2 -6
  64. data/lib/tcell_agent/sensor_events/sensor.rb +0 -62
  65. data/lib/tcell_agent/sensor_events/server_agent.rb +13 -18
  66. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +0 -108
  67. data/lib/tcell_agent/sensor_events/util/utils.rb +0 -2
  68. data/lib/tcell_agent/servers/passenger.rb +1 -28
  69. data/lib/tcell_agent/servers/puma.rb +3 -21
  70. data/lib/tcell_agent/servers/rails_server.rb +1 -1
  71. data/lib/tcell_agent/servers/thin.rb +2 -2
  72. data/lib/tcell_agent/servers/unicorn.rb +19 -80
  73. data/lib/tcell_agent/servers/webrick.rb +1 -1
  74. data/lib/tcell_agent/settings_reporter.rb +24 -24
  75. data/lib/tcell_agent/sinatra.rb +14 -16
  76. data/lib/tcell_agent/tcell_context.rb +40 -14
  77. data/lib/tcell_agent/utils/headers.rb +14 -0
  78. data/lib/tcell_agent/version.rb +1 -1
  79. data/spec/lib/tcell_agent/cmdi_spec.rb +0 -585
  80. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -18
  81. data/spec/lib/tcell_agent/configuration_spec.rb +4 -140
  82. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +46 -173
  83. data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +504 -0
  84. data/spec/lib/tcell_agent/instrumentation/cmdi/kernel_cmdi_spec.rb +435 -0
  85. data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +326 -0
  86. data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +556 -0
  87. data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +249 -0
  88. data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +105 -0
  89. data/spec/lib/tcell_agent/patches_spec.rb +25 -43
  90. data/spec/lib/tcell_agent/policies/appfirewall_policy_spec.rb +183 -0
  91. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +57 -0
  92. data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +84 -773
  93. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +161 -0
  94. data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +9 -9
  95. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +243 -198
  96. data/spec/lib/tcell_agent/policies/js_agent_policy_spec.rb +75 -0
  97. data/spec/lib/tcell_agent/policies/login_policy_spec.rb +165 -33
  98. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +84 -277
  99. data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +104 -0
  100. data/spec/lib/tcell_agent/policies/policy_polling_spec.rb +6 -0
  101. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +56 -0
  102. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +9 -18
  103. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +13 -30
  104. data/spec/lib/tcell_agent/rails/logger_spec.rb +27 -7
  105. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +17 -12
  106. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +14 -14
  107. data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +0 -35
  108. data/spec/lib/tcell_agent/settings_reporter_spec.rb +127 -153
  109. data/spec/spec_helper.rb +1 -1
  110. data/spec/support/builders.rb +104 -0
  111. data/spec/support/force_logger_mocking.rb +38 -0
  112. data/spec/support/resources/lfi_sample_file.txt +2 -0
  113. data/spec/support/static_agent_overrides.rb +0 -15
  114. metadata +63 -74
  115. data/lib/tcell_agent/agent/event_processor.rb +0 -326
  116. data/lib/tcell_agent/agent/fork_pipe_manager.rb +0 -113
  117. data/lib/tcell_agent/agent/policy_manager.rb +0 -219
  118. data/lib/tcell_agent/agent/policy_types.rb +0 -30
  119. data/lib/tcell_agent/api.rb +0 -91
  120. data/lib/tcell_agent/appsensor/injections_reporter.rb +0 -24
  121. data/lib/tcell_agent/config/child_process_events.rb +0 -8
  122. data/lib/tcell_agent/instrumentation/cmdi/backtick.rb +0 -10
  123. data/lib/tcell_agent/instrumentation/cmdi/exec.rb +0 -14
  124. data/lib/tcell_agent/instrumentation/cmdi/popen.rb +0 -28
  125. data/lib/tcell_agent/instrumentation/cmdi/spawn.rb +0 -11
  126. data/lib/tcell_agent/instrumentation/cmdi/system.rb +0 -11
  127. data/lib/tcell_agent/policies/http_tx_policy.rb +0 -60
  128. data/lib/tcell_agent/policies/login_fraud_policy.rb +0 -45
  129. data/lib/tcell_agent/policies/rust_policies.rb +0 -110
  130. data/lib/tcell_agent/rails.rb +0 -40
  131. data/lib/tcell_agent/rust/libtcellagent-1.3.2.dylib +0 -0
  132. data/lib/tcell_agent/rust/tcellagent-1.3.2.dll +0 -0
  133. data/lib/tcell_agent/rust/whisperer.rb +0 -308
  134. data/lib/tcell_agent/sensor_events/appsensor_event.rb +0 -52
  135. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +0 -45
  136. data/lib/tcell_agent/sensor_events/command_injection.rb +0 -75
  137. data/lib/tcell_agent/sensor_events/honeytokens.rb +0 -16
  138. data/lib/tcell_agent/sensor_events/login_fraud.rb +0 -60
  139. data/lib/tcell_agent/sensor_events/metrics.rb +0 -123
  140. data/lib/tcell_agent/sensor_events/patches.rb +0 -21
  141. data/lib/tcell_agent/start_background_thread.rb +0 -55
  142. data/lib/tcell_agent/system_info.rb +0 -11
  143. data/lib/tcell_agent/utils/io.rb +0 -38
  144. data/lib/tcell_agent/utils/passwords.rb +0 -28
  145. data/lib/tcell_agent/utils/queue_with_timeout.rb +0 -142
  146. data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +0 -100
  147. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +0 -535
  148. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +0 -133
  149. data/spec/lib/tcell_agent/api/api_spec.rb +0 -39
  150. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +0 -187
  151. data/spec/lib/tcell_agent/instrumentation_spec.rb +0 -225
  152. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +0 -517
  153. data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +0 -22
  154. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +0 -293
  155. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +0 -198
  156. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +0 -180
  157. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +0 -116
  158. data/spec/lib/tcell_agent/rust/models_spec.rb +0 -120
  159. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +0 -704
  160. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +0 -45
  161. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +0 -272
  162. data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +0 -52
  163. data/spec/lib/tcell_agent/utils/passwords_spec.rb +0 -143
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ module TCellAgent
4
+ describe PoliciesManager do
5
+ before(:all) do
6
+ assert_policy_state = proc do |policies, state|
7
+ expect(policies.keys.size).to eq(10)
8
+
9
+ policies.values.each do |policy|
10
+ next if policy.instance_of?(TCellAgent::Policies::LoginPolicy)
11
+ next if policy.instance_of?(TCellAgent::Policies::SystemEnablements)
12
+
13
+ expect(policy.enabled).to eq(state)
14
+ end
15
+
16
+ expect(
17
+ policies[
18
+ TCellAgent::Policies::LoginPolicy.api_identifier
19
+ ].login_success_enabled
20
+ ).to eq(state)
21
+ expect(
22
+ policies[
23
+ TCellAgent::Policies::LoginPolicy.api_identifier
24
+ ].login_failed_enabled
25
+ ).to eq(state)
26
+ end
27
+
28
+ @assert_all_policies_enabled = proc do |policies|
29
+ assert_policy_state.call(policies, true)
30
+ end
31
+ @assert_all_policies_disabled = proc do |policies|
32
+ assert_policy_state.call(policies, false)
33
+ end
34
+ end
35
+
36
+ describe '#initialize' do
37
+ context 'default PoliciesManager' do
38
+ it 'should have all policies disabled' do
39
+ native_agent = double('native_agent')
40
+ policies_manager = PoliciesManager.new(native_agent)
41
+
42
+ @assert_all_policies_disabled.call(policies_manager.policies)
43
+ end
44
+ end
45
+
46
+ describe '#process_policy_json' do
47
+ before(:each) do
48
+ @native_agent = double('native_agent')
49
+ @policies_manager = PoliciesManager.new(@native_agent)
50
+ end
51
+
52
+ context 'nil enablements' do
53
+ it 'all policies should remain disabled' do
54
+ @policies_manager.process_policy_json(nil, {})
55
+ @assert_all_policies_disabled.call(@policies_manager.policies)
56
+ end
57
+ end
58
+
59
+ context 'empty enablements' do
60
+ it 'all policies should remain disabled' do
61
+ @policies_manager.process_policy_json({}, {})
62
+ @assert_all_policies_disabled.call(@policies_manager.policies)
63
+ end
64
+ end
65
+
66
+ context 'empty enablements' do
67
+ it 'all policies should remain disabled' do
68
+ @policies_manager.process_policy_json({}, {})
69
+ @assert_all_policies_disabled.call(@policies_manager.policies)
70
+ end
71
+ end
72
+
73
+ context 'with enablements and policies_json' do
74
+ it 'all policies should be enabled' do
75
+ enablements = {
76
+ 'appfirewall' => true,
77
+ 'cmdi' => true,
78
+ 'headers' => true,
79
+ 'http_redirect' => true,
80
+ 'jsagentinjection' => true,
81
+ 'patches' => true,
82
+ 'local_file_access' => true,
83
+ 'login_success_enabled' => true,
84
+ 'login_failed_enabled' => true
85
+ }
86
+ policies_json = {
87
+ 'dlp' => {
88
+ 'policy_id' => 'policy-id',
89
+ 'version' => 1,
90
+ 'data' => {
91
+ 'data_discovery' => {
92
+ 'database_enabled' => true
93
+ }
94
+ }
95
+ }
96
+ }
97
+ @policies_manager.process_policy_json(enablements, policies_json)
98
+ @assert_all_policies_enabled.call(@policies_manager.policies)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ module TCellAgent
4
+ class PolicyPolling
5
+ end
6
+ end
@@ -0,0 +1,56 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ module TCellAgent
5
+ module Policies
6
+ describe HeadersPolicy do
7
+ describe '#get_headers' do
8
+ context 'with enabled policy' do
9
+ before(:each) do
10
+ configuration = TCellAgent::Tests::ConfigurationBuilder.new.build
11
+ @native_agent = TCellAgent::Rust::NativeAgent.create_agent(
12
+ configuration
13
+ )
14
+ @tcell_context = TCellAgent::Tests::TCellContextBuilder.new.update_attribute(
15
+ 'session_id', 'session-id'
16
+ ).update_attribute(
17
+ 'route_id', 'route-id'
18
+ ).build
19
+ end
20
+
21
+ after(:each) do
22
+ TCellAgent::Rust::NativeAgent.free_agent(@native_agent.agent_ptr)
23
+ end
24
+
25
+ it 'should return csp header' do
26
+ enablements = @native_agent.update_policies(
27
+ {
28
+ 'secure-headers' => {
29
+ 'version' => 1,
30
+ 'policy_id' => 'xyzd',
31
+ 'headers' => [
32
+ {
33
+ 'name' => 'X-Content-Type-Options',
34
+ 'value' => 'nosniff'
35
+ }
36
+ ]
37
+ }
38
+ }
39
+ )['enablements']
40
+ expect(enablements['headers']).to eq(true)
41
+
42
+ @policy = HeadersPolicy.new(@native_agent, enablements)
43
+ expect(@policy.enabled).to eq(true)
44
+
45
+ expect(
46
+ @policy.get_headers(@tcell_context)
47
+ ).to eq(
48
+ [{ 'name' => 'X-Content-Type-Options',
49
+ 'value' => 'nosniff' }]
50
+ )
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -12,21 +12,12 @@ module TCellAgent
12
12
  @csrf_class = WrapperClass.new
13
13
  end
14
14
 
15
- context 'nil rust policies' do
16
- it 'should not set csrf_exception_name' do
17
- expect(TCellAgent).to receive(:policy).and_return(nil)
18
- expect(@csrf_class).to_not receive(:request)
19
-
20
- @csrf_class.handle_unverified_request
21
- end
22
- end
23
-
24
15
  context 'appfirewall_enabled=false' do
25
16
  it 'should not set csrf_exception_name' do
26
- rust_policies = double('rust_policies',
27
- :appfirewall_enabled => false)
17
+ appfirewall_policy = double('appfirewall_policy',
18
+ :enabled => false)
28
19
 
29
- expect(TCellAgent).to receive(:policy).and_return(rust_policies)
20
+ expect(TCellAgent).to receive(:policy).and_return(appfirewall_policy)
30
21
  expect(@csrf_class).to_not receive(:request)
31
22
 
32
23
  @csrf_class.handle_unverified_request
@@ -35,12 +26,12 @@ module TCellAgent
35
26
 
36
27
  context 'appfirewall_enabled=true and nil tcell_data' do
37
28
  it 'should not set csrf_exception_name' do
38
- rust_policies = double('rust_policies',
39
- :appfirewall_enabled => true)
29
+ appfirewall_policy = double('appfirewall_policy',
30
+ :enabled => true)
40
31
  request = double('request',
41
32
  :env => {})
42
33
 
43
- expect(TCellAgent).to receive(:policy).and_return(rust_policies)
34
+ expect(TCellAgent).to receive(:policy).and_return(appfirewall_policy)
44
35
  expect(@csrf_class).to receive(:request).and_return(request)
45
36
 
46
37
  @csrf_class.handle_unverified_request
@@ -52,12 +43,12 @@ module TCellAgent
52
43
  tcell_data = TCellAgent::Instrumentation::TCellData.new
53
44
  expect(tcell_data.csrf_exception_name).to be(nil)
54
45
 
55
- rust_policies = double('rust_policies',
56
- :appfirewall_enabled => true)
46
+ appfirewall_policy = double('appfirewall_policy',
47
+ :enabled => true)
57
48
  request = double('request',
58
49
  :env => { TCellAgent::Instrumentation::TCELL_ID => tcell_data })
59
50
 
60
- expect(TCellAgent).to receive(:policy).and_return(rust_policies)
51
+ expect(TCellAgent).to receive(:policy).and_return(appfirewall_policy)
61
52
  expect(@csrf_class).to receive(:request).and_return(request)
62
53
 
63
54
  @csrf_class.handle_unverified_request
@@ -146,12 +146,11 @@ module TCellAgent
146
146
  context 'with nil response' do
147
147
  it 'should return the unmodified response' do
148
148
  logger = double('logger')
149
- expect(TCellAgent).to receive(:logger).and_return(logger)
150
- expect(TCellAgent).to receive(:logger).and_return(logger)
151
- expect(logger).to receive(:debug).with(
152
- /Exception in safe_block Handling JSAgent insert: NoMethodError happened, message is undefined method `sub'/
149
+ expect(TCellAgent::Instrumentation).to receive(:get_safe_block_logger).and_return(logger)
150
+ expect(logger).to receive(:error).with(
151
+ /Error Handling JSAgent insert \(NoMethodError\): undefined method `sub'/
153
152
  )
154
- expect(logger).to receive(:debug).with(kind_of(Array))
153
+ expect(logger).to receive(:exception) # exception stack trace
155
154
 
156
155
  response = JSAgent.handle_js_agent_insert('SCRIPT', nil)
157
156
 
@@ -197,23 +196,7 @@ module TCellAgent
197
196
  end
198
197
  end
199
198
 
200
- context 'with html response but no rust_policies' do
201
- it 'should not set js_agent_handler or script_insert' do
202
- request = double('request')
203
-
204
- expect(TCellAgent).to receive(:policy).with(
205
- TCellAgent::PolicyTypes::RUST
206
- ).and_return(nil)
207
- result = JSAgent.get_handler_and_script_insert(
208
- request,
209
- { 'Content-Type' => 'text/html' }
210
- )
211
-
212
- expect(result).to eq([nil, nil])
213
- end
214
- end
215
-
216
- context 'with html response and rust_policies' do
199
+ context 'with html response and js agent policy' do
217
200
  context 'with nil script_insert' do
218
201
  it 'should not set js_agent_handler or script_insert' do
219
202
  tcell_data = TCellAgent::Instrumentation::TCellData.new
@@ -221,12 +204,12 @@ module TCellAgent
221
204
  :env => {
222
205
  TCellAgent::Instrumentation::TCELL_ID => tcell_data
223
206
  })
224
- rust_policies = double('rust_policies')
207
+ js_agent_policy = double('js_agent_policy')
225
208
 
226
209
  expect(TCellAgent).to receive(:policy).with(
227
- TCellAgent::PolicyTypes::RUST
228
- ).and_return(rust_policies)
229
- expect(rust_policies).to receive(:get_js_agent_script_tag).with(
210
+ TCellAgent::PolicyTypes::JSAGENTINJECTION
211
+ ).and_return(js_agent_policy)
212
+ expect(js_agent_policy).to receive(:get_js_agent_script_tag).with(
230
213
  tcell_data
231
214
  ).and_return(nil)
232
215
 
@@ -246,12 +229,12 @@ module TCellAgent
246
229
  :env => {
247
230
  TCellAgent::Instrumentation::TCELL_ID => tcell_data
248
231
  })
249
- rust_policies = double('rust_policies')
232
+ js_agent_policy = double('js_agent_policy')
250
233
 
251
234
  expect(TCellAgent).to receive(:policy).with(
252
- TCellAgent::PolicyTypes::RUST
253
- ).and_return(rust_policies)
254
- expect(rust_policies).to receive(:get_js_agent_script_tag).with(
235
+ TCellAgent::PolicyTypes::JSAGENTINJECTION
236
+ ).and_return(js_agent_policy)
237
+ expect(js_agent_policy).to receive(:get_js_agent_script_tag).with(
255
238
  tcell_data
256
239
  ).and_return('SCRIPT')
257
240
 
@@ -3,6 +3,22 @@ require 'spec_helper'
3
3
  describe Logger do
4
4
  describe '#add' do
5
5
  context 'with a warn logger' do
6
+ before(:each) do
7
+ req_env = double('request_env')
8
+ lfi_policy = double('lfi_policy')
9
+ native_agent = double('native_agent')
10
+ @local_files_policy = TCellAgent::Policies::LocalFileInclusion.new(
11
+ native_agent, {}
12
+ )
13
+ allow(req_env).to receive(:[])
14
+ allow(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LFI).and_return(
15
+ lfi_policy
16
+ )
17
+ allow(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
18
+ :fetch
19
+ ).with(anything, {}).and_return(req_env)
20
+ allow(lfi_policy).to receive(:block_file_access?).and_return(false)
21
+ end
6
22
  context 'writing a debug message' do
7
23
  it 'should skip the tcell logic' do
8
24
  expect(TCellAgent::Instrumentation).to_not receive(:safe_block_no_log)
@@ -41,11 +57,12 @@ describe Logger do
41
57
 
42
58
  context 'with an empty message' do
43
59
  it 'should not run the context filter' do
60
+ dlp_policy = double('dlp_policy', :enabled => true)
44
61
  expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
45
62
  'Handling DLP log message filtering'
46
63
  ).and_call_original
47
64
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DATALOSS).and_return(
48
- double('dlp_policy')
65
+ dlp_policy
49
66
  )
50
67
  expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
51
68
  :fetch
@@ -66,9 +83,9 @@ describe Logger do
66
83
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DATALOSS).and_return(
67
84
  nil
68
85
  )
69
- expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
86
+ expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to_not receive(
70
87
  :fetch
71
- ).with(anything, nil).and_return(double('request_env'))
88
+ ).with(anything, nil)
72
89
 
73
90
  logger = Logger.new('/dev/null')
74
91
 
@@ -79,11 +96,12 @@ describe Logger do
79
96
 
80
97
  context 'with no request env' do
81
98
  it 'should not run the context filter' do
99
+ dlp_policy = double('dlp_policy', :enabled => true)
82
100
  expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
83
101
  'Handling DLP log message filtering'
84
102
  ).and_call_original
85
103
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DATALOSS).and_return(
86
- double('dlp_policy')
104
+ dlp_policy
87
105
  )
88
106
  expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
89
107
  :fetch
@@ -100,12 +118,13 @@ describe Logger do
100
118
  context 'with no tcell_context' do
101
119
  it 'should not run the context filter' do
102
120
  request_env = double('request_env')
121
+ dlp_policy = double('dlp_policy', :enabled => true)
103
122
 
104
123
  expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
105
124
  'Handling DLP log message filtering'
106
125
  ).and_call_original
107
126
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DATALOSS).and_return(
108
- double('dlp_policy')
127
+ dlp_policy
109
128
  )
110
129
  expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
111
130
  :fetch
@@ -120,15 +139,16 @@ describe Logger do
120
139
  end
121
140
 
122
141
  context 'with tcell_context' do
123
- it 'should not run the context filter' do
142
+ it 'should run the context filter' do
124
143
  request_env = double('request_env')
125
144
  tcell_context = double('tcell_context')
145
+ dlp_policy = double('dlp_policy', :enabled => true)
126
146
 
127
147
  expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
128
148
  'Handling DLP log message filtering'
129
149
  ).and_call_original
130
150
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DATALOSS).and_return(
131
- double('dlp_policy')
151
+ dlp_policy
132
152
  )
133
153
  expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
134
154
  :fetch
@@ -15,27 +15,28 @@ module TCellAgent
15
15
  'transaction_id',
16
16
  'http://test.com/'
17
17
  )
18
- @appsensor_meta_event = TCellAgent::SensorEvents::AppSensorMetaEvent.new(
19
- @meta_data
20
- )
21
18
  end
22
19
 
23
20
  context 'zero content length' do
24
- it 'appsensor_meta_event should be enqueued for processing' do
21
+ it 'appfirewall injections should be checked' do
25
22
  tcell_body_proxy = TCellBodyProxy.new(
26
23
  Rack::BodyProxy.new(['body']) {},
27
24
  true,
28
25
  nil, nil, nil, nil
29
26
  )
30
- tcell_body_proxy.appsensor_meta_event = @appsensor_meta_event
27
+ tcell_body_proxy.meta_data = @meta_data
31
28
 
32
29
  tcell_body_proxy.content_length = 0
33
30
 
31
+ appfirewall_policy = double('appfirewall_policy')
34
32
  expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
35
33
  'Running AppSensor deferred due to streaming'
36
34
  ).and_call_original
37
- expect(TCellAgent).to receive(:send_event).with(
38
- @appsensor_meta_event
35
+ expect(TCellAgent).to receive(:policy).with(
36
+ TCellAgent::PolicyTypes::APPSENSOR
37
+ ).and_return(appfirewall_policy)
38
+ expect(appfirewall_policy).to receive(:check_appfirewall_injections).with(
39
+ @meta_data
39
40
  )
40
41
 
41
42
  tcell_body_proxy.close
@@ -43,26 +44,30 @@ module TCellAgent
43
44
  end
44
45
 
45
46
  context 'non zero content length' do
46
- it 'appsensor_meta_event should be enqueued for processing' do
47
+ it 'should check for appfirewall injections' do
47
48
  tcell_body_proxy = TCellBodyProxy.new(
48
49
  Rack::BodyProxy.new(['body']) {},
49
50
  true,
50
51
  nil, nil, nil, nil
51
52
  )
52
- tcell_body_proxy.appsensor_meta_event = @appsensor_meta_event
53
+ tcell_body_proxy.meta_data = @meta_data
53
54
 
54
55
  tcell_body_proxy.content_length = 512
55
56
 
57
+ appfirewall_policy = double('appfirewall_policy')
56
58
  expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
57
59
  'Running AppSensor deferred due to streaming'
58
60
  ).and_call_original
59
- expect(TCellAgent).to receive(:send_event).with(
60
- @appsensor_meta_event
61
+ expect(TCellAgent).to receive(:policy).with(
62
+ TCellAgent::PolicyTypes::APPSENSOR
63
+ ).and_return(appfirewall_policy)
64
+ expect(appfirewall_policy).to receive(:check_appfirewall_injections).with(
65
+ @meta_data
61
66
  )
62
67
 
63
68
  tcell_body_proxy.close
64
69
 
65
- expect(@appsensor_meta_event.meta_data.response_content_bytes_len).to eq(512)
70
+ expect(@meta_data.response_content_bytes_len).to eq(512)
66
71
  end
67
72
  end
68
73
  end