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
@@ -6,13 +6,10 @@ module TCellAgent
6
6
  module Instrumentation
7
7
  module Rails
8
8
  module Middleware
9
-
10
-
11
9
  class MockAppsensorRackApp
12
-
13
10
  attr_reader :request_body
14
11
 
15
- def initialize(route_id=nil, hmac_session_id=nil)
12
+ def initialize(route_id = nil, hmac_session_id = nil)
16
13
  @route_id = route_id
17
14
  @hmac_session_id = hmac_session_id
18
15
  @request_headers = {}
@@ -21,12 +18,12 @@ module TCellAgent
21
18
  def call(env)
22
19
  @env = env
23
20
  rack_request = Rack::Request.new(env)
24
- response_headers = {'Content-Type' => 'text/html'}
25
- env["tcell.request_data"].transaction_id = "a-b-c-d-e-f"
26
- env["tcell.request_data"].hmac_session_id = @hmac_session_id
27
- env["tcell.request_data"].route_id = @route_id
28
- if (rack_request.params['rv'])
29
- response_headers["Location"] = rack_request.params['rv']
21
+ response_headers = { 'Content-Type' => 'text/html' }
22
+ env['tcell.request_data'].transaction_id = 'a-b-c-d-e-f'
23
+ env['tcell.request_data'].hmac_session_id = @hmac_session_id
24
+ env['tcell.request_data'].route_id = @route_id
25
+ if rack_request.params['rv']
26
+ response_headers['Location'] = rack_request.params['rv']
30
27
  end
31
28
  [200, response_headers, ['OK']]
32
29
  end
@@ -34,55 +31,86 @@ module TCellAgent
34
31
  def [](key)
35
32
  @env[key]
36
33
  end
37
-
38
34
  end
39
35
 
40
36
  describe HeadersMiddleware do
41
-
42
37
  let(:app) { MockAppsensorRackApp.new }
43
- let(:app2) { MockAppsensorRackApp.new("myrouteid", "hmac_sessionid") }
38
+ let(:app2) { MockAppsensorRackApp.new('myrouteid', 'hmac_sessionid') }
44
39
 
45
- subject { withTCellMiddleware( app ) }
40
+ subject { with_tcell_middleware(app) }
46
41
 
47
- context "Redirect Middleware" do
42
+ context 'Redirect Middleware' do
48
43
  before(:each) do
49
44
  TCellAgent.configuration = TCellAgent::Configuration.new
50
- TCellAgent.configuration.read_config_from_file(get_test_resource_path("normal_config.json"))
45
+ TCellAgent.configuration.read_config_from_file(get_test_resource_path('normal_config.json'))
51
46
  end
47
+
52
48
  let(:request) { Rack::MockRequest.new(subject) }
53
- let(:request2) { Rack::MockRequest.new( withTCellMiddleware( app2 )) }
49
+ let(:request2) { Rack::MockRequest.new(with_tcell_middleware(app2)) }
54
50
  let(:agent) { ::TCellAgent::Agent.new }
55
- context "Event" do
51
+
52
+ context 'Event' do
56
53
  before(:each) do
57
- TCellAgent.thread_agent.processPolicyJson({"http-redirect"=>{
58
- "policy_id"=>"153ed270-7481-11e5-9194-95dad9b9dec3",
59
- "data"=>{
60
- "enabled"=>true,
61
- "block"=>false,
62
- "whitelist"=>[]
63
- }
64
- }}, cache=false)
54
+ TCellAgent.thread_agent.processPolicyJson(
55
+ {
56
+ 'http-redirect' =>
57
+ {
58
+ 'policy_id' => '153ed270-7481-11e5-9194-95dad9b9dec3',
59
+ 'data' => {
60
+ 'enabled' => true,
61
+ 'block' => false,
62
+ 'whitelist' => []
63
+ }
64
+ }
65
+ },
66
+ false
67
+ )
65
68
  TCellAgent.empty_event_queue
66
69
  end
67
- it "sends redirect" do
68
- response = request.get("/some/path2?abcdef=adsfsadf&rv=https://www.google.com", 'CONTENT_TYPE' => 'text/html', 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
69
- expect(response['Location']).to eq("https://www.google.com")
70
- expected_as = {"event_type"=>"redirect", "method"=>"GET", "from_domain"=>"example.org", "status_code"=>200, "remote_addr"=>"1.3.3.4", "from"=>"/some/path2?abcdef=&rv=", "to"=>"www.google.com"}
70
+
71
+ it 'sends redirect' do
72
+ response = request.get(
73
+ '/some/path2?abcdef=adsfsadf&rv=https://www.google.com',
74
+ 'CONTENT_TYPE' => 'text/html',
75
+ 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6'
76
+ )
77
+ expect(response['Location']).to eq('https://www.google.com')
78
+ expected_as = {
79
+ 'event_type' => 'redirect',
80
+ 'method' => 'GET',
81
+ 'from_domain' => 'example.org',
82
+ 'status_code' => 200,
83
+ 'remote_addr' => '1.3.3.4',
84
+ 'from' => '/some/path2?abcdef=&rv=',
85
+ 'to' => 'www.google.com'
86
+ }
71
87
  expect(TCellAgent.event_queue).to include(expected_as)
72
88
  end
73
- it "sends redirect event with extra info" do
74
- response = request2.get("/some/path2?abcdef=adsfsadf&rv=https://www.google.com", 'CONTENT_TYPE' => 'text/html', 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
75
- expect(response['Location']).to eq("https://www.google.com")
76
- expected_as = {"event_type"=>"redirect", "method"=>"GET", "from_domain"=>"example.org", "status_code"=>200, "remote_addr"=>"1.3.3.4", "rid"=>"myrouteid", "from"=>"/some/path2?abcdef=&rv=", "to"=>"www.google.com", "sid"=>"hmac_sessionid"}
89
+
90
+ it 'sends redirect event with extra info' do
91
+ response = request2.get(
92
+ '/some/path2?abcdef=adsfsadf&rv=https://www.google.com',
93
+ 'CONTENT_TYPE' => 'text/html',
94
+ 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6'
95
+ )
96
+ expect(response['Location']).to eq('https://www.google.com')
97
+ expected_as = {
98
+ 'event_type' => 'redirect',
99
+ 'method' => 'GET',
100
+ 'from_domain' => 'example.org',
101
+ 'status_code' => 200,
102
+ 'remote_addr' => '1.3.3.4',
103
+ 'rid' => 'myrouteid',
104
+ 'from' => '/some/path2?abcdef=&rv=',
105
+ 'to' => 'www.google.com',
106
+ 'sid' => 'hmac_sessionid'
107
+ }
77
108
  expect(TCellAgent.event_queue).to include(expected_as)
78
109
  end
79
-
80
- end #/conext
81
- end #/context
82
- end #/describe
83
-
84
-
110
+ end
111
+ end
85
112
  end
86
113
  end
87
114
  end
88
115
  end
116
+ end
@@ -3,32 +3,33 @@ require 'spec_helper'
3
3
  module TCellAgent
4
4
  module Instrumentation
5
5
  module Rails
6
-
7
6
  describe TCellBodyProxy do
8
-
9
- context "#close" do
7
+ context '#close' do
10
8
  before(:each) do
11
9
  @appsensor_meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new(
12
- "get",
13
- "remote_address",
14
- "route_id",
15
- "session_id",
16
- "user_id",
17
- "transaction_id")
10
+ 'get',
11
+ 'remote_address',
12
+ 'route_id',
13
+ 'session_id',
14
+ 'user_id',
15
+ 'transaction_id',
16
+ 'http://test.com/'
17
+ )
18
18
  end
19
19
 
20
- context "zero content length" do
21
- it "appsensor_meta event should be enqueued for processing" do
20
+ context 'zero content length' do
21
+ it 'appsensor_meta event should be enqueued for processing' do
22
22
  tcell_body_proxy = TCellBodyProxy.new(
23
- Rack::BodyProxy.new(["body"]) { },
23
+ Rack::BodyProxy.new(['body']) {},
24
24
  true,
25
- nil, nil, nil, nil)
25
+ nil, nil, nil, nil
26
+ )
26
27
  tcell_body_proxy.appsensor_meta = @appsensor_meta
27
28
 
28
29
  tcell_body_proxy.content_length = 0
29
30
 
30
31
  expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
31
- "Running AppSensor deferred due to streaming"
32
+ 'Running AppSensor deferred due to streaming'
32
33
  ).and_call_original
33
34
  expect(TCellAgent).to receive(:send_event).with(
34
35
  @appsensor_meta
@@ -38,18 +39,19 @@ module TCellAgent
38
39
  end
39
40
  end
40
41
 
41
- context "non zero content length" do
42
- it "appsensor_meta event should be enqueued for processing" do
42
+ context 'non zero content length' do
43
+ it 'appsensor_meta event should be enqueued for processing' do
43
44
  tcell_body_proxy = TCellBodyProxy.new(
44
- Rack::BodyProxy.new(["body"]) { },
45
+ Rack::BodyProxy.new(['body']) {},
45
46
  true,
46
- nil, nil, nil, nil)
47
+ nil, nil, nil, nil
48
+ )
47
49
  tcell_body_proxy.appsensor_meta = @appsensor_meta
48
50
 
49
51
  tcell_body_proxy.content_length = 512
50
52
 
51
53
  expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
52
- "Running AppSensor deferred due to streaming"
54
+ 'Running AppSensor deferred due to streaming'
53
55
  ).and_call_original
54
56
  expect(TCellAgent).to receive(:send_event).with(
55
57
  @appsensor_meta
@@ -62,27 +64,30 @@ module TCellAgent
62
64
  end
63
65
  end
64
66
 
65
- context "#each" do
66
- context "with no block given" do
67
- it "should return an enumerator" do
67
+ context '#each' do
68
+ context 'with no block given' do
69
+ it 'should return an enumerator' do
68
70
  tcell_body_proxy = TCellBodyProxy.new(
69
- Rack::BodyProxy.new(["body"]) { },
71
+ Rack::BodyProxy.new(['body']) {},
70
72
  true,
71
- nil, nil, nil, nil)
72
- expect(tcell_body_proxy.each.class.name).to eq("Enumerator")
73
+ nil, nil, nil, nil
74
+ )
75
+ expect(tcell_body_proxy.each.class.name).to eq('Enumerator')
73
76
  end
74
77
  end
75
78
 
76
- context "with a string response" do
77
- context "with a chunked response" do
78
- it "should only calculate content length" do
79
+ context 'with a string response' do
80
+ context 'with a chunked response' do
81
+ it 'should only calculate content length' do
79
82
  tcell_body_proxy = TCellBodyProxy.new(
80
- Rack::BodyProxy.new(["2d\r\nsome content\r\n"]) { },
83
+ Rack::BodyProxy.new(["2d\r\nsome content\r\n"]) {},
81
84
  false,
82
- nil, nil, nil, nil)
85
+ nil, nil, nil, nil
86
+ )
83
87
 
84
88
  expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
85
- "Processing tcell body proxy body").and_call_original
89
+ 'Processing tcell body proxy body'
90
+ ).and_call_original
86
91
 
87
92
  tcell_body_proxy.each { |b| }
88
93
 
@@ -90,16 +95,18 @@ module TCellAgent
90
95
  end
91
96
  end
92
97
 
93
- context "with a non chunked response" do
94
- context "that should not be processed" do
95
- it "should only calculate content length" do
98
+ context 'with a non chunked response' do
99
+ context 'that should not be processed' do
100
+ it 'should only calculate content length' do
96
101
  tcell_body_proxy = TCellBodyProxy.new(
97
- Rack::BodyProxy.new(["some content"]) { },
102
+ Rack::BodyProxy.new(['some content']) {},
98
103
  false,
99
- nil, nil, nil, nil)
104
+ nil, nil, nil, nil
105
+ )
100
106
 
101
107
  expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
102
- "Processing tcell body proxy body").and_call_original
108
+ 'Processing tcell body proxy body'
109
+ ).and_call_original
103
110
 
104
111
  tcell_body_proxy.each { |b| }
105
112
 
@@ -107,19 +114,21 @@ module TCellAgent
107
114
  end
108
115
  end
109
116
 
110
- context "that should be processed" do
111
- it "should call js and dlp procs as well as calculate content length" do
112
- js_agent_insertion_proc = double("js_agent_insertion_proc")
113
- dlp_cleaner_proc = double("dlp_cleaner_proc")
117
+ context 'that should be processed' do
118
+ it 'should call js and dlp procs as well as calculate content length' do
119
+ js_agent_insertion_proc = double('js_agent_insertion_proc')
120
+ dlp_cleaner_proc = double('dlp_cleaner_proc')
114
121
  tcell_body_proxy = TCellBodyProxy.new(
115
- Rack::BodyProxy.new(["some content"]) { },
122
+ Rack::BodyProxy.new(['some content']) {},
116
123
  true,
117
- js_agent_insertion_proc, "script_insert", dlp_cleaner_proc, nil)
124
+ js_agent_insertion_proc, 'script_insert', dlp_cleaner_proc, nil
125
+ )
118
126
 
119
127
  expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
120
- "Processing tcell body proxy body").and_call_original
121
- expect(js_agent_insertion_proc).to receive(:call).with("script_insert", "some content")
122
- expect(dlp_cleaner_proc).to receive(:call).with(nil, "some content")
128
+ 'Processing tcell body proxy body'
129
+ ).and_call_original
130
+ expect(js_agent_insertion_proc).to receive(:call).with('script_insert', 'some content')
131
+ expect(dlp_cleaner_proc).to receive(:call).with(nil, 'some content')
123
132
 
124
133
  tcell_body_proxy.each { |b| }
125
134
 
@@ -129,23 +138,27 @@ module TCellAgent
129
138
  end
130
139
  end
131
140
 
132
- context "with an ActionView::OutputBuffer" do
133
- context "that should not be processed" do
134
- it "should only calculate content length" do
135
- body_chunk = "some content"
136
- js_agent_insertion_proc = double("js_agent_insertion_proc")
137
- dlp_cleaner_proc = double("dlp_cleaner_proc")
141
+ context 'with an ActionView::OutputBuffer' do
142
+ context 'that should not be processed' do
143
+ it 'should only calculate content length' do
144
+ body_chunk = 'some content'
145
+ js_agent_insertion_proc = double('js_agent_insertion_proc')
146
+ dlp_cleaner_proc = double('dlp_cleaner_proc')
138
147
  tcell_body_proxy = TCellBodyProxy.new(
139
- Rack::BodyProxy.new([body_chunk]) { },
148
+ Rack::BodyProxy.new([body_chunk]) {},
140
149
  false,
141
- nil, nil, nil, nil)
150
+ nil, nil, nil, nil
151
+ )
142
152
 
143
153
  expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
144
- "Processing tcell body proxy body").and_call_original
154
+ 'Processing tcell body proxy body'
155
+ ).and_call_original
145
156
  expect(body_chunk).to receive(:class).and_return(
146
- double("body_class", name: "ActionView::OutputBuffer"))
157
+ double('body_class', :name => 'ActionView::OutputBuffer')
158
+ )
147
159
  expect(body_chunk).to receive(:class).and_return(
148
- double("body_class", name: "ActionView::OutputBuffer"))
160
+ double('body_class', :name => 'ActionView::OutputBuffer')
161
+ )
149
162
  expect(js_agent_insertion_proc).to_not receive(:call)
150
163
  expect(dlp_cleaner_proc).to_not receive(:call)
151
164
 
@@ -155,19 +168,21 @@ module TCellAgent
155
168
  end
156
169
  end
157
170
 
158
- context "that should be processed" do
159
- it "should call js and dlp procs as well as calculate content length" do
160
- body_chunk = "some content"
161
- js_agent_insertion_proc = double("js_agent_insertion_proc")
162
- dlp_cleaner_proc = double("dlp_cleaner_proc")
171
+ context 'that should be processed' do
172
+ it 'should call js and dlp procs as well as calculate content length' do
173
+ body_chunk = 'some content'
174
+ js_agent_insertion_proc = double('js_agent_insertion_proc')
175
+ dlp_cleaner_proc = double('dlp_cleaner_proc')
163
176
  tcell_body_proxy = TCellBodyProxy.new(
164
- Rack::BodyProxy.new([body_chunk]) { },
177
+ Rack::BodyProxy.new([body_chunk]) {},
165
178
  true,
166
- js_agent_insertion_proc, "script_insert", dlp_cleaner_proc, nil)
179
+ js_agent_insertion_proc, 'script_insert', dlp_cleaner_proc, nil
180
+ )
167
181
 
168
182
  expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
169
- "Processing tcell body proxy body").and_call_original
170
- expect(js_agent_insertion_proc).to receive(:call).with("script_insert", body_chunk)
183
+ 'Processing tcell body proxy body'
184
+ ).and_call_original
185
+ expect(js_agent_insertion_proc).to receive(:call).with('script_insert', body_chunk)
171
186
  expect(dlp_cleaner_proc).to receive(:call).with(nil, body_chunk)
172
187
 
173
188
  tcell_body_proxy.each { |b| }
@@ -178,7 +193,6 @@ module TCellAgent
178
193
  end
179
194
  end
180
195
  end
181
-
182
196
  end
183
197
  end
184
198
  end
@@ -2,80 +2,76 @@ require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
4
  module Utils
5
-
6
- describe ".responses" do
7
-
8
- context ".empty_content?" do
9
- context "with nil status code" do
10
- context "with empty headers" do
11
- it "should return false" do
5
+ describe '.responses' do
6
+ context '.empty_content?' do
7
+ context 'with nil status code' do
8
+ context 'with empty headers' do
9
+ it 'should return false' do
12
10
  expect(Rails.empty_content?(nil, {})).to eq(false)
13
11
  end
14
12
  end
15
13
 
16
- context "with Content-Length header" do
17
- context "that is zero" do
18
- it "should return true" do
19
- expect(Rails.empty_content?(nil, {'Content-Length' => 0})).to eq(true)
14
+ context 'with Content-Length header' do
15
+ context 'that is zero' do
16
+ it 'should return true' do
17
+ expect(Rails.empty_content?(nil, { 'Content-Length' => 0 })).to eq(true)
20
18
  end
21
19
  end
22
20
 
23
- context "that is non zero" do
24
- it "should return false" do
25
- expect(Rails.empty_content?(nil, {'Content-Length' => 1})).to eq(false)
21
+ context 'that is non zero' do
22
+ it 'should return false' do
23
+ expect(Rails.empty_content?(nil, { 'Content-Length' => 1 })).to eq(false)
26
24
  end
27
25
  end
28
26
  end
29
27
  end
30
28
 
31
- context "with a status code" do
32
- context "that contains no content" do
33
- context "with empty headers" do
34
- it "should return true" do
29
+ context 'with a status code' do
30
+ context 'that contains no content' do
31
+ context 'with empty headers' do
32
+ it 'should return true' do
35
33
  expect(Rails.empty_content?(204, {})).to eq(true)
36
34
  end
37
35
  end
38
36
 
39
- context "with Content-Length header" do
40
- context "that is zero" do
41
- it "should return true" do
42
- expect(Rails.empty_content?(204, {'Content-Length' => 0})).to eq(true)
37
+ context 'with Content-Length header' do
38
+ context 'that is zero' do
39
+ it 'should return true' do
40
+ expect(Rails.empty_content?(204, { 'Content-Length' => 0 })).to eq(true)
43
41
  end
44
42
  end
45
43
 
46
- context "that is non zero" do
47
- it "should return true" do
48
- expect(Rails.empty_content?(204, {'Content-Length' => 1})).to eq(true)
44
+ context 'that is non zero' do
45
+ it 'should return true' do
46
+ expect(Rails.empty_content?(204, { 'Content-Length' => 1 })).to eq(true)
49
47
  end
50
48
  end
51
49
  end
52
50
  end
53
51
 
54
- context "that contains content" do
55
- context "with empty headers" do
56
- it "should return false" do
52
+ context 'that contains content' do
53
+ context 'with empty headers' do
54
+ it 'should return false' do
57
55
  expect(Rails.empty_content?(200, {})).to eq(false)
58
56
  end
59
57
  end
60
58
 
61
- context "with Content-Length header" do
62
- context "that is zero" do
63
- it "should return true" do
64
- expect(Rails.empty_content?(200, {'Content-Length' => 0})).to eq(true)
59
+ context 'with Content-Length header' do
60
+ context 'that is zero' do
61
+ it 'should return true' do
62
+ expect(Rails.empty_content?(200, { 'Content-Length' => 0 })).to eq(true)
65
63
  end
66
64
  end
67
65
 
68
- context "that is non zero" do
69
- it "should return false" do
70
- expect(Rails.empty_content?(200, {'Content-Length' => 1})).to eq(false)
66
+ context 'that is non zero' do
67
+ it 'should return false' do
68
+ expect(Rails.empty_content?(200, { 'Content-Length' => 1 })).to eq(false)
71
69
  end
72
70
  end
73
71
  end
74
72
  end
75
73
  end
76
74
  end
77
-
78
75
  end
79
-
80
76
  end
81
77
  end