Class: Contrast::Agent::Reporting::FindingEventSignature

Inherits:
ReportableHash show all
Defined in:
lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb

Overview

This is the new FindingEventSignature class which will include all the needed information for the new reporting system to relay this information in the Finding/Trace messages. These FindingEventSignatures are used by TeamServer to construct the method signature for the assess feature. They represent the method invoked when the FindingEvent was generated.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ReportableHash

#event_json, #valid?

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Constructor Details

#initialize(policy_node, args, ret) ⇒ FindingEventSignature

invoked method

Parameters:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 42

def initialize policy_node, args, ret
  node = policy_node
  @arg_types = []
  args&.each { |arg| arg_types << type_name(arg) }
  @class_name = node.class_name
  @constructor = node.method_name == :new || node.method_name == :initialize
  # 8 is STATIC in Java... we have to placate them for now it has been requested that flags be removed since it
  # isn't used
  @flags = 8 unless node.instance_method?
  @method_name = node.method_name.to_s
  @return_type = type_name(ret)
  # if there's a ret, then this method isn't nil. not 100% full proof since you can return nil, but this is the
  # best we've got currently.
  @void_method = ret.nil? || ret.object.nil? || ret.object == Contrast::Utils::ObjectShare::NIL_STRING
  super()
end

Instance Attribute Details

#arg_typesString (readonly)

Returns the types of the arguments in this event; may be different for each invocation of the method.

Returns:

  • (String)

    the types of the arguments in this event; may be different for each invocation of the method.



17
18
19
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 17

def arg_types
  @arg_types
end

#class_nameString (readonly)

Returns the name of the class of this object or the name itself if of Module type.

Returns:

  • (String)

    the name of the class of this object or the name itself if of Module type.



19
20
21
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 19

def class_name
  @class_name
end

#constructorBoolean (readonly)

Returns if the method is a constructor or not.

Returns:

  • (Boolean)

    if the method is a constructor or not.



21
22
23
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 21

def constructor
  @constructor
end

#expression_typeString (readonly)

Returns unused.

Returns:



23
24
25
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 23

def expression_type
  @expression_type
end

#flagsInteger (readonly)

Returns the Java flags; static or not.

Returns:

  • (Integer)

    the Java flags; static or not.



25
26
27
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 25

def flags
  @flags
end

#method_nameString (readonly)

Returns the name of the method.

Returns:

  • (String)

    the name of the method.



27
28
29
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 27

def method_name
  @method_name
end

#operatorString (readonly)

Returns unused.

Returns:



29
30
31
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 29

def operator
  @operator
end

#return_typeString (readonly)

Returns the type of the return in this event; may be different for each invocation of the method.

Returns:

  • (String)

    the type of the return in this event; may be different for each invocation of the method.



31
32
33
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 31

def return_type
  @return_type
end

#signatureString (readonly)

Returns unused.

Returns:



33
34
35
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 33

def signature
  @signature
end

#void_methodBoolean (readonly)

Returns if the method is void or not; may be different for each invocation of the method.

Returns:

  • (Boolean)

    if the method is void or not; may be different for each invocation of the method.



35
36
37
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 35

def void_method
  @void_method
end

Instance Method Details

#to_controlled_hashHash

Convert the instance variables on the class, and other information, into the identifiers required for TeamServer to process the JSON form of this message.

Returns:

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 64

def to_controlled_hash
  validate
  {
      argTypes: arg_types,
      className: class_name,
      constructor: constructor,
      # expressionType: expression_type, # This is unused by the Ruby agent
      flags: flags.to_i,
      methodName: method_name,
      # operator: operator, # This is unused by the Ruby agent
      returnType: return_type,
      # signature: signature, # This is unused by the Ruby agent
      voidMethod: void_method
  }
end

#validateObject

Raises:

  • (ArgumentError)


80
81
82
83
# File 'lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb', line 80

def validate
  raise(ArgumentError, "#{ self } did not have a proper argTypes. Unable to continue.") unless arg_types
  raise(ArgumentError, "#{ self } did not have a proper constructor. Unable to continue.") if constructor.nil?
end