Sha256: 347a94153993ac07fa72275c2f381204c1d69bd8254773ea8134fb369c22f5b7
Contents?: true
Size: 1.93 KB
Versions: 3
Compression:
Stored size: 1.93 KB
Contents
# 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/utils/string_utils' module Contrast module Api module Decorators # Used to decorate the RouteCoverage protobuf model to handle conversion between framework route classes module RouteCoverage def self.included klass klass.extend(ClassMethods) end # Class methods for RouteCoverage module ClassMethods def source_or_string obj if obj.cs__is_a?(Regexp) obj.source elsif obj.cs__respond_to?(:safe_string) obj.safe_string else obj.to_s end end # Convert ActionDispatch::Journey::Route to Contrast::Api::Dtm::RouteCoverage # @param journey_obj [ActionDispatch::Journey::Route] a rails route # @return [Contrast::Api::Dtm::RouteCoverage] def from_action_dispatch_journey journey_obj msg = new msg.route = "#{ journey_obj.defaults[:controller] }##{ journey_obj.defaults[:action] }" verb = source_or_string(journey_obj.verb) msg.verb = Contrast::Utils::StringUtils.force_utf8(verb) url = source_or_string(journey_obj.path.spec) msg.url = Contrast::Utils::StringUtils.force_utf8(url) msg end def from_sinatra_route clazz, method, pattern safe_pattern = source_or_string(pattern) msg = new msg.route = "#{ clazz }##{ method } #{ safe_pattern }" msg.verb = Contrast::Utils::StringUtils.force_utf8(method) msg.url = Contrast::Utils::StringUtils.force_utf8(safe_pattern) msg end end end end end end Contrast::Api::Dtm::RouteCoverage.include(Contrast::Api::Decorators::RouteCoverage)
Version data entries
3 entries across 3 versions & 1 rubygems