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.
- checksums.yaml +4 -4
- data/Rakefile +9 -22
- data/bin/tcell_agent +127 -132
- data/lib/tcell_agent/agent/event_processor.rb +23 -22
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +7 -7
- data/lib/tcell_agent/agent/policy_manager.rb +20 -15
- data/lib/tcell_agent/agent/policy_types.rb +5 -11
- data/lib/tcell_agent/agent/static_agent.rb +5 -1
- data/lib/tcell_agent/agent.rb +6 -4
- data/lib/tcell_agent/api.rb +7 -9
- data/lib/tcell_agent/appsensor/meta_data.rb +11 -4
- data/lib/tcell_agent/authlogic.rb +3 -3
- data/lib/tcell_agent/cmdi.rb +6 -4
- data/lib/tcell_agent/config/unknown_options.rb +3 -1
- data/lib/tcell_agent/configuration.rb +47 -49
- data/lib/tcell_agent/devise.rb +2 -2
- data/lib/tcell_agent/hooks/login_fraud.rb +58 -29
- data/lib/tcell_agent/instrumentation.rb +11 -10
- data/lib/tcell_agent/logger.rb +2 -2
- data/lib/tcell_agent/patches/meta_data.rb +9 -13
- data/lib/tcell_agent/patches.rb +7 -10
- data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -5
- data/lib/tcell_agent/policies/content_security_policy.rb +6 -12
- data/lib/tcell_agent/policies/dataloss_policy.rb +2 -2
- data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
- data/lib/tcell_agent/policies/policy.rb +0 -2
- data/lib/tcell_agent/policies/rust_policies.rb +90 -0
- data/lib/tcell_agent/policies/secure_headers_policy.rb +2 -2
- data/lib/tcell_agent/rails/auth/authlogic.rb +42 -24
- data/lib/tcell_agent/rails/auth/devise.rb +44 -23
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +33 -15
- data/lib/tcell_agent/rails/better_ip.rb +1 -1
- data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
- data/lib/tcell_agent/rails/dlp/process_request.rb +1 -1
- data/lib/tcell_agent/rails/dlp.rb +6 -6
- data/lib/tcell_agent/rails/dlp_handler.rb +1 -1
- data/lib/tcell_agent/rails/js_agent_insert.rb +1 -1
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +1 -1
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +3 -2
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +10 -9
- data/lib/tcell_agent/rails/routes/grape.rb +6 -6
- data/lib/tcell_agent/rails/routes.rb +8 -11
- data/lib/tcell_agent/rust/libtcellagent-0.11.1.dylib +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-0.6.1.so → libtcellagent-0.11.1.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +16 -0
- data/lib/tcell_agent/rust/tcellagent-0.11.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +119 -48
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +17 -20
- data/lib/tcell_agent/sensor_events/command_injection.rb +50 -5
- data/lib/tcell_agent/sensor_events/login_fraud.rb +34 -18
- data/lib/tcell_agent/sensor_events/patches.rb +21 -0
- data/lib/tcell_agent/sensor_events/server_agent.rb +3 -3
- data/lib/tcell_agent/sensor_events/util/utils.rb +4 -3
- data/lib/tcell_agent/servers/puma.rb +2 -2
- data/lib/tcell_agent/servers/unicorn.rb +1 -1
- data/lib/tcell_agent/utils/passwords.rb +28 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/lib/tcell_agent.rb +1 -5
- data/spec/apps/rails-3.2/config/tcell_agent.config +15 -0
- data/spec/apps/rails-3.2/log/development.log +0 -0
- data/spec/apps/rails-3.2/log/test.log +12 -0
- data/spec/apps/rails-4.1/log/test.log +0 -0
- data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +46 -45
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +276 -164
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +44 -47
- data/spec/lib/tcell_agent/api/api_spec.rb +16 -16
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +131 -116
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +55 -51
- data/spec/lib/tcell_agent/cmdi_spec.rb +413 -436
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +145 -128
- data/spec/lib/tcell_agent/configuration_spec.rb +165 -169
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +144 -153
- data/spec/lib/tcell_agent/instrumentation_spec.rb +84 -85
- data/spec/lib/tcell_agent/patches_spec.rb +70 -111
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +313 -244
- data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +28 -28
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +643 -513
- data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +55 -102
- data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +111 -134
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +141 -146
- data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +8 -8
- data/spec/lib/tcell_agent/policies/login_policy_spec.rb +15 -17
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +231 -559
- data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +27 -27
- data/spec/lib/tcell_agent/rails/better_ip_spec.rb +30 -34
- data/spec/lib/tcell_agent/rails/logger_spec.rb +50 -49
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +182 -199
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +110 -84
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +107 -85
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +68 -40
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +81 -67
- data/spec/lib/tcell_agent/rails/responses_spec.rb +33 -37
- data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +116 -121
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +25 -28
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +87 -85
- data/spec/lib/tcell_agent/rails_spec.rb +1 -6
- data/spec/lib/tcell_agent/rust/models_spec.rb +112 -0
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +502 -179
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +44 -33
- data/spec/lib/tcell_agent/sensor_events/dlp_spec.rb +4 -4
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +183 -169
- data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +25 -25
- data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +17 -20
- data/spec/lib/tcell_agent/utils/params_spec.rb +28 -28
- data/spec/lib/tcell_agent/utils/passwords_spec.rb +143 -0
- data/spec/lib/tcell_agent/utils/strings_spec.rb +35 -35
- data/spec/lib/tcell_agent_spec.rb +8 -8
- data/spec/spec_helper.rb +4 -4
- data/spec/support/middleware_helper.rb +10 -10
- data/spec/support/static_agent_overrides.rb +16 -12
- data/tcell_agent.gemspec +17 -33
- metadata +43 -198
- data/LICENSE_libinjection +0 -32
- data/Readme.txt +0 -7
- data/ext/libinjection/extconf.rb +0 -3
- data/ext/libinjection/libinjection.h +0 -65
- data/ext/libinjection/libinjection_html5.c +0 -847
- data/ext/libinjection/libinjection_html5.h +0 -54
- data/ext/libinjection/libinjection_sqli.c +0 -2317
- data/ext/libinjection/libinjection_sqli.h +0 -295
- data/ext/libinjection/libinjection_sqli_data.h +0 -9004
- data/ext/libinjection/libinjection_wrap.c +0 -3525
- data/ext/libinjection/libinjection_xss.c +0 -531
- data/ext/libinjection/libinjection_xss.h +0 -21
- data/lib/tcell_agent/appsensor/injections_matcher.rb +0 -155
- data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +0 -49
- data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +0 -67
- data/lib/tcell_agent/appsensor/rules/baserules.json +0 -467
- data/lib/tcell_agent/patches/block_rule.rb +0 -93
- data/lib/tcell_agent/patches/sensors_matcher.rb +0 -31
- data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +0 -23
- data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +0 -23
- data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +0 -117
- data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +0 -26
- data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +0 -22
- data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +0 -34
- data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +0 -34
- data/lib/tcell_agent/policies/appsensor_policy.rb +0 -49
- data/lib/tcell_agent/policies/command_injection_policy.rb +0 -196
- data/lib/tcell_agent/policies/honeytokens_policy.rb +0 -69
- data/lib/tcell_agent/policies/patches_policy.rb +0 -84
- data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
- data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
- data/spec/apps/rails-3.2/Gemfile +0 -25
- data/spec/apps/rails-3.2/Gemfile.lock +0 -126
- data/spec/apps/rails-3.2/Rakefile +0 -7
- data/spec/apps/rails-3.2/app/assets/images/rails.png +0 -0
- data/spec/apps/rails-3.2/app/assets/javascripts/application.js +0 -15
- data/spec/apps/rails-3.2/app/assets/stylesheets/application.css +0 -13
- data/spec/apps/rails-3.2/app/controllers/application_controller.rb +0 -3
- data/spec/apps/rails-3.2/app/controllers/t_cell_app_controller.rb +0 -5
- data/spec/apps/rails-3.2/app/helpers/application_helper.rb +0 -2
- data/spec/apps/rails-3.2/app/views/layouts/application.html.erb +0 -14
- data/spec/apps/rails-3.2/app/views/t_cell_app/index.html.erb +0 -1
- data/spec/apps/rails-3.2/config/application.rb +0 -63
- data/spec/apps/rails-3.2/config/boot.rb +0 -6
- data/spec/apps/rails-3.2/config/environment.rb +0 -5
- data/spec/apps/rails-3.2/config/environments/test.rb +0 -37
- data/spec/apps/rails-3.2/config/routes.rb +0 -11
- data/spec/apps/rails-3.2/config.ru +0 -4
- data/spec/apps/rails-4.1/Gemfile +0 -7
- data/spec/apps/rails-4.1/Gemfile.lock +0 -114
- data/spec/apps/rails-4.1/Rakefile +0 -6
- data/spec/apps/rails-4.1/app/assets/javascripts/application.js +0 -16
- data/spec/apps/rails-4.1/app/assets/stylesheets/application.css +0 -15
- data/spec/apps/rails-4.1/app/controllers/application_controller.rb +0 -5
- data/spec/apps/rails-4.1/app/controllers/t_cell_app_controller.rb +0 -5
- data/spec/apps/rails-4.1/app/helpers/application_helper.rb +0 -2
- data/spec/apps/rails-4.1/app/views/layouts/application.html.erb +0 -14
- data/spec/apps/rails-4.1/app/views/t_cell_app/index.html.erb +0 -1
- data/spec/apps/rails-4.1/config/application.rb +0 -24
- data/spec/apps/rails-4.1/config/boot.rb +0 -4
- data/spec/apps/rails-4.1/config/environment.rb +0 -5
- data/spec/apps/rails-4.1/config/environments/test.rb +0 -41
- data/spec/apps/rails-4.1/config/initializers/assets.rb +0 -8
- data/spec/apps/rails-4.1/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/apps/rails-4.1/config/initializers/cookies_serializer.rb +0 -3
- data/spec/apps/rails-4.1/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/apps/rails-4.1/config/initializers/inflections.rb +0 -16
- data/spec/apps/rails-4.1/config/initializers/mime_types.rb +0 -4
- data/spec/apps/rails-4.1/config/initializers/session_store.rb +0 -3
- data/spec/apps/rails-4.1/config/initializers/wrap_parameters.rb +0 -14
- data/spec/apps/rails-4.1/config/locales/en.yml +0 -23
- data/spec/apps/rails-4.1/config/routes.rb +0 -12
- data/spec/apps/rails-4.1/config/secrets.yml +0 -22
- data/spec/apps/rails-4.1/config.ru +0 -4
- data/spec/controllers/application_controller.rb +0 -12
- data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +0 -522
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -23
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +0 -159
- data/spec/lib/tcell_agent/patches/block_rule_spec.rb +0 -458
- data/spec/lib/tcell_agent/patches/sensors_matcher_spec.rb +0 -35
- data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +0 -167
- data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +0 -246
- data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +0 -882
- 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
|
-
[
|
|
13
|
+
['/api/grape/route']
|
|
16
14
|
end
|
|
17
|
-
|
|
18
15
|
end
|
|
19
16
|
|
|
20
|
-
describe
|
|
21
|
-
context
|
|
17
|
+
describe '.instrument_route' do
|
|
18
|
+
context 'with a nil route' do
|
|
22
19
|
it "shouldn't be reported" do
|
|
23
|
-
configuration = double(
|
|
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
|
|
34
|
-
context
|
|
35
|
-
it
|
|
36
|
-
stub_const(
|
|
37
|
-
stub_const(
|
|
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(
|
|
36
|
+
configuration = double('configuration', :enabled => true, :should_instrument? => true)
|
|
40
37
|
route = double(
|
|
41
|
-
|
|
42
|
-
path
|
|
43
|
-
defaults
|
|
44
|
-
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(
|
|
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
|
-
|
|
47
|
+
'/regular/route', 'GET', '-1187510355', nil, '{}'
|
|
50
48
|
).and_call_original
|
|
51
49
|
expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
|
|
52
|
-
|
|
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
|
|
60
|
-
it
|
|
61
|
-
stub_const(
|
|
62
|
-
stub_const(
|
|
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(
|
|
62
|
+
configuration = double('configuration', :enabled => true, :should_instrument? => true)
|
|
65
63
|
route = double(
|
|
66
|
-
|
|
67
|
-
path
|
|
68
|
-
defaults
|
|
69
|
-
app
|
|
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(
|
|
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
|
-
|
|
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
|
|
84
|
-
context
|
|
85
|
-
it
|
|
86
|
-
stub_const(
|
|
87
|
-
stub_const(
|
|
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(
|
|
88
|
+
configuration = double('configuration', :enabled => true, :should_instrument? => true)
|
|
90
89
|
route = double(
|
|
91
|
-
|
|
92
|
-
path
|
|
93
|
-
defaults
|
|
94
|
-
constraints
|
|
95
|
-
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
|
-
|
|
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
|
|
109
|
-
it
|
|
110
|
-
stub_const(
|
|
111
|
-
stub_const(
|
|
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(
|
|
113
|
+
configuration = double('configuration', :enabled => true, :should_instrument? => true)
|
|
114
114
|
route = double(
|
|
115
|
-
|
|
116
|
-
path
|
|
117
|
-
defaults
|
|
118
|
-
constraints
|
|
119
|
-
app
|
|
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
|
-
|
|
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
|
|
133
|
-
context
|
|
134
|
-
it
|
|
135
|
-
stub_const(
|
|
136
|
-
stub_const(
|
|
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(
|
|
139
|
+
configuration = double('configuration', :enabled => true, :should_instrument? => true)
|
|
139
140
|
route = double(
|
|
140
|
-
|
|
141
|
-
path
|
|
142
|
-
defaults
|
|
143
|
-
constraints
|
|
144
|
-
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
|
-
|
|
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
|
|
158
|
-
it
|
|
159
|
-
stub_const(
|
|
160
|
-
stub_const(
|
|
161
|
-
configuration = double(
|
|
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
|
-
|
|
164
|
-
path
|
|
165
|
-
defaults
|
|
166
|
-
constraints
|
|
167
|
-
app
|
|
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
|
-
|
|
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
|