Skip to content

Commit 96bcdd2

Browse files
committed
Finished rspec
1 parent 4704648 commit 96bcdd2

File tree

2 files changed

+82
-13
lines changed

2 files changed

+82
-13
lines changed

spec/tools/egghunter_spec.rb

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,100 @@
55

66
describe Egghunter do
77

8-
subject do
9-
Egghunter::Driver.new
10-
end
8+
describe Egghunter::Driver do
9+
10+
subject do
11+
Egghunter::Driver.new
12+
end
13+
14+
let(:egg) {
15+
'W00T'
16+
}
17+
18+
describe '#run' do
19+
20+
def get_stdout(&block)
21+
out = $stdout
22+
$stdout = fake = StringIO.new
23+
begin
24+
yield
25+
ensure
26+
$stdout = out
27+
end
28+
fake.string
29+
end
30+
31+
let(:default_opts) {
32+
{ :platform => 'windows', :format => 'c', :eggtag => egg, :arch => 'x86' }
33+
}
34+
35+
before(:each) do
36+
allow(Egghunter::OptsConsole).to receive(:parse).with(any_args).and_return(options)
37+
end
1138

12-
describe '#run' do
39+
context 'when the platform is windows' do
40+
let(:options) { default_opts }
1341

14-
context 'when the platform is windows' do
15-
it 'returns a windows egghunter' do
42+
it 'returns a windows egghunter' do
43+
output = get_stdout { subject.run }
44+
expect(output).to include("\\x66\\x81\\xca\\xff")
45+
end
46+
end
47+
48+
context 'when the platform is linux' do
49+
let(:options) do
50+
{ :platform => 'linux', :format => 'c', :eggtag => egg, :arch => 'x86' }
51+
end
52+
53+
it 'returns a linux egghunter' do
54+
output = get_stdout { subject.run }
55+
expect(output).to include("\\xfc\\x66\\x81\\xc9\\xff")
56+
end
57+
end
58+
59+
context 'when the egg is WOOT' do
60+
let(:options) { default_opts }
61+
62+
it 'includes W00T in the egghunter' do
63+
output = get_stdout { subject.run }
64+
expect(output).to include("\\x57\\x30\\x30\\x54")
65+
end
1666
end
1767
end
68+
end
69+
1870

19-
context 'when the platform is linux' do
20-
it 'returns a linux egghunter' do
71+
describe Egghunter::OptsConsole do
72+
subject do
73+
Egghunter::OptsConsole
74+
end
75+
76+
context 'when no options are given' do
77+
it 'raises OptionParser::MissingArgument' do
78+
expect{subject.parse([])}.to raise_error(OptionParser::MissingArgument)
2179
end
2280
end
2381

24-
context 'when the output format is java' do
25-
it 'returns java format egghunter' do
82+
context 'when no format is specified and --list-formats isn\'t used' do
83+
it 'raises OptionParser::MissingArgument' do
84+
args = '-e AAAA'.split
85+
expect{subject.parse(args)}.to raise_error(OptionParser::MissingArgument)
2686
end
2787
end
2888

29-
context 'when the egg is WOOT' do
30-
it 'includes W00TW00T in the egghunter' do
89+
context 'when no egg is specified and --list-formats isn\'t used' do
90+
it 'raises OptionParser::MissingArgument' do
91+
args = '-f python'.split
92+
expect{subject.parse(args)}.to raise_error(OptionParser::MissingArgument)
3193
end
3294
end
3395

96+
context 'when :depsize is a string' do
97+
it 'raises OptionParser::InvalidOption' do
98+
args = '-e AAAA -f c --depsize STRING'.split
99+
expect{subject.parse(args)}.to raise_error(OptionParser::InvalidOption)
100+
end
101+
end
34102
end
103+
35104
end

tools/egghunter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def self.parse(args)
9393
raise OptionParser::MissingArgument, '-e is required'
9494
elsif options[:format] && !::Msf::Simple::Buffer.transform_formats.include?(options[:format])
9595
raise OptionParser::InvalidOption, "#{options[:format]} is not a valid format"
96-
elsif options[:depsize] && options[:depsize] =~ /^\d+$/
96+
elsif options[:depsize] && options[:depsize] !~ /^\d+$/
9797
raise OptionParser::InvalidOption, "--depsize must be a Fixnum"
9898
end
9999

0 commit comments

Comments
 (0)