Skip to content

Commit cf93a81

Browse files
committed
Add specs and pending examples for more Opt*s
[SeeRM rapid7#7535] [SeeRM rapid7#7536] [SeeRM rapid7#7537] [SeeRM rapid7#7539] [SeeRM rapid7#7540]
1 parent 7f80374 commit cf93a81

File tree

8 files changed

+137
-47
lines changed

8 files changed

+137
-47
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
require 'spec_helper'
3+
require 'msf/core/option_container'
4+
5+
describe Msf::OptionContainer do
6+
it "should create new options for it's args" do
7+
foo_inst = mock("foo_inst")
8+
foo_inst.stub(:advanced=)
9+
foo_inst.stub(:evasion=)
10+
foo_inst.stub(:owner=)
11+
12+
foo_class = mock("opt_class")
13+
foo_class.should_receive(:new).and_return(foo_inst)
14+
15+
foo_inst.should_receive(:name).and_return("thing")
16+
17+
subject = described_class.new({
18+
'thing' => [ foo_class, true, nil, false ]
19+
})
20+
subject["thing"].should == foo_inst
21+
22+
end
23+
24+
25+
end

spec/lib/msf/core/options/opt_address_range_spec.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@
55
describe Msf::OptAddressRange do
66
# Normalized values are just the original value for OptAddressRange
77
valid_values = [
8-
"192.0.2.0/24",
9-
"192.0.2.0-255",
10-
"192.0.2.0,1-255",
11-
"192.0.2.*",
12-
"192.0.2.0-192.0.2.255",
13-
].map{|a| [a, a]}
8+
{ :value => "192.0.2.0/24", :normalized => "192.0.2.0/24" },
9+
{ :value => "192.0.2.0-255", :normalized => "192.0.2.0-255" },
10+
{ :value => "192.0.2.0,1-255", :normalized => "192.0.2.0,1-255" },
11+
{ :value => "192.0.2.*", :normalized => "192.0.2.*" },
12+
{ :value => "192.0.2.0-192.0.2.255", :normalized => "192.0.2.0-192.0.2.255" },
13+
]
1414
invalid_values = [
1515
# Too many dots
16-
"192.0.2.0.0",
17-
"192.0.2.0.0,1",
18-
"192.0.2.0.0,1-2",
19-
# CIDR apparently doesn't validate before sending to addr_atoi
20-
#"192.0.2.0.0/24",
16+
{ :value => "192.0.2.0.0" },
17+
{ :value => "192.0.2.0.0,1" },
18+
{ :value => "192.0.2.0.0,1-2" },
19+
{ :pending => "Redmine #7536", :value => "192.0.2.0.0/24" },
2120
# Not enough dots
22-
"192.0.2",
23-
"192.0.2,1",
24-
"192.0.2,1-2",
25-
# CIDR apparently doesn't validate before sending to addr_atoi
26-
#"192.0.2/24", # Not enough dots, cidr
21+
{ :value => "192.0.2" },
22+
{ :value => "192.0.2,1" },
23+
{ :value => "192.0.2,1-2" },
24+
{ :pending => "Redmine #7536", :value => "192.0.2/24" },
2725
# Can't mix ranges and CIDR
28-
"192.0.2.0,1/24",
29-
"192.0.2.0-1/24",
30-
"192.0.2.0,1-2/24",
26+
{ :value => "192.0.2.0,1/24" },
27+
{ :value => "192.0.2.0-1/24" },
28+
{ :value => "192.0.2.0,1-2/24" },
29+
{ :value => "192.0.2.0/1-24" },
30+
{ :value => "192.0.2.0-192.0.2.1-255", },
3131
]
3232

3333
it_behaves_like "an option", valid_values, invalid_values
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
require 'spec_helper'
3+
require 'msf/core/option_container'
4+
5+
describe Msf::OptAddress do
6+
valid_values = [
7+
"192.0.2.0", "127.0.0.1", "2001:db8::", "::1"
8+
# Normalized values are just the original value
9+
].map{|a| { :value => a, :normalized => a } }
10+
11+
invalid_values = [
12+
# Too many dots
13+
{ :value => "192.0.2.0.0" },
14+
# Not enough
15+
{ :pending => "Redmine #7537", :value => "192.0.2" }
16+
]
17+
18+
it_behaves_like "an option", valid_values, invalid_values
19+
end
20+
21+

spec/lib/msf/core/options/opt_bool_spec.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
require 'msf/core/option_container'
44

55
describe Msf::OptBool do
6-
valid_values =
7-
[
8-
["true", true ],
9-
["yes", true ],
10-
["1", true ],
11-
["false", false],
12-
["no", false],
13-
["0", false],
14-
]
15-
invalid_values =
16-
[ "yer mom", "123", "012" ]
6+
valid_values = [
7+
{ :value => "true", :normalized => true },
8+
{ :value => "yes", :normalized => true },
9+
{ :value => "1", :normalized => true },
10+
{ :value => "false", :normalized => false },
11+
{ :value => "no", :normalized => false },
12+
{ :value => "0", :normalized => false },
13+
]
14+
invalid_values = [
15+
{ :value => "yer mom" },
16+
{ :value => "012" },
17+
{ :value => "123" },
18+
]
1719
it_behaves_like "an option", valid_values, invalid_values
1820
end
1921

spec/lib/msf/core/options/opt_int_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
describe Msf::OptInt do
66
valid_values = [
7-
"1", "10", "0",
8-
#"-1", # Negatives don't work
9-
].map{|v| [ v, v.to_i ] }
10-
valid_values.push([ "0x10", 16 ])
7+
{ :value => "1", :normalized => 1 },
8+
{ :value => "10", :normalized => 10 },
9+
{ :value => "0", :normalized => 0 },
10+
{ :value => "0x10", :normalized => 16 },
11+
{ :pending => "Redmine #7540", :value => "-1", :normalized => -1 }
12+
]
1113
invalid_values = [
12-
#"yer mom", # to_i makes this 0
13-
#"0.1", # to_i makes this 0
14+
{ :pending => "Redmine #7539", :value => "yer mom", },
15+
{ :pending => "Redmine #7539", :value => "0.1", },
1416
]
1517

1618
it_behaves_like "an option", valid_values, invalid_values
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
require 'spec_helper'
3+
require 'msf/core/option_container'
4+
5+
describe Msf::OptPath do
6+
valid_values = [
7+
{ :value => __FILE__, :normalized => __FILE__ },
8+
]
9+
invalid_values = [
10+
{ :value => "yer mom", },
11+
{ :value => "0.1", },
12+
{ :value => "-1", },
13+
{ :value => "65536", },
14+
{ :value => "$", },
15+
]
16+
17+
it_behaves_like "an option", valid_values, invalid_values
18+
end
19+

spec/lib/msf/core/options/opt_port_spec.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
require 'msf/core/option_container'
44

55
describe Msf::OptPort do
6-
valid_values = [ "0", "1", "80", "65535" ].map{|v|
7-
# This is bogus, but OptPort doesn't implement #normalize, so it
8-
# falls back to just returning the original value
9-
[ v, v ]
10-
}
11-
invalid_values = [ "yer mom", "0.1", "-1", "65536" ]
6+
valid_values = [
7+
{ :pending => "Redmine #7535", :value => "0", :normalized => 0 },
8+
{ :pending => "Redmine #7535", :value => "65536",:normalized => 65536 },
9+
{ :pending => "Redmine #7535", :value => "80", :normalized => 80 },
10+
]
11+
invalid_values = [
12+
{ :value => "yer mom", },
13+
{ :value => "0.1", },
14+
{ :value => "-1", },
15+
{ :value => "65536", },
16+
]
1217

1318
it_behaves_like "an option", valid_values, invalid_values
1419
end

spec/support/shared/examples/options.rb

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,34 @@
55
end
66

77
context "with valid values" do
8-
valid_values.each do |valid_value, normalized_value|
8+
valid_values.each do |vhash|
9+
valid_value = vhash[:value]
10+
normalized_value = vhash[:normalized]
11+
912
it "should be valid and normalize appropriately: #{valid_value}" do
10-
subject.valid?(valid_value).should be_true
11-
subject.normalize(valid_value).should == normalized_value
13+
block = Proc.new {
14+
subject.normalize(valid_value).should == normalized_value
15+
subject.valid?(valid_value).should be_true
16+
}
17+
if vhash[:pending]
18+
pending(vhash[:pending], &block)
19+
else
20+
block.call
21+
end
1222
end
1323
end
1424
end
1525

1626
context "with invalid values" do
17-
invalid_values.each do |invalid_value|
27+
invalid_values.each do |vhash|
28+
invalid_value = vhash[:value]
1829
it "should not be valid: #{invalid_value}" do
19-
subject.valid?(invalid_value).should be_false
30+
block = Proc.new { subject.valid?(invalid_value).should be_false }
31+
if vhash[:pending]
32+
pending(vhash[:pending], &block)
33+
else
34+
block.call
35+
end
2036
end
2137
end
2238
end

0 commit comments

Comments
 (0)