tcell_agent 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +9 -22
- data/bin/tcell_agent +127 -132
- data/lib/tcell_agent/agent/event_processor.rb +23 -22
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +7 -7
- data/lib/tcell_agent/agent/policy_manager.rb +20 -15
- data/lib/tcell_agent/agent/policy_types.rb +5 -11
- data/lib/tcell_agent/agent/static_agent.rb +5 -1
- data/lib/tcell_agent/agent.rb +6 -4
- data/lib/tcell_agent/api.rb +7 -9
- data/lib/tcell_agent/appsensor/meta_data.rb +11 -4
- data/lib/tcell_agent/authlogic.rb +3 -3
- data/lib/tcell_agent/cmdi.rb +6 -4
- data/lib/tcell_agent/config/unknown_options.rb +3 -1
- data/lib/tcell_agent/configuration.rb +47 -49
- data/lib/tcell_agent/devise.rb +2 -2
- data/lib/tcell_agent/hooks/login_fraud.rb +58 -29
- data/lib/tcell_agent/instrumentation.rb +11 -10
- data/lib/tcell_agent/logger.rb +2 -2
- data/lib/tcell_agent/patches/meta_data.rb +9 -13
- data/lib/tcell_agent/patches.rb +7 -10
- data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -5
- data/lib/tcell_agent/policies/content_security_policy.rb +6 -12
- data/lib/tcell_agent/policies/dataloss_policy.rb +2 -2
- data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
- data/lib/tcell_agent/policies/policy.rb +0 -2
- data/lib/tcell_agent/policies/rust_policies.rb +90 -0
- data/lib/tcell_agent/policies/secure_headers_policy.rb +2 -2
- data/lib/tcell_agent/rails/auth/authlogic.rb +42 -24
- data/lib/tcell_agent/rails/auth/devise.rb +44 -23
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +33 -15
- data/lib/tcell_agent/rails/better_ip.rb +1 -1
- data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
- data/lib/tcell_agent/rails/dlp/process_request.rb +1 -1
- data/lib/tcell_agent/rails/dlp.rb +6 -6
- data/lib/tcell_agent/rails/dlp_handler.rb +1 -1
- data/lib/tcell_agent/rails/js_agent_insert.rb +1 -1
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +1 -1
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +3 -2
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +10 -9
- data/lib/tcell_agent/rails/routes/grape.rb +6 -6
- data/lib/tcell_agent/rails/routes.rb +8 -11
- data/lib/tcell_agent/rust/libtcellagent-0.11.1.dylib +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-0.6.1.so → libtcellagent-0.11.1.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +16 -0
- data/lib/tcell_agent/rust/tcellagent-0.11.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +119 -48
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +17 -20
- data/lib/tcell_agent/sensor_events/command_injection.rb +50 -5
- data/lib/tcell_agent/sensor_events/login_fraud.rb +34 -18
- data/lib/tcell_agent/sensor_events/patches.rb +21 -0
- data/lib/tcell_agent/sensor_events/server_agent.rb +3 -3
- data/lib/tcell_agent/sensor_events/util/utils.rb +4 -3
- data/lib/tcell_agent/servers/puma.rb +2 -2
- data/lib/tcell_agent/servers/unicorn.rb +1 -1
- data/lib/tcell_agent/utils/passwords.rb +28 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/lib/tcell_agent.rb +1 -5
- data/spec/apps/rails-3.2/config/tcell_agent.config +15 -0
- data/spec/apps/rails-3.2/log/development.log +0 -0
- data/spec/apps/rails-3.2/log/test.log +12 -0
- data/spec/apps/rails-4.1/log/test.log +0 -0
- data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +46 -45
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +276 -164
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +44 -47
- data/spec/lib/tcell_agent/api/api_spec.rb +16 -16
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +131 -116
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +55 -51
- data/spec/lib/tcell_agent/cmdi_spec.rb +413 -436
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +145 -128
- data/spec/lib/tcell_agent/configuration_spec.rb +165 -169
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +144 -153
- data/spec/lib/tcell_agent/instrumentation_spec.rb +84 -85
- data/spec/lib/tcell_agent/patches_spec.rb +70 -111
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +313 -244
- data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +28 -28
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +643 -513
- data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +55 -102
- data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +111 -134
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +141 -146
- data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +8 -8
- data/spec/lib/tcell_agent/policies/login_policy_spec.rb +15 -17
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +231 -559
- data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +27 -27
- data/spec/lib/tcell_agent/rails/better_ip_spec.rb +30 -34
- data/spec/lib/tcell_agent/rails/logger_spec.rb +50 -49
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +182 -199
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +110 -84
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +107 -85
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +68 -40
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +81 -67
- data/spec/lib/tcell_agent/rails/responses_spec.rb +33 -37
- data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +116 -121
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +25 -28
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +87 -85
- data/spec/lib/tcell_agent/rails_spec.rb +1 -6
- data/spec/lib/tcell_agent/rust/models_spec.rb +112 -0
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +502 -179
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +44 -33
- data/spec/lib/tcell_agent/sensor_events/dlp_spec.rb +4 -4
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +183 -169
- data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +25 -25
- data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +17 -20
- data/spec/lib/tcell_agent/utils/params_spec.rb +28 -28
- data/spec/lib/tcell_agent/utils/passwords_spec.rb +143 -0
- data/spec/lib/tcell_agent/utils/strings_spec.rb +35 -35
- data/spec/lib/tcell_agent_spec.rb +8 -8
- data/spec/spec_helper.rb +4 -4
- data/spec/support/middleware_helper.rb +10 -10
- data/spec/support/static_agent_overrides.rb +16 -12
- data/tcell_agent.gemspec +17 -33
- metadata +43 -198
- data/LICENSE_libinjection +0 -32
- data/Readme.txt +0 -7
- data/ext/libinjection/extconf.rb +0 -3
- data/ext/libinjection/libinjection.h +0 -65
- data/ext/libinjection/libinjection_html5.c +0 -847
- data/ext/libinjection/libinjection_html5.h +0 -54
- data/ext/libinjection/libinjection_sqli.c +0 -2317
- data/ext/libinjection/libinjection_sqli.h +0 -295
- data/ext/libinjection/libinjection_sqli_data.h +0 -9004
- data/ext/libinjection/libinjection_wrap.c +0 -3525
- data/ext/libinjection/libinjection_xss.c +0 -531
- data/ext/libinjection/libinjection_xss.h +0 -21
- data/lib/tcell_agent/appsensor/injections_matcher.rb +0 -155
- data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +0 -49
- data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +0 -67
- data/lib/tcell_agent/appsensor/rules/baserules.json +0 -467
- data/lib/tcell_agent/patches/block_rule.rb +0 -93
- data/lib/tcell_agent/patches/sensors_matcher.rb +0 -31
- data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +0 -23
- data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +0 -23
- data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +0 -117
- data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +0 -26
- data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +0 -22
- data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +0 -34
- data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +0 -34
- data/lib/tcell_agent/policies/appsensor_policy.rb +0 -49
- data/lib/tcell_agent/policies/command_injection_policy.rb +0 -196
- data/lib/tcell_agent/policies/honeytokens_policy.rb +0 -69
- data/lib/tcell_agent/policies/patches_policy.rb +0 -84
- data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
- data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
- data/spec/apps/rails-3.2/Gemfile +0 -25
- data/spec/apps/rails-3.2/Gemfile.lock +0 -126
- data/spec/apps/rails-3.2/Rakefile +0 -7
- data/spec/apps/rails-3.2/app/assets/images/rails.png +0 -0
- data/spec/apps/rails-3.2/app/assets/javascripts/application.js +0 -15
- data/spec/apps/rails-3.2/app/assets/stylesheets/application.css +0 -13
- data/spec/apps/rails-3.2/app/controllers/application_controller.rb +0 -3
- data/spec/apps/rails-3.2/app/controllers/t_cell_app_controller.rb +0 -5
- data/spec/apps/rails-3.2/app/helpers/application_helper.rb +0 -2
- data/spec/apps/rails-3.2/app/views/layouts/application.html.erb +0 -14
- data/spec/apps/rails-3.2/app/views/t_cell_app/index.html.erb +0 -1
- data/spec/apps/rails-3.2/config/application.rb +0 -63
- data/spec/apps/rails-3.2/config/boot.rb +0 -6
- data/spec/apps/rails-3.2/config/environment.rb +0 -5
- data/spec/apps/rails-3.2/config/environments/test.rb +0 -37
- data/spec/apps/rails-3.2/config/routes.rb +0 -11
- data/spec/apps/rails-3.2/config.ru +0 -4
- data/spec/apps/rails-4.1/Gemfile +0 -7
- data/spec/apps/rails-4.1/Gemfile.lock +0 -114
- data/spec/apps/rails-4.1/Rakefile +0 -6
- data/spec/apps/rails-4.1/app/assets/javascripts/application.js +0 -16
- data/spec/apps/rails-4.1/app/assets/stylesheets/application.css +0 -15
- data/spec/apps/rails-4.1/app/controllers/application_controller.rb +0 -5
- data/spec/apps/rails-4.1/app/controllers/t_cell_app_controller.rb +0 -5
- data/spec/apps/rails-4.1/app/helpers/application_helper.rb +0 -2
- data/spec/apps/rails-4.1/app/views/layouts/application.html.erb +0 -14
- data/spec/apps/rails-4.1/app/views/t_cell_app/index.html.erb +0 -1
- data/spec/apps/rails-4.1/config/application.rb +0 -24
- data/spec/apps/rails-4.1/config/boot.rb +0 -4
- data/spec/apps/rails-4.1/config/environment.rb +0 -5
- data/spec/apps/rails-4.1/config/environments/test.rb +0 -41
- data/spec/apps/rails-4.1/config/initializers/assets.rb +0 -8
- data/spec/apps/rails-4.1/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/apps/rails-4.1/config/initializers/cookies_serializer.rb +0 -3
- data/spec/apps/rails-4.1/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/apps/rails-4.1/config/initializers/inflections.rb +0 -16
- data/spec/apps/rails-4.1/config/initializers/mime_types.rb +0 -4
- data/spec/apps/rails-4.1/config/initializers/session_store.rb +0 -3
- data/spec/apps/rails-4.1/config/initializers/wrap_parameters.rb +0 -14
- data/spec/apps/rails-4.1/config/locales/en.yml +0 -23
- data/spec/apps/rails-4.1/config/routes.rb +0 -12
- data/spec/apps/rails-4.1/config/secrets.yml +0 -22
- data/spec/apps/rails-4.1/config.ru +0 -4
- data/spec/controllers/application_controller.rb +0 -12
- data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +0 -522
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -23
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +0 -159
- data/spec/lib/tcell_agent/patches/block_rule_spec.rb +0 -458
- data/spec/lib/tcell_agent/patches/sensors_matcher_spec.rb +0 -35
- data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +0 -167
- data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +0 -246
- data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +0 -882
- data/spec/lib/tcell_agent/policies/honeytokens_policy_spec.rb +0 -22
@@ -6,13 +6,10 @@ module TCellAgent
|
|
6
6
|
module Instrumentation
|
7
7
|
module Rails
|
8
8
|
module Middleware
|
9
|
-
|
10
|
-
|
11
9
|
class MockAppsensorRackApp
|
12
|
-
|
13
10
|
attr_reader :request_body
|
14
11
|
|
15
|
-
def initialize(route_id=nil, hmac_session_id=nil)
|
12
|
+
def initialize(route_id = nil, hmac_session_id = nil)
|
16
13
|
@route_id = route_id
|
17
14
|
@hmac_session_id = hmac_session_id
|
18
15
|
@request_headers = {}
|
@@ -21,12 +18,12 @@ module TCellAgent
|
|
21
18
|
def call(env)
|
22
19
|
@env = env
|
23
20
|
rack_request = Rack::Request.new(env)
|
24
|
-
response_headers = {'Content-Type' => 'text/html'}
|
25
|
-
env[
|
26
|
-
env[
|
27
|
-
env[
|
28
|
-
if
|
29
|
-
response_headers[
|
21
|
+
response_headers = { 'Content-Type' => 'text/html' }
|
22
|
+
env['tcell.request_data'].transaction_id = 'a-b-c-d-e-f'
|
23
|
+
env['tcell.request_data'].hmac_session_id = @hmac_session_id
|
24
|
+
env['tcell.request_data'].route_id = @route_id
|
25
|
+
if rack_request.params['rv']
|
26
|
+
response_headers['Location'] = rack_request.params['rv']
|
30
27
|
end
|
31
28
|
[200, response_headers, ['OK']]
|
32
29
|
end
|
@@ -34,55 +31,86 @@ module TCellAgent
|
|
34
31
|
def [](key)
|
35
32
|
@env[key]
|
36
33
|
end
|
37
|
-
|
38
34
|
end
|
39
35
|
|
40
36
|
describe HeadersMiddleware do
|
41
|
-
|
42
37
|
let(:app) { MockAppsensorRackApp.new }
|
43
|
-
let(:app2) { MockAppsensorRackApp.new(
|
38
|
+
let(:app2) { MockAppsensorRackApp.new('myrouteid', 'hmac_sessionid') }
|
44
39
|
|
45
|
-
subject {
|
40
|
+
subject { with_tcell_middleware(app) }
|
46
41
|
|
47
|
-
context
|
42
|
+
context 'Redirect Middleware' do
|
48
43
|
before(:each) do
|
49
44
|
TCellAgent.configuration = TCellAgent::Configuration.new
|
50
|
-
TCellAgent.configuration.read_config_from_file(get_test_resource_path(
|
45
|
+
TCellAgent.configuration.read_config_from_file(get_test_resource_path('normal_config.json'))
|
51
46
|
end
|
47
|
+
|
52
48
|
let(:request) { Rack::MockRequest.new(subject) }
|
53
|
-
let(:request2) { Rack::MockRequest.new(
|
49
|
+
let(:request2) { Rack::MockRequest.new(with_tcell_middleware(app2)) }
|
54
50
|
let(:agent) { ::TCellAgent::Agent.new }
|
55
|
-
|
51
|
+
|
52
|
+
context 'Event' do
|
56
53
|
before(:each) do
|
57
|
-
TCellAgent.thread_agent.processPolicyJson(
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
TCellAgent.thread_agent.processPolicyJson(
|
55
|
+
{
|
56
|
+
'http-redirect' =>
|
57
|
+
{
|
58
|
+
'policy_id' => '153ed270-7481-11e5-9194-95dad9b9dec3',
|
59
|
+
'data' => {
|
60
|
+
'enabled' => true,
|
61
|
+
'block' => false,
|
62
|
+
'whitelist' => []
|
63
|
+
}
|
64
|
+
}
|
65
|
+
},
|
66
|
+
false
|
67
|
+
)
|
65
68
|
TCellAgent.empty_event_queue
|
66
69
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
70
|
+
|
71
|
+
it 'sends redirect' do
|
72
|
+
response = request.get(
|
73
|
+
'/some/path2?abcdef=adsfsadf&rv=https://www.google.com',
|
74
|
+
'CONTENT_TYPE' => 'text/html',
|
75
|
+
'REMOTE_ADDR' => '1.3.3.4,3.4.5.6'
|
76
|
+
)
|
77
|
+
expect(response['Location']).to eq('https://www.google.com')
|
78
|
+
expected_as = {
|
79
|
+
'event_type' => 'redirect',
|
80
|
+
'method' => 'GET',
|
81
|
+
'from_domain' => 'example.org',
|
82
|
+
'status_code' => 200,
|
83
|
+
'remote_addr' => '1.3.3.4',
|
84
|
+
'from' => '/some/path2?abcdef=&rv=',
|
85
|
+
'to' => 'www.google.com'
|
86
|
+
}
|
71
87
|
expect(TCellAgent.event_queue).to include(expected_as)
|
72
88
|
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
89
|
+
|
90
|
+
it 'sends redirect event with extra info' do
|
91
|
+
response = request2.get(
|
92
|
+
'/some/path2?abcdef=adsfsadf&rv=https://www.google.com',
|
93
|
+
'CONTENT_TYPE' => 'text/html',
|
94
|
+
'REMOTE_ADDR' => '1.3.3.4,3.4.5.6'
|
95
|
+
)
|
96
|
+
expect(response['Location']).to eq('https://www.google.com')
|
97
|
+
expected_as = {
|
98
|
+
'event_type' => 'redirect',
|
99
|
+
'method' => 'GET',
|
100
|
+
'from_domain' => 'example.org',
|
101
|
+
'status_code' => 200,
|
102
|
+
'remote_addr' => '1.3.3.4',
|
103
|
+
'rid' => 'myrouteid',
|
104
|
+
'from' => '/some/path2?abcdef=&rv=',
|
105
|
+
'to' => 'www.google.com',
|
106
|
+
'sid' => 'hmac_sessionid'
|
107
|
+
}
|
77
108
|
expect(TCellAgent.event_queue).to include(expected_as)
|
78
109
|
end
|
79
|
-
|
80
|
-
|
81
|
-
end #/context
|
82
|
-
end #/describe
|
83
|
-
|
84
|
-
|
110
|
+
end
|
111
|
+
end
|
85
112
|
end
|
86
113
|
end
|
87
114
|
end
|
88
115
|
end
|
116
|
+
end
|
@@ -3,32 +3,33 @@ require 'spec_helper'
|
|
3
3
|
module TCellAgent
|
4
4
|
module Instrumentation
|
5
5
|
module Rails
|
6
|
-
|
7
6
|
describe TCellBodyProxy do
|
8
|
-
|
9
|
-
context "#close" do
|
7
|
+
context '#close' do
|
10
8
|
before(:each) do
|
11
9
|
@appsensor_meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
'get',
|
11
|
+
'remote_address',
|
12
|
+
'route_id',
|
13
|
+
'session_id',
|
14
|
+
'user_id',
|
15
|
+
'transaction_id',
|
16
|
+
'http://test.com/'
|
17
|
+
)
|
18
18
|
end
|
19
19
|
|
20
|
-
context
|
21
|
-
it
|
20
|
+
context 'zero content length' do
|
21
|
+
it 'appsensor_meta event should be enqueued for processing' do
|
22
22
|
tcell_body_proxy = TCellBodyProxy.new(
|
23
|
-
Rack::BodyProxy.new([
|
23
|
+
Rack::BodyProxy.new(['body']) {},
|
24
24
|
true,
|
25
|
-
nil, nil, nil, nil
|
25
|
+
nil, nil, nil, nil
|
26
|
+
)
|
26
27
|
tcell_body_proxy.appsensor_meta = @appsensor_meta
|
27
28
|
|
28
29
|
tcell_body_proxy.content_length = 0
|
29
30
|
|
30
31
|
expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
|
31
|
-
|
32
|
+
'Running AppSensor deferred due to streaming'
|
32
33
|
).and_call_original
|
33
34
|
expect(TCellAgent).to receive(:send_event).with(
|
34
35
|
@appsensor_meta
|
@@ -38,18 +39,19 @@ module TCellAgent
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
context
|
42
|
-
it
|
42
|
+
context 'non zero content length' do
|
43
|
+
it 'appsensor_meta event should be enqueued for processing' do
|
43
44
|
tcell_body_proxy = TCellBodyProxy.new(
|
44
|
-
Rack::BodyProxy.new([
|
45
|
+
Rack::BodyProxy.new(['body']) {},
|
45
46
|
true,
|
46
|
-
nil, nil, nil, nil
|
47
|
+
nil, nil, nil, nil
|
48
|
+
)
|
47
49
|
tcell_body_proxy.appsensor_meta = @appsensor_meta
|
48
50
|
|
49
51
|
tcell_body_proxy.content_length = 512
|
50
52
|
|
51
53
|
expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
|
52
|
-
|
54
|
+
'Running AppSensor deferred due to streaming'
|
53
55
|
).and_call_original
|
54
56
|
expect(TCellAgent).to receive(:send_event).with(
|
55
57
|
@appsensor_meta
|
@@ -62,27 +64,30 @@ module TCellAgent
|
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
|
-
context
|
66
|
-
context
|
67
|
-
it
|
67
|
+
context '#each' do
|
68
|
+
context 'with no block given' do
|
69
|
+
it 'should return an enumerator' do
|
68
70
|
tcell_body_proxy = TCellBodyProxy.new(
|
69
|
-
Rack::BodyProxy.new([
|
71
|
+
Rack::BodyProxy.new(['body']) {},
|
70
72
|
true,
|
71
|
-
nil, nil, nil, nil
|
72
|
-
|
73
|
+
nil, nil, nil, nil
|
74
|
+
)
|
75
|
+
expect(tcell_body_proxy.each.class.name).to eq('Enumerator')
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
76
|
-
context
|
77
|
-
context
|
78
|
-
it
|
79
|
+
context 'with a string response' do
|
80
|
+
context 'with a chunked response' do
|
81
|
+
it 'should only calculate content length' do
|
79
82
|
tcell_body_proxy = TCellBodyProxy.new(
|
80
|
-
Rack::BodyProxy.new(["2d\r\nsome content\r\n"]) {
|
83
|
+
Rack::BodyProxy.new(["2d\r\nsome content\r\n"]) {},
|
81
84
|
false,
|
82
|
-
nil, nil, nil, nil
|
85
|
+
nil, nil, nil, nil
|
86
|
+
)
|
83
87
|
|
84
88
|
expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
|
85
|
-
|
89
|
+
'Processing tcell body proxy body'
|
90
|
+
).and_call_original
|
86
91
|
|
87
92
|
tcell_body_proxy.each { |b| }
|
88
93
|
|
@@ -90,16 +95,18 @@ module TCellAgent
|
|
90
95
|
end
|
91
96
|
end
|
92
97
|
|
93
|
-
context
|
94
|
-
context
|
95
|
-
it
|
98
|
+
context 'with a non chunked response' do
|
99
|
+
context 'that should not be processed' do
|
100
|
+
it 'should only calculate content length' do
|
96
101
|
tcell_body_proxy = TCellBodyProxy.new(
|
97
|
-
Rack::BodyProxy.new([
|
102
|
+
Rack::BodyProxy.new(['some content']) {},
|
98
103
|
false,
|
99
|
-
nil, nil, nil, nil
|
104
|
+
nil, nil, nil, nil
|
105
|
+
)
|
100
106
|
|
101
107
|
expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
|
102
|
-
|
108
|
+
'Processing tcell body proxy body'
|
109
|
+
).and_call_original
|
103
110
|
|
104
111
|
tcell_body_proxy.each { |b| }
|
105
112
|
|
@@ -107,19 +114,21 @@ module TCellAgent
|
|
107
114
|
end
|
108
115
|
end
|
109
116
|
|
110
|
-
context
|
111
|
-
it
|
112
|
-
js_agent_insertion_proc = double(
|
113
|
-
dlp_cleaner_proc = double(
|
117
|
+
context 'that should be processed' do
|
118
|
+
it 'should call js and dlp procs as well as calculate content length' do
|
119
|
+
js_agent_insertion_proc = double('js_agent_insertion_proc')
|
120
|
+
dlp_cleaner_proc = double('dlp_cleaner_proc')
|
114
121
|
tcell_body_proxy = TCellBodyProxy.new(
|
115
|
-
Rack::BodyProxy.new([
|
122
|
+
Rack::BodyProxy.new(['some content']) {},
|
116
123
|
true,
|
117
|
-
js_agent_insertion_proc,
|
124
|
+
js_agent_insertion_proc, 'script_insert', dlp_cleaner_proc, nil
|
125
|
+
)
|
118
126
|
|
119
127
|
expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
|
120
|
-
|
121
|
-
|
122
|
-
expect(
|
128
|
+
'Processing tcell body proxy body'
|
129
|
+
).and_call_original
|
130
|
+
expect(js_agent_insertion_proc).to receive(:call).with('script_insert', 'some content')
|
131
|
+
expect(dlp_cleaner_proc).to receive(:call).with(nil, 'some content')
|
123
132
|
|
124
133
|
tcell_body_proxy.each { |b| }
|
125
134
|
|
@@ -129,23 +138,27 @@ module TCellAgent
|
|
129
138
|
end
|
130
139
|
end
|
131
140
|
|
132
|
-
context
|
133
|
-
context
|
134
|
-
it
|
135
|
-
body_chunk =
|
136
|
-
js_agent_insertion_proc = double(
|
137
|
-
dlp_cleaner_proc = double(
|
141
|
+
context 'with an ActionView::OutputBuffer' do
|
142
|
+
context 'that should not be processed' do
|
143
|
+
it 'should only calculate content length' do
|
144
|
+
body_chunk = 'some content'
|
145
|
+
js_agent_insertion_proc = double('js_agent_insertion_proc')
|
146
|
+
dlp_cleaner_proc = double('dlp_cleaner_proc')
|
138
147
|
tcell_body_proxy = TCellBodyProxy.new(
|
139
|
-
Rack::BodyProxy.new([body_chunk]) {
|
148
|
+
Rack::BodyProxy.new([body_chunk]) {},
|
140
149
|
false,
|
141
|
-
nil, nil, nil, nil
|
150
|
+
nil, nil, nil, nil
|
151
|
+
)
|
142
152
|
|
143
153
|
expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
|
144
|
-
|
154
|
+
'Processing tcell body proxy body'
|
155
|
+
).and_call_original
|
145
156
|
expect(body_chunk).to receive(:class).and_return(
|
146
|
-
double(
|
157
|
+
double('body_class', :name => 'ActionView::OutputBuffer')
|
158
|
+
)
|
147
159
|
expect(body_chunk).to receive(:class).and_return(
|
148
|
-
double(
|
160
|
+
double('body_class', :name => 'ActionView::OutputBuffer')
|
161
|
+
)
|
149
162
|
expect(js_agent_insertion_proc).to_not receive(:call)
|
150
163
|
expect(dlp_cleaner_proc).to_not receive(:call)
|
151
164
|
|
@@ -155,19 +168,21 @@ module TCellAgent
|
|
155
168
|
end
|
156
169
|
end
|
157
170
|
|
158
|
-
context
|
159
|
-
it
|
160
|
-
body_chunk =
|
161
|
-
js_agent_insertion_proc = double(
|
162
|
-
dlp_cleaner_proc = double(
|
171
|
+
context 'that should be processed' do
|
172
|
+
it 'should call js and dlp procs as well as calculate content length' do
|
173
|
+
body_chunk = 'some content'
|
174
|
+
js_agent_insertion_proc = double('js_agent_insertion_proc')
|
175
|
+
dlp_cleaner_proc = double('dlp_cleaner_proc')
|
163
176
|
tcell_body_proxy = TCellBodyProxy.new(
|
164
|
-
Rack::BodyProxy.new([body_chunk]) {
|
177
|
+
Rack::BodyProxy.new([body_chunk]) {},
|
165
178
|
true,
|
166
|
-
js_agent_insertion_proc,
|
179
|
+
js_agent_insertion_proc, 'script_insert', dlp_cleaner_proc, nil
|
180
|
+
)
|
167
181
|
|
168
182
|
expect(TCellAgent::Instrumentation).to receive(:safe_block).with(
|
169
|
-
|
170
|
-
|
183
|
+
'Processing tcell body proxy body'
|
184
|
+
).and_call_original
|
185
|
+
expect(js_agent_insertion_proc).to receive(:call).with('script_insert', body_chunk)
|
171
186
|
expect(dlp_cleaner_proc).to receive(:call).with(nil, body_chunk)
|
172
187
|
|
173
188
|
tcell_body_proxy.each { |b| }
|
@@ -178,7 +193,6 @@ module TCellAgent
|
|
178
193
|
end
|
179
194
|
end
|
180
195
|
end
|
181
|
-
|
182
196
|
end
|
183
197
|
end
|
184
198
|
end
|
@@ -2,80 +2,76 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module TCellAgent
|
4
4
|
module Utils
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
context "with empty headers" do
|
11
|
-
it "should return false" do
|
5
|
+
describe '.responses' do
|
6
|
+
context '.empty_content?' do
|
7
|
+
context 'with nil status code' do
|
8
|
+
context 'with empty headers' do
|
9
|
+
it 'should return false' do
|
12
10
|
expect(Rails.empty_content?(nil, {})).to eq(false)
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
|
-
context
|
17
|
-
context
|
18
|
-
it
|
19
|
-
expect(Rails.empty_content?(nil, {'Content-Length' => 0})).to eq(true)
|
14
|
+
context 'with Content-Length header' do
|
15
|
+
context 'that is zero' do
|
16
|
+
it 'should return true' do
|
17
|
+
expect(Rails.empty_content?(nil, { 'Content-Length' => 0 })).to eq(true)
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
23
|
-
context
|
24
|
-
it
|
25
|
-
expect(Rails.empty_content?(nil, {'Content-Length' => 1})).to eq(false)
|
21
|
+
context 'that is non zero' do
|
22
|
+
it 'should return false' do
|
23
|
+
expect(Rails.empty_content?(nil, { 'Content-Length' => 1 })).to eq(false)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
31
|
-
context
|
32
|
-
context
|
33
|
-
context
|
34
|
-
it
|
29
|
+
context 'with a status code' do
|
30
|
+
context 'that contains no content' do
|
31
|
+
context 'with empty headers' do
|
32
|
+
it 'should return true' do
|
35
33
|
expect(Rails.empty_content?(204, {})).to eq(true)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
|
-
context
|
40
|
-
context
|
41
|
-
it
|
42
|
-
expect(Rails.empty_content?(204, {'Content-Length' => 0})).to eq(true)
|
37
|
+
context 'with Content-Length header' do
|
38
|
+
context 'that is zero' do
|
39
|
+
it 'should return true' do
|
40
|
+
expect(Rails.empty_content?(204, { 'Content-Length' => 0 })).to eq(true)
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
|
-
context
|
47
|
-
it
|
48
|
-
expect(Rails.empty_content?(204, {'Content-Length' => 1})).to eq(true)
|
44
|
+
context 'that is non zero' do
|
45
|
+
it 'should return true' do
|
46
|
+
expect(Rails.empty_content?(204, { 'Content-Length' => 1 })).to eq(true)
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
52
50
|
end
|
53
51
|
|
54
|
-
context
|
55
|
-
context
|
56
|
-
it
|
52
|
+
context 'that contains content' do
|
53
|
+
context 'with empty headers' do
|
54
|
+
it 'should return false' do
|
57
55
|
expect(Rails.empty_content?(200, {})).to eq(false)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
61
|
-
context
|
62
|
-
context
|
63
|
-
it
|
64
|
-
expect(Rails.empty_content?(200, {'Content-Length' => 0})).to eq(true)
|
59
|
+
context 'with Content-Length header' do
|
60
|
+
context 'that is zero' do
|
61
|
+
it 'should return true' do
|
62
|
+
expect(Rails.empty_content?(200, { 'Content-Length' => 0 })).to eq(true)
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
68
|
-
context
|
69
|
-
it
|
70
|
-
expect(Rails.empty_content?(200, {'Content-Length' => 1})).to eq(false)
|
66
|
+
context 'that is non zero' do
|
67
|
+
it 'should return false' do
|
68
|
+
expect(Rails.empty_content?(200, { 'Content-Length' => 1 })).to eq(false)
|
71
69
|
end
|
72
70
|
end
|
73
71
|
end
|
74
72
|
end
|
75
73
|
end
|
76
74
|
end
|
77
|
-
|
78
75
|
end
|
79
|
-
|
80
76
|
end
|
81
77
|
end
|