Module: Arachni::Element::Capabilities::Inputtable
- Included in:
- DOMOnly, Arachni::Element::Cookie, Arachni::Element::Cookie::Capabilities::Inputtable, DOM::Capabilities::Inputtable, Form, Header, Header, Header::Capabilities::Inputtable, JSON, JSON::Capabilities::Inputtable, Link, LinkTemplate, LinkTemplate::Capabilities::Inputtable, NestedCookie, XML::Capabilities::Inputtable
- Defined in:
- lib/arachni/element/capabilities/inputtable.rb
Overview
Defined Under Namespace
Classes: Error
Constant Summary collapse
- INPUTTABLE_CACHE =
{ inputtable_id: Support::Cache::LeastRecentlyPushed.new( 1_000 ) }
Instance Attribute Summary collapse
-
#default_inputs ⇒ Hash
readonly
Frozen version of #inputs, has all the original names and values.
-
#inputs ⇒ Hash
Frozen effective inputs.
-
#raw_inputs ⇒ Array
List of input names which should have their values submitted in raw form, without encoding.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](name) ⇒ String
Shorthand #inputs reader.
-
#[]=(name, value) ⇒ Object
Shorthand #inputs writer.
-
#changes ⇒ Hash
Returns changes make to the #inputs's inputs.
- #dup ⇒ Object
-
#has_inputs?(*args) ⇒ Bool
Checks whether or not the given inputs match the inputs ones.
- #initialize(options) ⇒ Object
-
#inputtable_id ⇒ String
Uniquely identifies the #inputs.
-
#raw_input?(name) ⇒ Boolean
`true` if the input `name` is in #raw_inputs, `false` otherwise.
-
#reset ⇒ Object
Resets the inputs to their original format/values.
- #to_h ⇒ Object
-
#try_input(&block) ⇒ Bool
Performs an input operation and silently handles Error::InvalidData.
-
#update(hash) ⇒ Auditable
`self`.
- #updated? ⇒ Boolean
-
#valid_input_data?(data) ⇒ Bool
abstract
`true` if the data can be carried by the element's inputs, `false` otherwise.
-
#valid_input_name?(name) ⇒ Bool
abstract
`true` if the name can be carried by the element's inputs, `false` otherwise.
-
#valid_input_name_data?(name) ⇒ Bool
`true` if `name` is both a #valid_input_name? and contains #valid_input_data?.
-
#valid_input_value?(value) ⇒ Bool
abstract
`true` if the value can be carried by the element's inputs, `false` otherwise.
-
#valid_input_value_data?(value) ⇒ Bool
`true` if `value` is both a #valid_input_value? and contains #valid_input_data?.
Instance Attribute Details
#default_inputs ⇒ Hash (readonly)
Frozen version of #inputs, has all the original names and values.
47 48 49 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 47 def default_inputs @default_inputs end |
#inputs ⇒ Hash
53 54 55 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 53 def inputs @inputs end |
#raw_inputs ⇒ Array
Null-bytes will always be encoded.
Returns List of input names which should have their values submitted in raw form, without encoding.
60 61 62 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 60 def raw_inputs @raw_inputs end |
Class Method Details
.inputtable_id(inputs, raw_inputs) ⇒ Object
271 272 273 274 275 276 277 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 271 def self.inputtable_id( inputs, raw_inputs ) INPUTTABLE_CACHE[:inputtable_id].fetch [inputs, raw_inputs] do id = inputs ? inputs.sort_by { |k, _| k }.hash.to_s : '' id << ':' id << (raw_inputs ? raw_inputs.sort.hash.to_s : '') end end |
Instance Method Details
#[](name) ⇒ String
Shorthand #inputs reader.
155 156 157 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 155 def []( name ) @inputs[name.to_s] end |
#[]=(name, value) ⇒ Object
Shorthand #inputs writer.
168 169 170 171 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 168 def []=( name, value ) update( name.to_s => value.to_s ) self[name] end |
#changes ⇒ Hash
Returns changes make to the #inputs's inputs.
128 129 130 131 132 133 134 135 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 128 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 |
#dup ⇒ Object
261 262 263 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 261 def dup copy_inputtable( super ) end |
#has_inputs?(*args) ⇒ Bool
Checks whether or not the given inputs match the inputs ones.
116 117 118 119 120 121 122 123 124 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 116 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 |
#initialize(options) ⇒ Object
62 63 64 65 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 62 def initialize( ) super @raw_inputs = [] end |
#inputtable_id ⇒ String
Returns Uniquely identifies the #inputs.
267 268 269 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 267 def inputtable_id Arachni::Element::Capabilities::Inputtable.inputtable_id( inputs, raw_inputs ) end |
#raw_input?(name) ⇒ Boolean
Returns `true` if the input `name` is in #raw_inputs, `false` otherwise.
72 73 74 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 72 def raw_input?( name ) @raw_inputs.include? name end |
#reset ⇒ Object
Resets the inputs to their original format/values.
142 143 144 145 146 147 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 142 def reset super if defined?( super ) self.inputs = @default_inputs.rpc_clone self.raw_inputs = [] self end |
#to_h ⇒ Object
279 280 281 282 283 284 285 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 279 def to_h (defined?( super ) ? super : {}).merge( inputs: inputs, raw_inputs: raw_inputs, default_inputs: default_inputs ) end |
#try_input(&block) ⇒ Bool
Performs an input operation and silently handles Arachni::Element::Capabilities::Inputtable::Error::InvalidData.
250 251 252 253 254 255 256 257 258 259 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 250 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`.
180 181 182 183 184 185 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 180 def update( hash ) return self if hash.empty? self.inputs = @inputs.merge( hash ) self end |
#updated? ⇒ Boolean
137 138 139 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 137 def updated? @default_inputs != self.inputs end |
#valid_input_data?(data) ⇒ Bool
Returns `true` if the data can be carried by the element's inputs, `false` otherwise.
239 240 241 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 239 def valid_input_data?( data ) true end |
#valid_input_name?(name) ⇒ Bool
Returns `true` if the name can be carried by the element's inputs, `false` otherwise.
195 196 197 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 195 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?.
205 206 207 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 205 def valid_input_name_data?( name ) valid_input_name?( name ) && valid_input_data?( name ) end |
#valid_input_value?(value) ⇒ Bool
Returns `true` if the value can be carried by the element's inputs, `false` otherwise.
217 218 219 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 217 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?.
227 228 229 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 227 def valid_input_value_data?( value ) valid_input_value?( value ) && valid_input_data?( value ) end |