tcell_agent 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -22
  3. data/bin/tcell_agent +127 -132
  4. data/lib/tcell_agent/agent/event_processor.rb +23 -22
  5. data/lib/tcell_agent/agent/fork_pipe_manager.rb +7 -7
  6. data/lib/tcell_agent/agent/policy_manager.rb +20 -15
  7. data/lib/tcell_agent/agent/policy_types.rb +5 -11
  8. data/lib/tcell_agent/agent/static_agent.rb +5 -1
  9. data/lib/tcell_agent/agent.rb +6 -4
  10. data/lib/tcell_agent/api.rb +7 -9
  11. data/lib/tcell_agent/appsensor/meta_data.rb +11 -4
  12. data/lib/tcell_agent/authlogic.rb +3 -3
  13. data/lib/tcell_agent/cmdi.rb +6 -4
  14. data/lib/tcell_agent/config/unknown_options.rb +3 -1
  15. data/lib/tcell_agent/configuration.rb +47 -49
  16. data/lib/tcell_agent/devise.rb +2 -2
  17. data/lib/tcell_agent/hooks/login_fraud.rb +58 -29
  18. data/lib/tcell_agent/instrumentation.rb +11 -10
  19. data/lib/tcell_agent/logger.rb +2 -2
  20. data/lib/tcell_agent/patches/meta_data.rb +9 -13
  21. data/lib/tcell_agent/patches.rb +7 -10
  22. data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -5
  23. data/lib/tcell_agent/policies/content_security_policy.rb +6 -12
  24. data/lib/tcell_agent/policies/dataloss_policy.rb +2 -2
  25. data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
  26. data/lib/tcell_agent/policies/policy.rb +0 -2
  27. data/lib/tcell_agent/policies/rust_policies.rb +90 -0
  28. data/lib/tcell_agent/policies/secure_headers_policy.rb +2 -2
  29. data/lib/tcell_agent/rails/auth/authlogic.rb +42 -24
  30. data/lib/tcell_agent/rails/auth/devise.rb +44 -23
  31. data/lib/tcell_agent/rails/auth/doorkeeper.rb +33 -15
  32. data/lib/tcell_agent/rails/better_ip.rb +1 -1
  33. data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
  34. data/lib/tcell_agent/rails/dlp/process_request.rb +1 -1
  35. data/lib/tcell_agent/rails/dlp.rb +6 -6
  36. data/lib/tcell_agent/rails/dlp_handler.rb +1 -1
  37. data/lib/tcell_agent/rails/js_agent_insert.rb +1 -1
  38. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +1 -1
  39. data/lib/tcell_agent/rails/middleware/context_middleware.rb +3 -2
  40. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +10 -9
  41. data/lib/tcell_agent/rails/routes/grape.rb +6 -6
  42. data/lib/tcell_agent/rails/routes.rb +8 -11
  43. data/lib/tcell_agent/rust/libtcellagent-0.11.1.dylib +0 -0
  44. data/lib/tcell_agent/rust/{libtcellagent-0.6.1.so → libtcellagent-0.11.1.so} +0 -0
  45. data/lib/tcell_agent/rust/models.rb +16 -0
  46. data/lib/tcell_agent/rust/tcellagent-0.11.1.dll +0 -0
  47. data/lib/tcell_agent/rust/whisperer.rb +119 -48
  48. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +17 -20
  49. data/lib/tcell_agent/sensor_events/command_injection.rb +50 -5
  50. data/lib/tcell_agent/sensor_events/login_fraud.rb +34 -18
  51. data/lib/tcell_agent/sensor_events/patches.rb +21 -0
  52. data/lib/tcell_agent/sensor_events/server_agent.rb +3 -3
  53. data/lib/tcell_agent/sensor_events/util/utils.rb +4 -3
  54. data/lib/tcell_agent/servers/puma.rb +2 -2
  55. data/lib/tcell_agent/servers/unicorn.rb +1 -1
  56. data/lib/tcell_agent/utils/passwords.rb +28 -0
  57. data/lib/tcell_agent/version.rb +1 -1
  58. data/lib/tcell_agent.rb +1 -5
  59. data/spec/apps/rails-3.2/config/tcell_agent.config +15 -0
  60. data/spec/apps/rails-3.2/log/development.log +0 -0
  61. data/spec/apps/rails-3.2/log/test.log +12 -0
  62. data/spec/apps/rails-4.1/log/test.log +0 -0
  63. data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +46 -45
  64. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +276 -164
  65. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +44 -47
  66. data/spec/lib/tcell_agent/api/api_spec.rb +16 -16
  67. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +131 -116
  68. data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +55 -51
  69. data/spec/lib/tcell_agent/cmdi_spec.rb +413 -436
  70. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +145 -128
  71. data/spec/lib/tcell_agent/configuration_spec.rb +165 -169
  72. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +144 -153
  73. data/spec/lib/tcell_agent/instrumentation_spec.rb +84 -85
  74. data/spec/lib/tcell_agent/patches_spec.rb +70 -111
  75. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +313 -244
  76. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +28 -28
  77. data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +643 -513
  78. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +55 -102
  79. data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +111 -134
  80. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +141 -146
  81. data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +8 -8
  82. data/spec/lib/tcell_agent/policies/login_policy_spec.rb +15 -17
  83. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +231 -559
  84. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +27 -27
  85. data/spec/lib/tcell_agent/rails/better_ip_spec.rb +30 -34
  86. data/spec/lib/tcell_agent/rails/logger_spec.rb +50 -49
  87. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +182 -199
  88. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +110 -84
  89. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +107 -85
  90. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +68 -40
  91. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +81 -67
  92. data/spec/lib/tcell_agent/rails/responses_spec.rb +33 -37
  93. data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +116 -121
  94. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +25 -28
  95. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +87 -85
  96. data/spec/lib/tcell_agent/rails_spec.rb +1 -6
  97. data/spec/lib/tcell_agent/rust/models_spec.rb +112 -0
  98. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +502 -179
  99. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +44 -33
  100. data/spec/lib/tcell_agent/sensor_events/dlp_spec.rb +4 -4
  101. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +183 -169
  102. data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +25 -25
  103. data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +17 -20
  104. data/spec/lib/tcell_agent/utils/params_spec.rb +28 -28
  105. data/spec/lib/tcell_agent/utils/passwords_spec.rb +143 -0
  106. data/spec/lib/tcell_agent/utils/strings_spec.rb +35 -35
  107. data/spec/lib/tcell_agent_spec.rb +8 -8
  108. data/spec/spec_helper.rb +4 -4
  109. data/spec/support/middleware_helper.rb +10 -10
  110. data/spec/support/static_agent_overrides.rb +16 -12
  111. data/tcell_agent.gemspec +17 -33
  112. metadata +43 -198
  113. data/LICENSE_libinjection +0 -32
  114. data/Readme.txt +0 -7
  115. data/ext/libinjection/extconf.rb +0 -3
  116. data/ext/libinjection/libinjection.h +0 -65
  117. data/ext/libinjection/libinjection_html5.c +0 -847
  118. data/ext/libinjection/libinjection_html5.h +0 -54
  119. data/ext/libinjection/libinjection_sqli.c +0 -2317
  120. data/ext/libinjection/libinjection_sqli.h +0 -295
  121. data/ext/libinjection/libinjection_sqli_data.h +0 -9004
  122. data/ext/libinjection/libinjection_wrap.c +0 -3525
  123. data/ext/libinjection/libinjection_xss.c +0 -531
  124. data/ext/libinjection/libinjection_xss.h +0 -21
  125. data/lib/tcell_agent/appsensor/injections_matcher.rb +0 -155
  126. data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +0 -49
  127. data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +0 -67
  128. data/lib/tcell_agent/appsensor/rules/baserules.json +0 -467
  129. data/lib/tcell_agent/patches/block_rule.rb +0 -93
  130. data/lib/tcell_agent/patches/sensors_matcher.rb +0 -31
  131. data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +0 -23
  132. data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +0 -23
  133. data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +0 -117
  134. data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +0 -26
  135. data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +0 -22
  136. data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +0 -34
  137. data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +0 -34
  138. data/lib/tcell_agent/policies/appsensor_policy.rb +0 -49
  139. data/lib/tcell_agent/policies/command_injection_policy.rb +0 -196
  140. data/lib/tcell_agent/policies/honeytokens_policy.rb +0 -69
  141. data/lib/tcell_agent/policies/patches_policy.rb +0 -84
  142. data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
  143. data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
  144. data/spec/apps/rails-3.2/Gemfile +0 -25
  145. data/spec/apps/rails-3.2/Gemfile.lock +0 -126
  146. data/spec/apps/rails-3.2/Rakefile +0 -7
  147. data/spec/apps/rails-3.2/app/assets/images/rails.png +0 -0
  148. data/spec/apps/rails-3.2/app/assets/javascripts/application.js +0 -15
  149. data/spec/apps/rails-3.2/app/assets/stylesheets/application.css +0 -13
  150. data/spec/apps/rails-3.2/app/controllers/application_controller.rb +0 -3
  151. data/spec/apps/rails-3.2/app/controllers/t_cell_app_controller.rb +0 -5
  152. data/spec/apps/rails-3.2/app/helpers/application_helper.rb +0 -2
  153. data/spec/apps/rails-3.2/app/views/layouts/application.html.erb +0 -14
  154. data/spec/apps/rails-3.2/app/views/t_cell_app/index.html.erb +0 -1
  155. data/spec/apps/rails-3.2/config/application.rb +0 -63
  156. data/spec/apps/rails-3.2/config/boot.rb +0 -6
  157. data/spec/apps/rails-3.2/config/environment.rb +0 -5
  158. data/spec/apps/rails-3.2/config/environments/test.rb +0 -37
  159. data/spec/apps/rails-3.2/config/routes.rb +0 -11
  160. data/spec/apps/rails-3.2/config.ru +0 -4
  161. data/spec/apps/rails-4.1/Gemfile +0 -7
  162. data/spec/apps/rails-4.1/Gemfile.lock +0 -114
  163. data/spec/apps/rails-4.1/Rakefile +0 -6
  164. data/spec/apps/rails-4.1/app/assets/javascripts/application.js +0 -16
  165. data/spec/apps/rails-4.1/app/assets/stylesheets/application.css +0 -15
  166. data/spec/apps/rails-4.1/app/controllers/application_controller.rb +0 -5
  167. data/spec/apps/rails-4.1/app/controllers/t_cell_app_controller.rb +0 -5
  168. data/spec/apps/rails-4.1/app/helpers/application_helper.rb +0 -2
  169. data/spec/apps/rails-4.1/app/views/layouts/application.html.erb +0 -14
  170. data/spec/apps/rails-4.1/app/views/t_cell_app/index.html.erb +0 -1
  171. data/spec/apps/rails-4.1/config/application.rb +0 -24
  172. data/spec/apps/rails-4.1/config/boot.rb +0 -4
  173. data/spec/apps/rails-4.1/config/environment.rb +0 -5
  174. data/spec/apps/rails-4.1/config/environments/test.rb +0 -41
  175. data/spec/apps/rails-4.1/config/initializers/assets.rb +0 -8
  176. data/spec/apps/rails-4.1/config/initializers/backtrace_silencers.rb +0 -7
  177. data/spec/apps/rails-4.1/config/initializers/cookies_serializer.rb +0 -3
  178. data/spec/apps/rails-4.1/config/initializers/filter_parameter_logging.rb +0 -4
  179. data/spec/apps/rails-4.1/config/initializers/inflections.rb +0 -16
  180. data/spec/apps/rails-4.1/config/initializers/mime_types.rb +0 -4
  181. data/spec/apps/rails-4.1/config/initializers/session_store.rb +0 -3
  182. data/spec/apps/rails-4.1/config/initializers/wrap_parameters.rb +0 -14
  183. data/spec/apps/rails-4.1/config/locales/en.yml +0 -23
  184. data/spec/apps/rails-4.1/config/routes.rb +0 -12
  185. data/spec/apps/rails-4.1/config/secrets.yml +0 -22
  186. data/spec/apps/rails-4.1/config.ru +0 -4
  187. data/spec/controllers/application_controller.rb +0 -12
  188. data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +0 -522
  189. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -23
  190. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +0 -159
  191. data/spec/lib/tcell_agent/patches/block_rule_spec.rb +0 -458
  192. data/spec/lib/tcell_agent/patches/sensors_matcher_spec.rb +0 -35
  193. data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +0 -139
  194. data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +0 -139
  195. data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +0 -167
  196. data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +0 -139
  197. data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +0 -246
  198. data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +0 -882
  199. data/spec/lib/tcell_agent/policies/honeytokens_policy_spec.rb +0 -22
@@ -2,62 +2,61 @@ require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
4
  module SensorEvents
5
-
6
5
  describe Agent do
7
-
8
- describe ".increment_session_info" do
9
- context "when running the parent process" do
10
- it "should increment the session info" do
6
+ describe '.increment_session_info' do
7
+ context 'when running the parent process' do
8
+ it 'should increment the session info' do
11
9
  expect(TCellAgent::Agent).to receive(:is_parent_process?).and_return(true)
12
10
  expect(TCellAgent).to_not receive(:queue_metric)
13
11
  expect_any_instance_of(SessionsMetric).to receive(:add_session_info).with(
14
- "hmac_session_id", "user_id", "ip_address", "user_agent"
12
+ 'hmac_session_id', 'user_id', 'ip_address', 'user_agent'
15
13
  )
16
14
  expect_any_instance_of(SessionsMetric).to receive(:flush).and_return(false)
17
15
  expect(TCellAgent).to_not receive(:send_event)
18
16
 
19
- TCellAgent.increment_session_info("hmac_session_id", "user_id", "ip_address", "user_agent")
17
+ TCellAgent.increment_session_info('hmac_session_id', 'user_id', 'ip_address', 'user_agent')
20
18
  end
21
19
 
22
- context "and the session becomes full" do
23
- it "should increment the session info and send the flush dummy event" do
20
+ context 'and the session becomes full' do
21
+ it 'should increment the session info and send the flush dummy event' do
24
22
  expect(TCellAgent::Agent).to receive(:is_parent_process?).and_return(true)
25
23
  expect(TCellAgent).to_not receive(:queue_metric)
26
24
  expect_any_instance_of(SessionsMetric).to receive(:add_session_info).with(
27
- "hmac_session_id", "user_id", "ip_address", "user_agent"
25
+ 'hmac_session_id', 'user_id', 'ip_address', 'user_agent'
28
26
  )
29
27
  expect_any_instance_of(SessionsMetric).to receive(:flush).and_return(true)
30
28
  expect(TCellAgent).to receive(:send_event).with(
31
29
  instance_of(TCellAgent::SensorEvents::FlushDummyEvent)
32
30
  )
33
31
 
34
- TCellAgent.increment_session_info("hmac_session_id", "user_id", "ip_address", "user_agent")
32
+ TCellAgent.increment_session_info('hmac_session_id', 'user_id', 'ip_address', 'user_agent')
35
33
  end
36
34
  end
37
35
  end
38
36
 
39
- context "when NOT running the parent process" do
40
- it "should queue the metric" do
37
+ context 'when NOT running the parent process' do
38
+ it 'should queue the metric' do
41
39
  expect(TCellAgent::Agent).to receive(:is_parent_process?).and_return(false)
42
- expect(TCellAgent).to receive(:queue_metric).with({
43
- "_type"=>"increment_session_info",
44
- "hmac_session_id"=>"hmac_session_id",
45
- "user_id"=>"user_id",
46
- "ip_address"=>"ip_address",
47
- "user_agent"=>"user_agent"
48
- })
40
+ expect(TCellAgent).to receive(:queue_metric).with(
41
+ {
42
+ '_type' => 'increment_session_info',
43
+ 'hmac_session_id' => 'hmac_session_id',
44
+ 'user_id' => 'user_id',
45
+ 'ip_address' => 'ip_address',
46
+ 'user_agent' => 'user_agent'
47
+ }
48
+ )
49
49
  expect_any_instance_of(SessionsMetric).to_not receive(:add_session_info)
50
50
  expect_any_instance_of(SessionsMetric).to_not receive(:flush)
51
51
  expect(TCellAgent).to_not receive(:send_event)
52
52
 
53
- TCellAgent.increment_session_info("hmac_session_id", "user_id", "ip_address", "user_agent")
53
+ TCellAgent.increment_session_info('hmac_session_id', 'user_id', 'ip_address', 'user_agent')
54
54
  end
55
55
  end
56
56
  end
57
57
 
58
- describe ".increment_route" do
59
- context "when running the parent process" do
60
-
58
+ describe '.increment_route' do
59
+ context 'when running the parent process' do
61
60
  before(:each) do
62
61
  TCellAgent.thread_agent.response_time_table = {}
63
62
  end
@@ -65,48 +64,47 @@ module TCellAgent
65
64
  TCellAgent.thread_agent.response_time_table = {}
66
65
  end
67
66
 
68
- context "with a route present" do
69
- it "should increment the route info" do
67
+ context 'with a route present' do
68
+ it 'should increment the route info' do
70
69
  expect(TCellAgent::Agent).to receive(:is_parent_process?).and_return(true)
71
70
  expect(TCellAgent).to_not receive(:queue_metric)
72
71
 
73
- TCellAgent.increment_route("/ma_route", 20)
72
+ TCellAgent.increment_route('/ma_route', 20)
74
73
 
75
74
  expect(TCellAgent.thread_agent.response_time_table).to eq(
76
- {"/ma_route"=>{"c"=>1, "mx"=>20, "mn"=>20, "t"=>20}}
75
+ { '/ma_route' => { 'c' => 1, 'mx' => 20, 'mn' => 20, 't' => 20 } }
77
76
  )
78
77
  end
79
78
  end
80
79
 
81
- context "with an empty route" do
82
- it "should increment the route info" do
80
+ context 'with an empty route' do
81
+ it 'should increment the route info' do
83
82
  expect(TCellAgent::Agent).to receive(:is_parent_process?).and_return(true)
84
83
  expect(TCellAgent).to_not receive(:queue_metric)
85
84
 
86
- TCellAgent.increment_route("", 20)
85
+ TCellAgent.increment_route('', 20)
87
86
 
88
87
  expect(TCellAgent.thread_agent.response_time_table).to eq(
89
- {"?"=>{"c"=>1, "mx"=>20, "mn"=>20, "t"=>20}}
88
+ { '?' => { 'c' => 1, 'mx' => 20, 'mn' => 20, 't' => 20 } }
90
89
  )
91
90
  end
92
91
  end
93
92
 
94
- context "with a nil route" do
95
- it "should increment the route info" do
93
+ context 'with a nil route' do
94
+ it 'should increment the route info' do
96
95
  expect(TCellAgent::Agent).to receive(:is_parent_process?).and_return(true)
97
96
  expect(TCellAgent).to_not receive(:queue_metric)
98
97
 
99
98
  TCellAgent.increment_route(nil, 20)
100
99
 
101
100
  expect(TCellAgent.thread_agent.response_time_table).to eq(
102
- {"?"=>{"c"=>1, "mx"=>20, "mn"=>20, "t"=>20}}
101
+ { '?' => { 'c' => 1, 'mx' => 20, 'mn' => 20, 't' => 20 } }
103
102
  )
104
103
  end
105
104
  end
106
-
107
105
  end
108
106
 
109
- context "when NOT running the parent process" do
107
+ context 'when NOT running the parent process' do
110
108
  before(:each) do
111
109
  TCellAgent.thread_agent.response_time_table = {}
112
110
  end
@@ -114,23 +112,22 @@ module TCellAgent
114
112
  TCellAgent.thread_agent.response_time_table = {}
115
113
  end
116
114
 
117
- it "should queue the metric" do
115
+ it 'should queue the metric' do
118
116
  expect(TCellAgent::Agent).to receive(:is_parent_process?).and_return(false)
119
- expect(TCellAgent).to receive(:queue_metric).with({
120
- "_type"=>"increment_route",
121
- "route_id"=>"/ma_route",
122
- "response_time"=>20
123
- })
117
+ expect(TCellAgent).to receive(:queue_metric).with(
118
+ {
119
+ '_type' => 'increment_route',
120
+ 'route_id' => '/ma_route',
121
+ 'response_time' => 20
122
+ }
123
+ )
124
124
 
125
- TCellAgent.increment_route("/ma_route", 20)
125
+ TCellAgent.increment_route('/ma_route', 20)
126
126
 
127
127
  expect(TCellAgent.thread_agent.response_time_table).to eq({})
128
128
  end
129
129
  end
130
130
  end
131
-
132
131
  end
133
-
134
132
  end
135
133
  end
136
-
@@ -1,35 +1,35 @@
1
1
  require 'spec_helper'
2
2
  require 'addressable/template'
3
3
 
4
-
5
4
  module TCellAgent
6
5
  class TCellApi
7
- describe "successful POST on /user/create" do
8
- it "should redirect to dashboard" do
6
+ describe 'successful POST on /user/create' do
7
+ it 'should redirect to dashboard' do
9
8
  tapi = TCellApi.new
10
- TCellAgent.configuration.app_id = "test-appid"
11
- TCellAgent.configuration.api_key = "test-apikey"
9
+ TCellAgent.configuration.app_id = 'test-appid'
10
+ TCellAgent.configuration.api_key = 'test-apikey'
12
11
 
13
- def checkreq(req)
14
- return '{"result":{"csp-headers":{"app_id":"testapp-Becwu","policy_id":' \
12
+ def checkreq(_req)
13
+ '{"result":{"csp-headers":{"app_id":"testapp-Becwu","policy_id":' \
15
14
  '"acf60560-4e76-11e5-874c-7d71d425b275","headers":[{"name":"Content-Security-Policy-Report-Only",' \
16
15
  '"value":"font-src \'none\'; script-src \'self\'; reflected-xss block; ' \
17
16
  'style-src \'self\'; connect-src' \
18
17
  ' \'none\'" ,"report-uri":"http://localhost:3000/csp/cab5e750e66d614bd46fd07a7078db1e74b4f427b2a135b2c96eca684a642707"}]}}}'
19
18
  end
20
19
  uri_template =
21
- Addressable::Template.new "https://api.tcell.io/api/v1/app/{app}/update"
22
- stub_request(:any, uri_template).
23
- to_return(lambda { |request| {
24
- :body => checkreq(request), :status => 200,
25
- :headers => { 'Content-Tyoe' => 'application/json' }
26
- } })
20
+ Addressable::Template.new 'https://api.tcell.io/api/v1/app/{app}/update'
21
+ stub_request(:any, uri_template)
22
+ .to_return(lambda { |request|
23
+ {
24
+ :body => checkreq(request), :status => 200,
25
+ :headers => { 'Content-Tyoe' => 'application/json' }
26
+ }
27
+ })
27
28
 
28
- # to_return(:body => resbody,
29
- result = tapi.poll_api()
29
+ result = tapi.poll_api
30
30
  TCellAgent.configuration.app_id = nil
31
31
  TCellAgent.configuration.api_key = nil
32
- expect(result["csp-headers"]["app_id"]).to eq("testapp-Becwu")
32
+ expect(result['csp-headers']['app_id']).to eq('testapp-Becwu')
33
33
  end
34
34
  end
35
35
  end
@@ -2,11 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
4
  module AppSensor
5
-
6
5
  describe InjectionsReporter do
7
- describe ".report_and_log" do
8
- context "with nil events" do
9
- it "should do nothing" do
6
+ describe '.report_and_log' do
7
+ context 'with nil events' do
8
+ it 'should do nothing' do
10
9
  expect(TCellAgent).to_not receive(:send_event)
11
10
  expect(TCellAgent).to_not receive(:logger)
12
11
 
@@ -14,8 +13,8 @@ module TCellAgent
14
13
  end
15
14
  end
16
15
 
17
- context "with empty events" do
18
- it "should do nothing" do
16
+ context 'with empty events' do
17
+ it 'should do nothing' do
19
18
  expect(TCellAgent).to_not receive(:send_event)
20
19
  expect(TCellAgent).to_not receive(:logger)
21
20
 
@@ -23,145 +22,161 @@ module TCellAgent
23
22
  end
24
23
  end
25
24
 
26
- context "with one event" do
27
- it "should send the event" do
28
- events = [{
29
- "pattern" => "1",
30
- "method" => "request_method",
31
- "uri" => "abosolute_uri",
32
- "parameter" => "avatar",
33
- "meta" => {"l" => "body"},
34
- "session_id" => "session_id",
35
- "route_id" => "route_id",
36
- "detection_point" => "xss",
37
- "user_id" => "user_id"
38
- }]
25
+ context 'with one event' do
26
+ it 'should send the event' do
27
+ events = [
28
+ {
29
+ 'pattern' => '1',
30
+ 'method' => 'request_method',
31
+ 'uri' => 'abosolute_uri',
32
+ 'parameter' => 'avatar',
33
+ 'meta' => { 'l' => 'body' },
34
+ 'session_id' => 'session_id',
35
+ 'route_id' => 'route_id',
36
+ 'detection_point' => 'xss',
37
+ 'user_id' => 'user_id'
38
+ }
39
+ ]
39
40
 
40
41
  expect(TCellAgent).to_not receive(:logger)
41
42
 
42
- expect(TCellAgent).to receive(:send_event).with({
43
- "event_type" => "as",
44
- "dp" => "xss",
45
- "param" => "avatar",
46
- "m" => "request_method",
47
- "pattern" => "1",
48
- "meta" => {"l" => "body"},
49
- "rid" => "route_id",
50
- "uri" => "abosolute_uri",
51
- "uid" => "user_id",
52
- "sid" => "session_id"
53
- })
43
+ expect(TCellAgent).to receive(:send_event).with(
44
+ {
45
+ 'event_type' => 'as',
46
+ 'dp' => 'xss',
47
+ 'param' => 'avatar',
48
+ 'm' => 'request_method',
49
+ 'pattern' => '1',
50
+ 'meta' => { 'l' => 'body' },
51
+ 'rid' => 'route_id',
52
+ 'uri' => 'abosolute_uri',
53
+ 'uid' => 'user_id',
54
+ 'sid' => 'session_id'
55
+ }
56
+ )
54
57
 
55
58
  InjectionsReporter.report_and_log(events)
56
59
  end
57
60
  end
58
61
 
59
- context "with one event with full payload" do
60
- it "should send and log the event" do
61
- events = [{
62
- "pattern" => "1",
63
- "method" => "request_method",
64
- "uri" => "abosolute_uri",
65
- "parameter" => "avatar",
66
- "meta" => {"l" => "body"},
67
- "session_id" => "session_id",
68
- "route_id" => "route_id",
69
- "detection_point" => "xss",
70
- "user_id" => "user_id",
71
- "full_payload" => "full_payload"
72
- }]
73
-
74
- logger = double("logger")
62
+ context 'with one event with full payload' do
63
+ it 'should send and log the event' do
64
+ events = [
65
+ {
66
+ 'pattern' => '1',
67
+ 'method' => 'request_method',
68
+ 'uri' => 'abosolute_uri',
69
+ 'parameter' => 'avatar',
70
+ 'meta' => { 'l' => 'body' },
71
+ 'session_id' => 'session_id',
72
+ 'route_id' => 'route_id',
73
+ 'detection_point' => 'xss',
74
+ 'user_id' => 'user_id',
75
+ 'full_payload' => 'full_payload'
76
+ }
77
+ ]
78
+
79
+ logger = double('logger')
75
80
 
76
81
  expect(TCellAgent).to receive(:logger).and_return(logger)
77
82
  expect(logger).to receive(:info).with(/"payload":"full_payload"/)
78
83
 
79
- expect(TCellAgent).to receive(:send_event).with({
80
- "event_type" => "as",
81
- "dp" => "xss",
82
- "param" => "avatar",
83
- "m" => "request_method",
84
- "pattern" => "1",
85
- "meta" => {"l" => "body"},
86
- "rid" => "route_id",
87
- "uri" => "abosolute_uri",
88
- "uid" => "user_id",
89
- "sid" => "session_id"
90
- })
84
+ expect(TCellAgent).to receive(:send_event).with(
85
+ {
86
+ 'event_type' => 'as',
87
+ 'dp' => 'xss',
88
+ 'param' => 'avatar',
89
+ 'm' => 'request_method',
90
+ 'pattern' => '1',
91
+ 'meta' => { 'l' => 'body' },
92
+ 'rid' => 'route_id',
93
+ 'uri' => 'abosolute_uri',
94
+ 'uid' => 'user_id',
95
+ 'sid' => 'session_id'
96
+ }
97
+ )
91
98
 
92
99
  InjectionsReporter.report_and_log(events)
93
100
  end
94
101
  end
95
102
 
96
- context "with one event with payload" do
97
- it "should send the event" do
98
- events = [{
99
- "pattern" => "1",
100
- "method" => "request_method",
101
- "uri" => "abosolute_uri",
102
- "parameter" => "avatar",
103
- "meta" => {"l" => "body"},
104
- "session_id" => "session_id",
105
- "route_id" => "route_id",
106
- "detection_point" => "xss",
107
- "user_id" => "user_id",
108
- "payload" => "payload"
109
- }]
103
+ context 'with one event with payload' do
104
+ it 'should send the event' do
105
+ events = [
106
+ {
107
+ 'pattern' => '1',
108
+ 'method' => 'request_method',
109
+ 'uri' => 'abosolute_uri',
110
+ 'parameter' => 'avatar',
111
+ 'meta' => { 'l' => 'body' },
112
+ 'session_id' => 'session_id',
113
+ 'route_id' => 'route_id',
114
+ 'detection_point' => 'xss',
115
+ 'user_id' => 'user_id',
116
+ 'payload' => 'payload'
117
+ }
118
+ ]
110
119
 
111
120
  expect(TCellAgent).to_not receive(:logger)
112
121
 
113
- expect(TCellAgent).to receive(:send_event).with({
114
- "event_type" => "as",
115
- "dp" => "xss",
116
- "param" => "avatar",
117
- "m" => "request_method",
118
- "pattern" => "1",
119
- "meta" => {"l" => "body"},
120
- "rid" => "route_id",
121
- "uri" => "abosolute_uri",
122
- "uid" => "user_id",
123
- "sid" => "session_id",
124
- "payload" => "payload"
125
- })
122
+ expect(TCellAgent).to receive(:send_event).with(
123
+ {
124
+ 'event_type' => 'as',
125
+ 'dp' => 'xss',
126
+ 'param' => 'avatar',
127
+ 'm' => 'request_method',
128
+ 'pattern' => '1',
129
+ 'meta' => { 'l' => 'body' },
130
+ 'rid' => 'route_id',
131
+ 'uri' => 'abosolute_uri',
132
+ 'uid' => 'user_id',
133
+ 'sid' => 'session_id',
134
+ 'payload' => 'payload'
135
+ }
136
+ )
126
137
 
127
138
  InjectionsReporter.report_and_log(events)
128
139
  end
129
140
  end
130
141
 
131
- context "with one event with payload and full payload" do
132
- it "should send and log the event" do
133
- events = [{
134
- "pattern" => "1",
135
- "method" => "request_method",
136
- "uri" => "abosolute_uri",
137
- "parameter" => "avatar",
138
- "meta" => {"l" => "body"},
139
- "session_id" => "session_id",
140
- "route_id" => "route_id",
141
- "detection_point" => "xss",
142
- "user_id" => "user_id",
143
- "payload" => "payload",
144
- "full_payload" => "full_payload"
145
- }]
146
-
147
- logger = double("logger")
142
+ context 'with one event with payload and full payload' do
143
+ it 'should send and log the event' do
144
+ events = [
145
+ {
146
+ 'pattern' => '1',
147
+ 'method' => 'request_method',
148
+ 'uri' => 'abosolute_uri',
149
+ 'parameter' => 'avatar',
150
+ 'meta' => { 'l' => 'body' },
151
+ 'session_id' => 'session_id',
152
+ 'route_id' => 'route_id',
153
+ 'detection_point' => 'xss',
154
+ 'user_id' => 'user_id',
155
+ 'payload' => 'payload',
156
+ 'full_payload' => 'full_payload'
157
+ }
158
+ ]
159
+
160
+ logger = double('logger')
148
161
 
149
162
  expect(TCellAgent).to receive(:logger).and_return(logger)
150
163
  expect(logger).to receive(:info).with(/"payload":"full_payload"/)
151
164
 
152
- expect(TCellAgent).to receive(:send_event).with({
153
- "event_type" => "as",
154
- "dp" => "xss",
155
- "param" => "avatar",
156
- "m" => "request_method",
157
- "pattern" => "1",
158
- "meta" => {"l" => "body"},
159
- "rid" => "route_id",
160
- "uri" => "abosolute_uri",
161
- "uid" => "user_id",
162
- "sid" => "session_id",
163
- "payload" => "payload"
164
- })
165
+ expect(TCellAgent).to receive(:send_event).with(
166
+ {
167
+ 'event_type' => 'as',
168
+ 'dp' => 'xss',
169
+ 'param' => 'avatar',
170
+ 'm' => 'request_method',
171
+ 'pattern' => '1',
172
+ 'meta' => { 'l' => 'body' },
173
+ 'rid' => 'route_id',
174
+ 'uri' => 'abosolute_uri',
175
+ 'uid' => 'user_id',
176
+ 'sid' => 'session_id',
177
+ 'payload' => 'payload'
178
+ }
179
+ )
165
180
 
166
181
  InjectionsReporter.report_and_log(events)
167
182
  end