metasploit_data_models 0.12.1-java → 0.14.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/mdm/web_vuln.rb +2 -1
- data/{lib/metasploit_data_models → app}/validators/ip_format_validator.rb +0 -0
- data/app/validators/parameters_validator.rb +117 -0
- data/{lib/metasploit_data_models → app}/validators/password_is_strong_validator.rb +0 -0
- data/db/migrate/20130515164311_change_web_vulns_confidence_to_integer.rb +48 -0
- data/db/migrate/20130515172727_valid_mdm_web_vuln_params.rb +30 -0
- data/lib/metasploit_data_models.rb +5 -13
- data/lib/metasploit_data_models/models.rb +21 -0
- data/lib/metasploit_data_models/validators.rb +19 -0
- data/lib/metasploit_data_models/version.rb +1 -1
- data/spec/app/models/mdm/web_vuln_spec.rb +182 -3
- data/spec/app/validators/parameters_validator_spec.rb +342 -0
- data/spec/dummy/db/schema.rb +2 -2
- metadata +11 -4
data/app/models/mdm/web_vuln.rb
CHANGED
@@ -121,6 +121,7 @@ class Mdm::WebVuln < ActiveRecord::Base
|
|
121
121
|
:in => METHODS
|
122
122
|
}
|
123
123
|
validates :name, :presence => true
|
124
|
+
validates :params, :parameters => true
|
124
125
|
validates :path, :presence => true
|
125
126
|
validates :pname, :presence => true
|
126
127
|
validates :proof, :presence => true
|
@@ -137,7 +138,7 @@ class Mdm::WebVuln < ActiveRecord::Base
|
|
137
138
|
# @!attribute [rw] params
|
138
139
|
# Parameters sent as part of request
|
139
140
|
#
|
140
|
-
# @return [Array<Array
|
141
|
+
# @return [Array<Array(String, String)>] Array of parameter key value pairs
|
141
142
|
serialize :params, MetasploitDataModels::Base64Serializer.new(:default => DEFAULT_PARAMS)
|
142
143
|
|
143
144
|
#
|
File without changes
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# Validates that attribute's value is Array<Array(String, String)> which is the only valid type signature for serialized
|
2
|
+
# parameters.
|
3
|
+
class ParametersValidator < ActiveModel::EachValidator
|
4
|
+
# Sentence explaining the valid type signature for parameters.
|
5
|
+
TYPE_SIGNATURE_SENTENCE = 'Valid parameters are an Array<Array(String, String)>.'
|
6
|
+
|
7
|
+
def validate_each(record, attribute, value)
|
8
|
+
if value.is_a? Array
|
9
|
+
value.each_with_index do |element, index|
|
10
|
+
if element.is_a? Array
|
11
|
+
if element.length != 2
|
12
|
+
extreme = :few
|
13
|
+
|
14
|
+
if element.length > 2
|
15
|
+
extreme = :many
|
16
|
+
end
|
17
|
+
|
18
|
+
length_error = length_error_at(
|
19
|
+
:extreme => extreme,
|
20
|
+
:element => element,
|
21
|
+
:index => index
|
22
|
+
)
|
23
|
+
|
24
|
+
record.errors[attribute] << length_error
|
25
|
+
else
|
26
|
+
parameter_name = element.first
|
27
|
+
|
28
|
+
if parameter_name.is_a? String
|
29
|
+
unless parameter_name.present?
|
30
|
+
error = error_at(
|
31
|
+
:element => element,
|
32
|
+
:index => index,
|
33
|
+
:prefix => "has blank parameter name"
|
34
|
+
)
|
35
|
+
record.errors[attribute] << error
|
36
|
+
end
|
37
|
+
else
|
38
|
+
error = error_at(
|
39
|
+
:element => element,
|
40
|
+
:index => index,
|
41
|
+
:prefix => "has non-String parameter name (#{parameter_name.inspect})"
|
42
|
+
)
|
43
|
+
record.errors[attribute] << error
|
44
|
+
end
|
45
|
+
|
46
|
+
parameter_value = element.second
|
47
|
+
|
48
|
+
unless parameter_value.is_a? String
|
49
|
+
error = error_at(
|
50
|
+
:element => element,
|
51
|
+
:index => index,
|
52
|
+
:prefix => "has non-String parameter value (#{parameter_value.inspect})"
|
53
|
+
)
|
54
|
+
record.errors[attribute] << error
|
55
|
+
end
|
56
|
+
end
|
57
|
+
else
|
58
|
+
error = error_at(
|
59
|
+
:element => element,
|
60
|
+
:index => index,
|
61
|
+
:prefix => 'has non-Array'
|
62
|
+
)
|
63
|
+
record.errors[attribute] << error
|
64
|
+
end
|
65
|
+
end
|
66
|
+
else
|
67
|
+
record.errors[attribute] << "is not an Array. #{TYPE_SIGNATURE_SENTENCE}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def error_at(options={})
|
74
|
+
options.assert_valid_keys(:element, :index, :prefix)
|
75
|
+
prefix = options.fetch(:prefix)
|
76
|
+
|
77
|
+
clause = location_clause(
|
78
|
+
:element => options[:element],
|
79
|
+
:index => options[:index]
|
80
|
+
)
|
81
|
+
sentence = "#{prefix} #{clause}."
|
82
|
+
|
83
|
+
sentences = [
|
84
|
+
sentence,
|
85
|
+
TYPE_SIGNATURE_SENTENCE
|
86
|
+
]
|
87
|
+
|
88
|
+
error = sentences.join(" ")
|
89
|
+
|
90
|
+
error
|
91
|
+
end
|
92
|
+
|
93
|
+
def length_error_at(options={})
|
94
|
+
options.assert_valid_keys(:element, :extreme, :index)
|
95
|
+
extreme = options.fetch(:extreme)
|
96
|
+
|
97
|
+
prefix = "has too #{extreme} elements"
|
98
|
+
error = error_at(
|
99
|
+
:element => options[:element],
|
100
|
+
:index => options[:index],
|
101
|
+
:prefix => prefix
|
102
|
+
)
|
103
|
+
|
104
|
+
error
|
105
|
+
end
|
106
|
+
|
107
|
+
def location_clause(options={})
|
108
|
+
options.assert_valid_keys(:element, :index)
|
109
|
+
|
110
|
+
element = options.fetch(:element)
|
111
|
+
index = options.fetch(:index)
|
112
|
+
|
113
|
+
clause = "at index #{index} (#{element.inspect})"
|
114
|
+
|
115
|
+
clause
|
116
|
+
end
|
117
|
+
end
|
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Changes web_vulns.confidence from text to integer as it is populated with integers.
|
2
|
+
class ChangeWebVulnsConfidenceToInteger < ActiveRecord::Migration
|
3
|
+
#
|
4
|
+
# CONSTANTS
|
5
|
+
#
|
6
|
+
|
7
|
+
# Columns in {TABLE} whose type needs to be change.
|
8
|
+
COLUMN = :confidence
|
9
|
+
# The correct type for {COLUMN}.
|
10
|
+
NEW_TYPE = :integer
|
11
|
+
# The incorrect type for {COLUMN}.
|
12
|
+
OLD_TYPE = :text
|
13
|
+
# The table in which {COLUMN} is defined.
|
14
|
+
TABLE = :web_vulns
|
15
|
+
|
16
|
+
#
|
17
|
+
# Methods
|
18
|
+
#
|
19
|
+
|
20
|
+
# Changes web_vulns.confidence back to text
|
21
|
+
#
|
22
|
+
# @return [void]
|
23
|
+
def down
|
24
|
+
alter_type(:to => OLD_TYPE)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Changes web_vulns.confidence to integer
|
28
|
+
#
|
29
|
+
# @return [void]
|
30
|
+
def up
|
31
|
+
alter_type(:to => NEW_TYPE)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Alters {COLUMN} type in {TABLE} from old to new type
|
37
|
+
#
|
38
|
+
# @param options [Hash{Symbol => #to_s}]
|
39
|
+
# @option options [#to_s] :from The old type name.
|
40
|
+
# @option options [#to_s] :to The new type name.
|
41
|
+
def alter_type(options={})
|
42
|
+
options.assert_valid_keys(:to)
|
43
|
+
|
44
|
+
new = options.fetch(:to)
|
45
|
+
|
46
|
+
execute "ALTER TABLE #{TABLE} ALTER COLUMN #{COLUMN} TYPE #{new} USING confidence::#{new}"
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class ValidMdmWebVulnParams < ActiveRecord::Migration
|
2
|
+
# Don't put back the bad format because there's not way to figure our which of the [] were '' before {#up} and
|
3
|
+
# which were `[]` before {#up}.
|
4
|
+
#
|
5
|
+
# @return [void]
|
6
|
+
def down
|
7
|
+
end
|
8
|
+
|
9
|
+
# Changes any Mdm::WebVuln#params with value `''` to value `[]`.
|
10
|
+
#
|
11
|
+
# @return [void]
|
12
|
+
def up
|
13
|
+
# Can't search serialized columns, so have to load all the Mdm::WebVulns in memory
|
14
|
+
Mdm::WebVuln.find_each do |web_vuln|
|
15
|
+
if web_vuln.invalid?
|
16
|
+
# cast nil, '' and {} to correct [].
|
17
|
+
if web_vuln.params.blank?
|
18
|
+
web_vuln.params = []
|
19
|
+
end
|
20
|
+
|
21
|
+
# If its still invalid have to destroy the Mdm::WebVuln or a different export error could occur.
|
22
|
+
if web_vuln.invalid?
|
23
|
+
web_vuln.destroy
|
24
|
+
else
|
25
|
+
web_vuln.save!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -16,12 +16,10 @@ require 'active_support/dependencies'
|
|
16
16
|
#
|
17
17
|
require 'mdm'
|
18
18
|
require 'mdm/module'
|
19
|
+
require 'metasploit_data_models/base64_serializer'
|
20
|
+
require 'metasploit_data_models/models'
|
19
21
|
require 'metasploit_data_models/version'
|
20
22
|
require 'metasploit_data_models/serialized_prefs'
|
21
|
-
require 'metasploit_data_models/base64_serializer'
|
22
|
-
|
23
|
-
require 'metasploit_data_models/validators/ip_format_validator'
|
24
|
-
require 'metasploit_data_models/validators/password_is_strong_validator'
|
25
23
|
|
26
24
|
# Only include the Rails engine when using Rails. This allows the non-Rails projects, like metasploit-framework to use
|
27
25
|
# the models by calling MetasploitDataModels.require_models.
|
@@ -30,16 +28,10 @@ if defined? Rails
|
|
30
28
|
end
|
31
29
|
|
32
30
|
module MetasploitDataModels
|
33
|
-
|
34
|
-
root.join('app', 'models')
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.require_models
|
38
|
-
models_globs = models_pathname.join('**', '*.rb')
|
31
|
+
extend MetasploitDataModels::Models
|
39
32
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
33
|
+
def self.app_pathname
|
34
|
+
root.join('app')
|
43
35
|
end
|
44
36
|
|
45
37
|
def self.root
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'metasploit_data_models/validators'
|
2
|
+
|
3
|
+
module MetasploitDataModels
|
4
|
+
module Models
|
5
|
+
include MetasploitDataModels::Validators
|
6
|
+
|
7
|
+
def models_pathname
|
8
|
+
app_pathname.join('models')
|
9
|
+
end
|
10
|
+
|
11
|
+
def require_models
|
12
|
+
autoload_validators
|
13
|
+
|
14
|
+
models_globs = models_pathname.join('**', '*.rb')
|
15
|
+
|
16
|
+
Dir.glob(models_globs) do |model_path|
|
17
|
+
require model_path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MetasploitDataModels
|
2
|
+
module Validators
|
3
|
+
# Mimics behavior of `app/validators` in Rails projects by adding it to
|
4
|
+
# `ActiveSupport::Dependencies.autoload_paths` if it is not already in the Array.
|
5
|
+
#
|
6
|
+
# @return [void]
|
7
|
+
def autoload_validators
|
8
|
+
validators_path = validators_pathname.to_s
|
9
|
+
|
10
|
+
unless ActiveSupport::Dependencies.autoload_paths.include? validators_path
|
11
|
+
ActiveSupport::Dependencies.autoload_paths << validators_path
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def validators_pathname
|
16
|
+
app_pathname.join('validators')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -4,5 +4,5 @@ module MetasploitDataModels
|
|
4
4
|
# metasploit-framework/data/sql/migrate to db/migrate in this project, not all models have specs that verify the
|
5
5
|
# migrations (with have_db_column and have_db_index) and certain models may not be shared between metasploit-framework
|
6
6
|
# and pro, so models may be removed in the future. Because of the unstable API the version should remain below 1.0.0
|
7
|
-
VERSION = '0.
|
7
|
+
VERSION = '0.14.1'
|
8
8
|
end
|
@@ -48,7 +48,7 @@ describe Mdm::WebVuln do
|
|
48
48
|
context 'columns' do
|
49
49
|
it { should have_db_column(:blame).of_type(:text) }
|
50
50
|
it { should have_db_column(:category).of_type(:text).with_options(:null => false) }
|
51
|
-
it { should have_db_column(:confidence).of_type(:
|
51
|
+
it { should have_db_column(:confidence).of_type(:integer).with_options(:null => false) }
|
52
52
|
it { should have_db_column(:description).of_type(:text) }
|
53
53
|
it { should have_db_column(:method).of_type(:string).with_options(:limit => 1024, :null => false) }
|
54
54
|
it { should have_db_column(:name).of_type(:string).with_options(:limit => 1024, :null => false) }
|
@@ -76,6 +76,25 @@ describe Mdm::WebVuln do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
+
context 'factories' do
|
80
|
+
context 'mdm_web_vuln' do
|
81
|
+
subject(:mdm_web_vuln) do
|
82
|
+
FactoryGirl.build(:mdm_web_vuln)
|
83
|
+
end
|
84
|
+
|
85
|
+
it { should be_valid }
|
86
|
+
|
87
|
+
context 'after reloading' do
|
88
|
+
before(:each) do
|
89
|
+
mdm_web_vuln.save!
|
90
|
+
mdm_web_vuln.reload
|
91
|
+
end
|
92
|
+
|
93
|
+
it { should be_valid }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
79
98
|
context 'validations' do
|
80
99
|
it { should validate_presence_of :category }
|
81
100
|
it { should ensure_inclusion_of(:confidence).in_range(confidence_range) }
|
@@ -83,8 +102,168 @@ describe Mdm::WebVuln do
|
|
83
102
|
it { should validate_presence_of :name }
|
84
103
|
it { should validate_presence_of :path }
|
85
104
|
|
86
|
-
|
87
|
-
|
105
|
+
context 'params' do
|
106
|
+
it 'should not validate presence of params because it default to [] and can never be nil' do
|
107
|
+
web_vuln.should_not validate_presence_of(:params)
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'validates parameters' do
|
111
|
+
let(:type_signature_sentence) do
|
112
|
+
"Valid parameters are an Array<Array(String, String)>."
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should validate params is an Array' do
|
116
|
+
web_vuln.params = ''
|
117
|
+
|
118
|
+
web_vuln.params.should_not be_an Array
|
119
|
+
web_vuln.should_not be_valid
|
120
|
+
web_vuln.errors[:params].should include(
|
121
|
+
"is not an Array. #{type_signature_sentence}"
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should allow empty Array' do
|
126
|
+
web_vuln.params = []
|
127
|
+
web_vuln.valid?
|
128
|
+
|
129
|
+
web_vuln.errors[:params].should be_empty
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'with bad element' do
|
133
|
+
let(:index) do
|
134
|
+
web_vuln.params.index(element)
|
135
|
+
end
|
136
|
+
|
137
|
+
before(:each) do
|
138
|
+
web_vuln.params = [element]
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'without Array' do
|
142
|
+
let(:element) do
|
143
|
+
{}
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should not be an Array' do
|
147
|
+
web_vuln.params.first.should_not be_an Array
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should validate elements of params are Arrays' do
|
151
|
+
web_vuln.should_not be_valid
|
152
|
+
web_vuln.errors[:params].should include(
|
153
|
+
"has non-Array at index #{index} (#{element.inspect}). " \
|
154
|
+
"#{type_signature_sentence}"
|
155
|
+
)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'with element length < 2' do
|
160
|
+
let(:element) do
|
161
|
+
['']
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should have length < 2' do
|
165
|
+
web_vuln.params.first.length.should < 2
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should validate elements of params are not too short' do
|
169
|
+
web_vuln.should_not be_valid
|
170
|
+
web_vuln.errors[:params].should include(
|
171
|
+
"has too few elements at index #{index} (#{element.inspect}). " \
|
172
|
+
"#{type_signature_sentence}"
|
173
|
+
)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'with element length > 2' do
|
178
|
+
let(:element) do
|
179
|
+
['', '', '']
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should have length > 2' do
|
183
|
+
web_vuln.params.first.length.should > 2
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should validate elements of params are not too long' do
|
187
|
+
web_vuln.should_not be_valid
|
188
|
+
web_vuln.errors[:params].should include(
|
189
|
+
"has too many elements at index #{index} (#{element.inspect}). " \
|
190
|
+
"#{type_signature_sentence}"
|
191
|
+
)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'parameter name' do
|
196
|
+
let(:element) do
|
197
|
+
[parameter_name, 'parameter_value']
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'with String' do
|
201
|
+
context 'with blank' do
|
202
|
+
let(:parameter_name) do
|
203
|
+
''
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should have blank parameter name' do
|
207
|
+
web_vuln.params.first.first.should be_empty
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should validate that parameter name is not empty' do
|
211
|
+
web_vuln.should_not be_valid
|
212
|
+
web_vuln.errors[:params].should include(
|
213
|
+
"has blank parameter name at index #{index} " \
|
214
|
+
"(#{element.inspect}). " \
|
215
|
+
"#{type_signature_sentence}"
|
216
|
+
)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'without String' do
|
222
|
+
let(:parameter_name) do
|
223
|
+
:parameter_name
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'should not have String for parameter name' do
|
227
|
+
web_vuln.params.first.first.should_not be_a String
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'should validate that parameter name is a String' do
|
231
|
+
web_vuln.should_not be_valid
|
232
|
+
web_vuln.errors[:params].should include(
|
233
|
+
"has non-String parameter name (#{parameter_name.inspect}) " \
|
234
|
+
"at index #{index} (#{element.inspect}). " \
|
235
|
+
"#{type_signature_sentence}"
|
236
|
+
)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context 'parameter value' do
|
242
|
+
let(:element) do
|
243
|
+
['parameter_name', parameter_value]
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'without String' do
|
247
|
+
let(:parameter_value) do
|
248
|
+
0
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'should not have String for parameter name' do
|
252
|
+
web_vuln.params.first.second.should_not be_a String
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'should validate that parameter value is a String' do
|
256
|
+
web_vuln.should_not be_valid
|
257
|
+
web_vuln.errors[:params].should include(
|
258
|
+
"has non-String parameter value (#{parameter_value}) " \
|
259
|
+
"at index #{index} (#{element.inspect}). " \
|
260
|
+
"#{type_signature_sentence}"
|
261
|
+
)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
88
267
|
end
|
89
268
|
|
90
269
|
it { should validate_presence_of :pname }
|
@@ -0,0 +1,342 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ParametersValidator do
|
4
|
+
subject(:parameters_validator) do
|
5
|
+
described_class.new(
|
6
|
+
:attributes => attributes
|
7
|
+
)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:attribute) do
|
11
|
+
:params
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:attributes) do
|
15
|
+
attribute
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:element) do
|
19
|
+
[]
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:index) do
|
23
|
+
rand(100)
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:type_signature_sentence) do
|
27
|
+
'Valid parameters are an Array<Array(String, String)>.'
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'CONSTANTS' do
|
31
|
+
it 'should define TYPE_SIGNATURE_SENTENCE' do
|
32
|
+
described_class::TYPE_SIGNATURE_SENTENCE.should == type_signature_sentence
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context '#error_at' do
|
37
|
+
subject(:error_at) do
|
38
|
+
parameters_validator.send(
|
39
|
+
:error_at,
|
40
|
+
:element => element,
|
41
|
+
:index => index,
|
42
|
+
:prefix => prefix
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:prefix) do
|
47
|
+
'has a prefix'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should include prefix' do
|
51
|
+
error_at.should include(prefix)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should include location_clause in same sentence as prefix' do
|
55
|
+
location_clause = parameters_validator.send(
|
56
|
+
:location_clause,
|
57
|
+
:element => element,
|
58
|
+
:index => index
|
59
|
+
)
|
60
|
+
|
61
|
+
error_at.should include("#{prefix} #{location_clause}.")
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should include TYPE_SIGNATURE_SENTENCE' do
|
65
|
+
error_at.should include(type_signature_sentence)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context '#length_error_at' do
|
70
|
+
subject(:length_error_at) do
|
71
|
+
parameters_validator.send(
|
72
|
+
:length_error_at,
|
73
|
+
:element => element,
|
74
|
+
:extreme => extreme,
|
75
|
+
:index => index
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:extreme) do
|
80
|
+
[:few, :many].sample
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should include extreme in prefix' do
|
84
|
+
parameters_validator.should_receive(:error_at) do |*args|
|
85
|
+
options = args.first
|
86
|
+
options[:prefix].should include(extreme.to_s)
|
87
|
+
end
|
88
|
+
|
89
|
+
length_error_at
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context '#location_clause' do
|
94
|
+
subject(:location_clause) do
|
95
|
+
parameters_validator.send(
|
96
|
+
:location_clause,
|
97
|
+
:element => element,
|
98
|
+
:index => index
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should include numerical index' do
|
103
|
+
location_clause.should include("at index #{index}")
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should include inspect of element' do
|
107
|
+
location_clause.should include(element.inspect)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context '#validate_each' do
|
112
|
+
subject(:errors) do
|
113
|
+
record.errors[attribute]
|
114
|
+
end
|
115
|
+
|
116
|
+
def validate_each
|
117
|
+
parameters_validator.validate_each(record, attribute, value)
|
118
|
+
end
|
119
|
+
|
120
|
+
let(:record) do
|
121
|
+
Object.new.tap { |object|
|
122
|
+
object.extend ActiveModel::Validations
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'with Array' do
|
127
|
+
let(:value) do
|
128
|
+
[]
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'element' do
|
132
|
+
let(:value) do
|
133
|
+
[element]
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'with Array' do
|
137
|
+
let(:element) do
|
138
|
+
[]
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'with length < 2' do
|
142
|
+
let(:element) do
|
143
|
+
[]
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should call #length_error_at with :extreme => :few' do
|
147
|
+
parameters_validator.should_receive(:length_error_at).with(
|
148
|
+
hash_including(
|
149
|
+
:extreme => :few
|
150
|
+
)
|
151
|
+
)
|
152
|
+
|
153
|
+
validate_each
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should record error' do
|
157
|
+
validate_each
|
158
|
+
|
159
|
+
errors.should_not be_empty
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'with length > 2' do
|
164
|
+
let(:element) do
|
165
|
+
['', '', '']
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should call #length_error_at with :extreme => :many' do
|
169
|
+
parameters_validator.should_receive(:length_error_at).with(
|
170
|
+
hash_including(
|
171
|
+
:extreme => :many
|
172
|
+
)
|
173
|
+
)
|
174
|
+
|
175
|
+
validate_each
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should record error' do
|
179
|
+
validate_each
|
180
|
+
|
181
|
+
errors.should_not be_empty
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'with length == 2' do
|
186
|
+
let(:element) do
|
187
|
+
[parameter_name, parameter_value]
|
188
|
+
end
|
189
|
+
|
190
|
+
let(:parameter_name) do
|
191
|
+
'parameter_name'
|
192
|
+
end
|
193
|
+
|
194
|
+
let(:parameter_value) do
|
195
|
+
'parameter_value'
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'parameter name' do
|
199
|
+
context 'with String' do
|
200
|
+
context 'with blank' do
|
201
|
+
let(:parameter_name) do
|
202
|
+
''
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should call error_at with blank parameter name prefix' do
|
206
|
+
parameters_validator.should_receive(:error_at).with(
|
207
|
+
hash_including(
|
208
|
+
:prefix => 'has blank parameter name'
|
209
|
+
)
|
210
|
+
)
|
211
|
+
|
212
|
+
validate_each
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should record error' do
|
216
|
+
validate_each
|
217
|
+
|
218
|
+
errors.should_not be_empty
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'without blank' do
|
223
|
+
let(:parameter_name) do
|
224
|
+
'parameter_name'
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should not record error' do
|
228
|
+
validate_each
|
229
|
+
|
230
|
+
errors.should be_blank
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context 'without String' do
|
236
|
+
let(:parameter_name) do
|
237
|
+
:parameter_name
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'should call error_at with non-String prefix' do
|
241
|
+
parameters_validator.should_receive(:error_at).with(
|
242
|
+
hash_including(
|
243
|
+
:prefix => "has non-String parameter name (#{parameter_name.inspect})"
|
244
|
+
)
|
245
|
+
)
|
246
|
+
|
247
|
+
validate_each
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'should record error' do
|
251
|
+
validate_each
|
252
|
+
|
253
|
+
errors.should_not be_empty
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'parameter value' do
|
259
|
+
context 'with String' do
|
260
|
+
let(:parameter_value) do
|
261
|
+
'parameter_value'
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'should not record error' do
|
265
|
+
validate_each
|
266
|
+
|
267
|
+
errors.should be_blank
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context 'without String' do
|
272
|
+
let(:parameter_value) do
|
273
|
+
0
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'should call error_at with non-String prefix' do
|
277
|
+
parameters_validator.should_receive(:error_at).with(
|
278
|
+
hash_including(
|
279
|
+
:prefix => "has non-String parameter value (#{parameter_value.inspect})"
|
280
|
+
)
|
281
|
+
)
|
282
|
+
|
283
|
+
validate_each
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'should record error' do
|
287
|
+
validate_each
|
288
|
+
|
289
|
+
errors.should_not be_empty
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
context 'without Array' do
|
297
|
+
let(:element) do
|
298
|
+
{}
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'should use #error_at with has non-Array for prefix' do
|
302
|
+
parameters_validator.should_receive(:error_at).with(
|
303
|
+
hash_including(
|
304
|
+
:prefix => 'has non-Array'
|
305
|
+
)
|
306
|
+
)
|
307
|
+
|
308
|
+
validate_each
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'should record error' do
|
312
|
+
validate_each
|
313
|
+
|
314
|
+
errors.should_not be_empty
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
context 'without Array' do
|
321
|
+
let(:value) do
|
322
|
+
''
|
323
|
+
end
|
324
|
+
|
325
|
+
before(:each) do
|
326
|
+
validate_each
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'should error that attribute is not an array' do
|
330
|
+
errors.any? { |error|
|
331
|
+
error.include? 'is not an Array.'
|
332
|
+
}.should be_true
|
333
|
+
end
|
334
|
+
|
335
|
+
it 'should include TYPE_SIGNATURE_SENTENCE' do
|
336
|
+
errors.each do |error|
|
337
|
+
error.should include(type_signature_sentence)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20130515172727) do
|
15
15
|
|
16
16
|
create_table "api_keys", :force => true do |t|
|
17
17
|
t.text "token"
|
@@ -581,7 +581,7 @@ ActiveRecord::Schema.define(:version => 20130430162145) do
|
|
581
581
|
t.string "name", :limit => 1024, :null => false
|
582
582
|
t.text "query"
|
583
583
|
t.text "category", :null => false
|
584
|
-
t.
|
584
|
+
t.integer "confidence", :null => false
|
585
585
|
t.text "description"
|
586
586
|
t.text "blame"
|
587
587
|
t.binary "request"
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: metasploit_data_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.14.1
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Samuel Huckins
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-05-
|
15
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rake
|
@@ -222,6 +222,9 @@ files:
|
|
222
222
|
- app/models/mdm/wmap_request.rb
|
223
223
|
- app/models/mdm/wmap_target.rb
|
224
224
|
- app/models/mdm/workspace.rb
|
225
|
+
- app/validators/ip_format_validator.rb
|
226
|
+
- app/validators/parameters_validator.rb
|
227
|
+
- app/validators/password_is_strong_validator.rb
|
225
228
|
- bin/mdm_console
|
226
229
|
- console_db.yml
|
227
230
|
- db/migrate/000_create_tables.rb
|
@@ -319,6 +322,8 @@ files:
|
|
319
322
|
- db/migrate/20130423211152_add_creds_counter_cache.rb
|
320
323
|
- db/migrate/20130430151353_change_required_columns_to_null_false_in_hosts.rb
|
321
324
|
- db/migrate/20130430162145_enforce_address_uniqueness_in_workspace_in_hosts.rb
|
325
|
+
- db/migrate/20130515164311_change_web_vulns_confidence_to_integer.rb
|
326
|
+
- db/migrate/20130515172727_valid_mdm_web_vuln_params.rb
|
322
327
|
- lib/mdm.rb
|
323
328
|
- lib/mdm/host/operating_system_normalization.rb
|
324
329
|
- lib/mdm/module.rb
|
@@ -326,9 +331,9 @@ files:
|
|
326
331
|
- lib/metasploit_data_models/base64_serializer.rb
|
327
332
|
- lib/metasploit_data_models/change_required_columns_to_null_false.rb
|
328
333
|
- lib/metasploit_data_models/engine.rb
|
334
|
+
- lib/metasploit_data_models/models.rb
|
329
335
|
- lib/metasploit_data_models/serialized_prefs.rb
|
330
|
-
- lib/metasploit_data_models/validators
|
331
|
-
- lib/metasploit_data_models/validators/password_is_strong_validator.rb
|
336
|
+
- lib/metasploit_data_models/validators.rb
|
332
337
|
- lib/metasploit_data_models/version.rb
|
333
338
|
- lib/tasks/yard.rake
|
334
339
|
- metasploit_data_models.gemspec
|
@@ -348,6 +353,7 @@ files:
|
|
348
353
|
- spec/app/models/mdm/vuln_ref_spec.rb
|
349
354
|
- spec/app/models/mdm/vuln_spec.rb
|
350
355
|
- spec/app/models/mdm/web_vuln_spec.rb
|
356
|
+
- spec/app/validators/parameters_validator_spec.rb
|
351
357
|
- spec/dummy/Rakefile
|
352
358
|
- spec/dummy/app/assets/javascripts/application.js
|
353
359
|
- spec/dummy/app/assets/stylesheets/application.css
|
@@ -450,6 +456,7 @@ test_files:
|
|
450
456
|
- spec/app/models/mdm/vuln_ref_spec.rb
|
451
457
|
- spec/app/models/mdm/vuln_spec.rb
|
452
458
|
- spec/app/models/mdm/web_vuln_spec.rb
|
459
|
+
- spec/app/validators/parameters_validator_spec.rb
|
453
460
|
- spec/dummy/Rakefile
|
454
461
|
- spec/dummy/app/assets/javascripts/application.js
|
455
462
|
- spec/dummy/app/assets/stylesheets/application.css
|