tcell_agent 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -2,39 +2,41 @@ require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
4
  module SensorEvents
5
-
6
5
  describe AppSensorMetaEvent do
7
-
8
- describe "#body_params" do
6
+ describe '#body_params' do
9
7
  before(:each) do
10
8
  @appsensor_meta = AppSensorMetaEvent.new(
11
- "get",
12
- "remote_address",
13
- "route_id",
14
- "session_id",
15
- "user_id",
16
- "transaction_id")
9
+ 'get',
10
+ 'remote_address',
11
+ 'route_id',
12
+ 'session_id',
13
+ 'user_id',
14
+ 'transaction_id',
15
+ 'http://test.com'
16
+ )
17
17
  end
18
18
 
19
- context "with text/html content type" do
20
- it "should set the body params to empty" do
19
+ context 'with text/html content type' do
20
+ it 'should set the body params to empty' do
21
21
  @appsensor_meta.set_body_dict(
22
22
  67,
23
- "text/html",
24
- {username:"tester",password:"pass"}.to_json
23
+ 'text/html',
24
+ {
25
+ :username => 'tester',
26
+ :password => 'pass'
27
+ }.to_json
25
28
  )
26
29
 
27
30
  expect(@appsensor_meta.body_dict).to eq({})
28
31
  end
29
32
  end
30
33
 
31
- context "with application/json content type" do
32
-
33
- context "with empty request body" do
34
- it "should set the body params to empty" do
34
+ context 'with application/json content type' do
35
+ context 'with empty request body' do
36
+ it 'should set the body params to empty' do
35
37
  @appsensor_meta.set_body_dict(
36
38
  67,
37
- "application/json",
39
+ 'application/json',
38
40
  nil
39
41
  )
40
42
 
@@ -42,11 +44,11 @@ module TCellAgent
42
44
  end
43
45
  end
44
46
 
45
- context "with bad json in the body" do
46
- it "should set the body params to empty" do
47
+ context 'with bad json in the body' do
48
+ it 'should set the body params to empty' do
47
49
  @appsensor_meta.set_body_dict(
48
50
  67,
49
- "application/json",
51
+ 'application/json',
50
52
  '{"username":"tester""password":"pass"}'
51
53
  )
52
54
 
@@ -54,32 +56,41 @@ module TCellAgent
54
56
  end
55
57
  end
56
58
 
57
- context "with valid json in the body" do
58
- it "should set the body params" do
59
+ context 'with valid json in the body' do
60
+ it 'should set the body params' do
59
61
  @appsensor_meta.set_body_dict(
60
62
  67,
61
- "application/json",
62
- {username:"tester",password:"pass"}.to_json
63
+ 'application/json',
64
+ {
65
+ :username => 'tester',
66
+ :password => 'pass'
67
+ }.to_json
63
68
  )
64
69
 
65
- expect(@appsensor_meta.body_dict).to eq({["username"]=>"tester",["password"]=>"pass"})
70
+ expect(@appsensor_meta.body_dict).to eq(
71
+ {
72
+ ['username'] => 'tester',
73
+ ['password'] => 'pass'
74
+ }
75
+ )
66
76
  end
67
77
  end
68
78
 
69
- context "with a json body that's too big" do
70
- it "should set the body params to empty" do
79
+ context 'with a json body that is too big' do
80
+ it 'should set the body params to empty' do
71
81
  @appsensor_meta.set_body_dict(
72
- 20000000,
73
- "application/json",
74
- {username:"tester",password:"pass"}.to_json
82
+ 20_000_000,
83
+ 'application/json',
84
+ {
85
+ :username => 'tester',
86
+ :password => 'pass'
87
+ }.to_json
75
88
  )
76
89
  expect(@appsensor_meta.body_dict).to eq({})
77
90
  end
78
91
  end
79
92
  end
80
93
  end
81
-
82
94
  end
83
-
84
95
  end
85
96
  end
@@ -3,10 +3,10 @@ require 'spec_helper'
3
3
  module TCellAgent
4
4
  module SensorEvents
5
5
  describe DlpEvent do
6
- context "Domain from Url" do
7
- it "Test Simple Domain" do
8
- dlp_event = DlpEvent.new("a","b","c").for_request("x","y")
9
- expect(dlp_event["context"]).to eq("x")
6
+ context 'Domain from Url' do
7
+ it 'Test Simple Domain' do
8
+ dlp_event = DlpEvent.new('a', 'b', 'c').for_request('x', 'y')
9
+ expect(dlp_event['context']).to eq('x')
10
10
  end
11
11
  end
12
12
  end
@@ -3,256 +3,270 @@ require 'spec_helper'
3
3
  module TCellAgent
4
4
  module SensorEvents
5
5
  describe SessionsMetric do
6
- describe "#initialize" do
7
- context "empty sessions info" do
8
- it "should have the event type set" do
6
+ describe '#initialize' do
7
+ context 'empty sessions info' do
8
+ it 'should have the event type set' do
9
9
  sessions_metric = SessionsMetric.new
10
- expect(sessions_metric).to eq({"event_type" => "metrics", "sessions" => {}})
10
+ expect(sessions_metric).to eq({ 'event_type' => 'metrics', 'sessions' => {} })
11
11
  end
12
12
  end
13
13
  end
14
14
 
15
- describe "#add_session_info" do
16
- context "empty sessions info" do
17
- context "adding session info" do
18
- it "should have the session info" do
15
+ describe '#add_session_info' do
16
+ context 'empty sessions info' do
17
+ context 'adding session info' do
18
+ it 'should have the session info' do
19
19
  sessions_metric = SessionsMetric.new
20
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", "user_agent")
20
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
21
21
 
22
22
  expect(sessions_metric.has_sessions?).to eq(true)
23
- expect(sessions_metric).to eq({
24
- "event_type"=>"metrics",
25
- "sessions"=>{
26
- "hmac_session_id" => [
27
- {
28
- "uid"=>"user_id",
29
- "track"=>[
30
- ["user_agent", ["127.0.0.1"]]
31
- ]
32
- }
33
- ]
23
+ expect(sessions_metric).to eq(
24
+ {
25
+ 'event_type' => 'metrics',
26
+ 'sessions' => {
27
+ 'hmac_session_id' => [
28
+ {
29
+ 'uid' => 'user_id',
30
+ 'track' => [
31
+ ['user_agent', ['127.0.0.1']]
32
+ ]
33
+ }
34
+ ]
35
+ }
34
36
  }
35
- })
37
+ )
36
38
  end
37
39
  end
38
40
 
39
- context "adding a really long user agent" do
40
- it "should truncate the agent" do
41
- long_user_agent = "user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_"
42
- long_user_agent += "user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent"
43
- long_user_agent += "user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent"
44
- long_user_agent += "user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent"
41
+ context 'adding a really long user agent' do
42
+ it 'should truncate the agent' do
43
+ long_user_agent = 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_'
44
+ long_user_agent += 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent'
45
+ long_user_agent += 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent'
46
+ long_user_agent += 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent'
45
47
  sessions_metric = SessionsMetric.new
46
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", long_user_agent)
47
- expect(sessions_metric).to eq({
48
- "event_type"=>"metrics",
49
- "sessions"=>{
50
- "hmac_session_id" => [
51
- {
52
- "uid"=>"user_id",
53
- "track"=>[
54
- ["user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agentuser_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agentuser_agent_user_agent_user_", ["127.0.0.1"]]
55
- ]
56
- }
57
- ]
48
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', long_user_agent)
49
+
50
+ expect(sessions_metric).to eq(
51
+ {
52
+ 'event_type' => 'metrics',
53
+ 'sessions' => {
54
+ 'hmac_session_id' => [
55
+ {
56
+ 'uid' => 'user_id',
57
+ 'track' => [
58
+ ['user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agentuser_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agentuser_agent_user_agent_user_', ['127.0.0.1']]
59
+ ]
60
+ }
61
+ ]
62
+ }
58
63
  }
59
- })
64
+ )
60
65
  end
61
66
  end
62
67
  end
63
68
 
64
- context "with an existing session info" do
65
- context "adding the same info" do
66
- it "should not do anything" do
69
+ context 'with an existing session info' do
70
+ context 'adding the same info' do
71
+ it 'should not do anything' do
67
72
  sessions_metric = SessionsMetric.new
68
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", "user_agent")
69
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", "user_agent")
73
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
74
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
70
75
 
71
- expect(sessions_metric).to eq({
72
- "event_type"=>"metrics",
73
- "sessions"=>{
74
- "hmac_session_id" => [
75
- {
76
- "uid"=>"user_id",
77
- "track"=>[
78
- ["user_agent", ["127.0.0.1"]]
79
- ]
80
- }
81
- ]
76
+ expect(sessions_metric).to eq(
77
+ {
78
+ 'event_type' => 'metrics',
79
+ 'sessions' => {
80
+ 'hmac_session_id' => [
81
+ {
82
+ 'uid' => 'user_id',
83
+ 'track' => [
84
+ ['user_agent', ['127.0.0.1']]
85
+ ]
86
+ }
87
+ ]
88
+ }
82
89
  }
83
- })
90
+ )
84
91
  end
85
92
  end
86
93
 
87
-
88
- context "adding a new session" do
89
- it "should add the new info" do
94
+ context 'adding a new session' do
95
+ it 'should add the new info' do
90
96
  sessions_metric = SessionsMetric.new
91
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", "user_agent")
92
-
93
- sessions_metric.add_session_info("hmac_session_id_dos", "user_id_dos", "127.0.0.1_dos", "user_agent_dos")
94
- expect(sessions_metric).to eq({
95
- "event_type"=>"metrics",
96
- "sessions"=>{
97
- "hmac_session_id" => [
98
- {
99
- "uid"=>"user_id",
100
- "track"=>[
101
- ["user_agent", ["127.0.0.1"]]
102
- ]
103
- }
104
- ],
105
- "hmac_session_id_dos" => [
106
- {
107
- "uid"=>"user_id_dos",
108
- "track"=>[
109
- ["user_agent_dos", ["127.0.0.1_dos"]]
110
- ]
111
- }
112
- ]
113
- }
114
- })
115
- end
116
-
117
- context "with the same user_id" do
118
- it "should add the new info" do
119
- sessions_metric = SessionsMetric.new
120
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", "user_agent")
97
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
121
98
 
122
- sessions_metric.add_session_info("hmac_session_id_dos", "user_id", "127.0.0.1", "user_agent")
123
- expect(sessions_metric).to eq({
124
- "event_type"=>"metrics",
125
- "sessions"=>{
126
- "hmac_session_id" => [
99
+ sessions_metric.add_session_info('hmac_session_id_dos', 'user_id_dos', '127.0.0.1_dos', 'user_agent_dos')
100
+ expect(sessions_metric).to eq(
101
+ {
102
+ 'event_type' => 'metrics',
103
+ 'sessions' => {
104
+ 'hmac_session_id' => [
127
105
  {
128
- "uid"=>"user_id",
129
- "track"=>[
130
- ["user_agent", ["127.0.0.1"]]
106
+ 'uid' => 'user_id',
107
+ 'track' => [
108
+ ['user_agent', ['127.0.0.1']]
131
109
  ]
132
110
  }
133
111
  ],
134
- "hmac_session_id_dos" => [
112
+ 'hmac_session_id_dos' => [
135
113
  {
136
- "uid"=>"user_id",
137
- "track"=>[
138
- ["user_agent", ["127.0.0.1"]]
114
+ 'uid' => 'user_id_dos',
115
+ 'track' => [
116
+ ['user_agent_dos', ['127.0.0.1_dos']]
139
117
  ]
140
118
  }
141
119
  ]
142
120
  }
143
- })
121
+ }
122
+ )
123
+ end
124
+
125
+ context 'with the same user_id' do
126
+ it 'should add the new info' do
127
+ sessions_metric = SessionsMetric.new
128
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
129
+
130
+ sessions_metric.add_session_info('hmac_session_id_dos', 'user_id', '127.0.0.1', 'user_agent')
131
+ expect(sessions_metric).to eq(
132
+ {
133
+ 'event_type' => 'metrics',
134
+ 'sessions' => {
135
+ 'hmac_session_id' => [
136
+ {
137
+ 'uid' => 'user_id',
138
+ 'track' => [
139
+ ['user_agent', ['127.0.0.1']]
140
+ ]
141
+ }
142
+ ],
143
+ 'hmac_session_id_dos' => [
144
+ {
145
+ 'uid' => 'user_id',
146
+ 'track' => [
147
+ ['user_agent', ['127.0.0.1']]
148
+ ]
149
+ }
150
+ ]
151
+ }
152
+ }
153
+ )
144
154
  end
145
155
  end
146
156
  end
147
157
 
148
- context "adding new info for the existing session" do
149
- context "adding a new user_id" do
150
- it "should append the ip address to the existing info" do
158
+ context 'adding new info for the existing session' do
159
+ context 'adding a new user_id' do
160
+ it 'should append the ip address to the existing info' do
151
161
  sessions_metric = SessionsMetric.new
152
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", "user_agent")
153
- sessions_metric.add_session_info("hmac_session_id", "user_id_dos", "127.0.0.1", "user_agent")
162
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
163
+ sessions_metric.add_session_info('hmac_session_id', 'user_id_dos', '127.0.0.1', 'user_agent')
154
164
 
155
- expect(sessions_metric).to eq({
156
- "event_type"=>"metrics",
157
- "sessions"=>{
158
- "hmac_session_id" => [
159
- {
160
- "uid"=>"user_id",
161
- "track"=>[
162
- ["user_agent", ["127.0.0.1"]]
163
- ]
164
- },
165
- {
166
- "uid"=>"user_id_dos",
167
- "track"=>[
168
- ["user_agent", ["127.0.0.1"]]
169
- ]
170
- }
171
- ]
165
+ expect(sessions_metric).to eq(
166
+ {
167
+ 'event_type' => 'metrics',
168
+ 'sessions' => {
169
+ 'hmac_session_id' => [
170
+ {
171
+ 'uid' => 'user_id',
172
+ 'track' => [
173
+ ['user_agent', ['127.0.0.1']]
174
+ ]
175
+ },
176
+ {
177
+ 'uid' => 'user_id_dos',
178
+ 'track' => [
179
+ ['user_agent', ['127.0.0.1']]
180
+ ]
181
+ }
182
+ ]
183
+ }
172
184
  }
173
- })
185
+ )
174
186
  end
175
187
  end
176
188
 
177
- context "adding a new ip address" do
178
- it "should append the ip address to the existing info" do
189
+ context 'adding a new ip address' do
190
+ it 'should append the ip address to the existing info' do
179
191
  sessions_metric = SessionsMetric.new
180
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", "user_agent")
181
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1_dos", "user_agent")
192
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
193
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1_dos', 'user_agent')
182
194
 
183
- expect(sessions_metric).to eq({
184
- "event_type"=>"metrics",
185
- "sessions"=>{
186
- "hmac_session_id" => [
187
- {
188
- "uid"=>"user_id",
189
- "track"=>[
190
- ["user_agent", ["127.0.0.1", "127.0.0.1_dos"]]
191
- ]
192
- }
193
- ]
195
+ expect(sessions_metric).to eq(
196
+ {
197
+ 'event_type' => 'metrics',
198
+ 'sessions' => {
199
+ 'hmac_session_id' => [
200
+ {
201
+ 'uid' => 'user_id',
202
+ 'track' => [
203
+ ['user_agent', ['127.0.0.1', '127.0.0.1_dos']]
204
+ ]
205
+ }
206
+ ]
207
+ }
194
208
  }
195
- })
209
+ )
196
210
  end
197
211
  end
198
212
 
199
- context "adding a new user agent" do
200
- it "should add the new user agent" do
213
+ context 'adding a new user agent' do
214
+ it 'should add the new user agent' do
201
215
  sessions_metric = SessionsMetric.new
202
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", "user_agent")
203
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", "user_agent_dos")
216
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
217
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent_dos')
204
218
 
205
- expect(sessions_metric).to eq({
206
- "event_type"=>"metrics",
207
- "sessions"=>{
208
- "hmac_session_id" => [
209
- {
210
- "uid"=>"user_id",
211
- "track"=>[
212
- ["user_agent", ["127.0.0.1"]],
213
- ["user_agent_dos", ["127.0.0.1"]]
214
- ]
215
- }
216
- ]
219
+ expect(sessions_metric).to eq(
220
+ {
221
+ 'event_type' => 'metrics',
222
+ 'sessions' => {
223
+ 'hmac_session_id' => [
224
+ {
225
+ 'uid' => 'user_id',
226
+ 'track' => [
227
+ ['user_agent', ['127.0.0.1']],
228
+ ['user_agent_dos', ['127.0.0.1']]
229
+ ]
230
+ }
231
+ ]
232
+ }
217
233
  }
218
- })
234
+ )
219
235
  end
220
236
  end
221
237
  end
222
-
223
238
  end
224
239
 
225
- context "adding 200 sessions" do
226
- it "should update its state to flush" do
240
+ context 'adding 200 sessions' do
241
+ it 'should update its state to flush' do
227
242
  sessions_metric = SessionsMetric.new
228
243
  expect(sessions_metric.flush).to eq(false)
229
244
 
230
245
  200.times do |x|
231
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1_#{x}", "user_agent")
246
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', "127.0.0.1_#{x}", 'user_agent')
232
247
  end
233
248
 
234
249
  expect(sessions_metric.flush).to eq(true)
235
250
  end
236
251
  end
237
252
 
238
- context "adding 251 sessions" do
239
- it "should drop session after 250" do
240
- logger = double("logger")
253
+ context 'adding 251 sessions' do
254
+ it 'should drop session after 250' do
255
+ logger = double('logger')
241
256
  sessions_metric = SessionsMetric.new
242
257
 
243
258
  expect(sessions_metric.flush).to eq(false)
244
259
  expect(TCellAgent).to receive(:logger).and_return(logger)
245
- expect(logger).to receive(:warn).with("Sessions Metric is full. Information dropped")
260
+ expect(logger).to receive(:warn).with('Sessions Metric is full. Information dropped')
246
261
 
247
262
  250.times do |x|
248
- sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1_#{x}", "user_agent")
263
+ sessions_metric.add_session_info('hmac_session_id', 'user_id', "127.0.0.1_#{x}", 'user_agent')
249
264
  end
250
265
 
251
266
  expect(sessions_metric.flush).to eq(true)
252
267
  end
253
268
  end
254
269
  end
255
-
256
270
  end
257
271
  end
258
272
  end