appmap 0.35.2 → 0.39.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +1 -1
  3. data/.gitignore +2 -1
  4. data/.rubocop.yml +15 -1
  5. data/.travis.yml +0 -7
  6. data/CHANGELOG.md +22 -0
  7. data/README.md +24 -12
  8. data/Rakefile +3 -2
  9. data/appmap.gemspec +2 -1
  10. data/appmap.yml +1 -7
  11. data/lib/appmap.rb +2 -2
  12. data/lib/appmap/class_map.rb +20 -6
  13. data/lib/appmap/config.rb +66 -22
  14. data/lib/appmap/event.rb +16 -1
  15. data/lib/appmap/hook/method.rb +18 -12
  16. data/lib/appmap/rails/request_handler.rb +20 -4
  17. data/lib/appmap/railtie.rb +1 -1
  18. data/lib/appmap/rspec.rb +1 -1
  19. data/lib/appmap/trace.rb +18 -7
  20. data/lib/appmap/version.rb +2 -2
  21. data/spec/abstract_controller4_base_spec.rb +27 -28
  22. data/spec/abstract_controller_base_spec.rb +132 -67
  23. data/spec/class_map_spec.rb +36 -0
  24. data/spec/fixtures/hook/instance_method.rb +4 -0
  25. data/spec/fixtures/{rails_users_app → rails5_users_app}/.dockerignore +0 -0
  26. data/spec/fixtures/{rails_users_app → rails5_users_app}/.gitignore +0 -0
  27. data/spec/fixtures/{rails_users_app → rails5_users_app}/.rspec +0 -0
  28. data/{.ruby-version → spec/fixtures/rails5_users_app/.ruby-version} +0 -0
  29. data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile +0 -0
  30. data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile.pg +0 -0
  31. data/spec/fixtures/rails5_users_app/Gemfile +51 -0
  32. data/spec/fixtures/{rails_users_app → rails5_users_app}/Rakefile +0 -0
  33. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/api/users_controller.rb +0 -0
  34. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/application_controller.rb +0 -0
  35. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/concerns/.keep +0 -0
  36. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/health_controller.rb +0 -0
  37. data/spec/fixtures/rails5_users_app/app/controllers/users_controller.rb +13 -0
  38. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/activerecord/user.rb +0 -0
  39. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/concerns/.keep +0 -0
  40. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/sequel/user.rb +0 -0
  41. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/views/layouts/application.html.haml +0 -0
  42. data/spec/fixtures/{rails_users_app → rails5_users_app}/app/views/users/index.html.haml +0 -0
  43. data/spec/fixtures/rails5_users_app/appmap.yml +4 -0
  44. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/appmap +0 -0
  45. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/byebug +0 -0
  46. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/gli +0 -0
  47. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/htmldiff +0 -0
  48. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ldiff +0 -0
  49. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/nokogiri +0 -0
  50. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rackup +0 -0
  51. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rails +0 -0
  52. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rake +0 -0
  53. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rspec +0 -0
  54. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-parse +0 -0
  55. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-rewrite +0 -0
  56. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sequel +0 -0
  57. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/setup +0 -0
  58. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sprockets +0 -0
  59. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/thor +0 -0
  60. data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/update +0 -0
  61. data/spec/fixtures/{rails_users_app → rails5_users_app}/config.ru +0 -0
  62. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/application.rb +0 -0
  63. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/boot.rb +0 -0
  64. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/credentials.yml.enc +0 -0
  65. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/database.yml +0 -0
  66. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environment.rb +0 -0
  67. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/development.rb +0 -0
  68. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/production.rb +0 -0
  69. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/test.rb +0 -0
  70. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/application_controller_renderer.rb +0 -0
  71. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/backtrace_silencers.rb +0 -0
  72. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/cors.rb +0 -0
  73. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/filter_parameter_logging.rb +0 -0
  74. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/inflections.rb +0 -0
  75. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/mime_types.rb +0 -0
  76. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/record_button.rb +0 -0
  77. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/wrap_parameters.rb +0 -0
  78. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/locales/en.yml +0 -0
  79. data/spec/fixtures/{rails_users_app → rails5_users_app}/config/routes.rb +1 -1
  80. data/spec/fixtures/{rails_users_app → rails5_users_app}/create_app +0 -0
  81. data/spec/fixtures/{rails_users_app → rails5_users_app}/db/migrate/20190728211408_create_users.rb +0 -0
  82. data/spec/fixtures/{rails_users_app → rails5_users_app}/db/schema.rb +0 -0
  83. data/spec/fixtures/{rails_users_app → rails5_users_app}/docker-compose.yml +0 -0
  84. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/api_users.feature +0 -0
  85. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/env.rb +0 -0
  86. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/hooks.rb +0 -0
  87. data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/steps.rb +0 -0
  88. data/spec/fixtures/{rails_users_app → rails5_users_app}/lib/tasks/.keep +0 -0
  89. data/spec/fixtures/{rails_users_app → rails5_users_app}/log/.keep +0 -0
  90. data/spec/fixtures/{rails_users_app → rails5_users_app}/public/robots.txt +0 -0
  91. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/controllers/users_controller_api_spec.rb +1 -1
  92. data/spec/fixtures/rails5_users_app/spec/controllers/users_controller_spec.rb +27 -0
  93. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/models/user_spec.rb +0 -0
  94. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/rails_helper.rb +0 -0
  95. data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/spec_helper.rb +0 -0
  96. data/spec/fixtures/{rails_users_app → rails5_users_app}/users_app/.gitignore +0 -0
  97. data/spec/fixtures/rails6_users_app/.dockerignore +1 -0
  98. data/spec/fixtures/rails6_users_app/.gitignore +39 -0
  99. data/spec/fixtures/rails6_users_app/.rspec +1 -0
  100. data/spec/fixtures/{rails_users_app → rails6_users_app}/.ruby-version +0 -0
  101. data/spec/fixtures/rails6_users_app/Dockerfile +29 -0
  102. data/spec/fixtures/rails6_users_app/Dockerfile.pg +3 -0
  103. data/spec/fixtures/{rails_users_app → rails6_users_app}/Gemfile +1 -1
  104. data/spec/fixtures/rails6_users_app/Rakefile +6 -0
  105. data/spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb +27 -0
  106. data/spec/fixtures/rails6_users_app/app/controllers/application_controller.rb +2 -0
  107. data/spec/fixtures/rails6_users_app/app/controllers/concerns/.keep +0 -0
  108. data/spec/fixtures/rails6_users_app/app/controllers/health_controller.rb +5 -0
  109. data/spec/fixtures/rails6_users_app/app/controllers/users_controller.rb +13 -0
  110. data/spec/fixtures/rails6_users_app/app/models/activerecord/user.rb +18 -0
  111. data/spec/fixtures/rails6_users_app/app/models/concerns/.keep +0 -0
  112. data/spec/fixtures/rails6_users_app/app/models/sequel/user.rb +25 -0
  113. data/spec/fixtures/rails6_users_app/app/views/layouts/application.html.haml +7 -0
  114. data/spec/fixtures/rails6_users_app/app/views/users/index.html.haml +7 -0
  115. data/spec/fixtures/rails6_users_app/appmap.yml +5 -0
  116. data/spec/fixtures/rails6_users_app/bin/appmap +29 -0
  117. data/spec/fixtures/rails6_users_app/bin/byebug +29 -0
  118. data/spec/fixtures/rails6_users_app/bin/gli +29 -0
  119. data/spec/fixtures/rails6_users_app/bin/htmldiff +29 -0
  120. data/spec/fixtures/rails6_users_app/bin/ldiff +29 -0
  121. data/spec/fixtures/rails6_users_app/bin/nokogiri +29 -0
  122. data/spec/fixtures/rails6_users_app/bin/rackup +29 -0
  123. data/spec/fixtures/rails6_users_app/bin/rails +4 -0
  124. data/spec/fixtures/rails6_users_app/bin/rake +29 -0
  125. data/spec/fixtures/rails6_users_app/bin/rspec +29 -0
  126. data/spec/fixtures/rails6_users_app/bin/ruby-parse +29 -0
  127. data/spec/fixtures/rails6_users_app/bin/ruby-rewrite +29 -0
  128. data/spec/fixtures/rails6_users_app/bin/sequel +29 -0
  129. data/spec/fixtures/rails6_users_app/bin/setup +25 -0
  130. data/spec/fixtures/rails6_users_app/bin/sprockets +29 -0
  131. data/spec/fixtures/rails6_users_app/bin/thor +29 -0
  132. data/spec/fixtures/rails6_users_app/bin/update +25 -0
  133. data/spec/fixtures/rails6_users_app/config.ru +5 -0
  134. data/spec/fixtures/rails6_users_app/config/application.rb +51 -0
  135. data/spec/fixtures/rails6_users_app/config/boot.rb +3 -0
  136. data/spec/fixtures/rails6_users_app/config/credentials.yml.enc +1 -0
  137. data/spec/fixtures/rails6_users_app/config/database.yml +18 -0
  138. data/spec/fixtures/rails6_users_app/config/environment.rb +5 -0
  139. data/spec/fixtures/rails6_users_app/config/environments/development.rb +40 -0
  140. data/spec/fixtures/rails6_users_app/config/environments/production.rb +68 -0
  141. data/spec/fixtures/rails6_users_app/config/environments/test.rb +36 -0
  142. data/spec/fixtures/rails6_users_app/config/initializers/application_controller_renderer.rb +8 -0
  143. data/spec/fixtures/rails6_users_app/config/initializers/backtrace_silencers.rb +7 -0
  144. data/spec/fixtures/rails6_users_app/config/initializers/cors.rb +16 -0
  145. data/spec/fixtures/rails6_users_app/config/initializers/filter_parameter_logging.rb +4 -0
  146. data/spec/fixtures/rails6_users_app/config/initializers/inflections.rb +16 -0
  147. data/spec/fixtures/rails6_users_app/config/initializers/mime_types.rb +4 -0
  148. data/spec/fixtures/rails6_users_app/config/initializers/record_button.rb +3 -0
  149. data/spec/fixtures/rails6_users_app/config/initializers/wrap_parameters.rb +9 -0
  150. data/spec/fixtures/rails6_users_app/config/locales/en.yml +33 -0
  151. data/spec/fixtures/rails6_users_app/config/routes.rb +11 -0
  152. data/spec/fixtures/rails6_users_app/create_app +27 -0
  153. data/spec/fixtures/rails6_users_app/db/migrate/20190728211408_create_users.rb +9 -0
  154. data/spec/fixtures/rails6_users_app/db/schema.rb +23 -0
  155. data/spec/fixtures/rails6_users_app/docker-compose.yml +28 -0
  156. data/spec/fixtures/rails6_users_app/features/api_users.feature +13 -0
  157. data/spec/fixtures/rails6_users_app/features/support/env.rb +4 -0
  158. data/spec/fixtures/rails6_users_app/features/support/hooks.rb +11 -0
  159. data/spec/fixtures/rails6_users_app/features/support/steps.rb +18 -0
  160. data/spec/fixtures/rails6_users_app/lib/tasks/.keep +0 -0
  161. data/spec/fixtures/rails6_users_app/log/.keep +0 -0
  162. data/spec/fixtures/rails6_users_app/public/robots.txt +1 -0
  163. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_api_spec.rb +29 -0
  164. data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_spec.rb +27 -0
  165. data/spec/fixtures/rails6_users_app/spec/models/user_spec.rb +39 -0
  166. data/spec/fixtures/rails6_users_app/spec/rails_helper.rb +66 -0
  167. data/spec/fixtures/rails6_users_app/spec/spec_helper.rb +96 -0
  168. data/spec/fixtures/rails6_users_app/users_app/.gitignore +20 -0
  169. data/spec/hook_spec.rb +103 -22
  170. data/spec/rails_spec_helper.rb +5 -5
  171. data/spec/railtie_spec.rb +31 -32
  172. data/spec/record_sql_rails4_pg_spec.rb +47 -48
  173. data/spec/record_sql_rails_pg_spec.rb +62 -63
  174. data/spec/remote_recording_spec.rb +90 -89
  175. data/spec/rspec_feature_metadata_spec.rb +17 -18
  176. data/test/expectations/openssl_test_key_sign1.json +55 -0
  177. data/test/expectations/openssl_test_key_sign2.json +58 -0
  178. data/test/fixtures/gem_test/Gemfile +6 -0
  179. data/test/fixtures/gem_test/appmap.yml +3 -0
  180. data/test/fixtures/gem_test/test/to_param_test.rb +14 -0
  181. data/test/gem_test.rb +34 -0
  182. data/test/minitest_test.rb +2 -2
  183. data/test/openssl_test.rb +10 -117
  184. metadata +173 -80
  185. data/spec/fixtures/rails_users_app/app/controllers/users_controller.rb +0 -5
  186. data/spec/fixtures/rails_users_app/appmap.yml +0 -3
@@ -27,7 +27,7 @@ describe 'AppMap class Hooking', docker: false do
27
27
 
28
28
  def invoke_test_file(file, setup: nil, &block)
29
29
  AppMap.configuration = nil
30
- package = AppMap::Config::Package.new(file)
30
+ package = AppMap::Config::Package.build_from_path(file)
31
31
  config = AppMap::Config.new('hook_spec', [ package ])
32
32
  AppMap.configuration = config
33
33
  tracer = nil
@@ -52,9 +52,9 @@ describe 'AppMap class Hooking', docker: false do
52
52
 
53
53
  events = collect_events(tracer).to_yaml
54
54
 
55
- expect(Diffy::Diff.new(events_yaml, events).to_s).to eq('')
55
+ expect(Diffy::Diff.new(events_yaml, events).to_s).to eq('') if events_yaml
56
56
 
57
- [ config, tracer ]
57
+ [ config, tracer, events ]
58
58
  end
59
59
 
60
60
  after do
@@ -112,6 +112,10 @@ describe 'AppMap class Hooking', docker: false do
112
112
  :type: function
113
113
  :location: spec/fixtures/hook/instance_method.rb:8
114
114
  :static: false
115
+ :source: |2
116
+ def say_default
117
+ 'default'
118
+ end
115
119
  YAML
116
120
  end
117
121
 
@@ -177,8 +181,8 @@ describe 'AppMap class Hooking', docker: false do
177
181
  :static: false
178
182
  :parameters:
179
183
  - :name: :kw
180
- :class: Hash
181
- :value: '{:kw=>"kw"}'
184
+ :class: String
185
+ :value: kw
182
186
  :kind: :key
183
187
  :receiver:
184
188
  :class: InstanceMethod
@@ -225,6 +229,48 @@ describe 'AppMap class Hooking', docker: false do
225
229
  end
226
230
  end
227
231
 
232
+ it 'hooks an instance method that takes keyword arguments' do
233
+ events_yaml = <<~YAML
234
+ ---
235
+ - :id: 1
236
+ :event: :call
237
+ :defined_class: InstanceMethod
238
+ :method_id: say_kws
239
+ :path: spec/fixtures/hook/instance_method.rb
240
+ :lineno: 20
241
+ :static: false
242
+ :parameters:
243
+ - :name: :args
244
+ :class: Array
245
+ :value: "[4, 5]"
246
+ :kind: :rest
247
+ - :name: :kw1
248
+ :class: String
249
+ :value: one
250
+ :kind: :keyreq
251
+ - :name: :kw2
252
+ :class: Integer
253
+ :value: '2'
254
+ :kind: :key
255
+ - :name: :kws
256
+ :class: Hash
257
+ :value: "{:kw3=>:three}"
258
+ :kind: :keyrest
259
+ :receiver:
260
+ :class: InstanceMethod
261
+ :value: Instance Method fixture
262
+ - :id: 2
263
+ :event: :return
264
+ :parent_id: 1
265
+ :return_value:
266
+ :class: String
267
+ :value: one2{:kw3=>:three}45
268
+ YAML
269
+ test_hook_behavior 'spec/fixtures/hook/instance_method.rb', events_yaml do
270
+ expect(InstanceMethod.new.say_kws(4, 5, kw1: 'one', kw2: 2, kw3: :three)).to eq('one2{:kw3=>:three}45')
271
+ end
272
+ end
273
+
228
274
  it 'hooks an instance method that takes a block argument' do
229
275
  events_yaml = <<~YAML
230
276
  ---
@@ -233,7 +279,7 @@ describe 'AppMap class Hooking', docker: false do
233
279
  :defined_class: InstanceMethod
234
280
  :method_id: say_block
235
281
  :path: spec/fixtures/hook/instance_method.rb
236
- :lineno: 20
282
+ :lineno: 24
237
283
  :static: false
238
284
  :parameters:
239
285
  - :name: :block
@@ -401,7 +447,7 @@ describe 'AppMap class Hooking', docker: false do
401
447
 
402
448
  # Verify the native extension works as expected
403
449
  expect(AppMap::Hook.singleton_method_owner_name(say_instance_defined)).to eq('SingletonMethod')
404
-
450
+
405
451
  expect(s.say_instance_defined).to eq('defined for an instance')
406
452
  end
407
453
  end
@@ -432,7 +478,7 @@ describe 'AppMap class Hooking', docker: false do
432
478
  expect(SingletonMethod::STRUCT_TEST.say_struct_singleton).to eq('singleton for a struct')
433
479
  end
434
480
  end
435
-
481
+
436
482
  it 'Reports exceptions' do
437
483
  events_yaml = <<~YAML
438
484
  ---
@@ -479,8 +525,8 @@ describe 'AppMap class Hooking', docker: false do
479
525
  :static: false
480
526
  :parameters:
481
527
  - :name: :args
482
- :class: Symbol
483
- :value: to_s
528
+ :class: Array
529
+ :value: "[:to_s]"
484
530
  :kind: :rest
485
531
  :receiver:
486
532
  :class: Class
@@ -527,8 +573,8 @@ describe 'AppMap class Hooking', docker: false do
527
573
  :static: false
528
574
  :parameters:
529
575
  - :name: :args
530
- :class: Symbol
531
- :value: to_s
576
+ :class: Array
577
+ :value: "[:to_s]"
532
578
  :kind: :rest
533
579
  :receiver:
534
580
  :class: Class
@@ -649,8 +695,8 @@ describe 'AppMap class Hooking', docker: false do
649
695
  :static: false
650
696
  :parameters:
651
697
  - :name: arg
652
- :class: String
653
- :value: string
698
+ :class: Array
699
+ :value: '["string"]'
654
700
  :kind: :rest
655
701
  :receiver:
656
702
  :class: Digest::SHA256
@@ -669,8 +715,8 @@ describe 'AppMap class Hooking', docker: false do
669
715
  :static: false
670
716
  :parameters:
671
717
  - :name: arg
672
- :class: String
673
- :value: string
718
+ :class: Array
719
+ :value: '["string"]'
674
720
  :kind: :rest
675
721
  :receiver:
676
722
  :class: Digest::SHA256
@@ -695,9 +741,33 @@ describe 'AppMap class Hooking', docker: false do
695
741
  :value: 'true'
696
742
  YAML
697
743
 
698
- test_hook_behavior 'spec/fixtures/hook/compare.rb', events_yaml do
744
+ _, _, events = test_hook_behavior 'spec/fixtures/hook/compare.rb', nil do
699
745
  expect(Compare.compare('string', 'string')).to be_truthy
700
746
  end
747
+ secure_compare_event = YAML.load(events).find { |evt| evt[:defined_class] == 'ActiveSupport::SecurityUtils' }
748
+ secure_compare_event.delete(:lineno)
749
+
750
+ expect(Diffy::Diff.new(<<~YAML, secure_compare_event.to_yaml).to_s).to eq('')
751
+ ---
752
+ :id: 2
753
+ :event: :call
754
+ :defined_class: ActiveSupport::SecurityUtils
755
+ :method_id: secure_compare
756
+ :path: lib/active_support/security_utils.rb
757
+ :static: true
758
+ :parameters:
759
+ - :name: :a
760
+ :class: String
761
+ :value: string
762
+ :kind: :req
763
+ - :name: :b
764
+ :class: String
765
+ :value: string
766
+ :kind: :req
767
+ :receiver:
768
+ :class: Module
769
+ :value: ActiveSupport::SecurityUtils
770
+ YAML
701
771
  end
702
772
 
703
773
  it 'gets labeled in the classmap' do
@@ -713,6 +783,10 @@ describe 'AppMap class Hooking', docker: false do
713
783
  :type: function
714
784
  :location: spec/fixtures/hook/compare.rb:4
715
785
  :static: true
786
+ :source: |2
787
+ def self.compare(s1, s2)
788
+ ActiveSupport::SecurityUtils.secure_compare(s1, s2)
789
+ end
716
790
  - :name: active_support
717
791
  :type: package
718
792
  :children:
@@ -729,6 +803,15 @@ describe 'AppMap class Hooking', docker: false do
729
803
  :labels:
730
804
  - security
731
805
  - crypto
806
+ :comment: |
807
+ # Constant time string comparison, for variable length strings.
808
+ #
809
+ # The values are first processed by SHA256, so that we don't leak length info
810
+ # via timing attacks.
811
+ :source: |2
812
+ def secure_compare(a, b)
813
+ fixed_length_secure_compare(::Digest::SHA256.digest(a), ::Digest::SHA256.digest(b)) && a == b
814
+ end
732
815
  - :name: openssl
733
816
  :type: package
734
817
  :children:
@@ -747,16 +830,14 @@ describe 'AppMap class Hooking', docker: false do
747
830
  - crypto
748
831
  YAML
749
832
 
750
- config, tracer = invoke_test_file 'spec/fixtures/hook/compare.rb' do
833
+ _, tracer = invoke_test_file 'spec/fixtures/hook/compare.rb' do
751
834
  expect(Compare.compare('string', 'string')).to be_truthy
752
835
  end
753
836
  cm = AppMap::Util.sanitize_paths(AppMap::ClassMap.build_from_methods(tracer.event_methods))
754
837
  entry = cm[1][:children][0][:children][0][:children][0]
755
838
  # Sanity check, make sure we got the right one
756
839
  expect(entry[:name]).to eq('secure_compare')
757
- spec = Gem::Specification.find_by_name('activesupport')
758
- entry[:location].gsub!(spec.base_dir + '/', '')
759
- expect(Diffy::Diff.new(classmap_yaml, cm.to_yaml).to_s).to eq('')
840
+ expect(entry[:labels]).to eq(%w[security crypto])
760
841
  end
761
842
  end
762
843
 
@@ -768,7 +849,7 @@ describe 'AppMap class Hooking', docker: false do
768
849
  :defined_class: InstanceMethod
769
850
  :method_id: say_the_time
770
851
  :path: spec/fixtures/hook/instance_method.rb
771
- :lineno: 24
852
+ :lineno: 28
772
853
  :static: false
773
854
  :parameters: []
774
855
  :receiver:
@@ -29,10 +29,10 @@ def run_cmd(*cmd, &failed)
29
29
  raise 'Command failed'
30
30
  end
31
31
 
32
- shared_context 'Rails app pg database' do
33
- before(:all) do
34
- raise 'you must set @fixure_dir' unless @fixture_dir
32
+ shared_context 'Rails app pg database' do |fixture_dir|
33
+ define_method(:fixture_dir) { fixture_dir }
35
34
 
35
+ before(:all) do
36
36
  print_pg_logs = lambda do
37
37
  logs, = run_cmd 'docker-compose logs pg'
38
38
  puts "docker-compose logs for pg:"
@@ -40,7 +40,7 @@ shared_context 'Rails app pg database' do
40
40
  puts logs
41
41
  end
42
42
 
43
- Dir.chdir @fixture_dir do
43
+ Dir.chdir fixture_dir do
44
44
  run_cmd 'docker-compose down -v'
45
45
  cmd = 'docker-compose up -d pg'
46
46
  run_cmd cmd
@@ -54,7 +54,7 @@ shared_context 'Rails app pg database' do
54
54
  after(:all) do
55
55
  if ENV['NOKILL'] != 'true'
56
56
  cmd = 'docker-compose down -v'
57
- run_cmd cmd, chdir: @fixture_dir
57
+ run_cmd cmd, chdir: fixture_dir
58
58
  end
59
59
  end
60
60
  end
@@ -1,43 +1,42 @@
1
1
  require 'rails_spec_helper'
2
2
 
3
3
  describe 'AppMap tracer via Railtie' do
4
- before(:all) { @fixture_dir = 'spec/fixtures/rails_users_app' }
5
- include_context 'Rails app pg database'
6
-
7
- let(:env) { {} }
4
+ include_context 'Rails app pg database', 'spec/fixtures/rails5_users_app' do
5
+ let(:env) { {} }
8
6
 
9
- let(:cmd) { %(docker-compose run --rm -e RAILS_ENV -e APPMAP app ./bin/rails r "puts Rails.configuration.appmap.enabled.inspect") }
10
- let(:command_capture2) do
11
- require 'open3'
12
- Open3.capture3(env, cmd, chdir: @fixture_dir).tap do |result|
13
- unless result[2] == 0
14
- $stderr.puts <<~END
15
- Failed to run rails_users_app container
16
- <<< Output:
17
- #{result[0]}
18
- #{result[1]}
19
- >>> End of output
20
- END
21
- raise 'Failed to run rails_users_app container'
7
+ let(:cmd) { %(docker-compose run --rm -e RAILS_ENV -e APPMAP app ./bin/rails r "puts Rails.configuration.appmap.enabled.inspect") }
8
+ let(:command_capture2) do
9
+ require 'open3'
10
+ Open3.capture3(env, cmd, chdir: fixture_dir).tap do |result|
11
+ unless result[2] == 0
12
+ warn <<~STDERR
13
+ Failed to run rails5_users_app container
14
+ <<< Output:
15
+ #{result[0]}
16
+ #{result[1]}
17
+ >>> End of output
18
+ STDERR
19
+ raise 'Failed to run rails5_users_app container'
20
+ end
22
21
  end
23
22
  end
24
- end
25
- let(:command_output) { command_capture2[0].strip }
26
- let(:command_result) { command_capture2[2] }
27
-
28
- it 'is disabled by default' do
29
- expect(command_output).to eq('nil')
30
- end
23
+ let(:command_output) { command_capture2[0].strip }
24
+ let(:command_result) { command_capture2[2] }
31
25
 
32
- describe 'with APPMAP=true' do
33
- let(:env) { { 'APPMAP' => 'true' } }
34
- it 'is enabled' do
35
- expect(command_output.split("\n")).to include('true')
26
+ it 'is disabled by default' do
27
+ expect(command_output).to eq('nil')
36
28
  end
37
- context 'and RAILS_ENV=test' do
38
- let(:env) { { 'APPMAP' => 'true', 'RAILS_ENV' => 'test' } }
39
- it 'is disabled' do
40
- expect(command_output).to eq('nil')
29
+
30
+ describe 'with APPMAP=true' do
31
+ let(:env) { { 'APPMAP' => 'true' } }
32
+ it 'is enabled' do
33
+ expect(command_output.split("\n")).to include('true')
34
+ end
35
+ context 'and RAILS_ENV=test' do
36
+ let(:env) { { 'APPMAP' => 'true', 'RAILS_ENV' => 'test' } }
37
+ it 'is disabled' do
38
+ expect(command_output).to eq('nil')
39
+ end
41
40
  end
42
41
  end
43
42
  end
@@ -1,75 +1,74 @@
1
1
  require 'rails_spec_helper'
2
2
 
3
3
  describe 'Record SQL queries in a Rails4 app' do
4
- before(:all) { @fixture_dir = 'spec/fixtures/rails4_users_app' }
5
- include_context 'Rails app pg database'
6
-
7
- around(:each) do |example|
8
- FileUtils.rm_rf tmpdir
9
- FileUtils.mkdir_p tmpdir
10
- cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
11
- run_cmd cmd, chdir: @fixture_dir
4
+ include_context 'Rails app pg database', 'spec/fixtures/rails4_users_app' do
5
+ around(:each) do |example|
6
+ FileUtils.rm_rf tmpdir
7
+ FileUtils.mkdir_p tmpdir
8
+ cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
9
+ run_cmd cmd, chdir: fixture_dir
12
10
 
13
- example.run
14
- end
11
+ example.run
12
+ end
13
+
14
+ let(:tmpdir) { "tmp/spec/record_sql_rails_pg_spec" }
15
+ let(:appmap) { JSON.parse(File.read(appmap_json)).to_yaml }
15
16
 
16
- let(:tmpdir) { "tmp/spec/record_sql_rails_pg_spec" }
17
- let(:appmap) { JSON.parse(File.read(appmap_json)).to_yaml }
17
+ context 'when running specs' do
18
+ let(:test_line_number) { 31 }
19
+ let(:orm_module) { 'activerecord' }
18
20
 
19
- context 'when running specs' do
20
- let(:test_line_number) { 31 }
21
- let(:orm_module) { 'activerecord' }
21
+ it { is_expected.to be }
22
+ end
22
23
 
23
- it { is_expected.to be }
24
- end
25
-
26
- context 'while creating a new record' do
27
- let(:test_line_number) { 8 }
28
- let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
24
+ context 'while creating a new record' do
25
+ let(:test_line_number) { 8 }
26
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
29
27
 
30
- xcontext 'using Sequel ORM' do
31
- let(:orm_module) { 'sequel' }
32
- it 'detects the sql INSERT' do
33
- expect(appmap).to include(<<-SQL_QUERY.strip)
28
+ xcontext 'using Sequel ORM' do
29
+ let(:orm_module) { 'sequel' }
30
+ it 'detects the sql INSERT' do
31
+ expect(appmap).to include(<<-SQL_QUERY.strip)
34
32
  sql_query:
35
33
  sql: INSERT INTO "users" ("login") VALUES ('alice') RETURNING *
36
- SQL_QUERY
34
+ SQL_QUERY
35
+ end
37
36
  end
38
- end
39
- context 'using ActiveRecord ORM' do
40
- let(:orm_module) { 'activerecord' }
41
- it 'detects the sql INSERT' do
42
- expect(appmap).to include(<<-SQL_QUERY.strip)
37
+ context 'using ActiveRecord ORM' do
38
+ let(:orm_module) { 'activerecord' }
39
+ it 'detects the sql INSERT' do
40
+ expect(appmap).to include(<<-SQL_QUERY.strip)
43
41
  sql_query:
44
42
  sql: INSERT INTO "users" ("login", "created_at", "updated_at") VALUES ($1, $2,
45
43
  $3) RETURNING "id"
46
- SQL_QUERY
44
+ SQL_QUERY
45
+ end
47
46
  end
48
47
  end
49
- end
50
48
 
51
- context 'while listing records' do
52
- let(:test_line_number) { 23 }
53
- let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
49
+ context 'while listing records' do
50
+ let(:test_line_number) { 23 }
51
+ let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
54
52
 
55
- xcontext 'using Sequel ORM' do
56
- let(:orm_module) { 'sequel' }
57
- it 'detects the sql SELECT' do
58
- expect(appmap).to include(<<-SQL_QUERY.strip)
53
+ xcontext 'using Sequel ORM' do
54
+ let(:orm_module) { 'sequel' }
55
+ it 'detects the sql SELECT' do
56
+ expect(appmap).to include(<<-SQL_QUERY.strip)
59
57
  sql_query:
60
58
  sql: SELECT * FROM "users"
61
- SQL_QUERY
59
+ SQL_QUERY
62
60
 
63
- expect(appmap).to include('sql:')
61
+ expect(appmap).to include('sql:')
62
+ end
64
63
  end
65
- end
66
- context 'using ActiveRecord ORM' do
67
- let(:orm_module) { 'activerecord' }
68
- it 'detects the sql SELECT' do
69
- expect(appmap).to include(<<-SQL_QUERY.strip)
64
+ context 'using ActiveRecord ORM' do
65
+ let(:orm_module) { 'activerecord' }
66
+ it 'detects the sql SELECT' do
67
+ expect(appmap).to include(<<-SQL_QUERY.strip)
70
68
  sql_query:
71
69
  sql: SELECT "users".* FROM "users"
72
- SQL_QUERY
70
+ SQL_QUERY
71
+ end
73
72
  end
74
73
  end
75
74
  end