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
@@ -1,14 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module TCellAgent
|
4
|
-
|
5
4
|
module Hooks
|
6
5
|
module V1
|
7
6
|
module Frameworks
|
8
7
|
module Rails
|
9
8
|
module Login
|
10
|
-
def self.register_login_event(status, rails_request, user_id, user_valid=nil)
|
11
|
-
end
|
9
|
+
def self.register_login_event(status, rails_request, user_id, user_valid = nil, password = nil); end
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
@@ -18,55 +16,55 @@ module TCellAgent
|
|
18
16
|
module Hooks
|
19
17
|
module V1
|
20
18
|
module Login
|
21
|
-
LOGIN_SUCCESS =
|
22
|
-
LOGIN_FAILURE =
|
23
|
-
|
24
|
-
end
|
19
|
+
LOGIN_SUCCESS = 'success'.freeze
|
20
|
+
LOGIN_FAILURE = 'failure'.freeze
|
21
|
+
|
22
|
+
def self.register_login_event(status, session_id, user_agent, referrer, remote_addr, header_keys, user_id, document_uri, user_valid = nil, password = nil); end
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
describe
|
27
|
+
describe 'manually requiring auth hooks' do
|
30
28
|
before(:all) do
|
31
29
|
require 'tcell_agent/hooks/login_fraud'
|
32
30
|
end
|
33
31
|
|
34
|
-
describe
|
35
|
-
context
|
36
|
-
context
|
37
|
-
it
|
38
|
-
login_fraud = double(
|
32
|
+
describe 'Using generic interface' do
|
33
|
+
context 'with a login failure' do
|
34
|
+
context 'with login_failed_enabled set to true' do
|
35
|
+
it 'should report the login failure' do
|
36
|
+
login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => true)
|
39
37
|
|
40
38
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
41
39
|
login_fraud
|
42
40
|
)
|
43
41
|
expect(TCellAgent).to receive(:send_event).with(
|
44
42
|
{
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
43
|
+
'event_type' => 'login',
|
44
|
+
'header_keys' => %w[USER_AGENT X_FORWARDED_FOR],
|
45
|
+
'user_agent' => 'user_agent',
|
46
|
+
'referrer' => 'referrer',
|
47
|
+
'remote_addr' => '1.1.1.1',
|
48
|
+
'user_id' => 'user_id',
|
49
|
+
'document_uri' => 'http://tcell.tcell.io/login?param_name=',
|
50
|
+
'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
|
51
|
+
'event_name' => 'login-failure'
|
54
52
|
}
|
55
53
|
)
|
56
54
|
|
57
55
|
status = Hooks::V1::Login::LOGIN_FAILURE
|
58
|
-
header_keys = [
|
59
|
-
document_uri =
|
56
|
+
header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
|
57
|
+
document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
|
60
58
|
|
61
59
|
Hooks::V1::Login.register_login_event(
|
62
|
-
status,
|
60
|
+
status, 'session_id', 'user_agent', 'referrer', '1.1.1.1', header_keys, 'user_id', document_uri
|
63
61
|
)
|
64
62
|
end
|
65
63
|
end
|
66
64
|
|
67
|
-
context
|
68
|
-
it
|
69
|
-
login_fraud = double(
|
65
|
+
context 'with login_failed_enabled set to false' do
|
66
|
+
it 'should NOT report the login failure' do
|
67
|
+
login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => false)
|
70
68
|
|
71
69
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
72
70
|
login_fraud
|
@@ -74,51 +72,51 @@ module TCellAgent
|
|
74
72
|
expect(TCellAgent).to_not receive(:send_event)
|
75
73
|
|
76
74
|
status = Hooks::V1::Login::LOGIN_FAILURE
|
77
|
-
header_keys = [
|
78
|
-
document_uri =
|
75
|
+
header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
|
76
|
+
document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
|
79
77
|
|
80
78
|
Hooks::V1::Login.register_login_event(
|
81
|
-
status,
|
79
|
+
status, 'session_id', 'user_agent', 'referrer', '1.1.1.1', header_keys, 'user_id', document_uri
|
82
80
|
)
|
83
81
|
end
|
84
82
|
end
|
85
83
|
end
|
86
84
|
|
87
|
-
context
|
88
|
-
context
|
89
|
-
it
|
90
|
-
login_fraud = double(
|
85
|
+
context 'with a login success' do
|
86
|
+
context 'with login_success_enabled set to true' do
|
87
|
+
it 'should report the login success' do
|
88
|
+
login_fraud = double('login_fraud', :enabled => true, :login_success_enabled => true)
|
91
89
|
|
92
90
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
93
91
|
login_fraud
|
94
92
|
)
|
95
93
|
expect(TCellAgent).to receive(:send_event).with(
|
96
94
|
{
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
95
|
+
'event_type' => 'login',
|
96
|
+
'header_keys' => %w[USER_AGENT X_FORWARDED_FOR],
|
97
|
+
'user_agent' => 'user_agent',
|
98
|
+
'referrer' => 'referrer',
|
99
|
+
'remote_addr' => '1.1.1.1',
|
100
|
+
'user_id' => 'user_id',
|
101
|
+
'document_uri' => 'http://tcell.tcell.io/login?param_name=',
|
102
|
+
'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
|
103
|
+
'event_name' => 'login-success'
|
106
104
|
}
|
107
105
|
)
|
108
106
|
|
109
107
|
status = Hooks::V1::Login::LOGIN_SUCCESS
|
110
|
-
header_keys = [
|
111
|
-
document_uri =
|
108
|
+
header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
|
109
|
+
document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
|
112
110
|
|
113
111
|
Hooks::V1::Login.register_login_event(
|
114
|
-
status,
|
112
|
+
status, 'session_id', 'user_agent', 'referrer', '1.1.1.1', header_keys, 'user_id', document_uri
|
115
113
|
)
|
116
114
|
end
|
117
115
|
end
|
118
116
|
|
119
|
-
context
|
120
|
-
it
|
121
|
-
login_fraud = double(
|
117
|
+
context 'with login_success_enabled set to false' do
|
118
|
+
it 'should NOT report the login success' do
|
119
|
+
login_fraud = double('login_fraud', :enabled => true, :login_success_enabled => false)
|
122
120
|
|
123
121
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
124
122
|
login_fraud
|
@@ -126,58 +124,57 @@ module TCellAgent
|
|
126
124
|
expect(TCellAgent).to_not receive(:send_event)
|
127
125
|
|
128
126
|
status = Hooks::V1::Login::LOGIN_SUCCESS
|
129
|
-
header_keys = [
|
130
|
-
document_uri =
|
127
|
+
header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
|
128
|
+
document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
|
131
129
|
|
132
130
|
Hooks::V1::Login.register_login_event(
|
133
|
-
status,
|
131
|
+
status, 'session_id', 'user_agent', 'referrer', '1.1.1.1', header_keys, 'user_id', document_uri
|
134
132
|
)
|
135
133
|
end
|
136
134
|
end
|
137
135
|
end
|
138
136
|
|
139
|
-
context
|
140
|
-
it
|
141
|
-
login_fraud = double(
|
142
|
-
logger = double(
|
137
|
+
context 'with an unknown status' do
|
138
|
+
it 'should log the error' do
|
139
|
+
login_fraud = double('login_fraud', :enabled => true)
|
140
|
+
logger = double('logger')
|
143
141
|
|
144
142
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
145
143
|
login_fraud
|
146
144
|
)
|
147
145
|
expect(TCellAgent).to_not receive(:send_event)
|
148
146
|
expect(TCellAgent).to receive(:logger).and_return(logger)
|
149
|
-
expect(logger).to receive(:error).with(
|
147
|
+
expect(logger).to receive(:error).with('Unkown login status: mumbo-jumbo')
|
150
148
|
|
151
|
-
status =
|
152
|
-
header_keys = [
|
153
|
-
document_uri =
|
149
|
+
status = 'mumbo-jumbo'
|
150
|
+
header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
|
151
|
+
document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
|
154
152
|
|
155
153
|
Hooks::V1::Login.register_login_event(
|
156
|
-
status,
|
154
|
+
status, 'session_id', 'user_agent', 'referrer', '1.1.1.1', header_keys, 'user_id', document_uri
|
157
155
|
)
|
158
156
|
end
|
159
157
|
end
|
160
158
|
end
|
161
159
|
|
162
|
-
describe
|
163
|
-
context
|
164
|
-
context
|
165
|
-
it
|
166
|
-
login_fraud = double(
|
167
|
-
rails_request = double(
|
160
|
+
describe 'Using rails interface' do
|
161
|
+
context 'with a login failure' do
|
162
|
+
context 'with login_failed_enabled set to true' do
|
163
|
+
it 'should report the login failure' do
|
164
|
+
login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => true)
|
165
|
+
rails_request = double('rails_request')
|
168
166
|
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
169
|
-
tcell_data.user_agent =
|
170
|
-
tcell_data.referrer =
|
171
|
-
tcell_data.ip_address =
|
172
|
-
tcell_data.path =
|
173
|
-
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac(
|
167
|
+
tcell_data.user_agent = 'user_agent'
|
168
|
+
tcell_data.referrer = 'referrer'
|
169
|
+
tcell_data.ip_address = '1.1.1.1'
|
170
|
+
tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
|
171
|
+
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
|
174
172
|
request_env = {
|
175
173
|
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
176
|
-
|
177
|
-
|
174
|
+
'HTTP_USER_AGENT' => true,
|
175
|
+
'HTTP_X_FORWARDED_FOR' => true
|
178
176
|
}
|
179
177
|
|
180
|
-
|
181
178
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
182
179
|
login_fraud
|
183
180
|
)
|
@@ -185,43 +182,42 @@ module TCellAgent
|
|
185
182
|
expect(rails_request).to receive(:env).and_return(request_env)
|
186
183
|
expect(TCellAgent).to receive(:send_event).with(
|
187
184
|
{
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
185
|
+
'event_type' => 'login',
|
186
|
+
'header_keys' => %w[USER_AGENT X_FORWARDED_FOR],
|
187
|
+
'user_agent' => 'user_agent',
|
188
|
+
'referrer' => 'referrer',
|
189
|
+
'remote_addr' => '1.1.1.1',
|
190
|
+
'user_id' => 'user_id',
|
191
|
+
'document_uri' => 'http://tcell.tcell.io/login?param_name=',
|
192
|
+
'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
|
193
|
+
'event_name' => 'login-failure'
|
197
194
|
}
|
198
195
|
)
|
199
196
|
|
200
197
|
status = Hooks::V1::Login::LOGIN_FAILURE
|
201
198
|
|
202
199
|
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
203
|
-
status, rails_request,
|
200
|
+
status, rails_request, 'user_id'
|
204
201
|
)
|
205
202
|
end
|
206
203
|
end
|
207
204
|
|
208
|
-
context
|
209
|
-
it
|
210
|
-
login_fraud = double(
|
211
|
-
rails_request = double(
|
205
|
+
context 'with login_failed_enabled set to false' do
|
206
|
+
it 'should NOT report the login failure' do
|
207
|
+
login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => false)
|
208
|
+
rails_request = double('rails_request')
|
212
209
|
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
213
|
-
tcell_data.user_agent =
|
214
|
-
tcell_data.referrer =
|
215
|
-
tcell_data.ip_address =
|
216
|
-
tcell_data.path =
|
217
|
-
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac(
|
210
|
+
tcell_data.user_agent = 'user_agent'
|
211
|
+
tcell_data.referrer = 'referrer'
|
212
|
+
tcell_data.ip_address = '1.1.1.1'
|
213
|
+
tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
|
214
|
+
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
|
218
215
|
request_env = {
|
219
216
|
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
220
|
-
|
221
|
-
|
217
|
+
'HTTP_USER_AGENT' => true,
|
218
|
+
'HTTP_X_FORWARDED_FOR' => true
|
222
219
|
}
|
223
220
|
|
224
|
-
|
225
221
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
226
222
|
login_fraud
|
227
223
|
)
|
@@ -232,30 +228,29 @@ module TCellAgent
|
|
232
228
|
status = Hooks::V1::Login::LOGIN_FAILURE
|
233
229
|
|
234
230
|
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
235
|
-
status, rails_request,
|
231
|
+
status, rails_request, 'user_id'
|
236
232
|
)
|
237
233
|
end
|
238
234
|
end
|
239
235
|
end
|
240
236
|
|
241
|
-
context
|
242
|
-
context
|
243
|
-
it
|
244
|
-
login_fraud = double(
|
245
|
-
rails_request = double(
|
237
|
+
context 'with a login success' do
|
238
|
+
context 'with login_success_enabled set to true' do
|
239
|
+
it 'should report the login success' do
|
240
|
+
login_fraud = double('login_fraud', :enabled => true, :login_success_enabled => true)
|
241
|
+
rails_request = double('rails_request')
|
246
242
|
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
247
|
-
tcell_data.user_agent =
|
248
|
-
tcell_data.referrer =
|
249
|
-
tcell_data.ip_address =
|
250
|
-
tcell_data.path =
|
251
|
-
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac(
|
243
|
+
tcell_data.user_agent = 'user_agent'
|
244
|
+
tcell_data.referrer = 'referrer'
|
245
|
+
tcell_data.ip_address = '1.1.1.1'
|
246
|
+
tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
|
247
|
+
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
|
252
248
|
request_env = {
|
253
249
|
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
254
|
-
|
255
|
-
|
250
|
+
'HTTP_USER_AGENT' => true,
|
251
|
+
'HTTP_X_FORWARDED_FOR' => true
|
256
252
|
}
|
257
253
|
|
258
|
-
|
259
254
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
260
255
|
login_fraud
|
261
256
|
)
|
@@ -263,43 +258,42 @@ module TCellAgent
|
|
263
258
|
expect(rails_request).to receive(:env).and_return(request_env)
|
264
259
|
expect(TCellAgent).to receive(:send_event).with(
|
265
260
|
{
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
261
|
+
'event_type' => 'login',
|
262
|
+
'header_keys' => %w[USER_AGENT X_FORWARDED_FOR],
|
263
|
+
'user_agent' => 'user_agent',
|
264
|
+
'referrer' => 'referrer',
|
265
|
+
'remote_addr' => '1.1.1.1',
|
266
|
+
'user_id' => 'user_id',
|
267
|
+
'document_uri' => 'http://tcell.tcell.io/login?param_name=',
|
268
|
+
'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
|
269
|
+
'event_name' => 'login-success'
|
275
270
|
}
|
276
271
|
)
|
277
272
|
|
278
273
|
status = Hooks::V1::Login::LOGIN_SUCCESS
|
279
274
|
|
280
275
|
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
281
|
-
status, rails_request,
|
276
|
+
status, rails_request, 'user_id'
|
282
277
|
)
|
283
278
|
end
|
284
279
|
end
|
285
280
|
|
286
|
-
context
|
287
|
-
it
|
288
|
-
login_fraud = double(
|
289
|
-
rails_request = double(
|
281
|
+
context 'with login_success_enabled set to false' do
|
282
|
+
it 'should NOT report the login success' do
|
283
|
+
login_fraud = double('login_fraud', :enabled => true, :login_success_enabled => false)
|
284
|
+
rails_request = double('rails_request')
|
290
285
|
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
291
|
-
tcell_data.user_agent =
|
292
|
-
tcell_data.referrer =
|
293
|
-
tcell_data.ip_address =
|
294
|
-
tcell_data.path =
|
295
|
-
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac(
|
286
|
+
tcell_data.user_agent = 'user_agent'
|
287
|
+
tcell_data.referrer = 'referrer'
|
288
|
+
tcell_data.ip_address = '1.1.1.1'
|
289
|
+
tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
|
290
|
+
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
|
296
291
|
request_env = {
|
297
292
|
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
298
|
-
|
299
|
-
|
293
|
+
'HTTP_USER_AGENT' => true,
|
294
|
+
'HTTP_X_FORWARDED_FOR' => true
|
300
295
|
}
|
301
296
|
|
302
|
-
|
303
297
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
304
298
|
login_fraud
|
305
299
|
)
|
@@ -310,30 +304,29 @@ module TCellAgent
|
|
310
304
|
status = Hooks::V1::Login::LOGIN_SUCCESS
|
311
305
|
|
312
306
|
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
313
|
-
status, rails_request,
|
307
|
+
status, rails_request, 'user_id'
|
314
308
|
)
|
315
309
|
end
|
316
310
|
end
|
317
311
|
end
|
318
312
|
|
319
|
-
context
|
320
|
-
it
|
321
|
-
login_fraud = double(
|
322
|
-
logger = double(
|
323
|
-
rails_request = double(
|
313
|
+
context 'with an unknown status' do
|
314
|
+
it 'should log the error' do
|
315
|
+
login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => true)
|
316
|
+
logger = double('logger')
|
317
|
+
rails_request = double('rails_request')
|
324
318
|
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
325
|
-
tcell_data.user_agent =
|
326
|
-
tcell_data.referrer =
|
327
|
-
tcell_data.ip_address =
|
328
|
-
tcell_data.path =
|
329
|
-
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac(
|
319
|
+
tcell_data.user_agent = 'user_agent'
|
320
|
+
tcell_data.referrer = 'referrer'
|
321
|
+
tcell_data.ip_address = '1.1.1.1'
|
322
|
+
tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
|
323
|
+
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
|
330
324
|
request_env = {
|
331
325
|
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
332
|
-
|
333
|
-
|
326
|
+
'HTTP_USER_AGENT' => true,
|
327
|
+
'HTTP_X_FORWARDED_FOR' => true
|
334
328
|
}
|
335
329
|
|
336
|
-
|
337
330
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
338
331
|
login_fraud
|
339
332
|
)
|
@@ -341,17 +334,15 @@ module TCellAgent
|
|
341
334
|
expect(rails_request).to receive(:env).and_return(request_env)
|
342
335
|
expect(TCellAgent).to_not receive(:send_event)
|
343
336
|
expect(TCellAgent).to receive(:logger).and_return(logger)
|
344
|
-
expect(logger).to receive(:error).with(
|
337
|
+
expect(logger).to receive(:error).with('Unkown login status: mumbo-jumbo')
|
345
338
|
|
346
|
-
status =
|
339
|
+
status = 'mumbo-jumbo'
|
347
340
|
|
348
341
|
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
349
|
-
status, rails_request,
|
342
|
+
status, rails_request, 'user_id'
|
350
343
|
)
|
351
344
|
end
|
352
345
|
end
|
353
346
|
end
|
354
|
-
|
355
347
|
end
|
356
|
-
|
357
348
|
end
|