tcell_agent 0.2.29 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.txt +7 -0
- data/bin/tcell_agent +9 -0
- data/lib/tcell_agent/agent/policy_manager.rb +3 -0
- data/lib/tcell_agent/agent/policy_types.rb +4 -1
- data/lib/tcell_agent/appsensor/injections_matcher.rb +20 -0
- data/lib/tcell_agent/appsensor/injections_reporter.rb +15 -56
- data/lib/tcell_agent/appsensor/meta_data.rb +56 -2
- data/lib/tcell_agent/appsensor/rules/baserules.json +371 -138
- data/lib/tcell_agent/cmdi.rb +113 -0
- data/lib/tcell_agent/config/unknown_options.rb +2 -0
- data/lib/tcell_agent/configuration.rb +30 -16
- data/lib/tcell_agent/hooks/login_fraud.rb +79 -0
- data/lib/tcell_agent/instrumentation.rb +6 -11
- data/lib/tcell_agent/patches/meta_data.rb +14 -11
- data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +5 -9
- data/lib/tcell_agent/policies/appsensor_policy.rb +22 -206
- data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -2
- data/lib/tcell_agent/policies/command_injection_policy.rb +196 -0
- data/lib/tcell_agent/policies/content_security_policy.rb +3 -2
- data/lib/tcell_agent/policies/dataloss_policy.rb +3 -1
- data/lib/tcell_agent/policies/honeytokens_policy.rb +3 -1
- data/lib/tcell_agent/policies/http_redirect_policy.rb +51 -37
- data/lib/tcell_agent/policies/http_tx_policy.rb +5 -1
- data/lib/tcell_agent/policies/login_fraud_policy.rb +6 -1
- data/lib/tcell_agent/policies/patches_policy.rb +3 -1
- data/lib/tcell_agent/policies/policy.rb +10 -0
- data/lib/tcell_agent/policies/secure_headers_policy.rb +5 -2
- data/lib/tcell_agent/rails/auth/devise.rb +12 -23
- data/lib/tcell_agent/rails/csrf_exception.rb +1 -1
- data/lib/tcell_agent/rails/dlp.rb +50 -54
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +0 -1
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +0 -1
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +7 -10
- data/lib/tcell_agent/rails/on_start.rb +0 -1
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +4 -4
- data/lib/tcell_agent/rails.rb +0 -2
- data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
- data/lib/tcell_agent/rust/libtcellagent-0.6.1.so +0 -0
- data/lib/tcell_agent/rust/models.rb +61 -0
- data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +112 -0
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +25 -21
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +31 -24
- data/lib/tcell_agent/sensor_events/command_injection.rb +58 -0
- data/lib/tcell_agent/sensor_events/discovery.rb +1 -1
- data/lib/tcell_agent/sensor_events/login_fraud.rb +3 -13
- data/lib/tcell_agent/sensor_events/sensor.rb +81 -77
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +8 -0
- data/lib/tcell_agent/start_background_thread.rb +12 -3
- data/lib/tcell_agent/utils/io.rb +4 -1
- data/lib/tcell_agent/utils/params.rb +1 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/lib/tcell_agent.rb +0 -1
- data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +27 -9
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +143 -193
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +67 -0
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -10
- data/spec/lib/tcell_agent/cmdi_spec.rb +748 -0
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +8 -0
- data/spec/lib/tcell_agent/configuration_spec.rb +138 -6
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +357 -0
- data/spec/lib/tcell_agent/patches/block_rule_spec.rb +70 -87
- data/spec/lib/tcell_agent/patches_spec.rb +9 -4
- data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +186 -9
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +309 -484
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +736 -0
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +222 -41
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +56 -32
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +161 -85
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +40 -72
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +267 -0
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +20 -15
- data/spec/spec_helper.rb +0 -9
- data/tcell_agent.gemspec +8 -3
- metadata +40 -39
- data/lib/tcell_agent/appsensor/sensor.rb +0 -52
- data/lib/tcell_agent/policies/appsensor/database_sensor.rb +0 -56
- data/lib/tcell_agent/policies/appsensor/misc_sensor.rb +0 -59
- data/lib/tcell_agent/policies/appsensor/payloads_policy.rb +0 -150
- data/lib/tcell_agent/policies/appsensor/request_size_sensor.rb +0 -25
- data/lib/tcell_agent/policies/appsensor/response_codes_sensor.rb +0 -73
- data/lib/tcell_agent/policies/appsensor/response_size_sensor.rb +0 -25
- data/lib/tcell_agent/policies/appsensor/size_sensor.rb +0 -71
- data/lib/tcell_agent/policies/appsensor/user_agent_sensor.rb +0 -47
- data/lib/tcell_agent/rails/auth/hooks.rb +0 -79
- data/lib/tcell_agent/sensor_events/util/redirect_utils.rb +0 -22
- data/spec/lib/tcell_agent/policies/appsensor/database_sensor_spec.rb +0 -165
- data/spec/lib/tcell_agent/policies/appsensor/misc_sensor_spec.rb +0 -429
- data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_apply_spec.rb +0 -466
- data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_from_json_spec.rb +0 -890
- data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_log_spec.rb +0 -417
- data/spec/lib/tcell_agent/policies/appsensor/request_size_sensor_spec.rb +0 -236
- data/spec/lib/tcell_agent/policies/appsensor/response_codes_sensor_spec.rb +0 -297
- data/spec/lib/tcell_agent/policies/appsensor/response_size_sensor_spec.rb +0 -241
- data/spec/lib/tcell_agent/policies/appsensor/user_agent_sensor_spec.rb +0 -172
- data/spec/lib/tcell_agent/rails/auth/hooks_spec.rb +0 -246
- data/spec/lib/tcell_agent/sensor_events/util/redirect_utils_spec.rb +0 -25
- data/spec/support/resources/baserules.json +0 -155
@@ -10,6 +10,7 @@ module TCellAgent
|
|
10
10
|
|
11
11
|
orig_allow_uap = ENV.fetch("TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS", nil)
|
12
12
|
orig_allow_uafp = ENV.fetch("TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS", nil)
|
13
|
+
orig_allow_ap = ENV.fetch("TCELL_AGENT_ALLOW_PAYLOADS", nil)
|
13
14
|
orig_demomode = ENV.fetch("TCELL_DEMOMODE", nil)
|
14
15
|
orig_agent_home = ENV.fetch("TCELL_AGENT_HOME", nil)
|
15
16
|
orig_agent_log_dir = ENV.fetch("TCELL_AGENT_LOG_DIR", nil)
|
@@ -24,6 +25,7 @@ module TCellAgent
|
|
24
25
|
ENV["TCELL_HACK"] = "hack the system"
|
25
26
|
ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS"] = "valid"
|
26
27
|
ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS"] = "valid"
|
28
|
+
ENV["TCELL_AGENT_ALLOW_PAYLOADS"] = "valid"
|
27
29
|
ENV["TCELL_DEMOMODE"] = "valid"
|
28
30
|
ENV["TCELL_AGENT_HOME"] = "valid"
|
29
31
|
ENV["TCELL_AGENT_LOG_DIR"] = "valid"
|
@@ -49,6 +51,11 @@ module TCellAgent
|
|
49
51
|
else
|
50
52
|
ENV.delete "TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS"
|
51
53
|
end
|
54
|
+
if orig_allow_ap
|
55
|
+
ENV["TCELL_AGENT_ALLOW_PAYLOADS"] = orig_allow_ap
|
56
|
+
else
|
57
|
+
ENV.delete "TCELL_AGENT_ALLOW_PAYLOADS"
|
58
|
+
end
|
52
59
|
if orig_demomode
|
53
60
|
ENV["TCELL_DEMOMODE"] = orig_demomode
|
54
61
|
else
|
@@ -135,6 +142,7 @@ module TCellAgent
|
|
135
142
|
"event_batch_size_limit" => 50,
|
136
143
|
"allow_unencrypted_appsensor_payloads" => true,
|
137
144
|
"allow_unencrypted_appfirewall_payloads" => true,
|
145
|
+
"allow_payloads" => true,
|
138
146
|
"data_exposure" => {
|
139
147
|
"data_ex_level" => "boo",
|
140
148
|
"max_data_ex_db_records_per_request" => 10000},
|
@@ -178,10 +178,10 @@ module TCellAgent
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
|
-
describe "#
|
181
|
+
describe "#allow_payloads" do
|
182
182
|
context "setting it via config" do
|
183
183
|
context "using allow_unencrypted_appsensor_payloads" do
|
184
|
-
it "should be
|
184
|
+
it "should be false" do
|
185
185
|
allow_unencrypted_appfirewall_payloads_enabled = double(
|
186
186
|
"no_data_ex",
|
187
187
|
read: {
|
@@ -189,7 +189,7 @@ module TCellAgent
|
|
189
189
|
applications: [
|
190
190
|
app_id: "app_id",
|
191
191
|
api_key: "api_key",
|
192
|
-
allow_unencrypted_appsensor_payloads:
|
192
|
+
allow_unencrypted_appsensor_payloads: false
|
193
193
|
]
|
194
194
|
}.to_json
|
195
195
|
)
|
@@ -202,12 +202,102 @@ module TCellAgent
|
|
202
202
|
|
203
203
|
configuration = Configuration.new
|
204
204
|
|
205
|
-
expect(configuration.
|
205
|
+
expect(configuration.allow_payloads).to eq(false)
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
209
|
context "using allow_unencrypted_appfirewall_payloads" do
|
210
|
-
it "should be
|
210
|
+
it "should be false" do
|
211
|
+
allow_unencrypted_appfirewall_payloads_enabled = double(
|
212
|
+
"no_data_ex",
|
213
|
+
read: {
|
214
|
+
version: 1,
|
215
|
+
applications: [
|
216
|
+
app_id: "app_id",
|
217
|
+
api_key: "api_key",
|
218
|
+
allow_unencrypted_appfirewall_payloads: false
|
219
|
+
]
|
220
|
+
}.to_json
|
221
|
+
)
|
222
|
+
expect(File).to receive(:file?).with(
|
223
|
+
File.join(Dir.getwd, "config/tcell_agent.config")
|
224
|
+
).and_return(true)
|
225
|
+
expect(File).to receive(:open).with(
|
226
|
+
File.join(Dir.getwd, "config/tcell_agent.config")
|
227
|
+
).and_return(allow_unencrypted_appfirewall_payloads_enabled)
|
228
|
+
|
229
|
+
configuration = Configuration.new
|
230
|
+
|
231
|
+
expect(configuration.allow_payloads).to eq(false)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context "using allow_payloads" do
|
236
|
+
it "should be false" do
|
237
|
+
allow_unencrypted_appfirewall_payloads_enabled = double(
|
238
|
+
"no_data_ex",
|
239
|
+
read: {
|
240
|
+
version: 1,
|
241
|
+
applications: [
|
242
|
+
app_id: "app_id",
|
243
|
+
api_key: "api_key",
|
244
|
+
allow_payloads: false
|
245
|
+
]
|
246
|
+
}.to_json
|
247
|
+
)
|
248
|
+
expect(File).to receive(:file?).with(
|
249
|
+
File.join(Dir.getwd, "config/tcell_agent.config")
|
250
|
+
).and_return(true)
|
251
|
+
expect(File).to receive(:open).with(
|
252
|
+
File.join(Dir.getwd, "config/tcell_agent.config")
|
253
|
+
).and_return(allow_unencrypted_appfirewall_payloads_enabled)
|
254
|
+
|
255
|
+
configuration = Configuration.new
|
256
|
+
|
257
|
+
expect(configuration.allow_payloads).to eq(false)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context "setting it via env var" do
|
263
|
+
context "TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS overrides config file" do
|
264
|
+
it "should be false" do
|
265
|
+
old_allow_unencrypted_appsensor_payloads = ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS"]
|
266
|
+
|
267
|
+
ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS"] = "false"
|
268
|
+
|
269
|
+
allow_unencrypted_appfirewall_payloads_enabled = double(
|
270
|
+
"no_data_ex",
|
271
|
+
read: {
|
272
|
+
version: 1,
|
273
|
+
applications: [
|
274
|
+
app_id: "app_id",
|
275
|
+
api_key: "api_key",
|
276
|
+
allow_unencrypted_appsensor_payloads: true
|
277
|
+
]
|
278
|
+
}.to_json
|
279
|
+
)
|
280
|
+
expect(File).to receive(:file?).with(
|
281
|
+
File.join(Dir.getwd, "config/tcell_agent.config")
|
282
|
+
).and_return(true)
|
283
|
+
expect(File).to receive(:open).with(
|
284
|
+
File.join(Dir.getwd, "config/tcell_agent.config")
|
285
|
+
).and_return(allow_unencrypted_appfirewall_payloads_enabled)
|
286
|
+
|
287
|
+
configuration = Configuration.new
|
288
|
+
|
289
|
+
ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS"] = old_allow_unencrypted_appsensor_payloads
|
290
|
+
|
291
|
+
expect(configuration.allow_payloads).to eq(false)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
context "TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS overrides config file" do
|
296
|
+
it "should be false" do
|
297
|
+
old_allow_unencrypted_appfirewall_payloads = ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS"]
|
298
|
+
|
299
|
+
ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS"] = "false"
|
300
|
+
|
211
301
|
allow_unencrypted_appfirewall_payloads_enabled = double(
|
212
302
|
"no_data_ex",
|
213
303
|
read: {
|
@@ -228,7 +318,49 @@ module TCellAgent
|
|
228
318
|
|
229
319
|
configuration = Configuration.new
|
230
320
|
|
231
|
-
|
321
|
+
ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS"] = old_allow_unencrypted_appfirewall_payloads
|
322
|
+
|
323
|
+
expect(configuration.allow_payloads).to eq(false)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
context "TCELL_AGENT_ALLOW_PAYLOADS overrides everything else" do
|
328
|
+
it "should be false" do
|
329
|
+
old_allow_unencrypted_appsensor_payloads = ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS"]
|
330
|
+
old_allow_unencrypted_appfirewall_payloads = ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS"]
|
331
|
+
old_tcell_agent_allow_payloads = ENV["TCELL_AGENT_ALLOW_PAYLOADS"]
|
332
|
+
|
333
|
+
ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS"] = "true"
|
334
|
+
ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS"] = "true"
|
335
|
+
ENV["TCELL_AGENT_ALLOW_PAYLOADS"] = "false"
|
336
|
+
|
337
|
+
allow_unencrypted_appfirewall_payloads_enabled = double(
|
338
|
+
"no_data_ex",
|
339
|
+
read: {
|
340
|
+
version: 1,
|
341
|
+
applications: [
|
342
|
+
app_id: "app_id",
|
343
|
+
api_key: "api_key",
|
344
|
+
allow_unencrypted_appsensor_payloads: true,
|
345
|
+
allow_unencrypted_appfirewall_payloads: true,
|
346
|
+
allow_payloads: true
|
347
|
+
]
|
348
|
+
}.to_json
|
349
|
+
)
|
350
|
+
expect(File).to receive(:file?).with(
|
351
|
+
File.join(Dir.getwd, "config/tcell_agent.config")
|
352
|
+
).and_return(true)
|
353
|
+
expect(File).to receive(:open).with(
|
354
|
+
File.join(Dir.getwd, "config/tcell_agent.config")
|
355
|
+
).and_return(allow_unencrypted_appfirewall_payloads_enabled)
|
356
|
+
|
357
|
+
configuration = Configuration.new
|
358
|
+
|
359
|
+
ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS"] = old_allow_unencrypted_appsensor_payloads
|
360
|
+
ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS"] = old_allow_unencrypted_appfirewall_payloads
|
361
|
+
ENV["TCELL_AGENT_ALLOW_PAYLOADS"] = old_tcell_agent_allow_payloads
|
362
|
+
|
363
|
+
expect(configuration.allow_payloads).to eq(false)
|
232
364
|
end
|
233
365
|
end
|
234
366
|
end
|
@@ -0,0 +1,357 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module TCellAgent
|
4
|
+
|
5
|
+
module Hooks
|
6
|
+
module V1
|
7
|
+
module Frameworks
|
8
|
+
module Rails
|
9
|
+
module Login
|
10
|
+
def self.register_login_event(status, rails_request, user_id, user_valid=nil)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Hooks
|
19
|
+
module V1
|
20
|
+
module Login
|
21
|
+
LOGIN_SUCCESS = "success"
|
22
|
+
LOGIN_FAILURE = "failure"
|
23
|
+
def self.register_login_event(status, session_id, user_agent, referrer, remote_addr, header_keys, user_id, document_uri, user_valid=nil)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "manually requiring auth hooks" do
|
30
|
+
before(:all) do
|
31
|
+
require 'tcell_agent/hooks/login_fraud'
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "Using generic interface" do
|
35
|
+
context "with a login failure" do
|
36
|
+
context "with login_failed_enabled set to true" do
|
37
|
+
it "should report the login failure" do
|
38
|
+
login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
|
39
|
+
|
40
|
+
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
41
|
+
login_fraud
|
42
|
+
)
|
43
|
+
expect(TCellAgent).to receive(:send_event).with(
|
44
|
+
{
|
45
|
+
"event_type" => "login",
|
46
|
+
"header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
|
47
|
+
"user_agent" => "user_agent",
|
48
|
+
"referrer" => "referrer",
|
49
|
+
"remote_addr" => "1.1.1.1",
|
50
|
+
"user_id" => "user_id",
|
51
|
+
"document_uri" => "http://tcell.tcell.io/login?param_name=",
|
52
|
+
"session" => "48c0ce7961d8d5d4bd57bd77976b3d38",
|
53
|
+
"event_name" => "login-failure"
|
54
|
+
}
|
55
|
+
)
|
56
|
+
|
57
|
+
status = Hooks::V1::Login::LOGIN_FAILURE
|
58
|
+
header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
|
59
|
+
document_uri = "http://tcell.tcell.io/login?param_name=param_value"
|
60
|
+
|
61
|
+
Hooks::V1::Login.register_login_event(
|
62
|
+
status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with login_failed_enabled set to false" do
|
68
|
+
it "should NOT report the login failure" do
|
69
|
+
login_fraud = double("login_fraud", enabled: true, login_failed_enabled: false)
|
70
|
+
|
71
|
+
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
72
|
+
login_fraud
|
73
|
+
)
|
74
|
+
expect(TCellAgent).to_not receive(:send_event)
|
75
|
+
|
76
|
+
status = Hooks::V1::Login::LOGIN_FAILURE
|
77
|
+
header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
|
78
|
+
document_uri = "http://tcell.tcell.io/login?param_name=param_value"
|
79
|
+
|
80
|
+
Hooks::V1::Login.register_login_event(
|
81
|
+
status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "with a login success" do
|
88
|
+
context "with login_success_enabled set to true" do
|
89
|
+
it "should report the login success" do
|
90
|
+
login_fraud = double("login_fraud", enabled: true, login_success_enabled: true)
|
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" => ["USER_AGENT", "X_FORWARDED_FOR"],
|
99
|
+
"user_agent" => "user_agent",
|
100
|
+
"referrer" => "referrer",
|
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
|
+
|
109
|
+
status = Hooks::V1::Login::LOGIN_SUCCESS
|
110
|
+
header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
|
111
|
+
document_uri = "http://tcell.tcell.io/login?param_name=param_value"
|
112
|
+
|
113
|
+
Hooks::V1::Login.register_login_event(
|
114
|
+
status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with login_success_enabled set to false" do
|
120
|
+
it "should NOT report the login success" do
|
121
|
+
login_fraud = double("login_fraud", enabled: true, login_success_enabled: false)
|
122
|
+
|
123
|
+
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
124
|
+
login_fraud
|
125
|
+
)
|
126
|
+
expect(TCellAgent).to_not receive(:send_event)
|
127
|
+
|
128
|
+
status = Hooks::V1::Login::LOGIN_SUCCESS
|
129
|
+
header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
|
130
|
+
document_uri = "http://tcell.tcell.io/login?param_name=param_value"
|
131
|
+
|
132
|
+
Hooks::V1::Login.register_login_event(
|
133
|
+
status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
|
134
|
+
)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "with an unknown status" do
|
140
|
+
it "should log the error" do
|
141
|
+
login_fraud = double("login_fraud", enabled: true)
|
142
|
+
logger = double("logger")
|
143
|
+
|
144
|
+
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
145
|
+
login_fraud
|
146
|
+
)
|
147
|
+
expect(TCellAgent).to_not receive(:send_event)
|
148
|
+
expect(TCellAgent).to receive(:logger).and_return(logger)
|
149
|
+
expect(logger).to receive(:error).with("Unkown login status: mumbo-jumbo")
|
150
|
+
|
151
|
+
status = "mumbo-jumbo"
|
152
|
+
header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
|
153
|
+
document_uri = "http://tcell.tcell.io/login?param_name=param_value"
|
154
|
+
|
155
|
+
Hooks::V1::Login.register_login_event(
|
156
|
+
status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
|
157
|
+
)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "Using rails interface" do
|
163
|
+
context "with a login failure" do
|
164
|
+
context "with login_failed_enabled set to true" do
|
165
|
+
it "should report the login failure" do
|
166
|
+
login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
|
167
|
+
rails_request = double("rails_request")
|
168
|
+
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
169
|
+
tcell_data.user_agent = "user_agent"
|
170
|
+
tcell_data.referrer = "referrer"
|
171
|
+
tcell_data.ip_address = "1.1.1.1"
|
172
|
+
tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
|
173
|
+
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
|
174
|
+
request_env = {
|
175
|
+
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
176
|
+
"HTTP_USER_AGENT" => true,
|
177
|
+
"HTTP_X_FORWARDED_FOR" => true
|
178
|
+
}
|
179
|
+
|
180
|
+
|
181
|
+
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
182
|
+
login_fraud
|
183
|
+
)
|
184
|
+
expect(rails_request).to receive(:env).and_return(request_env)
|
185
|
+
expect(rails_request).to receive(:env).and_return(request_env)
|
186
|
+
expect(TCellAgent).to receive(:send_event).with(
|
187
|
+
{
|
188
|
+
"event_type" => "login",
|
189
|
+
"header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
|
190
|
+
"user_agent" => "user_agent",
|
191
|
+
"referrer" => "referrer",
|
192
|
+
"remote_addr" => "1.1.1.1",
|
193
|
+
"user_id" => "user_id",
|
194
|
+
"document_uri" => "http://tcell.tcell.io/login?param_name=",
|
195
|
+
"session" => "48c0ce7961d8d5d4bd57bd77976b3d38",
|
196
|
+
"event_name" => "login-failure"
|
197
|
+
}
|
198
|
+
)
|
199
|
+
|
200
|
+
status = Hooks::V1::Login::LOGIN_FAILURE
|
201
|
+
|
202
|
+
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
203
|
+
status, rails_request, "user_id"
|
204
|
+
)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context "with login_failed_enabled set to false" do
|
209
|
+
it "should NOT report the login failure" do
|
210
|
+
login_fraud = double("login_fraud", enabled: true, login_failed_enabled: false)
|
211
|
+
rails_request = double("rails_request")
|
212
|
+
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
213
|
+
tcell_data.user_agent = "user_agent"
|
214
|
+
tcell_data.referrer = "referrer"
|
215
|
+
tcell_data.ip_address = "1.1.1.1"
|
216
|
+
tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
|
217
|
+
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
|
218
|
+
request_env = {
|
219
|
+
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
220
|
+
"HTTP_USER_AGENT" => true,
|
221
|
+
"HTTP_X_FORWARDED_FOR" => true
|
222
|
+
}
|
223
|
+
|
224
|
+
|
225
|
+
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
226
|
+
login_fraud
|
227
|
+
)
|
228
|
+
expect(rails_request).to receive(:env).and_return(request_env)
|
229
|
+
expect(rails_request).to receive(:env).and_return(request_env)
|
230
|
+
expect(TCellAgent).to_not receive(:send_event)
|
231
|
+
|
232
|
+
status = Hooks::V1::Login::LOGIN_FAILURE
|
233
|
+
|
234
|
+
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
235
|
+
status, rails_request, "user_id"
|
236
|
+
)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context "with a login success" do
|
242
|
+
context "with login_success_enabled set to true" do
|
243
|
+
it "should report the login success" do
|
244
|
+
login_fraud = double("login_fraud", enabled: true, login_success_enabled: true)
|
245
|
+
rails_request = double("rails_request")
|
246
|
+
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
247
|
+
tcell_data.user_agent = "user_agent"
|
248
|
+
tcell_data.referrer = "referrer"
|
249
|
+
tcell_data.ip_address = "1.1.1.1"
|
250
|
+
tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
|
251
|
+
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
|
252
|
+
request_env = {
|
253
|
+
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
254
|
+
"HTTP_USER_AGENT" => true,
|
255
|
+
"HTTP_X_FORWARDED_FOR" => true
|
256
|
+
}
|
257
|
+
|
258
|
+
|
259
|
+
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
260
|
+
login_fraud
|
261
|
+
)
|
262
|
+
expect(rails_request).to receive(:env).and_return(request_env)
|
263
|
+
expect(rails_request).to receive(:env).and_return(request_env)
|
264
|
+
expect(TCellAgent).to receive(:send_event).with(
|
265
|
+
{
|
266
|
+
"event_type" => "login",
|
267
|
+
"header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
|
268
|
+
"user_agent" => "user_agent",
|
269
|
+
"referrer" => "referrer",
|
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
|
+
}
|
276
|
+
)
|
277
|
+
|
278
|
+
status = Hooks::V1::Login::LOGIN_SUCCESS
|
279
|
+
|
280
|
+
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
281
|
+
status, rails_request, "user_id"
|
282
|
+
)
|
283
|
+
end
|
284
|
+
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 = "referrer"
|
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
|
+
|
303
|
+
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
304
|
+
login_fraud
|
305
|
+
)
|
306
|
+
expect(rails_request).to receive(:env).and_return(request_env)
|
307
|
+
expect(rails_request).to receive(:env).and_return(request_env)
|
308
|
+
expect(TCellAgent).to_not receive(:send_event)
|
309
|
+
|
310
|
+
status = Hooks::V1::Login::LOGIN_SUCCESS
|
311
|
+
|
312
|
+
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
313
|
+
status, rails_request, "user_id"
|
314
|
+
)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
context "with an unknown status" do
|
320
|
+
it "should log the error" do
|
321
|
+
login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
|
322
|
+
logger = double("logger")
|
323
|
+
rails_request = double("rails_request")
|
324
|
+
tcell_data = TCellAgent::Instrumentation::TCellData.new
|
325
|
+
tcell_data.user_agent = "user_agent"
|
326
|
+
tcell_data.referrer = "referrer"
|
327
|
+
tcell_data.ip_address = "1.1.1.1"
|
328
|
+
tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
|
329
|
+
tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
|
330
|
+
request_env = {
|
331
|
+
TCellAgent::Instrumentation::TCELL_ID => tcell_data,
|
332
|
+
"HTTP_USER_AGENT" => true,
|
333
|
+
"HTTP_X_FORWARDED_FOR" => true
|
334
|
+
}
|
335
|
+
|
336
|
+
|
337
|
+
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
|
338
|
+
login_fraud
|
339
|
+
)
|
340
|
+
expect(rails_request).to receive(:env).and_return(request_env)
|
341
|
+
expect(rails_request).to receive(:env).and_return(request_env)
|
342
|
+
expect(TCellAgent).to_not receive(:send_event)
|
343
|
+
expect(TCellAgent).to receive(:logger).and_return(logger)
|
344
|
+
expect(logger).to receive(:error).with("Unkown login status: mumbo-jumbo")
|
345
|
+
|
346
|
+
status = "mumbo-jumbo"
|
347
|
+
|
348
|
+
Hooks::V1::Frameworks::Rails::Login.register_login_event(
|
349
|
+
status, rails_request, "user_id"
|
350
|
+
)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
end
|
356
|
+
|
357
|
+
end
|