relevance-tarantula 0.2.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,76 +0,0 @@
1
- class Relevance::Tarantula::AttackFormSubmission
2
- attr_accessor :method, :action, :data, :attack
3
-
4
- class << self
5
- def attacks
6
- # normalize from hash input to Attack
7
- @attacks = @attacks.map do |val|
8
- Hash === val ? Relevance::Tarantula::Attack.new(val) : val
9
- end
10
- @attacks
11
- end
12
- def attacks=(atts)
13
- # normalize from hash input to Attack
14
- @attacks = atts.map do |val|
15
- Hash === val ? Relevance::Tarantula::Attack.new(val) : val
16
- end
17
- end
18
- end
19
- @attacks = []
20
-
21
- def initialize(form, attack = nil)
22
- @method = form.method
23
- @action = form.action
24
- @attack = attack
25
- @data = mutate_selects(form).merge(mutate_text_areas(form)).merge(mutate_inputs(form))
26
- end
27
-
28
- def self.mutate(form)
29
- attacks and attacks.map do |attack|
30
- self.new(form, attack)
31
- end
32
- end
33
-
34
- def to_s
35
- "#{action} #{method} #{data.inspect} #{attack.inspect}"
36
- end
37
-
38
- # a form's signature is what makes it unique (e.g. action + fields)
39
- # used to keep track of which forms we have submitted already
40
- def signature
41
- [action, data.keys.sort, attack.name]
42
- end
43
-
44
- def create_random_data_for(form, tag_selector)
45
- form.search(tag_selector).inject({}) do |form_args, input|
46
- # TODO: test
47
- form_args[input['name']] = random_data(input) if input['name']
48
- form_args
49
- end
50
- end
51
-
52
- def mutate_inputs(form)
53
- create_random_data_for(form, 'input')
54
- end
55
-
56
- def mutate_text_areas(form)
57
- create_random_data_for(form, 'textarea')
58
- end
59
-
60
- def mutate_selects(form)
61
- form.search('select').inject({}) do |form_args, select|
62
- options = select.search('option')
63
- option = options.rand
64
- form_args[select['name']] = option['value']
65
- form_args
66
- end
67
- end
68
-
69
- def random_data(input)
70
- case input['name']
71
- when /^_method$/ then input['value']
72
- else
73
- attack.input
74
- end
75
- end
76
- end