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,7 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
4
  module Instrumentation
5
-
6
5
  # Fake out grape gem
7
6
  module Grape
8
7
  class API
@@ -10,19 +9,17 @@ module TCellAgent
10
9
  end
11
10
 
12
11
  class GrapeRoute < Grape::API
13
-
14
12
  def self.routes
15
- ["/api/grape/route"]
13
+ ['/api/grape/route']
16
14
  end
17
-
18
15
  end
19
16
 
20
- describe ".instrument_route" do
21
- context "with a nil route" do
17
+ describe '.instrument_route' do
18
+ context 'with a nil route' do
22
19
  it "shouldn't be reported" do
23
- configuration = double("configuration", enabled: true, should_instrument?: true)
20
+ configuration = double('configuration', :enabled => true, :should_instrument? => true)
24
21
 
25
- expect(TCellAgent).to receive(:configuration).and_return(configuration).twice()
22
+ expect(TCellAgent).to receive(:configuration).and_return(configuration).twice
26
23
  expect(TCellAgent::Instrumentation).to_not receive(:instrument_grape_api)
27
24
  expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
28
25
 
@@ -30,49 +27,51 @@ module TCellAgent
30
27
  end
31
28
  end
32
29
 
33
- context "with rails 5.0" do
34
- context "with a regular route" do
35
- it "should report it" do
36
- stub_const("::Rails::VERSION::MAJOR", 5)
37
- stub_const("::Rails::VERSION::MINOR", 0)
30
+ context 'with rails 5.0' do
31
+ context 'with a regular route' do
32
+ it 'should report it' do
33
+ stub_const('::Rails::VERSION::MAJOR', 5)
34
+ stub_const('::Rails::VERSION::MINOR', 0)
38
35
 
39
- configuration = double("configuration", enabled: true, should_instrument?: true)
36
+ configuration = double('configuration', :enabled => true, :should_instrument? => true)
40
37
  route = double(
41
- "route",
42
- path: double("path", spec: "/regular/route"),
43
- defaults: {},
44
- app: double("app", app: "some_app"))
38
+ 'route',
39
+ :path => double('path', :spec => '/regular/route'),
40
+ :defaults => {},
41
+ :app => double('app', :app => 'some_app')
42
+ )
45
43
 
46
- expect(TCellAgent).to receive(:configuration).and_return(configuration).twice()
47
- expect(route).to receive(:verb).and_return("GET|POST").twice()
44
+ expect(TCellAgent).to receive(:configuration).and_return(configuration).twice
45
+ expect(route).to receive(:verb).and_return('GET|POST').twice
48
46
  expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
49
- "/regular/route", "GET", "-1187510355", nil, "{}"
47
+ '/regular/route', 'GET', '-1187510355', nil, '{}'
50
48
  ).and_call_original
51
49
  expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
52
- "/regular/route", "POST", "1100742947", nil, "{}"
50
+ '/regular/route', 'POST', '1100742947', nil, '{}'
53
51
  ).and_call_original
54
52
 
55
53
  Rails.instrument_route(route)
56
54
  end
57
55
  end
58
56
 
59
- context "with a grape route" do
60
- it "should instrument the grape endpoint" do
61
- stub_const("::Rails::VERSION::MAJOR", 5)
62
- stub_const("::Rails::VERSION::MINOR", 0)
57
+ context 'with a grape route' do
58
+ it 'should instrument the grape endpoint' do
59
+ stub_const('::Rails::VERSION::MAJOR', 5)
60
+ stub_const('::Rails::VERSION::MINOR', 0)
63
61
 
64
- configuration = double("configuration", enabled: true, should_instrument?: true)
62
+ configuration = double('configuration', :enabled => true, :should_instrument? => true)
65
63
  route = double(
66
- "route",
67
- path: double("path", spec: "/grape"),
68
- defaults: {},
69
- app: double("app", app: GrapeRoute))
64
+ 'route',
65
+ :path => double('path', :spec => '/grape'),
66
+ :defaults => {},
67
+ :app => double('app', :app => GrapeRoute)
68
+ )
70
69
 
71
- expect(TCellAgent).to receive(:configuration).and_return(configuration).twice()
72
- expect(route).to receive(:verb).and_return("GET|POST")
70
+ expect(TCellAgent).to receive(:configuration).and_return(configuration).twice
71
+ expect(route).to receive(:verb).and_return('GET|POST')
73
72
  expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
74
73
  expect(TCellAgent::Instrumentation).to receive(:instrument_grape_api).with(
75
- "/grape", ["/api/grape/route"]
74
+ '/grape', ['/api/grape/route']
76
75
  )
77
76
 
78
77
  Rails.instrument_route(route)
@@ -80,47 +79,49 @@ module TCellAgent
80
79
  end
81
80
  end
82
81
 
83
- context "with rails 4.2" do
84
- context "with a regular route" do
85
- it "should report it" do
86
- stub_const("::Rails::VERSION::MAJOR", 4)
87
- stub_const("::Rails::VERSION::MINOR", 2)
82
+ context 'with rails 4.2' do
83
+ context 'with a regular route' do
84
+ it 'should report it' do
85
+ stub_const('::Rails::VERSION::MAJOR', 4)
86
+ stub_const('::Rails::VERSION::MINOR', 2)
88
87
 
89
- configuration = double("configuration", enabled: true, should_instrument?: true)
88
+ configuration = double('configuration', :enabled => true, :should_instrument? => true)
90
89
  route = double(
91
- "route",
92
- path: double("path", spec: "/regular/route"),
93
- defaults: {},
94
- constraints: {request_method: "DELETE"},
95
- app: double("app", app: "some_app"))
90
+ 'route',
91
+ :path => double('path', :spec => '/regular/route'),
92
+ :defaults => {},
93
+ :constraints => { :request_method => 'DELETE' },
94
+ :app => double('app', :app => 'some_app')
95
+ )
96
96
 
97
- expect(TCellAgent).to receive(:configuration).and_return(configuration).twice()
97
+ expect(TCellAgent).to receive(:configuration).and_return(configuration).twice
98
98
  expect(TCellAgent::Instrumentation).to_not receive(:instrument_grape_api)
99
99
  expect(route).to receive(:verb).and_return(/DELETE/).at_least(9)
100
100
  expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
101
- "/regular/route", "DELETE", "-990446408", nil, "{}"
101
+ '/regular/route', 'DELETE', '-990446408', nil, '{}'
102
102
  ).and_call_original
103
103
 
104
104
  Rails.instrument_route(route)
105
105
  end
106
106
  end
107
107
 
108
- context "with a grape route" do
109
- it "should instrument the grape endpoint" do
110
- stub_const("::Rails::VERSION::MAJOR", 4)
111
- stub_const("::Rails::VERSION::MINOR", 2)
108
+ context 'with a grape route' do
109
+ it 'should instrument the grape endpoint' do
110
+ stub_const('::Rails::VERSION::MAJOR', 4)
111
+ stub_const('::Rails::VERSION::MINOR', 2)
112
112
 
113
- configuration = double("configuration", enabled: true, should_instrument?: true)
113
+ configuration = double('configuration', :enabled => true, :should_instrument? => true)
114
114
  route = double(
115
- "route",
116
- path: double("path", spec: "/grape"),
117
- defaults: {},
118
- constraints: {request_method: "PUT"},
119
- app: double("app", app: GrapeRoute))
115
+ 'route',
116
+ :path => double('path', :spec => '/grape'),
117
+ :defaults => {},
118
+ :constraints => { :request_method => 'PUT' },
119
+ :app => double('app', :app => GrapeRoute)
120
+ )
120
121
 
121
- expect(TCellAgent).to receive(:configuration).and_return(configuration).twice()
122
+ expect(TCellAgent).to receive(:configuration).and_return(configuration).twice
122
123
  expect(TCellAgent::Instrumentation).to receive(:instrument_grape_api).with(
123
- "/grape", ["/api/grape/route"]
124
+ '/grape', ['/api/grape/route']
124
125
  )
125
126
  expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
126
127
 
@@ -129,46 +130,48 @@ module TCellAgent
129
130
  end
130
131
  end
131
132
 
132
- context "with rails 4.1" do
133
- context "with a regular route" do
134
- it "should report it" do
135
- stub_const("::Rails::VERSION::MAJOR", 4)
136
- stub_const("::Rails::VERSION::MINOR", 1)
133
+ context 'with rails 4.1' do
134
+ context 'with a regular route' do
135
+ it 'should report it' do
136
+ stub_const('::Rails::VERSION::MAJOR', 4)
137
+ stub_const('::Rails::VERSION::MINOR', 1)
137
138
 
138
- configuration = double("configuration", enabled: true, should_instrument?: true)
139
+ configuration = double('configuration', :enabled => true, :should_instrument? => true)
139
140
  route = double(
140
- "route",
141
- path: double("path", spec: "/regular/route"),
142
- defaults: {},
143
- constraints: {request_method: "PUT"},
144
- app: "some_app")
141
+ 'route',
142
+ :path => double('path', :spec => '/regular/route'),
143
+ :defaults => {},
144
+ :constraints => { :request_method => 'PUT' },
145
+ :app => 'some_app'
146
+ )
145
147
 
146
- expect(TCellAgent).to receive(:configuration).and_return(configuration).twice()
148
+ expect(TCellAgent).to receive(:configuration).and_return(configuration).twice
147
149
  expect(TCellAgent::Instrumentation).to_not receive(:instrument_grape_api)
148
150
  expect(route).to receive(:verb).and_return(/PUT/).at_least(9)
149
151
  expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
150
- "/regular/route", "PUT", "-1393108268", nil, "{}"
152
+ '/regular/route', 'PUT', '-1393108268', nil, '{}'
151
153
  ).and_call_original
152
154
 
153
155
  Rails.instrument_route(route)
154
156
  end
155
157
  end
156
158
 
157
- context "with a grape route" do
158
- it "should instrument the grape endpoint" do
159
- stub_const("::Rails::VERSION::MAJOR", 4)
160
- stub_const("::Rails::VERSION::MINOR", 1)
161
- configuration = double("configuration", enabled: true, should_instrument?: true)
159
+ context 'with a grape route' do
160
+ it 'should instrument the grape endpoint' do
161
+ stub_const('::Rails::VERSION::MAJOR', 4)
162
+ stub_const('::Rails::VERSION::MINOR', 1)
163
+ configuration = double('configuration', :enabled => true, :should_instrument? => true)
162
164
  route = double(
163
- "route",
164
- path: double("path", spec: "/grape"),
165
- defaults: {},
166
- constraints: {request_method: "PUT"},
167
- app: GrapeRoute)
165
+ 'route',
166
+ :path => double('path', :spec => '/grape'),
167
+ :defaults => {},
168
+ :constraints => { :request_method => 'PUT' },
169
+ :app => GrapeRoute
170
+ )
168
171
 
169
- expect(TCellAgent).to receive(:configuration).and_return(configuration).twice()
172
+ expect(TCellAgent).to receive(:configuration).and_return(configuration).twice
170
173
  expect(TCellAgent::Instrumentation).to receive(:instrument_grape_api).with(
171
- "/grape", ["/api/grape/route"]
174
+ '/grape', ['/api/grape/route']
172
175
  )
173
176
  expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
174
177
 
@@ -177,6 +180,5 @@ module TCellAgent
177
180
  end
178
181
  end
179
182
  end
180
-
181
183
  end
182
184
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module TCellAgent
4
-
5
4
  class MockRackApp
6
-
7
5
  attr_reader :request_body
8
6
 
9
7
  def initialize
@@ -13,16 +11,14 @@ module TCellAgent
13
11
  def call(env)
14
12
  @env = env
15
13
  @request_body = env['rack.input'].read
16
- [200, {'Content-Type' => 'text/plain'}, ['OK']]
14
+ [200, { 'Content-Type' => 'text/plain' }, ['OK']]
17
15
  end
18
16
 
19
17
  def [](key)
20
18
  @env[key]
21
19
  end
22
-
23
20
  end
24
21
 
25
-
26
22
  # describe MyMiddleware do
27
23
 
28
24
  # let(:file_like_object) { File.open("spec/resources/normal_config.json") }
@@ -53,5 +49,4 @@ module TCellAgent
53
49
  # end
54
50
  # end
55
51
  # end
56
-
57
52
  end
@@ -0,0 +1,112 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ module TCellAgent
5
+ module Rust
6
+ describe '.create_request_response' do
7
+ it 'should create request response' do
8
+ appsensor_meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new(
9
+ 'GET',
10
+ '192.168.1.1',
11
+ '12345',
12
+ 'session_id',
13
+ 'user_id',
14
+ 'transaction_id',
15
+ 'http://192.168.1.1/some/path?xss_param=<script>'
16
+ )
17
+ appsensor_meta.response_code = 200
18
+ appsensor_meta.user_agent = 'Mozilla'
19
+ appsensor_meta.path = '/some/path'
20
+ appsensor_meta.request_content_bytes_len = 1024
21
+ appsensor_meta.response_content_bytes_len = 2048
22
+ appsensor_meta.get_dict = { 'user' => { 'xss_param' => '<script>' } }
23
+ appsensor_meta.sql_exceptions = [{ 'exception_name' => 'OperationalError', 'exception_payload' => 'Developer Error' }]
24
+ appsensor_meta.csrf_exception_name = 'ActionController::InvalidAuthenticityToken'
25
+ appsensor_meta.path_parameters = { 'xss_param' => '<script>' }
26
+ appsensor_meta.post_dict = TCellAgent::Utils::Params.flatten({ 'already_flattened' => { 'xss_param' => '<script>' } })
27
+ appsensor_meta.body_dict = TCellAgent::Utils::Params.flatten({ 'already_flattened' => { 'xss_param' => '<script>' } })
28
+ appsensor_meta.cookie_dict = { 'xss_param' => '<script>' }
29
+ appsensor_meta.set_headers_dict({ 'HTTP_XSS_PARAM' => '<script>' })
30
+
31
+ result = Models.create_request_response(appsensor_meta)
32
+
33
+ expect(result).to eq({
34
+ 'method' => 'GET',
35
+ 'status_code' => 200,
36
+ 'route_id' => '12345',
37
+ 'path' => '/some/path',
38
+ 'query_params' => [
39
+ { 'name' => 'xss_param', 'value' => '<script>' }
40
+ ],
41
+ 'post_params' => [
42
+ { 'name' => 'xss_param', 'value' => '<script>' },
43
+ { 'name' => 'xss_param', 'value' => '<script>' }
44
+ ],
45
+ 'headers' => [
46
+ { 'name' => 'xss-param', 'value' => '<script>' }
47
+ ],
48
+ 'cookies' => [
49
+ { 'name' => 'xss_param', 'value' => '<script>' }
50
+ ],
51
+ 'path_params' => [
52
+ { 'name' => 'xss_param', 'value' => '<script>' }
53
+ ],
54
+ 'remote_address' => '192.168.1.1',
55
+ 'full_uri' => 'http://192.168.1.1/some/path?xss_param=<script>',
56
+ 'session_id' => 'session_id',
57
+ 'user_id' => 'user_id',
58
+ 'user_agent' => 'Mozilla',
59
+ 'request_bytes_length' => 1024,
60
+ 'response_bytes_length' => 2048,
61
+ 'csrf_exception' => {
62
+ 'exception_name' => 'ActionController::InvalidAuthenticityToken'
63
+ },
64
+ 'sql_exceptions' => [
65
+ {
66
+ 'exception_name' => 'OperationalError',
67
+ 'exception_payload' => 'Developer Error'
68
+ }
69
+ ]
70
+ })
71
+ end
72
+ end
73
+
74
+ describe '.create_patches_request' do
75
+ it 'should create patches request' do
76
+ appsensor_meta = TCellAgent::Patches::MetaData.new(
77
+ 'GET',
78
+ '192.168.1.1',
79
+ '12345',
80
+ 'session_id',
81
+ 'user_id',
82
+ 'transaction_id',
83
+ 'http://192.168.1.1/some/path?xss_param=<script>'
84
+ )
85
+
86
+ appsensor_meta.path = '/some/path'
87
+ appsensor_meta.request_content_bytes_len = 1024
88
+ appsensor_meta.get_dict = { 'user' => { 'xss_param' => '<script>' } }
89
+ appsensor_meta.post_dict = { 'user' => { 'xss_param' => '<script>' } }
90
+ appsensor_meta.body_dict = { 'user' => { 'xss_param' => '<script>' } }
91
+ appsensor_meta.cookie_dict = { 'xss_param' => '<script>' }
92
+ appsensor_meta.set_headers_dict({ 'HTTP_XSS_PARAM' => '<script>' })
93
+
94
+ result = Models.create_patches_request(appsensor_meta)
95
+
96
+ expect(result).to eq({
97
+ 'method' => 'GET',
98
+ 'path' => '/some/path',
99
+ 'remote_address' => '192.168.1.1',
100
+ 'request_bytes_length' => 1024,
101
+ 'query_params' => [{ 'name' => 'xss_param', 'value' => '<script>' }],
102
+ 'post_params' => [
103
+ { 'name' => 'xss_param', 'value' => '<script>' },
104
+ { 'name' => 'r', 'value' => { 'xss_param' => '<script>' } }
105
+ ],
106
+ 'headers' => [{ 'name' => 'xss-param', 'value' => '<script>' }],
107
+ 'cookies' => [{ 'name' => 'xss_param', 'value' => '<script>' }]
108
+ })
109
+ end
110
+ end
111
+ end
112
+ end