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.
- 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,62 +2,61 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module TCellAgent
|
4
4
|
module SensorEvents
|
5
|
-
|
6
5
|
describe Agent do
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
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(
|
17
|
+
TCellAgent.increment_session_info('hmac_session_id', 'user_id', 'ip_address', 'user_agent')
|
20
18
|
end
|
21
19
|
|
22
|
-
context
|
23
|
-
it
|
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
|
-
|
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(
|
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
|
40
|
-
it
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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(
|
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
|
59
|
-
context
|
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
|
69
|
-
it
|
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(
|
72
|
+
TCellAgent.increment_route('/ma_route', 20)
|
74
73
|
|
75
74
|
expect(TCellAgent.thread_agent.response_time_table).to eq(
|
76
|
-
{
|
75
|
+
{ '/ma_route' => { 'c' => 1, 'mx' => 20, 'mn' => 20, 't' => 20 } }
|
77
76
|
)
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
81
|
-
context
|
82
|
-
it
|
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(
|
85
|
+
TCellAgent.increment_route('', 20)
|
87
86
|
|
88
87
|
expect(TCellAgent.thread_agent.response_time_table).to eq(
|
89
|
-
{
|
88
|
+
{ '?' => { 'c' => 1, 'mx' => 20, 'mn' => 20, 't' => 20 } }
|
90
89
|
)
|
91
90
|
end
|
92
91
|
end
|
93
92
|
|
94
|
-
context
|
95
|
-
it
|
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
|
-
{
|
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
|
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
|
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
|
-
|
121
|
-
|
122
|
-
|
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(
|
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
|
8
|
-
it
|
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 =
|
11
|
-
TCellAgent.configuration.api_key =
|
9
|
+
TCellAgent.configuration.app_id = 'test-appid'
|
10
|
+
TCellAgent.configuration.api_key = 'test-apikey'
|
12
11
|
|
13
|
-
def checkreq(
|
14
|
-
|
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
|
22
|
-
stub_request(:any, uri_template)
|
23
|
-
to_return(lambda { |request|
|
24
|
-
|
25
|
-
|
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
|
-
|
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[
|
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
|
8
|
-
context
|
9
|
-
it
|
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
|
18
|
-
it
|
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
|
27
|
-
it
|
28
|
-
events = [
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
60
|
-
it
|
61
|
-
events = [
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
97
|
-
it
|
98
|
-
events = [
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
132
|
-
it
|
133
|
-
events = [
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
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
|