Sha256: ca9c03fe40aaa6138be2dd41a276c49307d95b7e41e1436b8cd548bfa4057739

Contents?: true

Size: 1.67 KB

Versions: 18

Compression:

Stored size: 1.67 KB

Contents

# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/utils/string_utils'
require 'contrast/utils/assess/tracking_util'
require 'base64'

module Contrast
  module Api
    module Decorators
      # Used to decorate the {Contrast::Api::Dtm::UserInput} protobuf model.
      module UserInput
        UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
          user_input.input_type = :UNKNOWN
        end
        UNKNOWN_USER_INPUT.cs__freeze

        def self.included klass
          klass.extend(ClassMethods)
        end

        # Used to add class methods to UserInput
        module ClassMethods
          def build_from_ia_result ia_result
            return UNKNOWN_USER_INPUT.dup unless ia_result

            user_input = new
            user_input.matcher_ids = ia_result.ids
            user_input.path = ia_result.path.to_s
            user_input.key = ia_result.key.to_s
            user_input.value = ia_result.value.to_s
            if ia_result.input_type
              #
              # InputAnalysis have local Agent implementation, so we need ot take care of difference
              # if we pass data from wrong place - we need to handle the TypeError in throws
              begin
                user_input.input_type = ia_result.input_type.to_i
              rescue TypeError, NoMethodError => _e
                user_input.input_type = ia_result.input_type
              end
            end

            user_input
          end
        end
      end
    end
  end
end

Contrast::Api::Dtm::UserInput.include(Contrast::Api::Decorators::UserInput)

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
contrast-agent-6.7.0 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.6.5 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.6.4 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.6.3 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.6.2 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.6.1 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.6.0 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.5.1 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.5.0 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.4.0 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.3.0 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.2.0 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.1.2 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.1.1 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.1.0 lib/contrast/api/decorators/user_input.rb
contrast-agent-6.0.0 lib/contrast/api/decorators/user_input.rb
contrast-agent-5.3.0 lib/contrast/api/decorators/user_input.rb
contrast-agent-5.2.0 lib/contrast/api/decorators/user_input.rb