tcell_agent 1.1.12 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/tcell_agent +45 -137
- data/lib/tcell_agent.rb +12 -14
- data/lib/tcell_agent/agent.rb +108 -97
- data/lib/tcell_agent/agent/route_manager.rb +0 -16
- data/lib/tcell_agent/agent/static_agent.rb +9 -30
- data/lib/tcell_agent/config_initializer.rb +66 -0
- data/lib/tcell_agent/configuration.rb +69 -345
- data/lib/tcell_agent/hooks/login_fraud.rb +30 -33
- data/lib/tcell_agent/instrument_servers.rb +23 -0
- data/lib/tcell_agent/instrumentation.rb +12 -10
- data/lib/tcell_agent/instrumentation/cmdi.rb +29 -25
- data/lib/tcell_agent/instrumentation/lfi.rb +84 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +25 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +131 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +102 -0
- data/lib/tcell_agent/logger.rb +49 -114
- data/lib/tcell_agent/patches.rb +6 -7
- data/lib/tcell_agent/policies/appfirewall_policy.rb +26 -0
- data/lib/tcell_agent/policies/command_injection_policy.rb +28 -0
- data/lib/tcell_agent/policies/dataloss_policy.rb +44 -44
- data/lib/tcell_agent/policies/headers_policy.rb +25 -0
- data/lib/tcell_agent/policies/http_redirect_policy.rb +13 -79
- data/lib/tcell_agent/policies/js_agent_policy.rb +27 -0
- data/lib/tcell_agent/policies/local_file_access.rb +28 -0
- data/lib/tcell_agent/policies/login_policy.rb +43 -0
- data/lib/tcell_agent/policies/patches_policy.rb +27 -0
- data/lib/tcell_agent/policies/policies_manager.rb +68 -0
- data/lib/tcell_agent/policies/policy_polling.rb +58 -0
- data/lib/tcell_agent/policies/policy_types.rb +14 -0
- data/lib/tcell_agent/policies/system_enablements.rb +27 -0
- data/lib/tcell_agent/rails/auth/authlogic.rb +46 -75
- data/lib/tcell_agent/rails/auth/authlogic_helper.rb +20 -0
- data/lib/tcell_agent/rails/auth/devise.rb +100 -105
- data/lib/tcell_agent/rails/auth/devise_helper.rb +29 -0
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +62 -76
- data/lib/tcell_agent/{userinfo.rb → rails/auth/userinfo.rb} +0 -0
- data/lib/tcell_agent/rails/csrf_exception.rb +2 -10
- data/lib/tcell_agent/rails/dlp.rb +35 -23
- data/lib/tcell_agent/rails/dlp_handler.rb +1 -2
- data/lib/tcell_agent/rails/js_agent_insert.rb +12 -13
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +4 -25
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -12
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +1 -2
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +14 -34
- data/lib/tcell_agent/{rails.rb → rails/railties/tcell_agent_railties.rb} +11 -16
- data/lib/tcell_agent/rails/railties/tcell_agent_unicorn_railties.rb +8 -0
- data/lib/tcell_agent/rails/routes.rb +10 -12
- data/lib/tcell_agent/rails/routes/grape.rb +4 -14
- data/lib/tcell_agent/rails/routes/route_id.rb +3 -1
- data/lib/tcell_agent/rails/settings_reporter.rb +23 -36
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +5 -4
- data/lib/tcell_agent/rust/agent_config.rb +60 -0
- data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.2.so → libtcellagent-5.0.2.dylib} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-1.3.2.so → libtcellagent-5.0.2.so} +0 -0
- data/lib/tcell_agent/rust/libtcellagent-alpine-5.0.2.so +0 -0
- data/lib/tcell_agent/rust/models.rb +6 -52
- data/lib/tcell_agent/rust/native_agent.rb +549 -0
- data/lib/tcell_agent/rust/native_agent_response.rb +42 -0
- data/lib/tcell_agent/rust/native_library.rb +69 -0
- data/lib/tcell_agent/rust/tcellagent-5.0.2.dll +0 -0
- data/lib/tcell_agent/sensor_events/agent_setting_event.rb +12 -0
- data/lib/tcell_agent/sensor_events/{app_config.rb → app_config_setting_event.rb} +0 -6
- data/lib/tcell_agent/sensor_events/dlp.rb +2 -6
- data/lib/tcell_agent/sensor_events/sensor.rb +0 -62
- data/lib/tcell_agent/sensor_events/server_agent.rb +13 -18
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +0 -108
- data/lib/tcell_agent/sensor_events/util/utils.rb +0 -2
- data/lib/tcell_agent/servers/passenger.rb +1 -28
- data/lib/tcell_agent/servers/puma.rb +3 -21
- data/lib/tcell_agent/servers/rails_server.rb +1 -2
- data/lib/tcell_agent/servers/thin.rb +2 -2
- data/lib/tcell_agent/servers/unicorn.rb +19 -80
- data/lib/tcell_agent/servers/webrick.rb +1 -2
- data/lib/tcell_agent/settings_reporter.rb +11 -90
- data/lib/tcell_agent/sinatra.rb +14 -16
- data/lib/tcell_agent/tcell_context.rb +40 -14
- data/lib/tcell_agent/utils/headers.rb +14 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/configuration_spec.rb +55 -346
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +46 -173
- data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +504 -0
- data/spec/lib/tcell_agent/instrumentation/cmdi/kernel_cmdi_spec.rb +435 -0
- data/spec/lib/tcell_agent/instrumentation/cmdi_spec.rb +201 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +326 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +562 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +264 -0
- data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +150 -0
- data/spec/lib/tcell_agent/patches_spec.rb +25 -43
- data/spec/lib/tcell_agent/policies/appfirewall_policy_spec.rb +183 -0
- data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +57 -0
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +84 -773
- data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +161 -0
- data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +9 -9
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +243 -198
- data/spec/lib/tcell_agent/policies/js_agent_policy_spec.rb +75 -0
- data/spec/lib/tcell_agent/policies/login_policy_spec.rb +165 -33
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +84 -277
- data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +104 -0
- data/spec/lib/tcell_agent/policies/policy_polling_spec.rb +6 -0
- data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +56 -0
- data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +9 -18
- data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +13 -30
- data/spec/lib/tcell_agent/rails/logger_spec.rb +27 -7
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +17 -12
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +14 -14
- data/spec/lib/tcell_agent/rust/agent_config_spec.rb +27 -0
- data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +0 -35
- data/spec/lib/tcell_agent/settings_reporter_spec.rb +56 -155
- data/spec/spec_helper.rb +1 -1
- data/spec/support/builders.rb +103 -0
- data/spec/support/force_logger_mocking.rb +38 -0
- data/spec/support/resources/lfi_sample_file.txt +2 -0
- data/spec/support/static_agent_overrides.rb +0 -15
- metadata +72 -83
- data/lib/tcell_agent/agent/event_processor.rb +0 -326
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +0 -113
- data/lib/tcell_agent/agent/policy_manager.rb +0 -219
- data/lib/tcell_agent/agent/policy_types.rb +0 -30
- data/lib/tcell_agent/api.rb +0 -91
- data/lib/tcell_agent/appsensor/injections_reporter.rb +0 -24
- data/lib/tcell_agent/authlogic.rb +0 -26
- data/lib/tcell_agent/config/child_process_events.rb +0 -8
- data/lib/tcell_agent/config/unknown_options.rb +0 -123
- data/lib/tcell_agent/devise.rb +0 -35
- data/lib/tcell_agent/instrumentation/cmdi/backtick.rb +0 -10
- data/lib/tcell_agent/instrumentation/cmdi/exec.rb +0 -14
- data/lib/tcell_agent/instrumentation/cmdi/popen.rb +0 -28
- data/lib/tcell_agent/instrumentation/cmdi/spawn.rb +0 -11
- data/lib/tcell_agent/instrumentation/cmdi/system.rb +0 -11
- data/lib/tcell_agent/policies/http_tx_policy.rb +0 -60
- data/lib/tcell_agent/policies/login_fraud_policy.rb +0 -45
- data/lib/tcell_agent/policies/rust_policies.rb +0 -110
- data/lib/tcell_agent/rails/on_start.rb +0 -41
- data/lib/tcell_agent/rust/libtcellagent-1.3.2.dylib +0 -0
- data/lib/tcell_agent/rust/tcellagent-1.3.2.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +0 -308
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +0 -52
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +0 -45
- data/lib/tcell_agent/sensor_events/command_injection.rb +0 -75
- data/lib/tcell_agent/sensor_events/honeytokens.rb +0 -16
- data/lib/tcell_agent/sensor_events/login_fraud.rb +0 -60
- data/lib/tcell_agent/sensor_events/metrics.rb +0 -123
- data/lib/tcell_agent/sensor_events/patches.rb +0 -21
- data/lib/tcell_agent/start_background_thread.rb +0 -55
- data/lib/tcell_agent/system_info.rb +0 -11
- data/lib/tcell_agent/utils/io.rb +0 -38
- data/lib/tcell_agent/utils/passwords.rb +0 -28
- data/lib/tcell_agent/utils/queue_with_timeout.rb +0 -142
- data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +0 -100
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +0 -535
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +0 -133
- data/spec/lib/tcell_agent/api/api_spec.rb +0 -39
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +0 -187
- data/spec/lib/tcell_agent/cmdi_spec.rb +0 -736
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -213
- data/spec/lib/tcell_agent/instrumentation_spec.rb +0 -225
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +0 -517
- data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +0 -22
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +0 -293
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +0 -198
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +0 -180
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +0 -116
- data/spec/lib/tcell_agent/rust/models_spec.rb +0 -120
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +0 -704
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +0 -45
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +0 -272
- data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +0 -52
- data/spec/lib/tcell_agent/utils/passwords_spec.rb +0 -143
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module TCellAgent
|
3
|
+
module Utils
|
4
|
+
module Headers
|
5
|
+
def self.clean_keys(request_env_or_header_keys)
|
6
|
+
if request_env_or_header_keys.is_a?(Hash)
|
7
|
+
request_env_or_header_keys.select { |k, _v| k.start_with? 'HTTP_' }.collect { |k, _v| k.sub(/^HTTP_/, '') }
|
8
|
+
else
|
9
|
+
request_env_or_header_keys.map { |k| k.sub(/^HTTP_/, '') }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/tcell_agent/version.rb
CHANGED
@@ -2,364 +2,73 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module TCellAgent
|
4
4
|
describe Configuration do
|
5
|
-
describe '
|
6
|
-
context '
|
7
|
-
it 'should
|
8
|
-
|
5
|
+
describe 'should_instrument?' do
|
6
|
+
context 'with the agent disabled' do
|
7
|
+
it 'should return false' do
|
8
|
+
config = Configuration.new
|
9
|
+
config.enabled = false
|
9
10
|
|
10
|
-
expect(
|
11
|
-
%r{/tcell/cache/tcell_agent.cache}
|
12
|
-
)
|
13
|
-
expect(configuration.log_filename).to eq(
|
14
|
-
File.join(Dir.getwd, 'tcell/logs/tcell_agent.log')
|
15
|
-
)
|
16
|
-
expect(configuration.config_filename).to eq(
|
17
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
18
|
-
)
|
11
|
+
expect(config.should_instrument?).to be_falsey
|
19
12
|
end
|
20
13
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
expect(configuration.cache_filename_with_app_id).to match(
|
31
|
-
%r{spec_tcell_home/cache/tcell_agent.cache}
|
32
|
-
)
|
33
|
-
expect(configuration.log_filename).to eq(
|
34
|
-
'spec_tcell_home/logs/tcell_agent.log'
|
35
|
-
)
|
36
|
-
expect(configuration.config_filename).to eq(
|
37
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
38
|
-
)
|
39
|
-
|
40
|
-
ENV['TCELL_AGENT_HOME'] = old_tcell_agent_home
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'TCELL_AGENT_HOME and TCELL_AGENT_LOG_DIR defined' do
|
45
|
-
it 'should set config filename to default, cache file and log file are updated' do
|
46
|
-
old_tcell_agent_home = ENV['TCELL_AGENT_HOME']
|
47
|
-
old_tcell_agent_log_dir = ENV['TCELL_AGENT_LOG_DIR']
|
48
|
-
|
49
|
-
ENV['TCELL_AGENT_HOME'] = 'spec_tcell_home'
|
50
|
-
ENV['TCELL_AGENT_LOG_DIR'] = 'spec_tcell_log_dir'
|
51
|
-
|
52
|
-
configuration = Configuration.new
|
53
|
-
|
54
|
-
expect(configuration.cache_filename_with_app_id).to match(
|
55
|
-
%r{spec_tcell_home/cache/tcell_agent.cache}
|
56
|
-
)
|
57
|
-
expect(configuration.log_filename).to eq(
|
58
|
-
'spec_tcell_log_dir/tcell_agent.log'
|
59
|
-
)
|
60
|
-
expect(configuration.config_filename).to eq(
|
61
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
62
|
-
)
|
63
|
-
|
64
|
-
ENV['TCELL_AGENT_HOME'] = old_tcell_agent_home
|
65
|
-
ENV['TCELL_AGENT_LOG_DIR'] = old_tcell_agent_log_dir
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'TCELL_AGENT_HOME, TCELL_AGENT_LOG_DIR, and TCELL_AGENT_CONFIG defined ' do
|
70
|
-
it 'should update config filename, cache file, and log file' do
|
71
|
-
old_tcell_agent_home = ENV['TCELL_AGENT_HOME']
|
72
|
-
old_tcell_agent_log_dir = ENV['TCELL_AGENT_LOG_DIR']
|
73
|
-
old_config_filename = ENV['TCELL_AGENT_CONFIG']
|
74
|
-
|
75
|
-
ENV['TCELL_AGENT_HOME'] = 'spec_tcell_home'
|
76
|
-
ENV['TCELL_AGENT_LOG_DIR'] = 'spec_tcell_log_dir'
|
77
|
-
ENV['TCELL_AGENT_CONFIG'] = 'spec_config/tcell_agent.config'
|
78
|
-
|
79
|
-
configuration = Configuration.new
|
80
|
-
|
81
|
-
expect(configuration.cache_filename_with_app_id).to match(
|
82
|
-
%r{spec_tcell_home/cache/tcell_agent.cache}
|
83
|
-
)
|
84
|
-
expect(configuration.log_filename).to eq(
|
85
|
-
'spec_tcell_log_dir/tcell_agent.log'
|
86
|
-
)
|
87
|
-
expect(configuration.config_filename).to eq(
|
88
|
-
'spec_config/tcell_agent.config'
|
89
|
-
)
|
90
|
-
|
91
|
-
ENV['TCELL_AGENT_HOME'] = old_tcell_agent_home
|
92
|
-
ENV['TCELL_AGENT_LOG_DIR'] = old_tcell_agent_log_dir
|
93
|
-
ENV['TCELL_AGENT_CONFIG'] = old_config_filename
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe '#data_exposure' do
|
99
|
-
context 'no data_exposure defined' do
|
100
|
-
it 'should set max_data_ex_db_records_per_request to default' do
|
101
|
-
no_data_ex = double(
|
102
|
-
'no_data_ex',
|
103
|
-
:read => {
|
104
|
-
:version => 1,
|
105
|
-
:applications => [
|
106
|
-
:app_id => 'app_id',
|
107
|
-
:name => 'test',
|
108
|
-
:api_key => 'api_key'
|
109
|
-
]
|
110
|
-
}.to_json
|
111
|
-
)
|
112
|
-
expect(File).to receive(:file?).with(
|
113
|
-
File.join(Dir.getwd, 'no_data_ex.config')
|
114
|
-
).and_return(true)
|
115
|
-
expect(File).to receive(:open).with(
|
116
|
-
File.join(Dir.getwd, 'no_data_ex.config')
|
117
|
-
).and_return(no_data_ex)
|
118
|
-
configuration = Configuration.new('no_data_ex.config')
|
119
|
-
|
120
|
-
expect(configuration.max_data_ex_db_records_per_request).to eq(1000)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context 'data_exposure is empty' do
|
125
|
-
it 'should set max_data_ex_db_records_per_request to default' do
|
126
|
-
no_data_ex = double(
|
127
|
-
'no_data_ex',
|
128
|
-
:read => {
|
129
|
-
:version => 1,
|
130
|
-
:applications => [
|
131
|
-
:app_id => 'app_id',
|
132
|
-
:name => 'test',
|
133
|
-
:api_key => 'api_key',
|
134
|
-
:data_exposure => {}
|
135
|
-
]
|
136
|
-
}.to_json
|
137
|
-
)
|
138
|
-
expect(File).to receive(:file?).with(
|
139
|
-
File.join(Dir.getwd, 'no_data_ex.config')
|
140
|
-
).and_return(true)
|
141
|
-
expect(File).to receive(:open).with(
|
142
|
-
File.join(Dir.getwd, 'no_data_ex.config')
|
143
|
-
).and_return(no_data_ex)
|
144
|
-
configuration = Configuration.new('no_data_ex.config')
|
145
|
-
|
146
|
-
expect(configuration.max_data_ex_db_records_per_request).to eq(1000)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context 'data_exposure contains an override' do
|
151
|
-
it 'should set max_data_ex_db_records_per_request to override' do
|
152
|
-
no_data_ex = double(
|
153
|
-
'no_data_ex',
|
154
|
-
:read => {
|
155
|
-
:version => 1,
|
156
|
-
:applications => [
|
157
|
-
:app_id => 'app_id',
|
158
|
-
:name => 'test',
|
159
|
-
:api_key => 'api_key',
|
160
|
-
:data_exposure => {
|
161
|
-
:max_data_ex_db_records_per_request => 5000
|
162
|
-
}
|
163
|
-
]
|
164
|
-
}.to_json
|
165
|
-
)
|
166
|
-
expect(File).to receive(:file?).with(
|
167
|
-
File.join(Dir.getwd, 'no_data_ex.config')
|
168
|
-
).and_return(true)
|
169
|
-
expect(File).to receive(:open).with(
|
170
|
-
File.join(Dir.getwd, 'no_data_ex.config')
|
171
|
-
).and_return(no_data_ex)
|
172
|
-
configuration = Configuration.new('no_data_ex.config')
|
173
|
-
|
174
|
-
expect(configuration.max_data_ex_db_records_per_request).to eq(5000)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe '#allow_payloads' do
|
180
|
-
context 'setting it via config' do
|
181
|
-
context 'using allow_unencrypted_appsensor_payloads' do
|
182
|
-
it 'should be false' do
|
183
|
-
allow_unencrypted_appfirewall_payloads_enabled = double(
|
184
|
-
'no_data_ex',
|
185
|
-
:read => {
|
186
|
-
:version => 1,
|
187
|
-
:applications => [
|
188
|
-
:app_id => 'app_id',
|
189
|
-
:api_key => 'api_key',
|
190
|
-
:allow_unencrypted_appsensor_payloads => false
|
191
|
-
]
|
192
|
-
}.to_json
|
193
|
-
)
|
194
|
-
expect(File).to receive(:file?).with(
|
195
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
196
|
-
).and_return(true)
|
197
|
-
expect(File).to receive(:open).with(
|
198
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
199
|
-
).and_return(allow_unencrypted_appfirewall_payloads_enabled)
|
200
|
-
|
201
|
-
configuration = Configuration.new
|
202
|
-
|
203
|
-
expect(configuration.allow_payloads).to eq(false)
|
14
|
+
context 'with the agent enabled' do
|
15
|
+
context 'with all instrumentation enabled' do
|
16
|
+
context 'with no parameters' do
|
17
|
+
it 'should return true' do
|
18
|
+
config = Configuration.new
|
19
|
+
|
20
|
+
expect(config.should_instrument?).to be_truthy
|
21
|
+
end
|
204
22
|
end
|
205
|
-
|
23
|
+
context 'with parameters' do
|
24
|
+
it 'should return true' do
|
25
|
+
config = Configuration.new
|
206
26
|
|
207
|
-
|
208
|
-
|
209
|
-
allow_unencrypted_appfirewall_payloads_enabled = double(
|
210
|
-
'no_data_ex',
|
211
|
-
:read => {
|
212
|
-
:version => 1,
|
213
|
-
:applications => [
|
214
|
-
:app_id => 'app_id',
|
215
|
-
:api_key => 'api_key',
|
216
|
-
:allow_unencrypted_appfirewall_payloads => false
|
217
|
-
]
|
218
|
-
}.to_json
|
219
|
-
)
|
220
|
-
expect(File).to receive(:file?).with(
|
221
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
222
|
-
).and_return(true)
|
223
|
-
expect(File).to receive(:open).with(
|
224
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
225
|
-
).and_return(allow_unencrypted_appfirewall_payloads_enabled)
|
226
|
-
|
227
|
-
configuration = Configuration.new
|
228
|
-
|
229
|
-
expect(configuration.allow_payloads).to eq(false)
|
27
|
+
expect(config.should_instrument?('devise')).to be_truthy
|
28
|
+
end
|
230
29
|
end
|
231
30
|
end
|
31
|
+
context 'with auth frameworks disabled' do
|
32
|
+
it 'should return false' do
|
33
|
+
config = Configuration.new
|
34
|
+
config.disabled_instrumentation = Set.new(%w[authlogic devise doorkeeper])
|
232
35
|
|
233
|
-
|
234
|
-
it 'should be false' do
|
235
|
-
allow_unencrypted_appfirewall_payloads_enabled = double(
|
236
|
-
'no_data_ex',
|
237
|
-
:read => {
|
238
|
-
:version => 1,
|
239
|
-
:applications => [
|
240
|
-
:app_id => 'app_id',
|
241
|
-
:api_key => 'api_key',
|
242
|
-
:allow_payloads => false
|
243
|
-
]
|
244
|
-
}.to_json
|
245
|
-
)
|
246
|
-
expect(File).to receive(:file?).with(
|
247
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
248
|
-
).and_return(true)
|
249
|
-
expect(File).to receive(:open).with(
|
250
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
251
|
-
).and_return(allow_unencrypted_appfirewall_payloads_enabled)
|
252
|
-
|
253
|
-
configuration = Configuration.new
|
254
|
-
|
255
|
-
expect(configuration.allow_payloads).to eq(false)
|
36
|
+
expect(config.should_instrument?('devise')).to be_falsey
|
256
37
|
end
|
257
38
|
end
|
258
39
|
end
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
:read => {
|
270
|
-
:version => 1,
|
271
|
-
:applications => [
|
272
|
-
:app_id => 'app_id',
|
273
|
-
:api_key => 'api_key',
|
274
|
-
:allow_unencrypted_appsensor_payloads => true
|
275
|
-
]
|
276
|
-
}.to_json
|
277
|
-
)
|
278
|
-
expect(File).to receive(:file?).with(
|
279
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
280
|
-
).and_return(true)
|
281
|
-
expect(File).to receive(:open).with(
|
282
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
283
|
-
).and_return(allow_unencrypted_appfirewall_payloads_enabled)
|
284
|
-
|
285
|
-
configuration = Configuration.new
|
286
|
-
|
287
|
-
ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS'] = old_allow_unencrypted_appsensor_payloads
|
288
|
-
|
289
|
-
expect(configuration.allow_payloads).to eq(false)
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
context 'TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS overrides config file' do
|
294
|
-
it 'should be false' do
|
295
|
-
old_allow_unencrypted_appfirewall_payloads = ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS']
|
296
|
-
|
297
|
-
ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS'] = 'false'
|
298
|
-
|
299
|
-
allow_unencrypted_appfirewall_payloads_enabled = double(
|
300
|
-
'no_data_ex',
|
301
|
-
:read => {
|
302
|
-
:version => 1,
|
303
|
-
:applications => [
|
304
|
-
:app_id => 'app_id',
|
305
|
-
:api_key => 'api_key',
|
306
|
-
:allow_unencrypted_appfirewall_payloads => true
|
307
|
-
]
|
308
|
-
}.to_json
|
309
|
-
)
|
310
|
-
expect(File).to receive(:file?).with(
|
311
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
312
|
-
).and_return(true)
|
313
|
-
expect(File).to receive(:open).with(
|
314
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
315
|
-
).and_return(allow_unencrypted_appfirewall_payloads_enabled)
|
316
|
-
|
317
|
-
configuration = Configuration.new
|
318
|
-
|
319
|
-
ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS'] = old_allow_unencrypted_appfirewall_payloads
|
320
|
-
|
321
|
-
expect(configuration.allow_payloads).to eq(false)
|
322
|
-
end
|
40
|
+
end
|
41
|
+
describe 'populate_configuration' do
|
42
|
+
context 'with a poor native_agent_config_response' do
|
43
|
+
it 'should not throw an error' do
|
44
|
+
native_agent_config_response = {}
|
45
|
+
|
46
|
+
config = Configuration.new
|
47
|
+
expect do
|
48
|
+
config.populate_configuration(native_agent_config_response)
|
49
|
+
end.not_to raise_error
|
323
50
|
end
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
]
|
346
|
-
}.to_json
|
347
|
-
)
|
348
|
-
expect(File).to receive(:file?).with(
|
349
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
350
|
-
).and_return(true)
|
351
|
-
expect(File).to receive(:open).with(
|
352
|
-
File.join(Dir.getwd, 'config/tcell_agent.config')
|
353
|
-
).and_return(allow_unencrypted_appfirewall_payloads_enabled)
|
354
|
-
|
355
|
-
configuration = Configuration.new
|
356
|
-
|
357
|
-
ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS'] = old_allow_unencrypted_appsensor_payloads
|
358
|
-
ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS'] = old_allow_unencrypted_appfirewall_payloads
|
359
|
-
ENV['TCELL_AGENT_ALLOW_PAYLOADS'] = old_tcell_agent_allow_payloads
|
360
|
-
|
361
|
-
expect(configuration.allow_payloads).to eq(false)
|
362
|
-
end
|
51
|
+
end
|
52
|
+
context 'with an elaborate native_agent_config_response' do
|
53
|
+
it 'should set all the correct configurations' do
|
54
|
+
native_agent_config_response = { 'enabled' => true,
|
55
|
+
'disabled_instrumentation' => %w[devise doorkeeper],
|
56
|
+
'update_policy' => 'true',
|
57
|
+
'applications' => { 'first' => { 'app_id' => 'app_id_placeholder',
|
58
|
+
'api_key' => 'api_key_paceholder',
|
59
|
+
'hmac_key' => 'hmac_key_placeholder',
|
60
|
+
'password_hmac_key' => 'password_hmac_key_placeholder',
|
61
|
+
'proxy_config' => { 'reverse_proxy' => true,
|
62
|
+
'reverse_proxy_ip_address_header' => 'X-Forwarded-For' } } },
|
63
|
+
'endpoint_config' => { 'api_url' => 'https://us.agent.tcell.insight.rapid7.com/api/v1' },
|
64
|
+
'ruby_config' => { 'enable_policy_polling' => true } }
|
65
|
+
|
66
|
+
config = Configuration.new
|
67
|
+
config.populate_configuration(native_agent_config_response)
|
68
|
+
|
69
|
+
expect(config.disabled_instrumentation).to be_a(Set)
|
70
|
+
expect(config.disabled_instrumentation).to include('devise', 'doorkeeper')
|
71
|
+
expect(config.enable_intercept_requests).to be_truthy
|
363
72
|
end
|
364
73
|
end
|
365
74
|
end
|
@@ -26,56 +26,30 @@ module TCellAgent
|
|
26
26
|
|
27
27
|
describe 'manually requiring auth hooks' do
|
28
28
|
before(:all) do
|
29
|
-
|
29
|
+
load 'lib/tcell_agent/hooks/login_fraud.rb'
|
30
|
+
load 'spec/support/force_logger_mocking.rb'
|
30
31
|
end
|
31
32
|
|
32
33
|
describe 'Using generic interface' do
|
33
34
|
context 'with a login failure' do
|
34
35
|
context 'with login_failed_enabled set to true' do
|
35
36
|
it 'should report the login failure' do
|
36
|
-
login_fraud = double('login_fraud', :
|
37
|
-
|
38
|
-
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LOGINFRAUD).and_return(
|
39
|
-
login_fraud
|
40
|
-
)
|
41
|
-
expect(TCellAgent).to receive(:send_event).with(
|
42
|
-
{
|
43
|
-
'event_type' => 'login',
|
44
|
-
'header_keys' => %w[USER_AGENT X_FORWARDED_FOR],
|
45
|
-
'user_agent' => 'user_agent',
|
46
|
-
'referrer' => 'http://tcell.tcell.io/?utm_campaign=',
|
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'
|
52
|
-
}
|
53
|
-
)
|
54
|
-
|
37
|
+
login_fraud = double('login_fraud', :login_failed_enabled => true)
|
55
38
|
status = Hooks::V1::Login::LOGIN_FAILURE
|
56
39
|
header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
|
57
40
|
document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
|
58
41
|
referrer = 'http://tcell.tcell.io/?utm_campaign=some-source'
|
59
42
|
|
60
|
-
|
61
|
-
|
62
|
-
)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LOGINFRAUD).and_return(
|
71
|
-
login_fraud
|
43
|
+
expect(TCellAgent).to receive(:policy).with(
|
44
|
+
TCellAgent::PolicyTypes::LOGINFRAUD
|
45
|
+
).and_return(login_fraud)
|
46
|
+
expect(login_fraud).to receive(:report_login_failure).with(
|
47
|
+
'user_id',
|
48
|
+
nil,
|
49
|
+
header_keys,
|
50
|
+
nil,
|
51
|
+
anything
|
72
52
|
)
|
73
|
-
expect(TCellAgent).to_not receive(:send_event)
|
74
|
-
|
75
|
-
status = Hooks::V1::Login::LOGIN_FAILURE
|
76
|
-
header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
|
77
|
-
document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
|
78
|
-
referrer = 'http://tcell.tcell.io/?utm_campaign=some-source'
|
79
53
|
|
80
54
|
Hooks::V1::Login.register_login_event(
|
81
55
|
status, 'session_id', 'user_agent', referrer, '1.1.1.1', header_keys, 'user_id', document_uri
|
@@ -87,49 +61,20 @@ module TCellAgent
|
|
87
61
|
context 'with a login success' do
|
88
62
|
context 'with login_success_enabled set to true' do
|
89
63
|
it 'should report the login success' do
|
90
|
-
login_fraud = double('login_fraud', :
|
91
|
-
|
92
|
-
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LOGINFRAUD).and_return(
|
93
|
-
login_fraud
|
94
|
-
)
|
95
|
-
expect(TCellAgent).to receive(:send_event).with(
|
96
|
-
{
|
97
|
-
'event_type' => 'login',
|
98
|
-
'header_keys' => %w[USER_AGENT X_FORWARDED_FOR],
|
99
|
-
'user_agent' => 'user_agent',
|
100
|
-
'referrer' => 'http://tcell.tcell.io/?utm_campaign=',
|
101
|
-
'remote_addr' => '1.1.1.1',
|
102
|
-
'user_id' => 'user_id',
|
103
|
-
'document_uri' => 'http://tcell.tcell.io/login?param_name=',
|
104
|
-
'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
|
105
|
-
'event_name' => 'login-success'
|
106
|
-
}
|
107
|
-
)
|
108
|
-
|
64
|
+
login_fraud = double('login_fraud', :login_success_enabled => true)
|
109
65
|
status = Hooks::V1::Login::LOGIN_SUCCESS
|
110
66
|
header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
|
111
67
|
document_uri = 'http://tcell.tcell.io/login?param_name=param_value'
|
112
68
|
referrer = 'http://tcell.tcell.io/?utm_campaign=some-source'
|
113
69
|
|
114
|
-
Hooks::V1::Login.register_login_event(
|
115
|
-
status, 'session_id', 'user_agent', referrer, '1.1.1.1', header_keys, 'user_id', document_uri
|
116
|
-
)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'with login_success_enabled set to false' do
|
121
|
-
it 'should NOT report the login success' do
|
122
|
-
login_fraud = double('login_fraud', :enabled => true, :login_success_enabled => false)
|
123
|
-
|
124
70
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LOGINFRAUD).and_return(
|
125
71
|
login_fraud
|
126
72
|
)
|
127
|
-
expect(
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
referrer = 'http://tcell.tcell.io/?utm_campaign=some-source'
|
73
|
+
expect(login_fraud).to receive(:report_login_success).with(
|
74
|
+
'user_id',
|
75
|
+
header_keys,
|
76
|
+
anything
|
77
|
+
)
|
133
78
|
|
134
79
|
Hooks::V1::Login.register_login_event(
|
135
80
|
status, 'session_id', 'user_agent', referrer, '1.1.1.1', header_keys, 'user_id', document_uri
|
@@ -140,15 +85,17 @@ module TCellAgent
|
|
140
85
|
|
141
86
|
context 'with an unknown status' do
|
142
87
|
it 'should log the error' do
|
143
|
-
login_fraud = double('login_fraud'
|
88
|
+
login_fraud = double('login_fraud')
|
144
89
|
logger = double('logger')
|
145
90
|
|
146
|
-
expect(TCellAgent).to receive(:policy).with(
|
147
|
-
|
148
|
-
)
|
91
|
+
expect(TCellAgent).to receive(:policy).with(
|
92
|
+
TCellAgent::PolicyTypes::LOGINFRAUD
|
93
|
+
).and_return(login_fraud)
|
149
94
|
expect(TCellAgent).to_not receive(:send_event)
|
150
|
-
expect(TCellAgent).to receive(:
|
151
|
-
expect(logger).to receive(:error).with(
|
95
|
+
expect(TCellAgent::Hooks::LoginFraud).to receive(:get_logger).and_return(logger)
|
96
|
+
expect(logger).to receive(:error).with(
|
97
|
+
'Unkown login status: mumbo-jumbo'
|
98
|
+
)
|
152
99
|
|
153
100
|
status = 'mumbo-jumbo'
|
154
101
|
header_keys = %w[HTTP_USER_AGENT HTTP_X_FORWARDED_FOR]
|
@@ -166,12 +113,12 @@ module TCellAgent
|
|
166
113
|
context 'with a login failure' do
|
167
114
|
context 'with login_failed_enabled set to true' do
|
168
115
|
it 'should report the login failure' do
|
169
|
-
login_fraud = double('login_fraud', :
|
116
|
+
login_fraud = double('login_fraud', :login_failed_enabled => true)
|
170
117
|
rails_request = double('rails_request')
|
171
118
|
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
172
119
|
tcell_data.user_agent = 'user_agent'
|
173
120
|
tcell_data.referrer = 'http://tcell.tcell.io/?utm_campaign=some-source'
|
174
|
-
tcell_data.
|
121
|
+
tcell_data.remote_address = '1.1.1.1'
|
175
122
|
tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
|
176
123
|
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
|
177
124
|
request_env = {
|
@@ -185,18 +132,12 @@ module TCellAgent
|
|
185
132
|
)
|
186
133
|
expect(rails_request).to receive(:env).and_return(request_env)
|
187
134
|
expect(rails_request).to receive(:env).and_return(request_env)
|
188
|
-
expect(
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
'remote_addr' => '1.1.1.1',
|
195
|
-
'user_id' => 'user_id',
|
196
|
-
'document_uri' => 'http://tcell.tcell.io/login?param_name=',
|
197
|
-
'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
|
198
|
-
'event_name' => 'login-failure'
|
199
|
-
}
|
135
|
+
expect(login_fraud).to receive(:report_login_failure).with(
|
136
|
+
'user_id',
|
137
|
+
nil,
|
138
|
+
request_env,
|
139
|
+
nil,
|
140
|
+
anything
|
200
141
|
)
|
201
142
|
|
202
143
|
status = Hooks::V1::Login::LOGIN_FAILURE
|
@@ -206,48 +147,17 @@ module TCellAgent
|
|
206
147
|
)
|
207
148
|
end
|
208
149
|
end
|
209
|
-
|
210
|
-
context 'with login_failed_enabled set to false' do
|
211
|
-
it 'should NOT report the login failure' do
|
212
|
-
login_fraud = double('login_fraud', :enabled => true, :login_failed_enabled => false)
|
213
|
-
rails_request = double('rails_request')
|
214
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
215
|
-
tcell_data.user_agent = 'user_agent'
|
216
|
-
tcell_data.referrer = 'http://tcell.tcell.io/?utm_campaign='
|
217
|
-
tcell_data.ip_address = '1.1.1.1'
|
218
|
-
tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
|
219
|
-
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
|
220
|
-
request_env = {
|
221
|
-
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
222
|
-
'HTTP_USER_AGENT' => true,
|
223
|
-
'HTTP_X_FORWARDED_FOR' => true
|
224
|
-
}
|
225
|
-
|
226
|
-
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LOGINFRAUD).and_return(
|
227
|
-
login_fraud
|
228
|
-
)
|
229
|
-
expect(rails_request).to receive(:env).and_return(request_env)
|
230
|
-
expect(rails_request).to receive(:env).and_return(request_env)
|
231
|
-
expect(TCellAgent).to_not receive(:send_event)
|
232
|
-
|
233
|
-
status = Hooks::V1::Login::LOGIN_FAILURE
|
234
|
-
|
235
|
-
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
236
|
-
status, rails_request, 'user_id'
|
237
|
-
)
|
238
|
-
end
|
239
|
-
end
|
240
150
|
end
|
241
151
|
|
242
152
|
context 'with a login success' do
|
243
153
|
context 'with login_success_enabled set to true' do
|
244
154
|
it 'should report the login success' do
|
245
|
-
login_fraud = double('login_fraud', :
|
155
|
+
login_fraud = double('login_fraud', :login_success_enabled => true)
|
246
156
|
rails_request = double('rails_request')
|
247
157
|
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
248
158
|
tcell_data.user_agent = 'user_agent'
|
249
159
|
tcell_data.referrer = 'http://tcell.tcell.io/?utm_campaign=some-source'
|
250
|
-
tcell_data.
|
160
|
+
tcell_data.remote_address = '1.1.1.1'
|
251
161
|
tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
|
252
162
|
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
|
253
163
|
request_env = {
|
@@ -261,18 +171,10 @@ module TCellAgent
|
|
261
171
|
)
|
262
172
|
expect(rails_request).to receive(:env).and_return(request_env)
|
263
173
|
expect(rails_request).to receive(:env).and_return(request_env)
|
264
|
-
expect(
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
'user_agent' => 'user_agent',
|
269
|
-
'referrer' => 'http://tcell.tcell.io/?utm_campaign=',
|
270
|
-
'remote_addr' => '1.1.1.1',
|
271
|
-
'user_id' => 'user_id',
|
272
|
-
'document_uri' => 'http://tcell.tcell.io/login?param_name=',
|
273
|
-
'session' => '48c0ce7961d8d5d4bd57bd77976b3d38',
|
274
|
-
'event_name' => 'login-success'
|
275
|
-
}
|
174
|
+
expect(login_fraud).to receive(:report_login_success).with(
|
175
|
+
'user_id',
|
176
|
+
request_env,
|
177
|
+
anything
|
276
178
|
)
|
277
179
|
|
278
180
|
status = Hooks::V1::Login::LOGIN_SUCCESS
|
@@ -282,48 +184,17 @@ module TCellAgent
|
|
282
184
|
)
|
283
185
|
end
|
284
186
|
end
|
285
|
-
|
286
|
-
context 'with login_success_enabled set to false' do
|
287
|
-
it 'should NOT report the login success' do
|
288
|
-
login_fraud = double('login_fraud', :enabled => true, :login_success_enabled => false)
|
289
|
-
rails_request = double('rails_request')
|
290
|
-
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
291
|
-
tcell_data.user_agent = 'user_agent'
|
292
|
-
tcell_data.referrer = 'http://tcell.tcell.io/?utm_campaign=some-source'
|
293
|
-
tcell_data.ip_address = '1.1.1.1'
|
294
|
-
tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
|
295
|
-
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
|
296
|
-
request_env = {
|
297
|
-
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
298
|
-
'HTTP_USER_AGENT' => true,
|
299
|
-
'HTTP_X_FORWARDED_FOR' => true
|
300
|
-
}
|
301
|
-
|
302
|
-
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LOGINFRAUD).and_return(
|
303
|
-
login_fraud
|
304
|
-
)
|
305
|
-
expect(rails_request).to receive(:env).and_return(request_env)
|
306
|
-
expect(rails_request).to receive(:env).and_return(request_env)
|
307
|
-
expect(TCellAgent).to_not receive(:send_event)
|
308
|
-
|
309
|
-
status = Hooks::V1::Login::LOGIN_SUCCESS
|
310
|
-
|
311
|
-
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
312
|
-
status, rails_request, 'user_id'
|
313
|
-
)
|
314
|
-
end
|
315
|
-
end
|
316
187
|
end
|
317
188
|
|
318
189
|
context 'with an unknown status' do
|
319
190
|
it 'should log the error' do
|
320
|
-
login_fraud = double('login_fraud', :
|
191
|
+
login_fraud = double('login_fraud', :login_failed_enabled => true)
|
321
192
|
logger = double('logger')
|
322
193
|
rails_request = double('rails_request')
|
323
194
|
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
324
195
|
tcell_data.user_agent = 'user_agent'
|
325
196
|
tcell_data.referrer = 'http://tcell.tcell.io/?utm_campaign=some-source'
|
326
|
-
tcell_data.
|
197
|
+
tcell_data.remote_address = '1.1.1.1'
|
327
198
|
tcell_data.path = 'http://tcell.tcell.io/login?param_name=param_value'
|
328
199
|
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac('session_id')
|
329
200
|
request_env = {
|
@@ -338,8 +209,10 @@ module TCellAgent
|
|
338
209
|
expect(rails_request).to receive(:env).and_return(request_env)
|
339
210
|
expect(rails_request).to receive(:env).and_return(request_env)
|
340
211
|
expect(TCellAgent).to_not receive(:send_event)
|
341
|
-
expect(TCellAgent).to receive(:
|
342
|
-
expect(logger).to receive(:error).with(
|
212
|
+
expect(TCellAgent::Hooks::LoginFraud).to receive(:get_logger).and_return(logger)
|
213
|
+
expect(logger).to receive(:error).with(
|
214
|
+
'Unkown login status: mumbo-jumbo'
|
215
|
+
)
|
343
216
|
|
344
217
|
status = 'mumbo-jumbo'
|
345
218
|
|