lib/contrast/framework/rails/support.rb in contrast-agent-3.12.2 vs lib/contrast/framework/rails/support.rb in contrast-agent-3.13.0
- old
+ new
@@ -1,31 +1,21 @@
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true
-cs__scoped_require 'contrast/api/dtm_pb'
+cs__scoped_require 'contrast/api/dtm.pb'
cs__scoped_require 'contrast/framework/base_support'
cs__scoped_require 'contrast/framework/rails/patch/support'
-cs__scoped_require 'contrast/framework/view_technologies_descriptor'
cs__scoped_require 'contrast/utils/string_utils'
module Contrast
module Framework
module Rails
# Used when Rails is present to define framework specific behavior
class Support < BaseSupport
extend Contrast::Framework::Rails::Patch::Support
class << self
- RAILS_VIEWS = [
- Contrast::Framework::ViewTechnologiesDescriptor.new('app/assets', 'coffee', %w[CoffeeScript]),
- Contrast::Framework::ViewTechnologiesDescriptor.new('app/assets', 'scss', %w[SASS]),
- Contrast::Framework::ViewTechnologiesDescriptor.new('app/views', 'html', %w[HTML5]),
- Contrast::Framework::ViewTechnologiesDescriptor.new('app/views', 'html.erb', %w[HTML5 ERB]),
- Contrast::Framework::ViewTechnologiesDescriptor.new('app/views', 'html.haml', %w[HTML5 HAML]),
- Contrast::Framework::ViewTechnologiesDescriptor.new('public', 'html', %w[HTML5])
- ].cs__freeze
-
RAILS_MODULE_NAME_VERSION = Gem::Version.new('6.0.0')
def detection_class
'Rails'
end
@@ -49,17 +39,13 @@
def server_type
'rails'
end
- def scan_views
- scan_view_directories(RAILS_VIEWS)
- end
-
def collect_routes
routes = ::Rails.application.routes.routes.map do |route|
- route_to_coverage(route)
+ Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
end
routes
end
def current_route request
@@ -77,11 +63,11 @@
return unless full_route
route = full_route[2] # route w/ highest precedence
return unless route
- route_to_coverage(route)
+ Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
end
def retrieve_request env
rails_env = ::Rails.application.env_config.merge(env)
::ActionDispatch::Request.new(rails_env || env)
@@ -90,24 +76,9 @@
AC_INSTANCE = 'action_controller.instance'
def streaming? env
return false unless defined?(::ActionController::Live)
env[AC_INSTANCE].cs__class.included_modules.include?(::ActionController::Live)
- end
-
- private
-
- # Convert ActionDispatch::Journey::Route to Contrast::Api::Dtm::RouteCoverage
- def route_to_coverage route
- route_coverage = Contrast::Api::Dtm::RouteCoverage.new
- route_coverage.route = "#{ route.defaults[:controller] }##{ route.defaults[:action] }"
-
- verb = source_or_string(route.verb)
- route_coverage.verb = Contrast::Utils::StringUtils.force_utf8(verb)
-
- url = source_or_string(route.path.spec)
- route_coverage.url = Contrast::Utils::StringUtils.force_utf8(url)
- route_coverage
end
end
end
end
end