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
@@ -1,14 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
-
5
4
  module Hooks
6
5
  module V1
7
6
  module Frameworks
8
7
  module Rails
9
8
  module Login
10
- def self.register_login_event(status, rails_request, user_id, user_valid=nil)
11
- end
9
+ def self.register_login_event(status, rails_request, user_id, user_valid = nil, password = nil); end
12
10
  end
13
11
  end
14
12
  end
@@ -18,55 +16,55 @@ module TCellAgent
18
16
  module Hooks
19
17
  module V1
20
18
  module Login
21
- LOGIN_SUCCESS = "success"
22
- LOGIN_FAILURE = "failure"
23
- def self.register_login_event(status, session_id, user_agent, referrer, remote_addr, header_keys, user_id, document_uri, user_valid=nil)
24
- end
19
+ LOGIN_SUCCESS = 'success'.freeze
20
+ LOGIN_FAILURE = 'failure'.freeze
21
+
22
+ def self.register_login_event(status, session_id, user_agent, referrer, remote_addr, header_keys, user_id, document_uri, user_valid = nil, password = nil); end
25
23
  end
26
24
  end
27
25
  end
28
26
 
29
- describe "manually requiring auth hooks" do
27
+ describe 'manually requiring auth hooks' do
30
28
  before(:all) do
31
29
  require 'tcell_agent/hooks/login_fraud'
32
30
  end
33
31
 
34
- describe "Using generic interface" do
35
- context "with a login failure" do
36
- context "with login_failed_enabled set to true" do
37
- it "should report the login failure" do
38
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
32
+ describe 'Using generic interface' do
33
+ context 'with a login failure' do
34
+ context 'with login_failed_enabled set to true' do
35
+ it 'should report the login failure' do
36
+ login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => true)
39
37
 
40
38
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
41
39
  login_fraud
42
40
  )
43
41
  expect(TCellAgent).to receive(:send_event).with(
44
42
  {
45
- "event_type" => "login",
46
- "header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
47
- "user_agent" => "user_agent",
48
- "referrer" => "referrer",
49
- "remote_addr" => "1.1.1.1",
50
- "user_id" => "user_id",
51
- "document_uri" => "http://tcell.tcell.io/login?param_name=",
52
- "session" => "48c0ce7961d8d5d4bd57bd77976b3d38",
53
- "event_name" => "login-failure"
43
+ 'event_type' => 'login',
44
+ 'header_keys' => %w[USER_AGENT X_FORWARDED_FOR],
45
+ 'user_agent' => 'user_agent',
46
+ 'referrer' => 'referrer',
47
+ 'remote_addr' => '1.1.1.1',
48
+ 'user_id' => 'user_id',
49
+ 'document_uri' => 'http://tcell.tcell.io/login?param_name=',
50
+ 'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
51
+ 'event_name' => 'login-failure'
54
52
  }
55
53
  )
56
54
 
57
55
  status = Hooks::V1::Login::LOGIN_FAILURE
58
- header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
59
- document_uri = "http://tcell.tcell.io/login?param_name=param_value"
56
+ header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
57
+ document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
60
58
 
61
59
  Hooks::V1::Login.register_login_event(
62
- status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
60
+ status, 'session_id', 'user_agent', 'referrer', '1.1.1.1', header_keys, 'user_id', document_uri
63
61
  )
64
62
  end
65
63
  end
66
64
 
67
- context "with login_failed_enabled set to false" do
68
- it "should NOT report the login failure" do
69
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: false)
65
+ context 'with login_failed_enabled set to false' do
66
+ it 'should NOT report the login failure' do
67
+ login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => false)
70
68
 
71
69
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
72
70
  login_fraud
@@ -74,51 +72,51 @@ module TCellAgent
74
72
  expect(TCellAgent).to_not receive(:send_event)
75
73
 
76
74
  status = Hooks::V1::Login::LOGIN_FAILURE
77
- header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
78
- document_uri = "http://tcell.tcell.io/login?param_name=param_value"
75
+ header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
76
+ document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
79
77
 
80
78
  Hooks::V1::Login.register_login_event(
81
- status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
79
+ status, 'session_id', 'user_agent', 'referrer', '1.1.1.1', header_keys, 'user_id', document_uri
82
80
  )
83
81
  end
84
82
  end
85
83
  end
86
84
 
87
- context "with a login success" do
88
- context "with login_success_enabled set to true" do
89
- it "should report the login success" do
90
- login_fraud = double("login_fraud", enabled: true, login_success_enabled: true)
85
+ context 'with a login success' do
86
+ context 'with login_success_enabled set to true' do
87
+ it 'should report the login success' do
88
+ login_fraud = double('login_fraud', :enabled => true, :login_success_enabled => true)
91
89
 
92
90
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
93
91
  login_fraud
94
92
  )
95
93
  expect(TCellAgent).to receive(:send_event).with(
96
94
  {
97
- "event_type" => "login",
98
- "header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
99
- "user_agent" => "user_agent",
100
- "referrer" => "referrer",
101
- "remote_addr" => "1.1.1.1",
102
- "user_id" => "user_id",
103
- "document_uri" => "http://tcell.tcell.io/login?param_name=",
104
- "session" => "48c0ce7961d8d5d4bd57bd77976b3d38",
105
- "event_name" => "login-success"
95
+ 'event_type' => 'login',
96
+ 'header_keys' => %w[USER_AGENT X_FORWARDED_FOR],
97
+ 'user_agent' => 'user_agent',
98
+ 'referrer' => 'referrer',
99
+ 'remote_addr' => '1.1.1.1',
100
+ 'user_id' => 'user_id',
101
+ 'document_uri' => 'http://tcell.tcell.io/login?param_name=',
102
+ 'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
103
+ 'event_name' => 'login-success'
106
104
  }
107
105
  )
108
106
 
109
107
  status = Hooks::V1::Login::LOGIN_SUCCESS
110
- header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
111
- document_uri = "http://tcell.tcell.io/login?param_name=param_value"
108
+ header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
109
+ document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
112
110
 
113
111
  Hooks::V1::Login.register_login_event(
114
- status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
112
+ status, 'session_id', 'user_agent', 'referrer', '1.1.1.1', header_keys, 'user_id', document_uri
115
113
  )
116
114
  end
117
115
  end
118
116
 
119
- context "with login_success_enabled set to false" do
120
- it "should NOT report the login success" do
121
- login_fraud = double("login_fraud", enabled: true, login_success_enabled: false)
117
+ context 'with login_success_enabled set to false' do
118
+ it 'should NOT report the login success' do
119
+ login_fraud = double('login_fraud', :enabled => true, :login_success_enabled => false)
122
120
 
123
121
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
124
122
  login_fraud
@@ -126,58 +124,57 @@ module TCellAgent
126
124
  expect(TCellAgent).to_not receive(:send_event)
127
125
 
128
126
  status = Hooks::V1::Login::LOGIN_SUCCESS
129
- header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
130
- document_uri = "http://tcell.tcell.io/login?param_name=param_value"
127
+ header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
128
+ document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
131
129
 
132
130
  Hooks::V1::Login.register_login_event(
133
- status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
131
+ status, 'session_id', 'user_agent', 'referrer', '1.1.1.1', header_keys, 'user_id', document_uri
134
132
  )
135
133
  end
136
134
  end
137
135
  end
138
136
 
139
- context "with an unknown status" do
140
- it "should log the error" do
141
- login_fraud = double("login_fraud", enabled: true)
142
- logger = double("logger")
137
+ context 'with an unknown status' do
138
+ it 'should log the error' do
139
+ login_fraud = double('login_fraud', :enabled => true)
140
+ logger = double('logger')
143
141
 
144
142
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
145
143
  login_fraud
146
144
  )
147
145
  expect(TCellAgent).to_not receive(:send_event)
148
146
  expect(TCellAgent).to receive(:logger).and_return(logger)
149
- expect(logger).to receive(:error).with("Unkown login status: mumbo-jumbo")
147
+ expect(logger).to receive(:error).with('Unkown login status: mumbo-jumbo')
150
148
 
151
- status = "mumbo-jumbo"
152
- header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
153
- document_uri = "http://tcell.tcell.io/login?param_name=param_value"
149
+ status = 'mumbo-jumbo'
150
+ header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
151
+ document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
154
152
 
155
153
  Hooks::V1::Login.register_login_event(
156
- status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
154
+ status, 'session_id', 'user_agent', 'referrer', '1.1.1.1', header_keys, 'user_id', document_uri
157
155
  )
158
156
  end
159
157
  end
160
158
  end
161
159
 
162
- describe "Using rails interface" do
163
- context "with a login failure" do
164
- context "with login_failed_enabled set to true" do
165
- it "should report the login failure" do
166
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
167
- rails_request = double("rails_request")
160
+ describe 'Using rails interface' do
161
+ context 'with a login failure' do
162
+ context 'with login_failed_enabled set to true' do
163
+ it 'should report the login failure' do
164
+ login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => true)
165
+ rails_request = double('rails_request')
168
166
  tcell_data = TCellAgent::Instrumentation::TCellData.new
169
- tcell_data.user_agent = "user_agent"
170
- tcell_data.referrer = "referrer"
171
- tcell_data.ip_address = "1.1.1.1"
172
- tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
173
- tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
167
+ tcell_data.user_agent = 'user_agent'
168
+ tcell_data.referrer = 'referrer'
169
+ tcell_data.ip_address = '1.1.1.1'
170
+ tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
171
+ tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
174
172
  request_env = {
175
173
  TCellAgent::Instrumentation::TCELL_ID => tcell_data,
176
- "HTTP_USER_AGENT" => true,
177
- "HTTP_X_FORWARDED_FOR" => true
174
+ 'HTTP_USER_AGENT' => true,
175
+ 'HTTP_X_FORWARDED_FOR' => true
178
176
  }
179
177
 
180
-
181
178
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
182
179
  login_fraud
183
180
  )
@@ -185,43 +182,42 @@ module TCellAgent
185
182
  expect(rails_request).to receive(:env).and_return(request_env)
186
183
  expect(TCellAgent).to receive(:send_event).with(
187
184
  {
188
- "event_type" => "login",
189
- "header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
190
- "user_agent" => "user_agent",
191
- "referrer" => "referrer",
192
- "remote_addr" => "1.1.1.1",
193
- "user_id" => "user_id",
194
- "document_uri" => "http://tcell.tcell.io/login?param_name=",
195
- "session" => "48c0ce7961d8d5d4bd57bd77976b3d38",
196
- "event_name" => "login-failure"
185
+ 'event_type' => 'login',
186
+ 'header_keys' => %w[USER_AGENT X_FORWARDED_FOR],
187
+ 'user_agent' => 'user_agent',
188
+ 'referrer' => 'referrer',
189
+ 'remote_addr' => '1.1.1.1',
190
+ 'user_id' => 'user_id',
191
+ 'document_uri' => 'http://tcell.tcell.io/login?param_name=',
192
+ 'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
193
+ 'event_name' => 'login-failure'
197
194
  }
198
195
  )
199
196
 
200
197
  status = Hooks::V1::Login::LOGIN_FAILURE
201
198
 
202
199
  Hooks::V1::Frameworks::Rails::Login.register_login_event(
203
- status, rails_request, "user_id"
200
+ status, rails_request, 'user_id'
204
201
  )
205
202
  end
206
203
  end
207
204
 
208
- context "with login_failed_enabled set to false" do
209
- it "should NOT report the login failure" do
210
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: false)
211
- rails_request = double("rails_request")
205
+ context 'with login_failed_enabled set to false' do
206
+ it 'should NOT report the login failure' do
207
+ login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => false)
208
+ rails_request = double('rails_request')
212
209
  tcell_data = TCellAgent::Instrumentation::TCellData.new
213
- tcell_data.user_agent = "user_agent"
214
- tcell_data.referrer = "referrer"
215
- tcell_data.ip_address = "1.1.1.1"
216
- tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
217
- tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
210
+ tcell_data.user_agent = 'user_agent'
211
+ tcell_data.referrer = 'referrer'
212
+ tcell_data.ip_address = '1.1.1.1'
213
+ tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
214
+ tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
218
215
  request_env = {
219
216
  TCellAgent::Instrumentation::TCELL_ID => tcell_data,
220
- "HTTP_USER_AGENT" => true,
221
- "HTTP_X_FORWARDED_FOR" => true
217
+ 'HTTP_USER_AGENT' => true,
218
+ 'HTTP_X_FORWARDED_FOR' => true
222
219
  }
223
220
 
224
-
225
221
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
226
222
  login_fraud
227
223
  )
@@ -232,30 +228,29 @@ module TCellAgent
232
228
  status = Hooks::V1::Login::LOGIN_FAILURE
233
229
 
234
230
  Hooks::V1::Frameworks::Rails::Login.register_login_event(
235
- status, rails_request, "user_id"
231
+ status, rails_request, 'user_id'
236
232
  )
237
233
  end
238
234
  end
239
235
  end
240
236
 
241
- context "with a login success" do
242
- context "with login_success_enabled set to true" do
243
- it "should report the login success" do
244
- login_fraud = double("login_fraud", enabled: true, login_success_enabled: true)
245
- rails_request = double("rails_request")
237
+ context 'with a login success' do
238
+ context 'with login_success_enabled set to true' do
239
+ it 'should report the login success' do
240
+ login_fraud = double('login_fraud', :enabled => true, :login_success_enabled => true)
241
+ rails_request = double('rails_request')
246
242
  tcell_data = TCellAgent::Instrumentation::TCellData.new
247
- tcell_data.user_agent = "user_agent"
248
- tcell_data.referrer = "referrer"
249
- tcell_data.ip_address = "1.1.1.1"
250
- tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
251
- tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
243
+ tcell_data.user_agent = 'user_agent'
244
+ tcell_data.referrer = 'referrer'
245
+ tcell_data.ip_address = '1.1.1.1'
246
+ tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
247
+ tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
252
248
  request_env = {
253
249
  TCellAgent::Instrumentation::TCELL_ID => tcell_data,
254
- "HTTP_USER_AGENT" => true,
255
- "HTTP_X_FORWARDED_FOR" => true
250
+ 'HTTP_USER_AGENT' => true,
251
+ 'HTTP_X_FORWARDED_FOR' => true
256
252
  }
257
253
 
258
-
259
254
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
260
255
  login_fraud
261
256
  )
@@ -263,43 +258,42 @@ module TCellAgent
263
258
  expect(rails_request).to receive(:env).and_return(request_env)
264
259
  expect(TCellAgent).to receive(:send_event).with(
265
260
  {
266
- "event_type" => "login",
267
- "header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
268
- "user_agent" => "user_agent",
269
- "referrer" => "referrer",
270
- "remote_addr" => "1.1.1.1",
271
- "user_id" => "user_id",
272
- "document_uri" => "http://tcell.tcell.io/login?param_name=",
273
- "session" => "48c0ce7961d8d5d4bd57bd77976b3d38",
274
- "event_name" => "login-success"
261
+ 'event_type' => 'login',
262
+ 'header_keys' => %w[USER_AGENT X_FORWARDED_FOR],
263
+ 'user_agent' => 'user_agent',
264
+ 'referrer' => 'referrer',
265
+ 'remote_addr' => '1.1.1.1',
266
+ 'user_id' => 'user_id',
267
+ 'document_uri' => 'http://tcell.tcell.io/login?param_name=',
268
+ 'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
269
+ 'event_name' => 'login-success'
275
270
  }
276
271
  )
277
272
 
278
273
  status = Hooks::V1::Login::LOGIN_SUCCESS
279
274
 
280
275
  Hooks::V1::Frameworks::Rails::Login.register_login_event(
281
- status, rails_request, "user_id"
276
+ status, rails_request, 'user_id'
282
277
  )
283
278
  end
284
279
  end
285
280
 
286
- context "with login_success_enabled set to false" do
287
- it "should NOT report the login success" do
288
- login_fraud = double("login_fraud", enabled: true, login_success_enabled: false)
289
- rails_request = double("rails_request")
281
+ context 'with login_success_enabled set to false' do
282
+ it 'should NOT report the login success' do
283
+ login_fraud = double('login_fraud', :enabled => true, :login_success_enabled => false)
284
+ rails_request = double('rails_request')
290
285
  tcell_data = TCellAgent::Instrumentation::TCellData.new
291
- tcell_data.user_agent = "user_agent"
292
- tcell_data.referrer = "referrer"
293
- tcell_data.ip_address = "1.1.1.1"
294
- tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
295
- tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
286
+ tcell_data.user_agent = 'user_agent'
287
+ tcell_data.referrer = 'referrer'
288
+ tcell_data.ip_address = '1.1.1.1'
289
+ tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
290
+ tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
296
291
  request_env = {
297
292
  TCellAgent::Instrumentation::TCELL_ID => tcell_data,
298
- "HTTP_USER_AGENT" => true,
299
- "HTTP_X_FORWARDED_FOR" => true
293
+ 'HTTP_USER_AGENT' => true,
294
+ 'HTTP_X_FORWARDED_FOR' => true
300
295
  }
301
296
 
302
-
303
297
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
304
298
  login_fraud
305
299
  )
@@ -310,30 +304,29 @@ module TCellAgent
310
304
  status = Hooks::V1::Login::LOGIN_SUCCESS
311
305
 
312
306
  Hooks::V1::Frameworks::Rails::Login.register_login_event(
313
- status, rails_request, "user_id"
307
+ status, rails_request, 'user_id'
314
308
  )
315
309
  end
316
310
  end
317
311
  end
318
312
 
319
- context "with an unknown status" do
320
- it "should log the error" do
321
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
322
- logger = double("logger")
323
- rails_request = double("rails_request")
313
+ context 'with an unknown status' do
314
+ it 'should log the error' do
315
+ login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => true)
316
+ logger = double('logger')
317
+ rails_request = double('rails_request')
324
318
  tcell_data = TCellAgent::Instrumentation::TCellData.new
325
- tcell_data.user_agent = "user_agent"
326
- tcell_data.referrer = "referrer"
327
- tcell_data.ip_address = "1.1.1.1"
328
- tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
329
- tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
319
+ tcell_data.user_agent = 'user_agent'
320
+ tcell_data.referrer = 'referrer'
321
+ tcell_data.ip_address = '1.1.1.1'
322
+ tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
323
+ tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
330
324
  request_env = {
331
325
  TCellAgent::Instrumentation::TCELL_ID => tcell_data,
332
- "HTTP_USER_AGENT" => true,
333
- "HTTP_X_FORWARDED_FOR" => true
326
+ 'HTTP_USER_AGENT' => true,
327
+ 'HTTP_X_FORWARDED_FOR' => true
334
328
  }
335
329
 
336
-
337
330
  expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
338
331
  login_fraud
339
332
  )
@@ -341,17 +334,15 @@ module TCellAgent
341
334
  expect(rails_request).to receive(:env).and_return(request_env)
342
335
  expect(TCellAgent).to_not receive(:send_event)
343
336
  expect(TCellAgent).to receive(:logger).and_return(logger)
344
- expect(logger).to receive(:error).with("Unkown login status: mumbo-jumbo")
337
+ expect(logger).to receive(:error).with('Unkown login status: mumbo-jumbo')
345
338
 
346
- status = "mumbo-jumbo"
339
+ status = 'mumbo-jumbo'
347
340
 
348
341
  Hooks::V1::Frameworks::Rails::Login.register_login_event(
349
- status, rails_request, "user_id"
342
+ status, rails_request, 'user_id'
350
343
  )
351
344
  end
352
345
  end
353
346
  end
354
-
355
347
  end
356
-
357
348
  end