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
@@ -4,52 +4,52 @@ module TCellAgent
4
4
  module SensorEvents
5
5
  module Util
6
6
  describe Util do
7
- context "SHA256 Hash test" do
8
- it "Create simple HMAC" do
9
- expect(Util).to receive(:get_hmac_key).and_return("testkey")
10
- expect(Util.hmac("testdata")).to eq("220afe7c01cca398fff2fc2c3687be94")
7
+ context 'SHA256 Hash test' do
8
+ it 'Create simple HMAC' do
9
+ expect(Util).to receive(:get_hmac_key).and_return('testkey')
10
+ expect(Util.hmac('testdata')).to eq('220afe7c01cca398fff2fc2c3687be94')
11
11
  end
12
- it "Check with config HMAC" do
12
+ it 'Check with config HMAC' do
13
13
  old_hmac = TCellAgent.configuration.hmac_key
14
- hmac_key = "HMAC KEY 123"
14
+ hmac_key = 'HMAC KEY 123'
15
15
  TCellAgent.configuration.hmac_key = hmac_key
16
16
  expect(Util.get_hmac_key).to eq(hmac_key)
17
17
  TCellAgent.configuration.hmac_key = old_hmac
18
18
  end
19
19
  end
20
- context "Parsing request cookies and replacing values" do
21
- it "Parsing regular uri without params" do
20
+ context 'Parsing request cookies and replacing values' do
21
+ it 'Parsing regular uri without params' do
22
22
  TCellAgent.configuration.app_id = nil
23
- original_uri = "http://foo.com/posts"
24
- expect_santized_uri = "http://foo.com/posts"
23
+ original_uri = 'http://foo.com/posts'
24
+ expect_santized_uri = 'http://foo.com/posts'
25
25
  expect(Util.sanitize_uri(original_uri)).to eq(expect_santized_uri)
26
26
  end
27
- it "Parsing regular uri with regular query string" do
27
+ it 'Parsing regular uri with regular query string' do
28
28
  TCellAgent.configuration.app_id = nil
29
- original_uri = "http://foo.com/posts?abcd"
30
- expect_santized_uri = "http://foo.com/posts?abcd="
29
+ original_uri = 'http://foo.com/posts?abcd'
30
+ expect_santized_uri = 'http://foo.com/posts?abcd='
31
31
  expect(Util.sanitize_uri(original_uri)).to eq(expect_santized_uri)
32
32
  end
33
- it "Parsing uri" do
33
+ it 'Parsing uri' do
34
34
  TCellAgent.configuration.app_id = nil
35
- original_uri = "http://foo.com/posts?id=30&limit=5#time=1305298413"
36
- expect_santized_uri = "http://foo.com/posts?id=61aa3630ced0e67b63a1c61e3b86f4d3&limit=89abb06a7bf0401b5911e61b68660c24#time=1305298413"
35
+ original_uri = 'http://foo.com/posts?id=30&limit=5#time=1305298413'
36
+ expect_santized_uri = 'http://foo.com/posts?id=61aa3630ced0e67b63a1c61e3b86f4d3&limit=89abb06a7bf0401b5911e61b68660c24#time=1305298413'
37
37
  expect(Util.sanitize_uri(original_uri)).to eq(expect_santized_uri)
38
38
  end
39
- it "returns an empty set" do
39
+ it 'returns an empty set' do
40
40
  TCellAgent.configuration.app_id = nil
41
- expect(Util.santize_request_cookie_string("ABC")).to eq("")
42
- expect(Util.santize_request_cookie_string("abcd=")).to match("")
41
+ expect(Util.santize_request_cookie_string('ABC')).to eq('')
42
+ expect(Util.santize_request_cookie_string('abcd=')).to match('')
43
43
  end
44
- it "parses a cookie" do
44
+ it 'parses a cookie' do
45
45
  TCellAgent.configuration.app_id = nil
46
- expect(Util.santize_request_cookie_string("x=y;z=a")).to eq("x=97cb9e2aa3ec93888b356dbcf13b280e;z=566c1a1c12ad909d628d4537e10773bf")
46
+ expect(Util.santize_request_cookie_string('x=y;z=a')).to eq('x=97cb9e2aa3ec93888b356dbcf13b280e;z=566c1a1c12ad909d628d4537e10773bf')
47
47
  end
48
48
  end
49
- context "Parsing a response set-cookie and replacing values" do
50
- it "sanitize a typical response set-cookie value" do
51
- santized_string = Util.santize_response_cookie_string("name=Nicholas; expires=Sat, 02 May 2009 23:38:25 GMT; httponly")
52
- expect(santized_string).to eq("name=beb56c04cdd764f6b7cbe6c078236aeb=; expires=Sat, 02 May 2009 23:38:25 GMT=; httponly=")
49
+ context 'Parsing a response set-cookie and replacing values' do
50
+ it 'sanitize a typical response set-cookie value' do
51
+ santized_string = Util.santize_response_cookie_string('name=Nicholas; expires=Sat, 02 May 2009 23:38:25 GMT; httponly')
52
+ expect(santized_string).to eq('name=beb56c04cdd764f6b7cbe6c078236aeb=; expires=Sat, 02 May 2009 23:38:25 GMT=; httponly=')
53
53
  end
54
54
  end
55
55
  end
@@ -1,49 +1,47 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe TCellAgent::BoundedQueue do
4
-
5
- describe "#full?" do
6
- it "should be true when the queue is full" do
4
+ describe '#full?' do
5
+ it 'should be true when the queue is full' do
7
6
  queue = TCellAgent::BoundedQueue.new(1)
8
- queue.push("one")
7
+ queue.push('one')
9
8
  expect(queue.full?).to eq(true)
10
9
  end
11
10
 
12
- it "should return false when the queue is not full" do
11
+ it 'should return false when the queue is not full' do
13
12
  queue = TCellAgent::BoundedQueue.new(1)
14
13
  expect(queue.full?).to eq(false)
15
14
  end
16
15
  end
17
16
 
18
- describe "#push" do
19
- context "pushing to a queue with space available" do
20
- it "should push the item" do
17
+ describe '#push' do
18
+ context 'pushing to a queue with space available' do
19
+ it 'should push the item' do
21
20
  queue = TCellAgent::BoundedQueue.new(1)
22
- queue.push("one")
21
+ queue.push('one')
23
22
 
24
23
  expect(queue.size).to eq(1)
25
24
  end
26
25
  end
27
26
 
28
- context "pushing to a full queue" do
29
- it "should not be possible to push anymore items" do
27
+ context 'pushing to a full queue' do
28
+ it 'should not be possible to push anymore items' do
30
29
  queue = TCellAgent::BoundedQueue.new(1)
31
- queue.push("one")
30
+ queue.push('one')
32
31
 
33
32
  expect(queue.size).to eq(1)
34
33
  expect(queue.full?).to eq(true)
35
34
 
36
- expect {
37
- queue.push("two", 0.1)
38
- }.to raise_error(RuntimeError)
35
+ expect do
36
+ queue.push('two', 0.1)
37
+ end.to raise_error(RuntimeError)
39
38
  end
40
39
  end
41
-
42
40
  end
43
41
 
44
- describe "#pop" do
45
- context "popping from an empty queue" do
46
- it "should return nil when there are no items" do
42
+ describe '#pop' do
43
+ context 'popping from an empty queue' do
44
+ it 'should return nil when there are no items' do
47
45
  queue = TCellAgent::BoundedQueue.new(1)
48
46
  expect(queue.size).to eq(0)
49
47
 
@@ -51,5 +49,4 @@ describe TCellAgent::BoundedQueue do
51
49
  end
52
50
  end
53
51
  end
54
-
55
52
  end
@@ -1,39 +1,39 @@
1
- # encoding: utf-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  module TCellAgent
6
4
  module Utils
7
-
8
5
  describe Params do
9
- context "flatten" do
10
- it "should" do
6
+ context 'flatten' do
7
+ it 'should' do
11
8
  expect(
12
- Params.flatten( {
13
- action: "index",
14
- utf8char: "Müller",
15
- waitlist_entries: {email: "emailone", preferences: {email: "emaildos"}},
16
- email_preferences: [:daily_digest, :reminders, "Müller"],
17
- users: [
18
- {email: "one@email.com"},
19
- {email: "dos@email.com"},
20
- ]
21
- },
22
- nil)
23
- ).to eq({
24
- ["action"]=>"index",
25
- ["utf8char"] => "Müller",
26
- ["waitlist_entries", "email"]=>"emailone",
27
- ["waitlist_entries", "preferences", "email"]=>"emaildos",
28
- [0, "email_preferences"]=>"daily_digest",
29
- [1, "email_preferences"]=>"reminders",
30
- [2, "email_preferences"]=>"Müller",
31
- [0, "users", "email"]=>"one@email.com",
32
- [1, "users", "email"]=>"dos@email.com"
33
- })
9
+ Params.flatten(
10
+ {
11
+ :action => 'index',
12
+ :utf8char => 'Müller',
13
+ :waitlist_entries => { :email => 'emailone', :preferences => { :email => 'emaildos' } },
14
+ :email_preferences => [:daily_digest, :reminders, 'Müller'],
15
+ :users => [
16
+ { :email => 'one@email.com' },
17
+ { :email => 'dos@email.com' }
18
+ ]
19
+ },
20
+ nil
21
+ )
22
+ ).to eq(
23
+ {
24
+ ['action'] => 'index',
25
+ ['utf8char'] => 'Müller',
26
+ %w[waitlist_entries email] => 'emailone',
27
+ %w[waitlist_entries preferences email] => 'emaildos',
28
+ [0, 'email_preferences'] => 'daily_digest',
29
+ [1, 'email_preferences'] => 'reminders',
30
+ [2, 'email_preferences'] => 'Müller',
31
+ [0, 'users', 'email'] => 'one@email.com',
32
+ [1, 'users', 'email'] => 'dos@email.com'
33
+ }
34
+ )
34
35
  end
35
36
  end
36
37
  end
37
-
38
38
  end
39
39
  end
@@ -0,0 +1,143 @@
1
+ require 'spec_helper'
2
+
3
+ module TCellAgent
4
+ module Utils
5
+ describe '.fingerprint_password' do
6
+ context 'with nil password' do
7
+ it 'should return nil' do
8
+ configuration = double('configuration',
9
+ :app_id => 'app_id',
10
+ :password_hmac_key => 'password_hmac_key')
11
+
12
+ expect(TCellAgent).to receive(:configuration).and_return(
13
+ configuration
14
+ )
15
+ expect(TCellAgent).to receive(:configuration).and_return(
16
+ configuration
17
+ )
18
+
19
+ expect(Passwords.fingerprint_password(nil, nil)).to be_nil
20
+ end
21
+ end
22
+
23
+ context "with '' password" do
24
+ it 'should return nil' do
25
+ configuration = double('configuration',
26
+ :app_id => 'app_id',
27
+ :password_hmac_key => 'password_hmac_key')
28
+
29
+ expect(TCellAgent).to receive(:configuration).and_return(
30
+ configuration
31
+ )
32
+ expect(TCellAgent).to receive(:configuration).and_return(
33
+ configuration
34
+ )
35
+
36
+ expect(Passwords.fingerprint_password('', nil)).to be_nil
37
+ end
38
+ end
39
+
40
+ context "with ' ' password" do
41
+ it 'should return nil' do
42
+ configuration = double('configuration',
43
+ :app_id => 'app_id',
44
+ :password_hmac_key => 'password_hmac_key')
45
+
46
+ expect(TCellAgent).to receive(:configuration).and_return(
47
+ configuration
48
+ )
49
+ expect(TCellAgent).to receive(:configuration).and_return(
50
+ configuration
51
+ )
52
+
53
+ expect(Passwords.fingerprint_password(' ', nil)).to be_nil
54
+ end
55
+ end
56
+
57
+ context 'with nil password_hmac_key' do
58
+ it 'should return nil' do
59
+ configuration = double('configuration',
60
+ :app_id => 'app_id',
61
+ :password_hmac_key => nil)
62
+
63
+ expect(TCellAgent).to receive(:configuration).and_return(
64
+ configuration
65
+ )
66
+ expect(TCellAgent).to receive(:configuration).and_return(
67
+ configuration
68
+ )
69
+
70
+ expect(Passwords.fingerprint_password('admin123', nil)).to be_nil
71
+ end
72
+ end
73
+
74
+ context "with '' password_hmac_key" do
75
+ it 'should return nil' do
76
+ configuration = double('configuration',
77
+ :app_id => 'app_id',
78
+ :password_hmac_key => '')
79
+
80
+ expect(TCellAgent).to receive(:configuration).and_return(
81
+ configuration
82
+ )
83
+ expect(TCellAgent).to receive(:configuration).and_return(
84
+ configuration
85
+ )
86
+
87
+ expect(Passwords.fingerprint_password('admin123', nil)).to be_nil
88
+ end
89
+ end
90
+
91
+ context "with ' ' password_hmac_key" do
92
+ it 'should return nil' do
93
+ configuration = double('configuration',
94
+ :app_id => 'app_id',
95
+ :password_hmac_key => ' ')
96
+
97
+ expect(TCellAgent).to receive(:configuration).and_return(
98
+ configuration
99
+ )
100
+ expect(TCellAgent).to receive(:configuration).and_return(
101
+ configuration
102
+ )
103
+
104
+ expect(Passwords.fingerprint_password('admin123', nil)).to be_nil
105
+ end
106
+ end
107
+
108
+ context 'with no user_id' do
109
+ it 'should return digest' do
110
+ configuration = double('configuration',
111
+ :app_id => 'TestAppId-AppId',
112
+ :password_hmac_key => 'password_hmac_key')
113
+
114
+ expect(TCellAgent).to receive(:configuration).and_return(
115
+ configuration
116
+ )
117
+ expect(TCellAgent).to receive(:configuration).and_return(
118
+ configuration
119
+ )
120
+
121
+ expect(Passwords.fingerprint_password('admin123', nil)).to eq('83ff14db')
122
+ end
123
+ end
124
+
125
+ context 'with user_id present' do
126
+ it 'should return digest' do
127
+ configuration = double('configuration',
128
+ :app_id => 'TestAppId-AppId',
129
+ :password_hmac_key => 'password_hmac_key')
130
+
131
+ expect(TCellAgent).to receive(:configuration).and_return(
132
+ configuration
133
+ )
134
+ expect(TCellAgent).to receive(:configuration).and_return(
135
+ configuration
136
+ )
137
+
138
+ expect(Passwords.fingerprint_password('admin123', 'user_id')).to eq('11a88b27')
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -2,77 +2,77 @@ require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
4
  module Utils
5
- describe ".blank?" do
6
- context "with nil" do
7
- it "should return true" do
5
+ describe '.blank?' do
6
+ context 'with nil' do
7
+ it 'should return true' do
8
8
  expect(Strings.blank?(nil)).to be(true)
9
9
  end
10
10
  end
11
11
 
12
- context "with empty string" do
13
- it "should return true" do
14
- expect(Strings.blank?("")).to be(true)
12
+ context 'with empty string' do
13
+ it 'should return true' do
14
+ expect(Strings.blank?('')).to be(true)
15
15
  end
16
16
  end
17
17
 
18
- context "with white space string" do
19
- it "should return true" do
18
+ context 'with white space string' do
19
+ it 'should return true' do
20
20
  expect(Strings.blank?("\t \r\n \s\s")).to be(true)
21
21
  end
22
22
  end
23
23
 
24
- context "with a string containing non whitespace chars" do
25
- it "should return false" do
26
- expect(Strings.blank?("A\t \r\n \s\s")).to be(false)
24
+ context 'with a string containing non whitespace chars' do
25
+ it 'should return false' do
26
+ expect(Strings.blank?('A\t \r\n \s\s')).to be(false)
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
- describe ".remove_trailing_slash" do
32
- context "with nil" do
33
- it "should return nil" do
31
+ describe '.remove_trailing_slash' do
32
+ context 'with nil' do
33
+ it 'should return nil' do
34
34
  expect(Strings.remove_trailing_slash(nil)).to eq(nil)
35
35
  end
36
36
  end
37
37
 
38
- context "with empty string" do
39
- it "should return empty string" do
40
- expect(Strings.remove_trailing_slash("")).to eq("")
38
+ context 'with empty string' do
39
+ it 'should return empty string' do
40
+ expect(Strings.remove_trailing_slash('')).to eq('')
41
41
  end
42
42
  end
43
43
 
44
- context "with / route" do
45
- it "should return /" do
46
- expect(Strings.remove_trailing_slash("/")).to eq("/")
44
+ context 'with / route' do
45
+ it 'should return /' do
46
+ expect(Strings.remove_trailing_slash('/')).to eq('/')
47
47
  end
48
48
  end
49
49
 
50
- context "with no trailing slash" do
51
- it "should return original string" do
52
- expect(Strings.remove_trailing_slash("/index")).to eq("/index")
50
+ context 'with no trailing slash' do
51
+ it 'should return original string' do
52
+ expect(Strings.remove_trailing_slash('/index')).to eq('/index')
53
53
  end
54
54
  end
55
55
 
56
- context "with a trailing slash" do
57
- it "should remove the trailing slash" do
58
- expect(Strings.remove_trailing_slash("/index")).to eq("/index")
56
+ context 'with a trailing slash' do
57
+ it 'should remove the trailing slash' do
58
+ expect(Strings.remove_trailing_slash('/index')).to eq('/index')
59
59
  end
60
60
  end
61
61
  end
62
62
 
63
- describe ".java_hashcode" do
64
- context "with some string" do
65
- it "should equal the older java hash" do
66
- java = 312563920
67
- us = Strings.java_hashcode("The quick brown fox jumped over the lazy dogs.")
63
+ describe '.java_hashcode' do
64
+ context 'with some string' do
65
+ it 'should equal the older java hash' do
66
+ java = 312_563_920
67
+ us = Strings.java_hashcode('The quick brown fox jumped over the lazy dogs.')
68
68
  expect(us).to eq(java)
69
69
 
70
- java = -1225848487
71
- us = Strings.java_hashcode("I have a negative hash")
70
+ java = -1_225_848_487
71
+ us = Strings.java_hashcode('I have a negative hash')
72
72
  expect(us).to eq(java)
73
73
 
74
- java = 628018387
75
- us = Strings.java_hashcode("你好世界")
74
+ java = 628_018_387
75
+ us = Strings.java_hashcode('你好世界')
76
76
  expect(us).to eq(java)
77
77
  end
78
78
  end
@@ -2,20 +2,20 @@ require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
4
  describe Agent do
5
- context "Agent Read File" do
5
+ context 'Agent Read File' do
6
6
  agent_worker = Agent.new(0)
7
- it "Reads in a policy file" do
7
+ it 'Reads in a policy file' do
8
8
  policy_file_json = {
9
- "csp-headers"=>{
10
- "policy_id"=>"00a1",
11
- "headers"=>[
12
- {"name"=>"csp", "value"=>"csp loaded header"}
9
+ 'csp-headers' => {
10
+ 'policy_id' => '00a1',
11
+ 'headers' => [
12
+ { 'name' => 'csp', 'value' => 'csp loaded header' }
13
13
  ]
14
14
  }
15
15
  }
16
16
  agent_worker.processPolicyJson(policy_file_json)
17
- expect(agent_worker.policies[TCellAgent::PolicyTypes::CSP].headers[0].type).to eq("csp")
18
- expect(agent_worker.policies[TCellAgent::PolicyTypes::CSP].headers[0].value).to eq("csp loaded header")
17
+ expect(agent_worker.policies[TCellAgent::PolicyTypes::CSP].headers[0].type).to eq('csp')
18
+ expect(agent_worker.policies[TCellAgent::PolicyTypes::CSP].headers[0].value).to eq('csp loaded header')
19
19
  end
20
20
  end
21
21
  end
data/spec/spec_helper.rb CHANGED
@@ -3,14 +3,14 @@ require 'rails'
3
3
  require 'webmock/rspec'
4
4
  require 'fork_break'
5
5
 
6
- ENV['TCELL_AGENT_SERVER'] = "mock"
6
+ ENV['TCELL_AGENT_SERVER'] = 'mock'
7
7
  require File.join(File.dirname(__FILE__), '..', 'lib', 'tcell_agent')
8
- require File.join(File.dirname(__FILE__), '..', 'lib', 'tcell_agent','rails') if defined?(Rails)
8
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'tcell_agent', 'rails') if defined?(Rails)
9
9
 
10
- Dir[File.join(File.dirname(__FILE__), "support", "**", "*.rb")].each { |f| require f }
10
+ Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each { |f| require f }
11
11
 
12
12
  def get_test_resource_path(name)
13
- File.join(File.dirname(__FILE__), "support", "resources", name)
13
+ File.join(File.dirname(__FILE__), 'support', 'resources', name)
14
14
  end
15
15
 
16
16
  require 'tcell_agent/agent'
@@ -2,16 +2,16 @@ require 'spec_helper'
2
2
  require 'rack/test'
3
3
  require 'rack'
4
4
 
5
- def withTCellMiddleware(app, inner_middleware=nil)
6
- TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware.new(
7
- TCellAgent::Instrumentation::Rails::Middleware::HeadersMiddleware.new(
8
- ActionDispatch::ParamsParser.new(
9
- TCellAgent::Instrumentation::Rails::Middleware::BodyFilterMiddleware.new(
10
- TCellAgent::Instrumentation::Rails::Middleware::GlobalMiddleware.new(
11
- app
12
- )
13
- )
14
- )
5
+ def with_tcell_middleware(app, _inner_middleware = nil)
6
+ TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware.new(
7
+ TCellAgent::Instrumentation::Rails::Middleware::HeadersMiddleware.new(
8
+ ActionDispatch::ParamsParser.new(
9
+ TCellAgent::Instrumentation::Rails::Middleware::BodyFilterMiddleware.new(
10
+ TCellAgent::Instrumentation::Rails::Middleware::GlobalMiddleware.new(
11
+ app
12
+ )
15
13
  )
14
+ )
16
15
  )
16
+ )
17
17
  end
@@ -1,36 +1,40 @@
1
1
  module TCellAgent
2
2
  @@spec_event_queue = []
3
+
3
4
  def self.empty_event_queue
4
5
  @@spec_event_queue = []
5
6
  end
7
+
6
8
  def self.event_queue
7
- return @@spec_event_queue
9
+ @@spec_event_queue
8
10
  end
11
+
9
12
  def self.send_event(event)
10
13
  event.post_process
11
14
  @@spec_event_queue.push(event)
12
15
  end
16
+
13
17
  def self.set_thread_agent(thread_agent)
14
18
  self.thread_agent = thread_agent
15
19
  end
20
+
16
21
  def self.queue_metric(event)
17
- #puts "Queue metric"
18
- self.thread_agent._queue_metric(event)
22
+ thread_agent._queue_metric(event)
19
23
  end
24
+
20
25
  def self.increment_session_info(hmac_session_id, user_id, ip_address, user_agent)
21
- #puts "Inc Session Info"
22
- self.thread_agent.increment_session_info(hmac_session_id, user_id, ip_address, user_agent)
26
+ thread_agent.increment_session_info(hmac_session_id, user_id, ip_address, user_agent)
23
27
  end
28
+
24
29
  def self.increment_route(route_id, response_time)
25
- self.thread_agent.increment_route(route_id, response_time)
26
- end
27
- def self.ensure_event_processor_running
28
- #puts "Ensure running"
29
- #self.thread_agent.ensure_event_processor_running
30
+ thread_agent.increment_route(route_id, response_time)
30
31
  end
32
+
33
+ def self.ensure_event_processor_running; end
34
+
31
35
  class TCellApi
32
- def send_event_set(events)
33
- puts "Send Events"
36
+ def send_event_set(_events)
37
+ puts 'Send Events'
34
38
  end
35
39
  end
36
40
  end