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.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -22
  3. data/bin/tcell_agent +127 -132
  4. data/lib/tcell_agent/agent/event_processor.rb +23 -22
  5. data/lib/tcell_agent/agent/fork_pipe_manager.rb +7 -7
  6. data/lib/tcell_agent/agent/policy_manager.rb +20 -15
  7. data/lib/tcell_agent/agent/policy_types.rb +5 -11
  8. data/lib/tcell_agent/agent/static_agent.rb +5 -1
  9. data/lib/tcell_agent/agent.rb +6 -4
  10. data/lib/tcell_agent/api.rb +7 -9
  11. data/lib/tcell_agent/appsensor/meta_data.rb +11 -4
  12. data/lib/tcell_agent/authlogic.rb +3 -3
  13. data/lib/tcell_agent/cmdi.rb +6 -4
  14. data/lib/tcell_agent/config/unknown_options.rb +3 -1
  15. data/lib/tcell_agent/configuration.rb +47 -49
  16. data/lib/tcell_agent/devise.rb +2 -2
  17. data/lib/tcell_agent/hooks/login_fraud.rb +58 -29
  18. data/lib/tcell_agent/instrumentation.rb +11 -10
  19. data/lib/tcell_agent/logger.rb +2 -2
  20. data/lib/tcell_agent/patches/meta_data.rb +9 -13
  21. data/lib/tcell_agent/patches.rb +7 -10
  22. data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -5
  23. data/lib/tcell_agent/policies/content_security_policy.rb +6 -12
  24. data/lib/tcell_agent/policies/dataloss_policy.rb +2 -2
  25. data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
  26. data/lib/tcell_agent/policies/policy.rb +0 -2
  27. data/lib/tcell_agent/policies/rust_policies.rb +90 -0
  28. data/lib/tcell_agent/policies/secure_headers_policy.rb +2 -2
  29. data/lib/tcell_agent/rails/auth/authlogic.rb +42 -24
  30. data/lib/tcell_agent/rails/auth/devise.rb +44 -23
  31. data/lib/tcell_agent/rails/auth/doorkeeper.rb +33 -15
  32. data/lib/tcell_agent/rails/better_ip.rb +1 -1
  33. data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
  34. data/lib/tcell_agent/rails/dlp/process_request.rb +1 -1
  35. data/lib/tcell_agent/rails/dlp.rb +6 -6
  36. data/lib/tcell_agent/rails/dlp_handler.rb +1 -1
  37. data/lib/tcell_agent/rails/js_agent_insert.rb +1 -1
  38. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +1 -1
  39. data/lib/tcell_agent/rails/middleware/context_middleware.rb +3 -2
  40. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +10 -9
  41. data/lib/tcell_agent/rails/routes/grape.rb +6 -6
  42. data/lib/tcell_agent/rails/routes.rb +8 -11
  43. data/lib/tcell_agent/rust/libtcellagent-0.11.1.dylib +0 -0
  44. data/lib/tcell_agent/rust/{libtcellagent-0.6.1.so → libtcellagent-0.11.1.so} +0 -0
  45. data/lib/tcell_agent/rust/models.rb +16 -0
  46. data/lib/tcell_agent/rust/tcellagent-0.11.1.dll +0 -0
  47. data/lib/tcell_agent/rust/whisperer.rb +119 -48
  48. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +17 -20
  49. data/lib/tcell_agent/sensor_events/command_injection.rb +50 -5
  50. data/lib/tcell_agent/sensor_events/login_fraud.rb +34 -18
  51. data/lib/tcell_agent/sensor_events/patches.rb +21 -0
  52. data/lib/tcell_agent/sensor_events/server_agent.rb +3 -3
  53. data/lib/tcell_agent/sensor_events/util/utils.rb +4 -3
  54. data/lib/tcell_agent/servers/puma.rb +2 -2
  55. data/lib/tcell_agent/servers/unicorn.rb +1 -1
  56. data/lib/tcell_agent/utils/passwords.rb +28 -0
  57. data/lib/tcell_agent/version.rb +1 -1
  58. data/lib/tcell_agent.rb +1 -5
  59. data/spec/apps/rails-3.2/config/tcell_agent.config +15 -0
  60. data/spec/apps/rails-3.2/log/development.log +0 -0
  61. data/spec/apps/rails-3.2/log/test.log +12 -0
  62. data/spec/apps/rails-4.1/log/test.log +0 -0
  63. data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +46 -45
  64. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +276 -164
  65. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +44 -47
  66. data/spec/lib/tcell_agent/api/api_spec.rb +16 -16
  67. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +131 -116
  68. data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +55 -51
  69. data/spec/lib/tcell_agent/cmdi_spec.rb +413 -436
  70. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +145 -128
  71. data/spec/lib/tcell_agent/configuration_spec.rb +165 -169
  72. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +144 -153
  73. data/spec/lib/tcell_agent/instrumentation_spec.rb +84 -85
  74. data/spec/lib/tcell_agent/patches_spec.rb +70 -111
  75. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +313 -244
  76. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +28 -28
  77. data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +643 -513
  78. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +55 -102
  79. data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +111 -134
  80. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +141 -146
  81. data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +8 -8
  82. data/spec/lib/tcell_agent/policies/login_policy_spec.rb +15 -17
  83. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +231 -559
  84. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +27 -27
  85. data/spec/lib/tcell_agent/rails/better_ip_spec.rb +30 -34
  86. data/spec/lib/tcell_agent/rails/logger_spec.rb +50 -49
  87. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +182 -199
  88. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +110 -84
  89. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +107 -85
  90. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +68 -40
  91. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +81 -67
  92. data/spec/lib/tcell_agent/rails/responses_spec.rb +33 -37
  93. data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +116 -121
  94. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +25 -28
  95. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +87 -85
  96. data/spec/lib/tcell_agent/rails_spec.rb +1 -6
  97. data/spec/lib/tcell_agent/rust/models_spec.rb +112 -0
  98. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +502 -179
  99. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +44 -33
  100. data/spec/lib/tcell_agent/sensor_events/dlp_spec.rb +4 -4
  101. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +183 -169
  102. data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +25 -25
  103. data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +17 -20
  104. data/spec/lib/tcell_agent/utils/params_spec.rb +28 -28
  105. data/spec/lib/tcell_agent/utils/passwords_spec.rb +143 -0
  106. data/spec/lib/tcell_agent/utils/strings_spec.rb +35 -35
  107. data/spec/lib/tcell_agent_spec.rb +8 -8
  108. data/spec/spec_helper.rb +4 -4
  109. data/spec/support/middleware_helper.rb +10 -10
  110. data/spec/support/static_agent_overrides.rb +16 -12
  111. data/tcell_agent.gemspec +17 -33
  112. metadata +43 -198
  113. data/LICENSE_libinjection +0 -32
  114. data/Readme.txt +0 -7
  115. data/ext/libinjection/extconf.rb +0 -3
  116. data/ext/libinjection/libinjection.h +0 -65
  117. data/ext/libinjection/libinjection_html5.c +0 -847
  118. data/ext/libinjection/libinjection_html5.h +0 -54
  119. data/ext/libinjection/libinjection_sqli.c +0 -2317
  120. data/ext/libinjection/libinjection_sqli.h +0 -295
  121. data/ext/libinjection/libinjection_sqli_data.h +0 -9004
  122. data/ext/libinjection/libinjection_wrap.c +0 -3525
  123. data/ext/libinjection/libinjection_xss.c +0 -531
  124. data/ext/libinjection/libinjection_xss.h +0 -21
  125. data/lib/tcell_agent/appsensor/injections_matcher.rb +0 -155
  126. data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +0 -49
  127. data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +0 -67
  128. data/lib/tcell_agent/appsensor/rules/baserules.json +0 -467
  129. data/lib/tcell_agent/patches/block_rule.rb +0 -93
  130. data/lib/tcell_agent/patches/sensors_matcher.rb +0 -31
  131. data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +0 -23
  132. data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +0 -23
  133. data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +0 -117
  134. data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +0 -26
  135. data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +0 -22
  136. data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +0 -34
  137. data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +0 -34
  138. data/lib/tcell_agent/policies/appsensor_policy.rb +0 -49
  139. data/lib/tcell_agent/policies/command_injection_policy.rb +0 -196
  140. data/lib/tcell_agent/policies/honeytokens_policy.rb +0 -69
  141. data/lib/tcell_agent/policies/patches_policy.rb +0 -84
  142. data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
  143. data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
  144. data/spec/apps/rails-3.2/Gemfile +0 -25
  145. data/spec/apps/rails-3.2/Gemfile.lock +0 -126
  146. data/spec/apps/rails-3.2/Rakefile +0 -7
  147. data/spec/apps/rails-3.2/app/assets/images/rails.png +0 -0
  148. data/spec/apps/rails-3.2/app/assets/javascripts/application.js +0 -15
  149. data/spec/apps/rails-3.2/app/assets/stylesheets/application.css +0 -13
  150. data/spec/apps/rails-3.2/app/controllers/application_controller.rb +0 -3
  151. data/spec/apps/rails-3.2/app/controllers/t_cell_app_controller.rb +0 -5
  152. data/spec/apps/rails-3.2/app/helpers/application_helper.rb +0 -2
  153. data/spec/apps/rails-3.2/app/views/layouts/application.html.erb +0 -14
  154. data/spec/apps/rails-3.2/app/views/t_cell_app/index.html.erb +0 -1
  155. data/spec/apps/rails-3.2/config/application.rb +0 -63
  156. data/spec/apps/rails-3.2/config/boot.rb +0 -6
  157. data/spec/apps/rails-3.2/config/environment.rb +0 -5
  158. data/spec/apps/rails-3.2/config/environments/test.rb +0 -37
  159. data/spec/apps/rails-3.2/config/routes.rb +0 -11
  160. data/spec/apps/rails-3.2/config.ru +0 -4
  161. data/spec/apps/rails-4.1/Gemfile +0 -7
  162. data/spec/apps/rails-4.1/Gemfile.lock +0 -114
  163. data/spec/apps/rails-4.1/Rakefile +0 -6
  164. data/spec/apps/rails-4.1/app/assets/javascripts/application.js +0 -16
  165. data/spec/apps/rails-4.1/app/assets/stylesheets/application.css +0 -15
  166. data/spec/apps/rails-4.1/app/controllers/application_controller.rb +0 -5
  167. data/spec/apps/rails-4.1/app/controllers/t_cell_app_controller.rb +0 -5
  168. data/spec/apps/rails-4.1/app/helpers/application_helper.rb +0 -2
  169. data/spec/apps/rails-4.1/app/views/layouts/application.html.erb +0 -14
  170. data/spec/apps/rails-4.1/app/views/t_cell_app/index.html.erb +0 -1
  171. data/spec/apps/rails-4.1/config/application.rb +0 -24
  172. data/spec/apps/rails-4.1/config/boot.rb +0 -4
  173. data/spec/apps/rails-4.1/config/environment.rb +0 -5
  174. data/spec/apps/rails-4.1/config/environments/test.rb +0 -41
  175. data/spec/apps/rails-4.1/config/initializers/assets.rb +0 -8
  176. data/spec/apps/rails-4.1/config/initializers/backtrace_silencers.rb +0 -7
  177. data/spec/apps/rails-4.1/config/initializers/cookies_serializer.rb +0 -3
  178. data/spec/apps/rails-4.1/config/initializers/filter_parameter_logging.rb +0 -4
  179. data/spec/apps/rails-4.1/config/initializers/inflections.rb +0 -16
  180. data/spec/apps/rails-4.1/config/initializers/mime_types.rb +0 -4
  181. data/spec/apps/rails-4.1/config/initializers/session_store.rb +0 -3
  182. data/spec/apps/rails-4.1/config/initializers/wrap_parameters.rb +0 -14
  183. data/spec/apps/rails-4.1/config/locales/en.yml +0 -23
  184. data/spec/apps/rails-4.1/config/routes.rb +0 -12
  185. data/spec/apps/rails-4.1/config/secrets.yml +0 -22
  186. data/spec/apps/rails-4.1/config.ru +0 -4
  187. data/spec/controllers/application_controller.rb +0 -12
  188. data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +0 -522
  189. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -23
  190. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +0 -159
  191. data/spec/lib/tcell_agent/patches/block_rule_spec.rb +0 -458
  192. data/spec/lib/tcell_agent/patches/sensors_matcher_spec.rb +0 -35
  193. data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +0 -139
  194. data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +0 -139
  195. data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +0 -167
  196. data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +0 -139
  197. data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +0 -246
  198. data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +0 -882
  199. 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 ".grape_route?" do
19
- context "rails 3" do
20
- context "with a regular route" do
21
- it "should return false" do
22
- stub_const("::Rails::VERSION::MAJOR", 3)
23
- stub_const("::Rails::VERSION::MINOR", 0)
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("route", app: RegularRoute.new)
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 "with a grape route" do
34
- it "should return false" do
35
- stub_const("::Rails::VERSION::MAJOR", 3)
36
- stub_const("::Rails::VERSION::MINOR", 0)
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("route", app: GrapeRoute)
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 "rails 4.0" do
48
- context "with a regular route" do
49
- it "should return false" do
50
- stub_const("::Rails::VERSION::MAJOR", 4)
51
- stub_const("::Rails::VERSION::MINOR", 0)
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("route", app: RegularRoute.new)
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 "with a grape route" do
62
- it "should return true" do
63
- stub_const("::Rails::VERSION::MAJOR", 4)
64
- stub_const("::Rails::VERSION::MINOR", 0)
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("route", app: GrapeRoute)
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 "rails 4.1" do
76
- context "with a regular route" do
77
- it "should return false" do
78
- stub_const("::Rails::VERSION::MAJOR", 4)
79
- stub_const("::Rails::VERSION::MINOR", 1)
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("route", app: RegularRoute.new)
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 "with a grape route" do
90
- it "should return true" do
91
- stub_const("::Rails::VERSION::MAJOR", 4)
92
- stub_const("::Rails::VERSION::MINOR", 1)
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("route", app: GrapeRoute)
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 "rails 4.2" do
104
- context "with a regular route" do
105
- it "should return false" do
106
- stub_const("::Rails::VERSION::MAJOR", 4)
107
- stub_const("::Rails::VERSION::MINOR", 2)
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("route", app: double("app", app: RegularRoute.new))
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 "with a grape route" do
118
- it "should return true" do
119
- stub_const("::Rails::VERSION::MAJOR", 4)
120
- stub_const("::Rails::VERSION::MINOR", 2)
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("route", app: double("app", app: GrapeRoute))
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 "rails 5.0" do
132
- context "with a regular route" do
133
- it "should return false" do
134
- stub_const("::Rails::VERSION::MAJOR", 5)
135
- stub_const("::Rails::VERSION::MINOR", 0)
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("route", app: double("app", app: RegularRoute.new))
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 "with a grape route" do
146
- it "should return true" do
147
- stub_const("::Rails::VERSION::MAJOR", 5)
148
- stub_const("::Rails::VERSION::MINOR", 0)
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("route", app: double("app", app: GrapeRoute))
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 ".grape_route_info" do
161
-
162
- context "with grape version 0.10.1" do
163
- it "should use route_method and route_path" do
164
- route = double("route")
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
- "grape" => grape_gem
169
- })
170
- expect(route).to receive(:route_method).and_return("POST")
171
- expect(route).to receive(:route_path).and_return("/grape_api/endpoint")
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("POST")
176
- expect(route_info[:path]).to eq("/grape_api/endpoint")
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 "with grape version 0.16.0" do
181
- it "should use request_method and path" do
182
- route = double("route")
183
- grape_gem = double("grape_gem", version: "0.16.0")
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
- "grape" => grape_gem
187
- })
188
- expect(route).to receive(:request_method).and_return("POST")
189
- expect(route).to receive(:path).and_return("/grape_api/endpoint")
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("POST")
194
- expect(route_info[:path]).to eq("/grape_api/endpoint")
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 ".instrument_grape_api" do
201
-
202
- context "with nil routes" do
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("/api", nil)
201
+ TCellAgent::Instrumentation.instrument_grape_api('/api', nil)
206
202
  end
207
203
  end
208
204
 
209
- context "with empty routes" do
210
- it "should not send any events" do
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("/api", [])
208
+ TCellAgent::Instrumentation.instrument_grape_api('/api', [])
213
209
  end
214
210
  end
215
211
 
216
- context "with grape version < 1.16" do
212
+ context 'with grape version < 1.16' do
217
213
  before(:each) do
218
- grape_gem = double("grape_gem", version: "0.10.1")
214
+ grape_gem = double('grape_gem', :version => '0.10.1')
219
215
 
220
216
  expect(Gem).to receive(:loaded_specs).and_return({
221
- "grape" => grape_gem
222
- }).at_least(1)
217
+ 'grape' => grape_gem
218
+ }).at_least(1)
223
219
  end
224
220
 
225
- context "with one route" do
226
- it "should send one event" do
227
- route = double("grape_route", route_method: "GET", route_path: "/users")
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
- "/api/users", "GET", "409553642", nil, nil
226
+ '/api/users', 'GET', '409553642', nil, nil
231
227
  ).and_call_original
232
228
 
233
- TCellAgent::Instrumentation.instrument_grape_api("/api", [route])
229
+ TCellAgent::Instrumentation.instrument_grape_api('/api', [route])
234
230
  end
235
231
  end
236
232
 
237
- context "with two routes" do
238
- it "should send two events" do
239
- route = double("grape_route", route_method: "GET", route_path: "/users")
240
- route_dos = double("grape_route", route_method: "POST", route_path: "/users")
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
- "/api/users", "GET", "409553642", nil, nil
239
+ '/api/users', 'GET', '409553642', nil, nil
244
240
  ).and_call_original
245
241
  expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
246
- "/api/users", "POST", "-2105512096", nil, nil
242
+ '/api/users', 'POST', '-2105512096', nil, nil
247
243
  ).and_call_original
248
244
 
249
- TCellAgent::Instrumentation.instrument_grape_api("/api", [route, route_dos])
245
+ TCellAgent::Instrumentation.instrument_grape_api('/api', [route, route_dos])
250
246
  end
251
247
  end
252
248
  end
253
249
 
254
- context "with grape version >= 1.16" do
250
+ context 'with grape version >= 1.16' do
255
251
  before(:each) do
256
- grape_gem = double("grape_gem", version: "0.16.0")
252
+ grape_gem = double('grape_gem', :version => '0.16.0')
257
253
 
258
254
  expect(Gem).to receive(:loaded_specs).and_return({
259
- "grape" => grape_gem
260
- }).at_least(1)
255
+ 'grape' => grape_gem
256
+ }).at_least(1)
261
257
  end
262
258
 
263
- context "with one route" do
264
- it "should send one event" do
265
- route = double("grape_route", request_method: "GET", path: "/users")
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
- "/api/users", "GET", "409553642", nil, nil
264
+ '/api/users', 'GET', '409553642', nil, nil
269
265
  ).and_call_original
270
266
 
271
- TCellAgent::Instrumentation.instrument_grape_api("/api", [route])
267
+ TCellAgent::Instrumentation.instrument_grape_api('/api', [route])
272
268
  end
273
269
  end
274
270
 
275
- context "with two routes" do
276
- it "should send two events" do
277
- route = double("grape_route", request_method: "GET", path: "/users")
278
- route_dos = double("grape_route", request_method: "POST", path: "/users")
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
- "/api/users", "GET", "409553642", nil, nil
277
+ '/api/users', 'GET', '409553642', nil, nil
282
278
  ).and_call_original
283
279
  expect(TCellAgent::SensorEvents::AppRoutesSensorEvent).to receive(:new).with(
284
- "/api/users", "POST", "-2105512096", nil, nil
280
+ '/api/users', 'POST', '-2105512096', nil, nil
285
281
  ).and_call_original
286
282
 
287
- TCellAgent::Instrumentation.instrument_grape_api("/api", [route, route_dos])
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 ".update_context" do
10
-
11
- context "with nil route" do
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 "with nil context" do
25
- it "should not set anything "do
26
- route = double("route")
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 "with a regular route and parameters" do
34
- it "should set the route id" do
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 = "GET"
35
+ tcell_context.request_method = 'GET'
38
36
 
39
37
  route = double(
40
- "route",
41
- path: double("path", spec: "/some/regular/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: 1}, route)
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("GET", "/some/regular/path")
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: 1})
50
+ expect(tcell_context.path_parameters).to eq({ :id => 1 })
52
51
  end
53
52
  end
54
53
 
55
- context "with a grape route and parameters" do
56
- it "should set the grape mount endpoint" do
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 = "GET"
58
+ tcell_context.request_method = 'GET'
60
59
 
61
60
  route = double(
62
- "route",
63
- path: double("path", spec: "/grape_api"))
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: 1}, route)
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("/grape_api")
71
- expect(tcell_context.path_parameters).to eq({id: 1})
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