tcell_agent 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -4,61 +4,61 @@ module TCellAgent
|
|
|
4
4
|
module Policies
|
|
5
5
|
describe SecureHeadersPolicy do
|
|
6
6
|
secure_headers_policy_json = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
{
|
|
7
|
+
'policy_id' => '01a1',
|
|
8
|
+
'headers' => [
|
|
9
|
+
{ 'name' => 'x-permitted-cross-domain-policies', 'value' => 'value123' }
|
|
10
10
|
]
|
|
11
11
|
}
|
|
12
12
|
secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
|
|
13
|
-
context
|
|
14
|
-
it
|
|
15
|
-
expect(secure_headers_policy.headers[0].name).to eq(
|
|
16
|
-
expect(secure_headers_policy.headers[0].value).to eq(
|
|
13
|
+
context 'secure header example' do
|
|
14
|
+
it 'returns true' do
|
|
15
|
+
expect(secure_headers_policy.headers[0].name).to eq('x-permitted-cross-domain-policies')
|
|
16
|
+
expect(secure_headers_policy.headers[0].value).to eq('value123')
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
describe SecureHeadersPolicy do
|
|
21
21
|
secure_headers_policy_json = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
{
|
|
22
|
+
'policy_id' => '01a1',
|
|
23
|
+
'headers' => [
|
|
24
|
+
{ 'name' => 'x-frame-options', 'value' => 'DENY' },
|
|
25
|
+
{ 'name' => 'x-xss-protection', 'value' => '1; mode=block' }
|
|
26
26
|
]
|
|
27
27
|
}
|
|
28
28
|
secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
|
|
29
|
-
context
|
|
30
|
-
it
|
|
31
|
-
expect(secure_headers_policy.headers[0].name).to eq(
|
|
32
|
-
expect(secure_headers_policy.headers[0].value).to eq(
|
|
33
|
-
expect(secure_headers_policy.headers[1].name).to eq(
|
|
34
|
-
expect(secure_headers_policy.headers[1].value).to eq(
|
|
29
|
+
context 'secure headers (2) example' do
|
|
30
|
+
it 'returns true' do
|
|
31
|
+
expect(secure_headers_policy.headers[0].name).to eq('x-frame-options')
|
|
32
|
+
expect(secure_headers_policy.headers[0].value).to eq('DENY')
|
|
33
|
+
expect(secure_headers_policy.headers[1].name).to eq('x-xss-protection')
|
|
34
|
+
expect(secure_headers_policy.headers[1].value).to eq('1; mode=block')
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
describe SecureHeadersPolicy do
|
|
39
39
|
secure_headers_policy_json = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{
|
|
40
|
+
'policy_id' => '01a1',
|
|
41
|
+
'headers' => [
|
|
42
|
+
{ 'name' => 'bad-header', 'value' => 'value123' }
|
|
43
43
|
]
|
|
44
44
|
}
|
|
45
45
|
secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
|
|
46
|
-
context
|
|
47
|
-
it
|
|
46
|
+
context 'secure header example, invalid header' do
|
|
47
|
+
it 'returns false' do
|
|
48
48
|
expect(secure_headers_policy.headers.length).to eq(0)
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
describe SecureHeadersPolicy do
|
|
53
53
|
secure_headers_policy_json = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{
|
|
54
|
+
'policy_id' => '01a1',
|
|
55
|
+
'headers' => [
|
|
56
|
+
{ 'name' => 'x-permitted-cross-domain-policies', 'value' => 'value123\\nabc' }
|
|
57
57
|
]
|
|
58
58
|
}
|
|
59
59
|
secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
|
|
60
|
-
context
|
|
61
|
-
it
|
|
60
|
+
context 'secure header, value is bad' do
|
|
61
|
+
it 'returns false' do
|
|
62
62
|
expect(secure_headers_policy.headers.length).to eq(0)
|
|
63
63
|
end
|
|
64
64
|
end
|
|
@@ -2,75 +2,71 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
module TCellAgent
|
|
4
4
|
module Utils
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
configuration = double("configuration")
|
|
11
|
-
request = double("request", ip: "127.0.0.0")
|
|
5
|
+
describe '.better_ip' do
|
|
6
|
+
context 'with reverse_proxy off' do
|
|
7
|
+
it 'should return the normal ip' do
|
|
8
|
+
configuration = double('configuration')
|
|
9
|
+
request = double('request', :ip => '127.0.0.0')
|
|
12
10
|
|
|
13
11
|
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
|
14
12
|
expect(configuration).to receive(:reverse_proxy).and_return(false)
|
|
15
|
-
expect(Rails.better_ip(request)).to eq(
|
|
13
|
+
expect(Rails.better_ip(request)).to eq('127.0.0.0')
|
|
16
14
|
end
|
|
17
15
|
end
|
|
18
16
|
|
|
19
|
-
context
|
|
20
|
-
context
|
|
21
|
-
it
|
|
22
|
-
configuration = double(
|
|
23
|
-
request = double(
|
|
24
|
-
env = double(
|
|
17
|
+
context 'with reverse_proxy on' do
|
|
18
|
+
context 'with empty reverse_proxy_ip_address_header' do
|
|
19
|
+
it 'should return normal ip' do
|
|
20
|
+
configuration = double('configuration')
|
|
21
|
+
request = double('request', :ip => '127.0.0.0')
|
|
22
|
+
env = double('env')
|
|
25
23
|
|
|
26
24
|
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
|
27
25
|
expect(configuration).to receive(:reverse_proxy).and_return(true)
|
|
28
26
|
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
|
29
|
-
expect(configuration).to receive(:reverse_proxy_ip_address_header).and_return(
|
|
27
|
+
expect(configuration).to receive(:reverse_proxy_ip_address_header).and_return('')
|
|
30
28
|
expect(request).to receive(:env).and_return(env)
|
|
31
|
-
expect(env).to receive(:[]).with(
|
|
32
|
-
expect(Rails.better_ip(request)).to eq(
|
|
29
|
+
expect(env).to receive(:[]).with('HTTP_X_FORWARDED_FOR').and_return('')
|
|
30
|
+
expect(Rails.better_ip(request)).to eq('127.0.0.0')
|
|
33
31
|
end
|
|
34
32
|
end
|
|
35
33
|
|
|
36
34
|
context "with reverse_proxy_ip_address_header that doesn't exist" do
|
|
37
|
-
it
|
|
38
|
-
configuration = double(
|
|
39
|
-
request = double(
|
|
40
|
-
env = double(
|
|
35
|
+
it 'should return normal ip' do
|
|
36
|
+
configuration = double('configuration')
|
|
37
|
+
request = double('request', :ip => '127.0.0.0')
|
|
38
|
+
env = double('env')
|
|
41
39
|
|
|
42
40
|
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
|
43
41
|
expect(configuration).to receive(:reverse_proxy).and_return(true)
|
|
44
42
|
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
|
45
43
|
expect(configuration).to receive(:reverse_proxy_ip_address_header).and_return(
|
|
46
|
-
|
|
44
|
+
'weird-http-proxy-header'
|
|
47
45
|
)
|
|
48
46
|
expect(request).to receive(:env).and_return(env)
|
|
49
|
-
expect(env).to receive(:[]).with(
|
|
50
|
-
expect(Rails.better_ip(request)).to eq(
|
|
47
|
+
expect(env).to receive(:[]).with('HTTP_WEIRD_HTTP_PROXY_HEADER').and_return(nil)
|
|
48
|
+
expect(Rails.better_ip(request)).to eq('127.0.0.0')
|
|
51
49
|
end
|
|
52
50
|
end
|
|
53
51
|
|
|
54
|
-
context
|
|
55
|
-
it
|
|
56
|
-
configuration = double(
|
|
57
|
-
request = double(
|
|
58
|
-
env = double(
|
|
52
|
+
context 'with reverse_proxy_ip_address_header that exists' do
|
|
53
|
+
it 'should return proxied ip' do
|
|
54
|
+
configuration = double('configuration')
|
|
55
|
+
request = double('request', :ip => '127.0.0.0')
|
|
56
|
+
env = double('env')
|
|
59
57
|
|
|
60
58
|
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
|
61
59
|
expect(configuration).to receive(:reverse_proxy).and_return(true)
|
|
62
60
|
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
|
63
61
|
expect(configuration).to receive(:reverse_proxy_ip_address_header).and_return(
|
|
64
|
-
|
|
62
|
+
'X-Real-IP'
|
|
65
63
|
)
|
|
66
64
|
expect(request).to receive(:env).and_return(env)
|
|
67
|
-
expect(env).to receive(:[]).with(
|
|
68
|
-
expect(Rails.better_ip(request)).to eq(
|
|
65
|
+
expect(env).to receive(:[]).with('HTTP_X_REAL_IP').and_return('192.168.99.100')
|
|
66
|
+
expect(Rails.better_ip(request)).to eq('192.168.99.100')
|
|
69
67
|
end
|
|
70
68
|
end
|
|
71
69
|
end
|
|
72
|
-
|
|
73
70
|
end
|
|
74
|
-
|
|
75
71
|
end
|
|
76
72
|
end
|
|
@@ -1,52 +1,55 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Logger do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
it "should skip the tcell logic" do
|
|
4
|
+
describe '#add' do
|
|
5
|
+
context 'with a warn logger' do
|
|
6
|
+
context 'writing a debug message' do
|
|
7
|
+
it 'should skip the tcell logic' do
|
|
9
8
|
expect(TCellAgent::Instrumentation).to_not receive(:safe_block_no_log)
|
|
10
9
|
|
|
11
10
|
logger = Logger.new('/dev/null')
|
|
12
11
|
|
|
13
12
|
logger.level = Logger::WARN
|
|
14
|
-
logger.add(Logger::DEBUG,
|
|
13
|
+
logger.add(Logger::DEBUG, 'This will not be logged')
|
|
15
14
|
end
|
|
16
15
|
end
|
|
17
16
|
|
|
18
|
-
context
|
|
19
|
-
it
|
|
20
|
-
expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
|
|
17
|
+
context 'writing a warn message' do
|
|
18
|
+
it 'should run the tcell logic' do
|
|
19
|
+
expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
|
|
20
|
+
'Handling DLP log message filtering'
|
|
21
|
+
)
|
|
21
22
|
|
|
22
23
|
logger = Logger.new('/dev/null')
|
|
23
24
|
|
|
24
25
|
logger.level = Logger::WARN
|
|
25
|
-
logger.add(Logger::WARN,
|
|
26
|
+
logger.add(Logger::WARN, 'This will be logged')
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
context
|
|
30
|
-
it
|
|
31
|
-
expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
|
|
30
|
+
context 'writing an error message' do
|
|
31
|
+
it 'should run the tcell logic' do
|
|
32
|
+
expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
|
|
33
|
+
'Handling DLP log message filtering'
|
|
34
|
+
)
|
|
32
35
|
|
|
33
36
|
logger = Logger.new('/dev/null')
|
|
34
37
|
|
|
35
38
|
logger.level = Logger::WARN
|
|
36
|
-
logger.add(Logger::ERROR,
|
|
39
|
+
logger.add(Logger::ERROR, 'This will be logged')
|
|
37
40
|
end
|
|
38
41
|
|
|
39
|
-
context
|
|
40
|
-
it
|
|
42
|
+
context 'with an empty message' do
|
|
43
|
+
it 'should not run the context filter' do
|
|
41
44
|
expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
|
|
42
|
-
|
|
45
|
+
'Handling DLP log message filtering'
|
|
43
46
|
).and_call_original
|
|
44
47
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DataLoss).and_return(
|
|
45
|
-
double(
|
|
48
|
+
double('dlp_policy')
|
|
46
49
|
)
|
|
47
50
|
expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
|
|
48
51
|
:fetch
|
|
49
|
-
).with(anything
|
|
52
|
+
).with(anything, nil).and_return(double('request_env'))
|
|
50
53
|
|
|
51
54
|
logger = Logger.new('/dev/null')
|
|
52
55
|
|
|
@@ -55,94 +58,92 @@ describe Logger do
|
|
|
55
58
|
end
|
|
56
59
|
end
|
|
57
60
|
|
|
58
|
-
context
|
|
59
|
-
it
|
|
61
|
+
context 'with no dlp policy' do
|
|
62
|
+
it 'should not run the context filter' do
|
|
60
63
|
expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
|
|
61
|
-
|
|
64
|
+
'Handling DLP log message filtering'
|
|
62
65
|
).and_call_original
|
|
63
66
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DataLoss).and_return(
|
|
64
67
|
nil
|
|
65
68
|
)
|
|
66
69
|
expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
|
|
67
70
|
:fetch
|
|
68
|
-
).with(anything
|
|
71
|
+
).with(anything, nil).and_return(double('request_env'))
|
|
69
72
|
|
|
70
73
|
logger = Logger.new('/dev/null')
|
|
71
74
|
|
|
72
75
|
logger.level = Logger::WARN
|
|
73
|
-
logger.add(Logger::ERROR,
|
|
76
|
+
logger.add(Logger::ERROR, 'My DLP Policy :(')
|
|
74
77
|
end
|
|
75
78
|
end
|
|
76
79
|
|
|
77
|
-
context
|
|
78
|
-
it
|
|
80
|
+
context 'with no request env' do
|
|
81
|
+
it 'should not run the context filter' do
|
|
79
82
|
expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
|
|
80
|
-
|
|
83
|
+
'Handling DLP log message filtering'
|
|
81
84
|
).and_call_original
|
|
82
85
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DataLoss).and_return(
|
|
83
|
-
double(
|
|
86
|
+
double('dlp_policy')
|
|
84
87
|
)
|
|
85
88
|
expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
|
|
86
89
|
:fetch
|
|
87
|
-
).with(anything
|
|
90
|
+
).with(anything, nil).and_return(nil)
|
|
88
91
|
|
|
89
92
|
logger = Logger.new('/dev/null')
|
|
90
93
|
|
|
91
94
|
logger.level = Logger::WARN
|
|
92
|
-
logger.add(Logger::ERROR,
|
|
95
|
+
logger.add(Logger::ERROR, 'My DLP Policy :(')
|
|
93
96
|
end
|
|
94
97
|
end
|
|
95
98
|
|
|
96
|
-
context
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
request_env = double("request_env")
|
|
99
|
+
context 'with a dlp policy, a message, and request env' do
|
|
100
|
+
context 'with no tcell_context' do
|
|
101
|
+
it 'should not run the context filter' do
|
|
102
|
+
request_env = double('request_env')
|
|
101
103
|
|
|
102
104
|
expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
|
|
103
|
-
|
|
105
|
+
'Handling DLP log message filtering'
|
|
104
106
|
).and_call_original
|
|
105
107
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DataLoss).and_return(
|
|
106
|
-
double(
|
|
108
|
+
double('dlp_policy')
|
|
107
109
|
)
|
|
108
110
|
expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
|
|
109
111
|
:fetch
|
|
110
|
-
).with(anything
|
|
112
|
+
).with(anything, nil).and_return(request_env)
|
|
111
113
|
expect(request_env).to receive(:[]).and_return(nil)
|
|
112
114
|
|
|
113
115
|
logger = Logger.new('/dev/null')
|
|
114
116
|
|
|
115
117
|
logger.level = Logger::WARN
|
|
116
|
-
logger.add(Logger::ERROR,
|
|
118
|
+
logger.add(Logger::ERROR, 'My DLP Policy :(')
|
|
117
119
|
end
|
|
118
120
|
end
|
|
119
121
|
|
|
120
|
-
context
|
|
121
|
-
it
|
|
122
|
-
request_env = double(
|
|
123
|
-
tcell_context = double(
|
|
122
|
+
context 'with tcell_context' do
|
|
123
|
+
it 'should not run the context filter' do
|
|
124
|
+
request_env = double('request_env')
|
|
125
|
+
tcell_context = double('tcell_context')
|
|
124
126
|
|
|
125
127
|
expect(TCellAgent::Instrumentation).to receive(:safe_block_no_log).with(
|
|
126
|
-
|
|
128
|
+
'Handling DLP log message filtering'
|
|
127
129
|
).and_call_original
|
|
128
130
|
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::DataLoss).and_return(
|
|
129
|
-
double(
|
|
131
|
+
double('dlp_policy')
|
|
130
132
|
)
|
|
131
133
|
expect(TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS).to receive(
|
|
132
134
|
:fetch
|
|
133
|
-
).with(anything
|
|
135
|
+
).with(anything, nil).and_return(request_env)
|
|
134
136
|
expect(request_env).to receive(:[]).and_return(tcell_context)
|
|
135
|
-
expect(tcell_context).to receive(:filter_log).with(
|
|
137
|
+
expect(tcell_context).to receive(:filter_log).with('My DLP Policy :(')
|
|
136
138
|
|
|
137
139
|
logger = Logger.new('/dev/null')
|
|
138
140
|
|
|
139
141
|
logger.level = Logger::WARN
|
|
140
|
-
logger.add(Logger::ERROR,
|
|
142
|
+
logger.add(Logger::ERROR, 'My DLP Policy :(')
|
|
141
143
|
end
|
|
142
144
|
end
|
|
143
145
|
end
|
|
144
146
|
end
|
|
145
147
|
end
|
|
146
148
|
end
|
|
147
|
-
|
|
148
149
|
end
|