Module: Arachni::Element::Capabilities::Inputtable

Overview

Author:

Defined Under Namespace

Classes: Error

Constant Summary collapse

INPUTTABLE_CACHE =
{
    inputtable_id: Support::Cache::LeastRecentlyPushed.new( 1_000 )
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_inputsHash (readonly)

Frozen version of #inputs, has all the original names and values.

Returns:



47
48
49
# File 'lib/arachni/element/capabilities/inputtable.rb', line 47

def default_inputs
  @default_inputs
end

#inputsHash

Note:

Can be modified via #update, #[]= or #inputs=.

Returns Frozen effective inputs.

Returns:

  • (Hash)

    Frozen effective inputs.



53
54
55
# File 'lib/arachni/element/capabilities/inputtable.rb', line 53

def inputs
  @inputs
end

Instance Method Details

#[](name) ⇒ String

Shorthand #inputs reader.

Parameters:

  • name (#to_s)

    Name.

Returns:



117
118
119
# File 'lib/arachni/element/capabilities/inputtable.rb', line 117

def []( name )
    @inputs[name.to_s]
end

#[]=(name, value) ⇒ Object

Shorthand #inputs writer.

Parameters:

  • name (#to_s)

    Name.

  • value (#to_s)

    Value.

Raises:



130
131
132
133
# File 'lib/arachni/element/capabilities/inputtable.rb', line 130

def []=( name, value )
    update( name.to_s => value.to_s )
    self[name]
end

#changesHash

Returns changes make to the #inputs‘s inputs.

Returns:

  • (Hash)

    Returns changes make to the #inputs‘s inputs.



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

def changes
    (@default_inputs.keys | @inputs.keys).inject( {} ) do |h, k|
        if @default_inputs[k] != @inputs[k]
            h[k] = @inputs[k]
        end
        h
    end
end

#dupObject



223
224
225
# File 'lib/arachni/element/capabilities/inputtable.rb', line 223

def dup
    copy_inputtable( super )
end

#has_inputs?(*args) ⇒ Bool

Checks whether or not the given inputs match the inputs ones.

Parameters:

  • args (Hash, Array, String, Symbol)

    Names of inputs to check (also accepts var-args).

Returns:

  • (Bool)


83
84
85
86
87
88
89
90
91
# File 'lib/arachni/element/capabilities/inputtable.rb', line 83

def has_inputs?( *args )
    if (h = args.first).is_a?( Hash )
        h.each { |k, v| return false if self[k] != v }
        true
    else
        keys = args.flatten.compact.map { |a| [a].map(&:to_s) }.flatten
        (@inputs.keys & keys).size == keys.size
    end
end

#inputtable_idString

Returns Uniquely identifies the #inputs.

Returns:



229
230
231
232
# File 'lib/arachni/element/capabilities/inputtable.rb', line 229

def inputtable_id
    INPUTTABLE_CACHE[:inputtable_id][@inputs] ||=
        @inputs ? @inputs.sort_by { |k, _| k }.hash.to_s : ''
end

#resetObject

Resets the inputs to their original format/values.



105
106
107
108
109
# File 'lib/arachni/element/capabilities/inputtable.rb', line 105

def reset
    super if defined?( super )
    self.inputs = @default_inputs.deep_clone
    self
end

#to_hObject



234
235
236
237
238
239
# File 'lib/arachni/element/capabilities/inputtable.rb', line 234

def to_h
    (defined?( super ) ? super : {}).merge(
        inputs:         inputs,
        default_inputs: default_inputs
    )
end

#try_input(&block) ⇒ Bool

Performs an input operation and silently handles Arachni::Element::Capabilities::Inputtable::Error::InvalidData.

Parameters:

  • block (Block)

    Input operation to try to perform.

Returns:

  • (Bool)

    ‘true` if the operation was successful, `false` otherwise.



212
213
214
215
216
217
218
219
220
221
# File 'lib/arachni/element/capabilities/inputtable.rb', line 212

def try_input( &block )
    block.call
    true
rescue Error::InvalidData => e
    return false if !respond_to?( :print_debug_level_1 )

    print_debug_level_1 e.to_s
    e.backtrace.each { |l| print_debug_level_1 l }
    false
end

#update(hash) ⇒ Auditable

Returns ‘self`.

Parameters:

  • hash (Hash)

    Inputs with which to update the #inputs inputs.

Returns:

Raises:



142
143
144
145
146
147
# File 'lib/arachni/element/capabilities/inputtable.rb', line 142

def update( hash )
    return self if hash.empty?

    self.inputs = @inputs.merge( hash )
    self
end

#valid_input_data?(data) ⇒ Bool

This method is abstract.

Returns ‘true` if the data can be carried by the element’s inputs, ‘false` otherwise.

Parameters:

  • data (String)

    Data to check.

Returns:

  • (Bool)

    ‘true` if the data can be carried by the element’s inputs, ‘false` otherwise.



201
202
203
# File 'lib/arachni/element/capabilities/inputtable.rb', line 201

def valid_input_data?( data )
    true
end

#valid_input_name?(name) ⇒ Bool

This method is abstract.

Returns ‘true` if the name can be carried by the element’s inputs, ‘false` otherwise.

Parameters:

  • name (String)

    Name to check.

Returns:

  • (Bool)

    ‘true` if the name can be carried by the element’s inputs, ‘false` otherwise.



157
158
159
# File 'lib/arachni/element/capabilities/inputtable.rb', line 157

def valid_input_name?( name )
    true
end

#valid_input_name_data?(name) ⇒ Bool

Returns ‘true` if `name` is both a #valid_input_name? and contains #valid_input_data?.

Parameters:

  • name (String)

    Name to check.

Returns:



167
168
169
# File 'lib/arachni/element/capabilities/inputtable.rb', line 167

def valid_input_name_data?( name )
    valid_input_name?( name ) && valid_input_data?( name )
end

#valid_input_value?(value) ⇒ Bool

This method is abstract.

Returns ‘true` if the value can be carried by the element’s inputs, ‘false` otherwise.

Parameters:

  • value (String)

    Value to check.

Returns:

  • (Bool)

    ‘true` if the value can be carried by the element’s inputs, ‘false` otherwise.



179
180
181
# File 'lib/arachni/element/capabilities/inputtable.rb', line 179

def valid_input_value?( value )
    true
end

#valid_input_value_data?(value) ⇒ Bool

Returns ‘true` if `value` is both a #valid_input_value? and contains #valid_input_data?.

Parameters:

  • value (String)

    Value to check.

Returns:



189
190
191
# File 'lib/arachni/element/capabilities/inputtable.rb', line 189

def valid_input_value_data?( value )
    valid_input_value?( value ) && valid_input_data?( value )
end