# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/agent/reporting/reporting_events/route_discovery_observation' require 'contrast/agent/reporting/reporting_events/reportable_hash' require 'contrast/utils/duck_utils' module Contrast module Agent module Reporting # This is the new Route Discovery class which will include all the needed information for the new reporting # system to relay this information in the Application Update messages. These discoveries are used by TeamServer # to construct the route coverage information for the assess feature. They represent those methods which map to # externally accessible endpoints within the application, as registered to the application framework. They may or # may not have been invoked at the time of reporting. # class RouteDiscovery < Contrast::Agent::Reporting::ReportableHash # @return [Array] the routes and verbs seen that match # to this Route. attr_reader :observations # @return [String] the unique identifier for this route; typically the method signature. Required for # reporting. attr_accessor :signature # @param signature [String] # @param observation [Contrast::Agent::Reporting::RouteDiscoveryObservation] def initialize signature, observation @signature = signature @observations = [] observations << observation super() end # Convert the instance variables on the class, and other information, into the identifiers required for # TeamServer to process the JSON form of this message. # # @return [Hash] # @raise [ArgumentError] def to_controlled_hash validate { count: 0, # we have this to make TS happy observations: @observations.map(&:to_controlled_hash), signature: @signature } end # Ensure the required fields are present. # # @raise [ArgumentError] def validate return unless Contrast::Utils::DuckUtils.empty_duck?(signature) raise(ArgumentError, "#{ self } did not have a proper signature. Unable to continue.") end end end end end