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
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module TCellAgent
|
4
4
|
module Instrumentation
|
5
|
-
|
6
5
|
# Fake out grape gem
|
7
6
|
module Grape
|
8
7
|
class API
|
@@ -15,14 +14,14 @@ module TCellAgent
|
|
15
14
|
class RegularRoute
|
16
15
|
end
|
17
16
|
|
18
|
-
describe
|
19
|
-
context
|
20
|
-
context
|
21
|
-
it
|
22
|
-
stub_const(
|
23
|
-
stub_const(
|
17
|
+
describe '.grape_route?' do
|
18
|
+
context 'rails 3' do
|
19
|
+
context 'with a regular route' do
|
20
|
+
it 'should return false' do
|
21
|
+
stub_const('::Rails::VERSION::MAJOR', 3)
|
22
|
+
stub_const('::Rails::VERSION::MINOR', 0)
|
24
23
|
|
25
|
-
route = double(
|
24
|
+
route = double('route', :app => RegularRoute.new)
|
26
25
|
|
27
26
|
is_grape_route = TCellAgent::Instrumentation.grape_route?(route)
|
28
27
|
|
@@ -30,12 +29,12 @@ module TCellAgent
|
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
|
-
context
|
34
|
-
it
|
35
|
-
stub_const(
|
36
|
-
stub_const(
|
32
|
+
context 'with a grape route' do
|
33
|
+
it 'should return false' do
|
34
|
+
stub_const('::Rails::VERSION::MAJOR', 3)
|
35
|
+
stub_const('::Rails::VERSION::MINOR', 0)
|
37
36
|
|
38
|
-
route = double(
|
37
|
+
route = double('route', :app => GrapeRoute)
|
39
38
|
|
40
39
|
is_grape_route = TCellAgent::Instrumentation.grape_route?(route)
|
41
40
|
|
@@ -44,13 +43,13 @@ module TCellAgent
|
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
|
-
context
|
48
|
-
context
|
49
|
-
it
|
50
|
-
stub_const(
|
51
|
-
stub_const(
|
46
|
+
context 'rails 4.0' do
|
47
|
+
context 'with a regular route' do
|
48
|
+
it 'should return false' do
|
49
|
+
stub_const('::Rails::VERSION::MAJOR', 4)
|
50
|
+
stub_const('::Rails::VERSION::MINOR', 0)
|
52
51
|
|
53
|
-
route = double(
|
52
|
+
route = double('route', :app => RegularRoute.new)
|
54
53
|
|
55
54
|
is_grape_route = TCellAgent::Instrumentation.grape_route?(route)
|
56
55
|
|
@@ -58,12 +57,12 @@ module TCellAgent
|
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
|
-
context
|
62
|
-
it
|
63
|
-
stub_const(
|
64
|
-
stub_const(
|
60
|
+
context 'with a grape route' do
|
61
|
+
it 'should return true' do
|
62
|
+
stub_const('::Rails::VERSION::MAJOR', 4)
|
63
|
+
stub_const('::Rails::VERSION::MINOR', 0)
|
65
64
|
|
66
|
-
route = double(
|
65
|
+
route = double('route', :app => GrapeRoute)
|
67
66
|
|
68
67
|
is_grape_route = TCellAgent::Instrumentation.grape_route?(route)
|
69
68
|
|
@@ -72,13 +71,13 @@ module TCellAgent
|
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
75
|
-
context
|
76
|
-
context
|
77
|
-
it
|
78
|
-
stub_const(
|
79
|
-
stub_const(
|
74
|
+
context 'rails 4.1' do
|
75
|
+
context 'with a regular route' do
|
76
|
+
it 'should return false' do
|
77
|
+
stub_const('::Rails::VERSION::MAJOR', 4)
|
78
|
+
stub_const('::Rails::VERSION::MINOR', 1)
|
80
79
|
|
81
|
-
route = double(
|
80
|
+
route = double('route', :app => RegularRoute.new)
|
82
81
|
|
83
82
|
is_grape_route = TCellAgent::Instrumentation.grape_route?(route)
|
84
83
|
|
@@ -86,12 +85,12 @@ module TCellAgent
|
|
86
85
|
end
|
87
86
|
end
|
88
87
|
|
89
|
-
context
|
90
|
-
it
|
91
|
-
stub_const(
|
92
|
-
stub_const(
|
88
|
+
context 'with a grape route' do
|
89
|
+
it 'should return true' do
|
90
|
+
stub_const('::Rails::VERSION::MAJOR', 4)
|
91
|
+
stub_const('::Rails::VERSION::MINOR', 1)
|
93
92
|
|
94
|
-
route = double(
|
93
|
+
route = double('route', :app => GrapeRoute)
|
95
94
|
|
96
95
|
is_grape_route = TCellAgent::Instrumentation.grape_route?(route)
|
97
96
|
|
@@ -100,13 +99,13 @@ module TCellAgent
|
|
100
99
|
end
|
101
100
|
end
|
102
101
|
|
103
|
-
context
|
104
|
-
context
|
105
|
-
it
|
106
|
-
stub_const(
|
107
|
-
stub_const(
|
102
|
+
context 'rails 4.2' do
|
103
|
+
context 'with a regular route' do
|
104
|
+
it 'should return false' do
|
105
|
+
stub_const('::Rails::VERSION::MAJOR', 4)
|
106
|
+
stub_const('::Rails::VERSION::MINOR', 2)
|
108
107
|
|
109
|
-
route = double(
|
108
|
+
route = double('route', :app => double('app', :app => RegularRoute.new))
|
110
109
|
|
111
110
|
is_grape_route = TCellAgent::Instrumentation.grape_route?(route)
|
112
111
|
|
@@ -114,12 +113,12 @@ module TCellAgent
|
|
114
113
|
end
|
115
114
|
end
|
116
115
|
|
117
|
-
context
|
118
|
-
it
|
119
|
-
stub_const(
|
120
|
-
stub_const(
|
116
|
+
context 'with a grape route' do
|
117
|
+
it 'should return true' do
|
118
|
+
stub_const('::Rails::VERSION::MAJOR', 4)
|
119
|
+
stub_const('::Rails::VERSION::MINOR', 2)
|
121
120
|
|
122
|
-
route = double(
|
121
|
+
route = double('route', :app => double('app', :app => GrapeRoute))
|
123
122
|
|
124
123
|
is_grape_route = TCellAgent::Instrumentation.grape_route?(route)
|
125
124
|
|
@@ -128,13 +127,13 @@ module TCellAgent
|
|
128
127
|
end
|
129
128
|
end
|
130
129
|
|
131
|
-
context
|
132
|
-
context
|
133
|
-
it
|
134
|
-
stub_const(
|
135
|
-
stub_const(
|
130
|
+
context 'rails 5.0' do
|
131
|
+
context 'with a regular route' do
|
132
|
+
it 'should return false' do
|
133
|
+
stub_const('::Rails::VERSION::MAJOR', 5)
|
134
|
+
stub_const('::Rails::VERSION::MINOR', 0)
|
136
135
|
|
137
|
-
route = double(
|
136
|
+
route = double('route', :app => double('app', :app => RegularRoute.new))
|
138
137
|
|
139
138
|
is_grape_route = TCellAgent::Instrumentation.grape_route?(route)
|
140
139
|
|
@@ -142,12 +141,12 @@ module TCellAgent
|
|
142
141
|
end
|
143
142
|
end
|
144
143
|
|
145
|
-
context
|
146
|
-
it
|
147
|
-
stub_const(
|
148
|
-
stub_const(
|
144
|
+
context 'with a grape route' do
|
145
|
+
it 'should return true' do
|
146
|
+
stub_const('::Rails::VERSION::MAJOR', 5)
|
147
|
+
stub_const('::Rails::VERSION::MINOR', 0)
|
149
148
|
|
150
|
-
route = double(
|
149
|
+
route = double('route', :app => double('app', :app => GrapeRoute))
|
151
150
|
|
152
151
|
is_grape_route = TCellAgent::Instrumentation.grape_route?(route)
|
153
152
|
|
@@ -157,138 +156,134 @@ module TCellAgent
|
|
157
156
|
end
|
158
157
|
end
|
159
158
|
|
160
|
-
describe
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
grape_gem = double("grape_gem", version: "0.10.1")
|
159
|
+
describe '.grape_route_info' do
|
160
|
+
context 'with grape version 0.10.1' do
|
161
|
+
it 'should use route_method and route_path' do
|
162
|
+
route = double('route')
|
163
|
+
grape_gem = double('grape_gem', :version => '0.10.1')
|
166
164
|
|
167
165
|
expect(Gem).to receive(:loaded_specs).and_return({
|
168
|
-
|
169
|
-
|
170
|
-
expect(route).to receive(:route_method).and_return(
|
171
|
-
expect(route).to receive(:route_path).and_return(
|
166
|
+
'grape' => grape_gem
|
167
|
+
})
|
168
|
+
expect(route).to receive(:route_method).and_return('POST')
|
169
|
+
expect(route).to receive(:route_path).and_return('/grape_api/endpoint')
|
172
170
|
|
173
171
|
route_info = TCellAgent::Instrumentation.grape_route_info(route)
|
174
172
|
|
175
|
-
expect(route_info[:method]).to eq(
|
176
|
-
expect(route_info[:path]).to eq(
|
173
|
+
expect(route_info[:method]).to eq('POST')
|
174
|
+
expect(route_info[:path]).to eq('/grape_api/endpoint')
|
177
175
|
end
|
178
176
|
end
|
179
177
|
|
180
|
-
context
|
181
|
-
it
|
182
|
-
route = double(
|
183
|
-
grape_gem = double(
|
178
|
+
context 'with grape version 0.16.0' do
|
179
|
+
it 'should use request_method and path' do
|
180
|
+
route = double('route')
|
181
|
+
grape_gem = double('grape_gem', :version => '0.16.0')
|
184
182
|
|
185
183
|
expect(Gem).to receive(:loaded_specs).and_return({
|
186
|
-
|
187
|
-
|
188
|
-
expect(route).to receive(:request_method).and_return(
|
189
|
-
expect(route).to receive(:path).and_return(
|
184
|
+
'grape' => grape_gem
|
185
|
+
})
|
186
|
+
expect(route).to receive(:request_method).and_return('POST')
|
187
|
+
expect(route).to receive(:path).and_return('/grape_api/endpoint')
|
190
188
|
|
191
189
|
route_info = TCellAgent::Instrumentation.grape_route_info(route)
|
192
190
|
|
193
|
-
expect(route_info[:method]).to eq(
|
194
|
-
expect(route_info[:path]).to eq(
|
191
|
+
expect(route_info[:method]).to eq('POST')
|
192
|
+
expect(route_info[:path]).to eq('/grape_api/endpoint')
|
195
193
|
end
|
196
194
|
end
|
197
|
-
|
198
195
|
end
|
199
196
|
|
200
|
-
describe
|
201
|
-
|
202
|
-
|
203
|
-
it "should not send any events" do
|
197
|
+
describe '.instrument_grape_api' do
|
198
|
+
context 'with nil routes' do
|
199
|
+
it 'should not send any events' do
|
204
200
|
expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
|
205
|
-
TCellAgent::Instrumentation.instrument_grape_api(
|
201
|
+
TCellAgent::Instrumentation.instrument_grape_api('/api', nil)
|
206
202
|
end
|
207
203
|
end
|
208
204
|
|
209
|
-
context
|
210
|
-
it
|
205
|
+
context 'with empty routes' do
|
206
|
+
it 'should not send any events' do
|
211
207
|
expect(TCellAgent::SensorEvents::Util).to_not receive(:calculateRouteId)
|
212
|
-
TCellAgent::Instrumentation.instrument_grape_api(
|
208
|
+
TCellAgent::Instrumentation.instrument_grape_api('/api', [])
|
213
209
|
end
|
214
210
|
end
|
215
211
|
|
216
|
-
context
|
212
|
+
context 'with grape version < 1.16' do
|
217
213
|
before(:each) do
|
218
|
-
grape_gem = double(
|
214
|
+
grape_gem = double('grape_gem', :version => '0.10.1')
|
219
215
|
|
220
216
|
expect(Gem).to receive(:loaded_specs).and_return({
|
221
|
-
|
222
|
-
|
217
|
+
'grape' => grape_gem
|
218
|
+
}).at_least(1)
|
223
219
|
end
|
224
220
|
|
225
|
-
context
|
226
|
-
it
|
227
|
-
route = double(
|
221
|
+
context 'with one route' do
|
222
|
+
it 'should send one event' do
|
223
|
+
route = double('grape_route', :route_method => 'GET', :route_path => '/users')
|
228
224
|
|
229
225
|
expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
|
230
|
-
|
226
|
+
'/api/users', 'GET', '409553642', nil, nil
|
231
227
|
).and_call_original
|
232
228
|
|
233
|
-
TCellAgent::Instrumentation.instrument_grape_api(
|
229
|
+
TCellAgent::Instrumentation.instrument_grape_api('/api', [route])
|
234
230
|
end
|
235
231
|
end
|
236
232
|
|
237
|
-
context
|
238
|
-
it
|
239
|
-
route = double(
|
240
|
-
route_dos = double(
|
233
|
+
context 'with two routes' do
|
234
|
+
it 'should send two events' do
|
235
|
+
route = double('grape_route', :route_method => 'GET', :route_path => '/users')
|
236
|
+
route_dos = double('grape_route', :route_method => 'POST', :route_path => '/users')
|
241
237
|
|
242
238
|
expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
|
243
|
-
|
239
|
+
'/api/users', 'GET', '409553642', nil, nil
|
244
240
|
).and_call_original
|
245
241
|
expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
|
246
|
-
|
242
|
+
'/api/users', 'POST', '-2105512096', nil, nil
|
247
243
|
).and_call_original
|
248
244
|
|
249
|
-
TCellAgent::Instrumentation.instrument_grape_api(
|
245
|
+
TCellAgent::Instrumentation.instrument_grape_api('/api', [route, route_dos])
|
250
246
|
end
|
251
247
|
end
|
252
248
|
end
|
253
249
|
|
254
|
-
context
|
250
|
+
context 'with grape version >= 1.16' do
|
255
251
|
before(:each) do
|
256
|
-
grape_gem = double(
|
252
|
+
grape_gem = double('grape_gem', :version => '0.16.0')
|
257
253
|
|
258
254
|
expect(Gem).to receive(:loaded_specs).and_return({
|
259
|
-
|
260
|
-
|
255
|
+
'grape' => grape_gem
|
256
|
+
}).at_least(1)
|
261
257
|
end
|
262
258
|
|
263
|
-
context
|
264
|
-
it
|
265
|
-
route = double(
|
259
|
+
context 'with one route' do
|
260
|
+
it 'should send one event' do
|
261
|
+
route = double('grape_route', :request_method => 'GET', :path => '/users')
|
266
262
|
|
267
263
|
expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
|
268
|
-
|
264
|
+
'/api/users', 'GET', '409553642', nil, nil
|
269
265
|
).and_call_original
|
270
266
|
|
271
|
-
TCellAgent::Instrumentation.instrument_grape_api(
|
267
|
+
TCellAgent::Instrumentation.instrument_grape_api('/api', [route])
|
272
268
|
end
|
273
269
|
end
|
274
270
|
|
275
|
-
context
|
276
|
-
it
|
277
|
-
route = double(
|
278
|
-
route_dos = double(
|
271
|
+
context 'with two routes' do
|
272
|
+
it 'should send two events' do
|
273
|
+
route = double('grape_route', :request_method => 'GET', :path => '/users')
|
274
|
+
route_dos = double('grape_route', :request_method => 'POST', :path => '/users')
|
279
275
|
|
280
276
|
expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
|
281
|
-
|
277
|
+
'/api/users', 'GET', '409553642', nil, nil
|
282
278
|
).and_call_original
|
283
279
|
expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
|
284
|
-
|
280
|
+
'/api/users', 'POST', '-2105512096', nil, nil
|
285
281
|
).and_call_original
|
286
282
|
|
287
|
-
TCellAgent::Instrumentation.instrument_grape_api(
|
283
|
+
TCellAgent::Instrumentation.instrument_grape_api('/api', [route, route_dos])
|
288
284
|
end
|
289
285
|
end
|
290
286
|
end
|
291
287
|
end
|
292
|
-
|
293
288
|
end
|
294
289
|
end
|
@@ -2,18 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module TCellAgent
|
4
4
|
module Instrumentation
|
5
|
-
|
6
5
|
describe RouteId do
|
7
6
|
TCELL_CONTEXT_KEY = TCellAgent::Instrumentation::TCELL_ID
|
8
7
|
|
9
|
-
describe
|
10
|
-
|
11
|
-
|
12
|
-
it "should not set anything" do
|
8
|
+
describe '.update_context' do
|
9
|
+
context 'with nil route' do
|
10
|
+
it 'should not set anything' do
|
13
11
|
tcell_context = TCellData.new
|
14
12
|
tcell_context.route_id = nil
|
15
13
|
|
16
|
-
RouteId.update_context({TCELL_CONTEXT_KEY => tcell_context}, {}, nil)
|
14
|
+
RouteId.update_context({ TCELL_CONTEXT_KEY => tcell_context }, {}, nil)
|
17
15
|
|
18
16
|
expect(tcell_context.route_id).to eq(nil)
|
19
17
|
expect(tcell_context.grape_mount_endpoint).to eq(nil)
|
@@ -21,60 +19,59 @@ module TCellAgent
|
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
|
-
context
|
25
|
-
it
|
26
|
-
route = double(
|
22
|
+
context 'with nil context' do
|
23
|
+
it 'should not set anything ' do
|
24
|
+
route = double('route')
|
27
25
|
expect(route).to_not receive(:path)
|
28
26
|
|
29
27
|
RouteId.update_context({}, {}, route)
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
33
|
-
context
|
34
|
-
it
|
31
|
+
context 'with a regular route and parameters' do
|
32
|
+
it 'should set the route id' do
|
35
33
|
tcell_context = TCellData.new
|
36
34
|
tcell_context.route_id = nil
|
37
|
-
tcell_context.request_method =
|
35
|
+
tcell_context.request_method = 'GET'
|
38
36
|
|
39
37
|
route = double(
|
40
|
-
|
41
|
-
path
|
38
|
+
'route',
|
39
|
+
:path => double('path', :spec => '/some/regular/path')
|
40
|
+
)
|
42
41
|
|
43
42
|
expect(TCellAgent::Instrumentation).to receive(:grape_route?).with(route).and_return(false)
|
44
43
|
|
45
|
-
RouteId.update_context({TCELL_CONTEXT_KEY => tcell_context}, {id
|
44
|
+
RouteId.update_context({ TCELL_CONTEXT_KEY => tcell_context }, { :id => 1 }, route)
|
46
45
|
|
47
46
|
expect(tcell_context.route_id).to eq(
|
48
|
-
TCellAgent::SensorEvents::Util.calculateRouteId(
|
47
|
+
TCellAgent::SensorEvents::Util.calculateRouteId('GET', '/some/regular/path')
|
49
48
|
)
|
50
49
|
expect(tcell_context.grape_mount_endpoint).to eq(nil)
|
51
|
-
expect(tcell_context.path_parameters).to eq({id
|
50
|
+
expect(tcell_context.path_parameters).to eq({ :id => 1 })
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
55
|
-
context
|
56
|
-
it
|
54
|
+
context 'with a grape route and parameters' do
|
55
|
+
it 'should set the grape mount endpoint' do
|
57
56
|
tcell_context = TCellData.new
|
58
57
|
tcell_context.route_id = nil
|
59
|
-
tcell_context.request_method =
|
58
|
+
tcell_context.request_method = 'GET'
|
60
59
|
|
61
60
|
route = double(
|
62
|
-
|
63
|
-
path
|
61
|
+
'route',
|
62
|
+
:path => double('path', :spec => '/grape_api')
|
63
|
+
)
|
64
64
|
|
65
65
|
expect(TCellAgent::Instrumentation).to receive(:grape_route?).with(route).and_return(true)
|
66
66
|
|
67
|
-
RouteId.update_context({TCELL_CONTEXT_KEY => tcell_context}, {id
|
67
|
+
RouteId.update_context({ TCELL_CONTEXT_KEY => tcell_context }, { :id => 1 }, route)
|
68
68
|
|
69
69
|
expect(tcell_context.route_id).to eq(nil)
|
70
|
-
expect(tcell_context.grape_mount_endpoint).to eq(
|
71
|
-
expect(tcell_context.path_parameters).to eq({id
|
70
|
+
expect(tcell_context.grape_mount_endpoint).to eq('/grape_api')
|
71
|
+
expect(tcell_context.path_parameters).to eq({ :id => 1 })
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
75
74
|
end
|
76
|
-
|
77
75
|
end
|
78
|
-
|
79
76
|
end
|
80
77
|
end
|