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,39 +2,41 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module TCellAgent
|
4
4
|
module SensorEvents
|
5
|
-
|
6
5
|
describe AppSensorMetaEvent do
|
7
|
-
|
8
|
-
describe "#body_params" do
|
6
|
+
describe '#body_params' do
|
9
7
|
before(:each) do
|
10
8
|
@appsensor_meta = AppSensorMetaEvent.new(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
'get',
|
10
|
+
'remote_address',
|
11
|
+
'route_id',
|
12
|
+
'session_id',
|
13
|
+
'user_id',
|
14
|
+
'transaction_id',
|
15
|
+
'http://test.com'
|
16
|
+
)
|
17
17
|
end
|
18
18
|
|
19
|
-
context
|
20
|
-
it
|
19
|
+
context 'with text/html content type' do
|
20
|
+
it 'should set the body params to empty' do
|
21
21
|
@appsensor_meta.set_body_dict(
|
22
22
|
67,
|
23
|
-
|
24
|
-
{
|
23
|
+
'text/html',
|
24
|
+
{
|
25
|
+
:username => 'tester',
|
26
|
+
:password => 'pass'
|
27
|
+
}.to_json
|
25
28
|
)
|
26
29
|
|
27
30
|
expect(@appsensor_meta.body_dict).to eq({})
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
|
-
context
|
32
|
-
|
33
|
-
|
34
|
-
it "should set the body params to empty" do
|
34
|
+
context 'with application/json content type' do
|
35
|
+
context 'with empty request body' do
|
36
|
+
it 'should set the body params to empty' do
|
35
37
|
@appsensor_meta.set_body_dict(
|
36
38
|
67,
|
37
|
-
|
39
|
+
'application/json',
|
38
40
|
nil
|
39
41
|
)
|
40
42
|
|
@@ -42,11 +44,11 @@ module TCellAgent
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
context
|
46
|
-
it
|
47
|
+
context 'with bad json in the body' do
|
48
|
+
it 'should set the body params to empty' do
|
47
49
|
@appsensor_meta.set_body_dict(
|
48
50
|
67,
|
49
|
-
|
51
|
+
'application/json',
|
50
52
|
'{"username":"tester""password":"pass"}'
|
51
53
|
)
|
52
54
|
|
@@ -54,32 +56,41 @@ module TCellAgent
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
context
|
58
|
-
it
|
59
|
+
context 'with valid json in the body' do
|
60
|
+
it 'should set the body params' do
|
59
61
|
@appsensor_meta.set_body_dict(
|
60
62
|
67,
|
61
|
-
|
62
|
-
{
|
63
|
+
'application/json',
|
64
|
+
{
|
65
|
+
:username => 'tester',
|
66
|
+
:password => 'pass'
|
67
|
+
}.to_json
|
63
68
|
)
|
64
69
|
|
65
|
-
expect(@appsensor_meta.body_dict).to eq(
|
70
|
+
expect(@appsensor_meta.body_dict).to eq(
|
71
|
+
{
|
72
|
+
['username'] => 'tester',
|
73
|
+
['password'] => 'pass'
|
74
|
+
}
|
75
|
+
)
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
69
|
-
context
|
70
|
-
it
|
79
|
+
context 'with a json body that is too big' do
|
80
|
+
it 'should set the body params to empty' do
|
71
81
|
@appsensor_meta.set_body_dict(
|
72
|
-
|
73
|
-
|
74
|
-
{
|
82
|
+
20_000_000,
|
83
|
+
'application/json',
|
84
|
+
{
|
85
|
+
:username => 'tester',
|
86
|
+
:password => 'pass'
|
87
|
+
}.to_json
|
75
88
|
)
|
76
89
|
expect(@appsensor_meta.body_dict).to eq({})
|
77
90
|
end
|
78
91
|
end
|
79
92
|
end
|
80
93
|
end
|
81
|
-
|
82
94
|
end
|
83
|
-
|
84
95
|
end
|
85
96
|
end
|
@@ -3,10 +3,10 @@ require 'spec_helper'
|
|
3
3
|
module TCellAgent
|
4
4
|
module SensorEvents
|
5
5
|
describe DlpEvent do
|
6
|
-
context
|
7
|
-
it
|
8
|
-
dlp_event = DlpEvent.new(
|
9
|
-
expect(dlp_event[
|
6
|
+
context 'Domain from Url' do
|
7
|
+
it 'Test Simple Domain' do
|
8
|
+
dlp_event = DlpEvent.new('a', 'b', 'c').for_request('x', 'y')
|
9
|
+
expect(dlp_event['context']).to eq('x')
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -3,256 +3,270 @@ require 'spec_helper'
|
|
3
3
|
module TCellAgent
|
4
4
|
module SensorEvents
|
5
5
|
describe SessionsMetric do
|
6
|
-
describe
|
7
|
-
context
|
8
|
-
it
|
6
|
+
describe '#initialize' do
|
7
|
+
context 'empty sessions info' do
|
8
|
+
it 'should have the event type set' do
|
9
9
|
sessions_metric = SessionsMetric.new
|
10
|
-
expect(sessions_metric).to eq({
|
10
|
+
expect(sessions_metric).to eq({ 'event_type' => 'metrics', 'sessions' => {} })
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe
|
16
|
-
context
|
17
|
-
context
|
18
|
-
it
|
15
|
+
describe '#add_session_info' do
|
16
|
+
context 'empty sessions info' do
|
17
|
+
context 'adding session info' do
|
18
|
+
it 'should have the session info' do
|
19
19
|
sessions_metric = SessionsMetric.new
|
20
|
-
sessions_metric.add_session_info(
|
20
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
21
21
|
|
22
22
|
expect(sessions_metric.has_sessions?).to eq(true)
|
23
|
-
expect(sessions_metric).to eq(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
expect(sessions_metric).to eq(
|
24
|
+
{
|
25
|
+
'event_type' => 'metrics',
|
26
|
+
'sessions' => {
|
27
|
+
'hmac_session_id' => [
|
28
|
+
{
|
29
|
+
'uid' => 'user_id',
|
30
|
+
'track' => [
|
31
|
+
['user_agent', ['127.0.0.1']]
|
32
|
+
]
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}
|
34
36
|
}
|
35
|
-
|
37
|
+
)
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
context
|
40
|
-
it
|
41
|
-
long_user_agent =
|
42
|
-
long_user_agent +=
|
43
|
-
long_user_agent +=
|
44
|
-
long_user_agent +=
|
41
|
+
context 'adding a really long user agent' do
|
42
|
+
it 'should truncate the agent' do
|
43
|
+
long_user_agent = 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_'
|
44
|
+
long_user_agent += 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent'
|
45
|
+
long_user_agent += 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent'
|
46
|
+
long_user_agent += 'user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent'
|
45
47
|
sessions_metric = SessionsMetric.new
|
46
|
-
sessions_metric.add_session_info(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
48
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', long_user_agent)
|
49
|
+
|
50
|
+
expect(sessions_metric).to eq(
|
51
|
+
{
|
52
|
+
'event_type' => 'metrics',
|
53
|
+
'sessions' => {
|
54
|
+
'hmac_session_id' => [
|
55
|
+
{
|
56
|
+
'uid' => 'user_id',
|
57
|
+
'track' => [
|
58
|
+
['user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agentuser_agent_user_agent_user_agent_user_agent_user_agent_user_agent_user_agentuser_agent_user_agent_user_', ['127.0.0.1']]
|
59
|
+
]
|
60
|
+
}
|
61
|
+
]
|
62
|
+
}
|
58
63
|
}
|
59
|
-
|
64
|
+
)
|
60
65
|
end
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
64
|
-
context
|
65
|
-
context
|
66
|
-
it
|
69
|
+
context 'with an existing session info' do
|
70
|
+
context 'adding the same info' do
|
71
|
+
it 'should not do anything' do
|
67
72
|
sessions_metric = SessionsMetric.new
|
68
|
-
sessions_metric.add_session_info(
|
69
|
-
sessions_metric.add_session_info(
|
73
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
74
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
70
75
|
|
71
|
-
expect(sessions_metric).to eq(
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
expect(sessions_metric).to eq(
|
77
|
+
{
|
78
|
+
'event_type' => 'metrics',
|
79
|
+
'sessions' => {
|
80
|
+
'hmac_session_id' => [
|
81
|
+
{
|
82
|
+
'uid' => 'user_id',
|
83
|
+
'track' => [
|
84
|
+
['user_agent', ['127.0.0.1']]
|
85
|
+
]
|
86
|
+
}
|
87
|
+
]
|
88
|
+
}
|
82
89
|
}
|
83
|
-
|
90
|
+
)
|
84
91
|
end
|
85
92
|
end
|
86
93
|
|
87
|
-
|
88
|
-
|
89
|
-
it "should add the new info" do
|
94
|
+
context 'adding a new session' do
|
95
|
+
it 'should add the new info' do
|
90
96
|
sessions_metric = SessionsMetric.new
|
91
|
-
sessions_metric.add_session_info(
|
92
|
-
|
93
|
-
sessions_metric.add_session_info("hmac_session_id_dos", "user_id_dos", "127.0.0.1_dos", "user_agent_dos")
|
94
|
-
expect(sessions_metric).to eq({
|
95
|
-
"event_type"=>"metrics",
|
96
|
-
"sessions"=>{
|
97
|
-
"hmac_session_id" => [
|
98
|
-
{
|
99
|
-
"uid"=>"user_id",
|
100
|
-
"track"=>[
|
101
|
-
["user_agent", ["127.0.0.1"]]
|
102
|
-
]
|
103
|
-
}
|
104
|
-
],
|
105
|
-
"hmac_session_id_dos" => [
|
106
|
-
{
|
107
|
-
"uid"=>"user_id_dos",
|
108
|
-
"track"=>[
|
109
|
-
["user_agent_dos", ["127.0.0.1_dos"]]
|
110
|
-
]
|
111
|
-
}
|
112
|
-
]
|
113
|
-
}
|
114
|
-
})
|
115
|
-
end
|
116
|
-
|
117
|
-
context "with the same user_id" do
|
118
|
-
it "should add the new info" do
|
119
|
-
sessions_metric = SessionsMetric.new
|
120
|
-
sessions_metric.add_session_info("hmac_session_id", "user_id", "127.0.0.1", "user_agent")
|
97
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
121
98
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
99
|
+
sessions_metric.add_session_info('hmac_session_id_dos', 'user_id_dos', '127.0.0.1_dos', 'user_agent_dos')
|
100
|
+
expect(sessions_metric).to eq(
|
101
|
+
{
|
102
|
+
'event_type' => 'metrics',
|
103
|
+
'sessions' => {
|
104
|
+
'hmac_session_id' => [
|
127
105
|
{
|
128
|
-
|
129
|
-
|
130
|
-
[
|
106
|
+
'uid' => 'user_id',
|
107
|
+
'track' => [
|
108
|
+
['user_agent', ['127.0.0.1']]
|
131
109
|
]
|
132
110
|
}
|
133
111
|
],
|
134
|
-
|
112
|
+
'hmac_session_id_dos' => [
|
135
113
|
{
|
136
|
-
|
137
|
-
|
138
|
-
[
|
114
|
+
'uid' => 'user_id_dos',
|
115
|
+
'track' => [
|
116
|
+
['user_agent_dos', ['127.0.0.1_dos']]
|
139
117
|
]
|
140
118
|
}
|
141
119
|
]
|
142
120
|
}
|
143
|
-
}
|
121
|
+
}
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'with the same user_id' do
|
126
|
+
it 'should add the new info' do
|
127
|
+
sessions_metric = SessionsMetric.new
|
128
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
129
|
+
|
130
|
+
sessions_metric.add_session_info('hmac_session_id_dos', 'user_id', '127.0.0.1', 'user_agent')
|
131
|
+
expect(sessions_metric).to eq(
|
132
|
+
{
|
133
|
+
'event_type' => 'metrics',
|
134
|
+
'sessions' => {
|
135
|
+
'hmac_session_id' => [
|
136
|
+
{
|
137
|
+
'uid' => 'user_id',
|
138
|
+
'track' => [
|
139
|
+
['user_agent', ['127.0.0.1']]
|
140
|
+
]
|
141
|
+
}
|
142
|
+
],
|
143
|
+
'hmac_session_id_dos' => [
|
144
|
+
{
|
145
|
+
'uid' => 'user_id',
|
146
|
+
'track' => [
|
147
|
+
['user_agent', ['127.0.0.1']]
|
148
|
+
]
|
149
|
+
}
|
150
|
+
]
|
151
|
+
}
|
152
|
+
}
|
153
|
+
)
|
144
154
|
end
|
145
155
|
end
|
146
156
|
end
|
147
157
|
|
148
|
-
context
|
149
|
-
context
|
150
|
-
it
|
158
|
+
context 'adding new info for the existing session' do
|
159
|
+
context 'adding a new user_id' do
|
160
|
+
it 'should append the ip address to the existing info' do
|
151
161
|
sessions_metric = SessionsMetric.new
|
152
|
-
sessions_metric.add_session_info(
|
153
|
-
sessions_metric.add_session_info(
|
162
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
163
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id_dos', '127.0.0.1', 'user_agent')
|
154
164
|
|
155
|
-
expect(sessions_metric).to eq(
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
165
|
+
expect(sessions_metric).to eq(
|
166
|
+
{
|
167
|
+
'event_type' => 'metrics',
|
168
|
+
'sessions' => {
|
169
|
+
'hmac_session_id' => [
|
170
|
+
{
|
171
|
+
'uid' => 'user_id',
|
172
|
+
'track' => [
|
173
|
+
['user_agent', ['127.0.0.1']]
|
174
|
+
]
|
175
|
+
},
|
176
|
+
{
|
177
|
+
'uid' => 'user_id_dos',
|
178
|
+
'track' => [
|
179
|
+
['user_agent', ['127.0.0.1']]
|
180
|
+
]
|
181
|
+
}
|
182
|
+
]
|
183
|
+
}
|
172
184
|
}
|
173
|
-
|
185
|
+
)
|
174
186
|
end
|
175
187
|
end
|
176
188
|
|
177
|
-
context
|
178
|
-
it
|
189
|
+
context 'adding a new ip address' do
|
190
|
+
it 'should append the ip address to the existing info' do
|
179
191
|
sessions_metric = SessionsMetric.new
|
180
|
-
sessions_metric.add_session_info(
|
181
|
-
sessions_metric.add_session_info(
|
192
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
193
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1_dos', 'user_agent')
|
182
194
|
|
183
|
-
expect(sessions_metric).to eq(
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
195
|
+
expect(sessions_metric).to eq(
|
196
|
+
{
|
197
|
+
'event_type' => 'metrics',
|
198
|
+
'sessions' => {
|
199
|
+
'hmac_session_id' => [
|
200
|
+
{
|
201
|
+
'uid' => 'user_id',
|
202
|
+
'track' => [
|
203
|
+
['user_agent', ['127.0.0.1', '127.0.0.1_dos']]
|
204
|
+
]
|
205
|
+
}
|
206
|
+
]
|
207
|
+
}
|
194
208
|
}
|
195
|
-
|
209
|
+
)
|
196
210
|
end
|
197
211
|
end
|
198
212
|
|
199
|
-
context
|
200
|
-
it
|
213
|
+
context 'adding a new user agent' do
|
214
|
+
it 'should add the new user agent' do
|
201
215
|
sessions_metric = SessionsMetric.new
|
202
|
-
sessions_metric.add_session_info(
|
203
|
-
sessions_metric.add_session_info(
|
216
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent')
|
217
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', '127.0.0.1', 'user_agent_dos')
|
204
218
|
|
205
|
-
expect(sessions_metric).to eq(
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
219
|
+
expect(sessions_metric).to eq(
|
220
|
+
{
|
221
|
+
'event_type' => 'metrics',
|
222
|
+
'sessions' => {
|
223
|
+
'hmac_session_id' => [
|
224
|
+
{
|
225
|
+
'uid' => 'user_id',
|
226
|
+
'track' => [
|
227
|
+
['user_agent', ['127.0.0.1']],
|
228
|
+
['user_agent_dos', ['127.0.0.1']]
|
229
|
+
]
|
230
|
+
}
|
231
|
+
]
|
232
|
+
}
|
217
233
|
}
|
218
|
-
|
234
|
+
)
|
219
235
|
end
|
220
236
|
end
|
221
237
|
end
|
222
|
-
|
223
238
|
end
|
224
239
|
|
225
|
-
context
|
226
|
-
it
|
240
|
+
context 'adding 200 sessions' do
|
241
|
+
it 'should update its state to flush' do
|
227
242
|
sessions_metric = SessionsMetric.new
|
228
243
|
expect(sessions_metric.flush).to eq(false)
|
229
244
|
|
230
245
|
200.times do |x|
|
231
|
-
sessions_metric.add_session_info(
|
246
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', "127.0.0.1_#{x}", 'user_agent')
|
232
247
|
end
|
233
248
|
|
234
249
|
expect(sessions_metric.flush).to eq(true)
|
235
250
|
end
|
236
251
|
end
|
237
252
|
|
238
|
-
context
|
239
|
-
it
|
240
|
-
logger = double(
|
253
|
+
context 'adding 251 sessions' do
|
254
|
+
it 'should drop session after 250' do
|
255
|
+
logger = double('logger')
|
241
256
|
sessions_metric = SessionsMetric.new
|
242
257
|
|
243
258
|
expect(sessions_metric.flush).to eq(false)
|
244
259
|
expect(TCellAgent).to receive(:logger).and_return(logger)
|
245
|
-
expect(logger).to receive(:warn).with(
|
260
|
+
expect(logger).to receive(:warn).with('Sessions Metric is full. Information dropped')
|
246
261
|
|
247
262
|
250.times do |x|
|
248
|
-
sessions_metric.add_session_info(
|
263
|
+
sessions_metric.add_session_info('hmac_session_id', 'user_id', "127.0.0.1_#{x}", 'user_agent')
|
249
264
|
end
|
250
265
|
|
251
266
|
expect(sessions_metric.flush).to eq(true)
|
252
267
|
end
|
253
268
|
end
|
254
269
|
end
|
255
|
-
|
256
270
|
end
|
257
271
|
end
|
258
272
|
end
|