Class: Arachni::Element::GenericDOM

Inherits:
Base show all
Includes:
Capabilities::WithAuditor
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.

Instance Attribute Summary collapse

Attributes included from Capabilities::WithAuditor

#auditor

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 inherited from Base

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

Methods included from Utilities

#available_port, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_document, #forms_from_response, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_document, #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?, #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):



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

def initialize( options = {} )
    super

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

    @initialization_options = options
end

Instance Attribute Details

#transitionPage::DOM::Transition (readonly)



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

def transition
  @transition
end

Class Method Details

.from_rpc_data(data) ⇒ GenericDOM

Returns Restored element.

Parameters:

Returns:



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

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


58
59
60
# File 'lib/arachni/element/generic_dom.rb', line 58

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:



50
51
52
# File 'lib/arachni/element/generic_dom.rb', line 50

def element
    transition.element
end

#eventSymbol Also known as: method

Returns DOM event.

Returns:

  • (Symbol)

    DOM event.

See Also:



41
42
43
# File 'lib/arachni/element/generic_dom.rb', line 41

def event
    transition.event
end

#nameString? Also known as: affected_input_name

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

Returns:



64
65
66
# File 'lib/arachni/element/generic_dom.rb', line 64

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

#to_hHash

Returns:



78
79
80
# File 'lib/arachni/element/generic_dom.rb', line 78

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.



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

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


86
87
88
# File 'lib/arachni/element/generic_dom.rb', line 86

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:



72
73
74
# File 'lib/arachni/element/generic_dom.rb', line 72

def value
    transition.options[:value]
end