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
@@ -4,61 +4,61 @@ module TCellAgent
4
4
  module Policies
5
5
  describe SecureHeadersPolicy do
6
6
  secure_headers_policy_json = {
7
- "policy_id"=>"01a1",
8
- "headers"=>[
9
- {"name"=>"x-permitted-cross-domain-policies", "value"=>"value123"}
7
+ 'policy_id' => '01a1',
8
+ 'headers' => [
9
+ { 'name' => 'x-permitted-cross-domain-policies', 'value' => 'value123' }
10
10
  ]
11
11
  }
12
12
  secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
13
- context "secure header example" do
14
- it "returns true" do
15
- expect(secure_headers_policy.headers[0].name).to eq("x-permitted-cross-domain-policies")
16
- expect(secure_headers_policy.headers[0].value).to eq("value123")
13
+ context 'secure header example' do
14
+ it 'returns true' do
15
+ expect(secure_headers_policy.headers[0].name).to eq('x-permitted-cross-domain-policies')
16
+ expect(secure_headers_policy.headers[0].value).to eq('value123')
17
17
  end
18
18
  end
19
19
  end
20
20
  describe SecureHeadersPolicy do
21
21
  secure_headers_policy_json = {
22
- "policy_id"=>"01a1",
23
- "headers"=>[
24
- {"name"=>"x-frame-options", "value"=>"DENY"},
25
- {"name"=>"x-xss-protection", "value"=>"1; mode=block"}
22
+ 'policy_id' => '01a1',
23
+ 'headers' => [
24
+ { 'name' => 'x-frame-options', 'value' => 'DENY' },
25
+ { 'name' => 'x-xss-protection', 'value' => '1; mode=block' }
26
26
  ]
27
27
  }
28
28
  secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
29
- context "secure headers (2) example" do
30
- it "returns true" do
31
- expect(secure_headers_policy.headers[0].name).to eq("x-frame-options")
32
- expect(secure_headers_policy.headers[0].value).to eq("DENY")
33
- expect(secure_headers_policy.headers[1].name).to eq("x-xss-protection")
34
- expect(secure_headers_policy.headers[1].value).to eq("1; mode=block")
29
+ context 'secure headers (2) example' do
30
+ it 'returns true' do
31
+ expect(secure_headers_policy.headers[0].name).to eq('x-frame-options')
32
+ expect(secure_headers_policy.headers[0].value).to eq('DENY')
33
+ expect(secure_headers_policy.headers[1].name).to eq('x-xss-protection')
34
+ expect(secure_headers_policy.headers[1].value).to eq('1; mode=block')
35
35
  end
36
36
  end
37
37
  end
38
38
  describe SecureHeadersPolicy do
39
39
  secure_headers_policy_json = {
40
- "policy_id"=>"01a1",
41
- "headers"=>[
42
- {"name"=>"bad-header", "value"=>"value123"}
40
+ 'policy_id' => '01a1',
41
+ 'headers' => [
42
+ { 'name' => 'bad-header', 'value' => 'value123' }
43
43
  ]
44
44
  }
45
45
  secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
46
- context "secure header example, invalid header" do
47
- it "returns false" do
46
+ context 'secure header example, invalid header' do
47
+ it 'returns false' do
48
48
  expect(secure_headers_policy.headers.length).to eq(0)
49
49
  end
50
50
  end
51
51
  end
52
52
  describe SecureHeadersPolicy do
53
53
  secure_headers_policy_json = {
54
- "policy_id"=>"01a1",
55
- "headers"=>[
56
- {"name"=>"x-permitted-cross-domain-policies", "value"=>"value123\\nabc"}
54
+ 'policy_id' => '01a1',
55
+ 'headers' => [
56
+ { 'name' => 'x-permitted-cross-domain-policies', 'value' => 'value123\\nabc' }
57
57
  ]
58
58
  }
59
59
  secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
60
- context "secure header, value is bad" do
61
- it "returns false" do
60
+ context 'secure header, value is bad' do
61
+ it 'returns false' do
62
62
  expect(secure_headers_policy.headers.length).to eq(0)
63
63
  end
64
64
  end
@@ -2,75 +2,71 @@ require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
4
  module Utils
5
-
6
- describe ".better_ip" do
7
-
8
- context "with reverse_proxy off" do
9
- it "should return the normal ip" do
10
- configuration = double("configuration")
11
- request = double("request", ip: "127.0.0.0")
5
+ describe '.better_ip' do
6
+ context 'with reverse_proxy off' do
7
+ it 'should return the normal ip' do
8
+ configuration = double('configuration')
9
+ request = double('request', :ip => '127.0.0.0')
12
10
 
13
11
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
14
12
  expect(configuration).to receive(:reverse_proxy).and_return(false)
15
- expect(Rails.better_ip(request)).to eq("127.0.0.0")
13
+ expect(Rails.better_ip(request)).to eq('127.0.0.0')
16
14
  end
17
15
  end
18
16
 
19
- context "with reverse_proxy on" do
20
- context "with empty reverse_proxy_ip_address_header" do
21
- it "should return normal ip" do
22
- configuration = double("configuration")
23
- request = double("request", ip: "127.0.0.0")
24
- env = double("env")
17
+ context 'with reverse_proxy on' do
18
+ context 'with empty reverse_proxy_ip_address_header' do
19
+ it 'should return normal ip' do
20
+ configuration = double('configuration')
21
+ request = double('request', :ip => '127.0.0.0')
22
+ env = double('env')
25
23
 
26
24
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
27
25
  expect(configuration).to receive(:reverse_proxy).and_return(true)
28
26
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
29
- expect(configuration).to receive(:reverse_proxy_ip_address_header).and_return("")
27
+ expect(configuration).to receive(:reverse_proxy_ip_address_header).and_return('')
30
28
  expect(request).to receive(:env).and_return(env)
31
- expect(env).to receive(:[]).with("HTTP_X_FORWARDED_FOR").and_return("")
32
- expect(Rails.better_ip(request)).to eq("127.0.0.0")
29
+ expect(env).to receive(:[]).with('HTTP_X_FORWARDED_FOR').and_return('')
30
+ expect(Rails.better_ip(request)).to eq('127.0.0.0')
33
31
  end
34
32
  end
35
33
 
36
34
  context "with reverse_proxy_ip_address_header that doesn't exist" do
37
- it "should return normal ip" do
38
- configuration = double("configuration")
39
- request = double("request", ip: "127.0.0.0")
40
- env = double("env")
35
+ it 'should return normal ip' do
36
+ configuration = double('configuration')
37
+ request = double('request', :ip => '127.0.0.0')
38
+ env = double('env')
41
39
 
42
40
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
43
41
  expect(configuration).to receive(:reverse_proxy).and_return(true)
44
42
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
45
43
  expect(configuration).to receive(:reverse_proxy_ip_address_header).and_return(
46
- "weird-http-proxy-header"
44
+ 'weird-http-proxy-header'
47
45
  )
48
46
  expect(request).to receive(:env).and_return(env)
49
- expect(env).to receive(:[]).with("HTTP_WEIRD_HTTP_PROXY_HEADER").and_return(nil)
50
- expect(Rails.better_ip(request)).to eq("127.0.0.0")
47
+ expect(env).to receive(:[]).with('HTTP_WEIRD_HTTP_PROXY_HEADER').and_return(nil)
48
+ expect(Rails.better_ip(request)).to eq('127.0.0.0')
51
49
  end
52
50
  end
53
51
 
54
- context "with reverse_proxy_ip_address_header that exists" do
55
- it "should return proxied ip" do
56
- configuration = double("configuration")
57
- request = double("request", ip: "127.0.0.0")
58
- env = double("env")
52
+ context 'with reverse_proxy_ip_address_header that exists' do
53
+ it 'should return proxied ip' do
54
+ configuration = double('configuration')
55
+ request = double('request', :ip => '127.0.0.0')
56
+ env = double('env')
59
57
 
60
58
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
61
59
  expect(configuration).to receive(:reverse_proxy).and_return(true)
62
60
  expect(TCellAgent).to receive(:configuration).and_return(configuration)
63
61
  expect(configuration).to receive(:reverse_proxy_ip_address_header).and_return(
64
- "X-Real-IP"
62
+ 'X-Real-IP'
65
63
  )
66
64
  expect(request).to receive(:env).and_return(env)
67
- expect(env).to receive(:[]).with("HTTP_X_REAL_IP").and_return("192.168.99.100")
68
- expect(Rails.better_ip(request)).to eq("192.168.99.100")
65
+ expect(env).to receive(:[]).with('HTTP_X_REAL_IP').and_return('192.168.99.100')
66
+ expect(Rails.better_ip(request)).to eq('192.168.99.100')
69
67
  end
70
68
  end
71
69
  end
72
-
73
70
  end
74
-
75
71
  end
76
72
  end
@@ -1,52 +1,55 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Logger do
4
-
5
- describe "#add" do
6
- context "with a warn logger" do
7
- context "writing a debug message" do
8
- it "should skip the tcell logic" do
4
+ describe '#add' do
5
+ context 'with a warn logger' do
6
+ context 'writing a debug message' do
7
+ it 'should skip the tcell logic' do
9
8
  expect(TCellAgent::Instrumentation).to_not receive(:safe_block_no_log)
10
9
 
11
10
  logger = Logger.new('/dev/null')
12
11
 
13
12
  logger.level = Logger::WARN
14
- logger.add(Logger::DEBUG, "This will not be logged")
13
+ logger.add(Logger::DEBUG, 'This will not be logged')
15
14
  end
16
15
  end
17
16
 
18
- context "writing a warn message" do
19
- it "should run the tcell logic" do
20
- expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with("Handling JSAgent add")
17
+ context 'writing a warn message' do
18
+ it 'should run the tcell logic' do
19
+ expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
20
+ 'Handling DLP log message filtering'
21
+ )
21
22
 
22
23
  logger = Logger.new('/dev/null')
23
24
 
24
25
  logger.level = Logger::WARN
25
- logger.add(Logger::WARN, "This will be logged")
26
+ logger.add(Logger::WARN, 'This will be logged')
26
27
  end
27
28
  end
28
29
 
29
- context "writing an error message" do
30
- it "should run the tcell logic" do
31
- expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with("Handling JSAgent add")
30
+ context 'writing an error message' do
31
+ it 'should run the tcell logic' do
32
+ expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
33
+ 'Handling DLP log message filtering'
34
+ )
32
35
 
33
36
  logger = Logger.new('/dev/null')
34
37
 
35
38
  logger.level = Logger::WARN
36
- logger.add(Logger::ERROR, "This will be logged")
39
+ logger.add(Logger::ERROR, 'This will be logged')
37
40
  end
38
41
 
39
- context "with an empty message" do
40
- it "should not run the context filter" do
42
+ context 'with an empty message' do
43
+ it 'should not run the context filter' do
41
44
  expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
42
- "Handling JSAgent add"
45
+ 'Handling DLP log message filtering'
43
46
  ).and_call_original
44
47
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DataLoss).and_return(
45
- double("dlp_policy")
48
+ double('dlp_policy')
46
49
  )
47
50
  expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
48
51
  :fetch
49
- ).with(anything(), nil).and_return(double("request_env"))
52
+ ).with(anything, nil).and_return(double('request_env'))
50
53
 
51
54
  logger = Logger.new('/dev/null')
52
55
 
@@ -55,94 +58,92 @@ describe Logger do
55
58
  end
56
59
  end
57
60
 
58
- context "with no dlp policy" do
59
- it "should not run the context filter" do
61
+ context 'with no dlp policy' do
62
+ it 'should not run the context filter' do
60
63
  expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
61
- "Handling JSAgent add"
64
+ 'Handling DLP log message filtering'
62
65
  ).and_call_original
63
66
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DataLoss).and_return(
64
67
  nil
65
68
  )
66
69
  expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
67
70
  :fetch
68
- ).with(anything(), nil).and_return(double("request_env"))
71
+ ).with(anything, nil).and_return(double('request_env'))
69
72
 
70
73
  logger = Logger.new('/dev/null')
71
74
 
72
75
  logger.level = Logger::WARN
73
- logger.add(Logger::ERROR, "My DLP Policy :(")
76
+ logger.add(Logger::ERROR, 'My DLP Policy :(')
74
77
  end
75
78
  end
76
79
 
77
- context "with no request env" do
78
- it "should not run the context filter" do
80
+ context 'with no request env' do
81
+ it 'should not run the context filter' do
79
82
  expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
80
- "Handling JSAgent add"
83
+ 'Handling DLP log message filtering'
81
84
  ).and_call_original
82
85
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DataLoss).and_return(
83
- double("dlp_policy")
86
+ double('dlp_policy')
84
87
  )
85
88
  expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
86
89
  :fetch
87
- ).with(anything(), nil).and_return(nil)
90
+ ).with(anything, nil).and_return(nil)
88
91
 
89
92
  logger = Logger.new('/dev/null')
90
93
 
91
94
  logger.level = Logger::WARN
92
- logger.add(Logger::ERROR, "My DLP Policy :(")
95
+ logger.add(Logger::ERROR, 'My DLP Policy :(')
93
96
  end
94
97
  end
95
98
 
96
- context "with a dlp policy, a message, and request env" do
97
-
98
- context "with no tcell_context" do
99
- it "should not run the context filter" do
100
- request_env = double("request_env")
99
+ context 'with a dlp policy, a message, and request env' do
100
+ context 'with no tcell_context' do
101
+ it 'should not run the context filter' do
102
+ request_env = double('request_env')
101
103
 
102
104
  expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
103
- "Handling JSAgent add"
105
+ 'Handling DLP log message filtering'
104
106
  ).and_call_original
105
107
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DataLoss).and_return(
106
- double("dlp_policy")
108
+ double('dlp_policy')
107
109
  )
108
110
  expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
109
111
  :fetch
110
- ).with(anything(), nil).and_return(request_env)
112
+ ).with(anything, nil).and_return(request_env)
111
113
  expect(request_env).to receive(:[]).and_return(nil)
112
114
 
113
115
  logger = Logger.new('/dev/null')
114
116
 
115
117
  logger.level = Logger::WARN
116
- logger.add(Logger::ERROR, "My DLP Policy :(")
118
+ logger.add(Logger::ERROR, 'My DLP Policy :(')
117
119
  end
118
120
  end
119
121
 
120
- context "with tcell_context" do
121
- it "should not run the context filter" do
122
- request_env = double("request_env")
123
- tcell_context = double("tcell_context")
122
+ context 'with tcell_context' do
123
+ it 'should not run the context filter' do
124
+ request_env = double('request_env')
125
+ tcell_context = double('tcell_context')
124
126
 
125
127
  expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
126
- "Handling JSAgent add"
128
+ 'Handling DLP log message filtering'
127
129
  ).and_call_original
128
130
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DataLoss).and_return(
129
- double("dlp_policy")
131
+ double('dlp_policy')
130
132
  )
131
133
  expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
132
134
  :fetch
133
- ).with(anything(), nil).and_return(request_env)
135
+ ).with(anything, nil).and_return(request_env)
134
136
  expect(request_env).to receive(:[]).and_return(tcell_context)
135
- expect(tcell_context).to receive(:filter_log).with("My DLP Policy :(")
137
+ expect(tcell_context).to receive(:filter_log).with('My DLP Policy :(')
136
138
 
137
139
  logger = Logger.new('/dev/null')
138
140
 
139
141
  logger.level = Logger::WARN
140
- logger.add(Logger::ERROR, "My DLP Policy :(")
142
+ logger.add(Logger::ERROR, 'My DLP Policy :(')
141
143
  end
142
144
  end
143
145
  end
144
146
  end
145
147
  end
146
148
  end
147
-
148
149
  end