Class: Arachni::Element::GenericDOM

Inherits:
Base show all
Includes:
Capabilities::WithAuditor, Capabilities::WithSource
Defined in:
lib/arachni/element/generic_dom.rb

Overview

Represents generic DOM elements, basically anything that can be part of a Page::DOM::Transition, and is used just for wrapping them in something that presents an interface compatible with the other, more traditional, elements when logging issues.

Author:

Constant Summary

Constants inherited from Base

Base::MAX_SIZE

Instance Attribute Summary collapse

Attributes included from Capabilities::WithAuditor

#auditor

Attributes included from Capabilities::WithSource

#source

Attributes inherited from Base

#initialization_options, #page

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Capabilities::WithAuditor

#dup, #marshal_dump, #orphan?, #prepare_for_report, #remove_auditor

Methods included from Capabilities::WithSource

#dup

Methods inherited from Base

#==, #action, #dup, #hash, #id, #marshal_dump, #marshal_load, #persistent_hash, #prepare_for_report, #reset, #to_hash, too_big?, type, #url, #url=

Methods included from Utilities

#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_file, #cookies_from_parser, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_parser, #forms_from_response, #full_and_absolute_url?, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_parser, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_set_cookie, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #random_seed, #redundant_path?, #regexp_array_match, #remove_constants, #request_parse_body, #seconds_to_hms, #skip_page?, #skip_path?, #skip_resource?, #skip_response?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parse_query, #uri_parser, #uri_rewrite

Methods included from Capabilities::WithScope

#scope

Constructor Details

#initialize(options = {}) ⇒ GenericDOM

Returns a new instance of GenericDOM.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):



29
30
31
32
33
34
35
36
37
# File 'lib/arachni/element/generic_dom.rb', line 29

def initialize( options = {} )
    super

    @transition = options[:transition]
    fail 'Missing element locator.' if !@transition

    self.source = element.to_s
    @initialization_options = options
end

Instance Attribute Details

#transitionPage::DOM::Transition (readonly)



24
25
26
# File 'lib/arachni/element/generic_dom.rb', line 24

def transition
  @transition
end

Class Method Details

.from_rpc_data(data) ⇒ GenericDOM

Returns Restored element.

Parameters:

Returns:



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/arachni/element/generic_dom.rb', line 110

def from_rpc_data( data )
    instance = allocate
    data.each do |name, value|
        value = case name
                    when 'transition'
                        Arachni::Page::DOM::Transition.from_rpc_data( value )

                    when 'initialization_options'
                        value = value.is_a?( Hash ) ? value.my_symbolize_keys(false) : value
                        value[:transition] =
                            Arachni::Page::DOM::Transition.from_rpc_data( value[:transition] )
                        value

                    else
                        value
                end

        instance.instance_variable_set( "@#{name}", value )
    end
    instance
end

Instance Method Details

#attributesHash

Returns Element attributes.

Returns:

  • (Hash)

    Element attributes.

See Also:

  • Browser::Element::Locator#attributes


60
61
62
# File 'lib/arachni/element/generic_dom.rb', line 60

def attributes
    element.attributes
end

#elementBrowser::Element::Locator

Returns Locator for the logged element.

Returns:

  • (Browser::Element::Locator)

    Locator for the logged element.

See Also:



52
53
54
# File 'lib/arachni/element/generic_dom.rb', line 52

def element
    transition.element
end

#eventSymbol Also known as: method

Returns DOM event.

Returns:

  • (Symbol)

    DOM event.

See Also:



43
44
45
# File 'lib/arachni/element/generic_dom.rb', line 43

def event
    transition.event
end

#nameString? Also known as: affected_input_name

Returns Name or ID from the #attributes if any are defined.

Returns:



66
67
68
# File 'lib/arachni/element/generic_dom.rb', line 66

def name
    attributes['name'] || attributes['id']
end

#to_hHash

Returns:



80
81
82
# File 'lib/arachni/element/generic_dom.rb', line 80

def to_h
    super.merge( transition: transition.to_h.tap { |h| h[:element] = h[:element].to_h } )
end

#to_rpc_dataHash

Returns Data representing the state and data of the element to be passed to from_rpc_data.

Returns:

  • (Hash)

    Data representing the state and data of the element to be passed to from_rpc_data.



95
96
97
98
99
100
101
# File 'lib/arachni/element/generic_dom.rb', line 95

def to_rpc_data
    data = super
    data['initialization_options'] = data['initialization_options'].dup
    data['initialization_options']['transition'] =
        data['initialization_options']['transition'].to_rpc_data
    data
end

#typeSymbol

Returns Element tag name.

Returns:

  • (Symbol)

    Element tag name.

See Also:

  • Browser::Element::Locator#tag_name


88
89
90
# File 'lib/arachni/element/generic_dom.rb', line 88

def type
    element.tag_name
end

#valueString? Also known as: affected_input_value

Returns Element value (in case of an input) from the #transition Page::DOM::Transition#options.

Returns:



74
75
76
# File 'lib/arachni/element/generic_dom.rb', line 74

def value
    transition.options[:value]
end