Add specs for several Opt* classes
parent
bf41d3d0fd
commit
7f34586780
|
@ -0,0 +1,36 @@
|
|||
|
||||
require 'spec_helper'
|
||||
require 'msf/core/option_container'
|
||||
|
||||
describe Msf::OptAddressRange do
|
||||
# Normalized values are just the original value for OptAddressRange
|
||||
valid_values = [
|
||||
"192.0.2.0/24",
|
||||
"192.0.2.0-255",
|
||||
"192.0.2.0,1-255",
|
||||
"192.0.2.*",
|
||||
"192.0.2.0-192.0.2.255",
|
||||
].map{|a| [a, a]}
|
||||
invalid_values = [
|
||||
# Too many dots
|
||||
"192.0.2.0.0",
|
||||
"192.0.2.0.0,1",
|
||||
"192.0.2.0.0,1-2",
|
||||
# CIDR apparently doesn't validate before sending to addr_atoi
|
||||
#"192.0.2.0.0/24",
|
||||
# Not enough dots
|
||||
"192.0.2",
|
||||
"192.0.2,1",
|
||||
"192.0.2,1-2",
|
||||
# CIDR apparently doesn't validate before sending to addr_atoi
|
||||
#"192.0.2/24", # Not enough dots, cidr
|
||||
# Can't mix ranges and CIDR
|
||||
"192.0.2.0,1/24",
|
||||
"192.0.2.0-1/24",
|
||||
"192.0.2.0,1-2/24",
|
||||
]
|
||||
|
||||
it_behaves_like "an option", valid_values, invalid_values
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
require 'spec_helper'
|
||||
require 'msf/core/option_container'
|
||||
|
||||
describe Msf::OptBool do
|
||||
valid_values =
|
||||
[
|
||||
["true", true ],
|
||||
["yes", true ],
|
||||
["1", true ],
|
||||
["false", false],
|
||||
["no", false],
|
||||
["0", false],
|
||||
]
|
||||
invalid_values =
|
||||
[ "yer mom", "123", "012" ]
|
||||
it_behaves_like "an option", valid_values, invalid_values
|
||||
end
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
require 'spec_helper'
|
||||
require 'msf/core/option_container'
|
||||
|
||||
describe Msf::OptInt do
|
||||
valid_values = [
|
||||
"1", "10", "0",
|
||||
#"-1", # Negatives don't work
|
||||
].map{|v| [ v, v.to_i ] }
|
||||
valid_values.push([ "0x10", 16 ])
|
||||
invalid_values = [
|
||||
#"yer mom", # to_i makes this 0
|
||||
#"0.1", # to_i makes this 0
|
||||
]
|
||||
|
||||
it_behaves_like "an option", valid_values, invalid_values
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
require 'spec_helper'
|
||||
require 'msf/core/option_container'
|
||||
|
||||
describe Msf::OptPort do
|
||||
valid_values = [ "0", "1", "80", "65535" ].map{|v|
|
||||
# This is bogus, but OptPort doesn't implement #normalize, so it
|
||||
# falls back to just returning the original value
|
||||
[ v, v ]
|
||||
}
|
||||
invalid_values = [ "yer mom", "0.1", "-1" "65536" ]
|
||||
|
||||
it_behaves_like "an option", valid_values, invalid_values
|
||||
end
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
shared_examples_for "an option" do |valid_values, invalid_values|
|
||||
subject do
|
||||
described_class.new("name")
|
||||
end
|
||||
|
||||
context "with valid values" do
|
||||
valid_values.each do |valid_value, normalized_value|
|
||||
it "should be valid and normalize appropriately: #{valid_value}" do
|
||||
subject.valid?(valid_value).should be_true
|
||||
subject.normalize(valid_value).should == normalized_value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid values" do
|
||||
invalid_values.each do |invalid_value|
|
||||
it "should not be valid: #{invalid_value}" do
|
||||
subject.valid?(invalid_value).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue