Add specs for the JavaDeserializer tool

bug/bundler_fix
jvazquez-r7 2014-12-04 16:33:33 -06:00
parent 08f69da41a
commit 8c11e6047b
1 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,71 @@
require 'rex/java'
require 'stringio'
load Metasploit::Framework.root.join('tools/java_deserializer.rb').to_path
describe JavaDeserializer do
before(:all) do
@out = $stdout
@err = $stderr
$stdout = StringIO.new
$stderr = StringIO.new
end
after(:all) do
$stdout = @out
$stderr = @err
end
subject(:deserializer) do
described_class.new
end
let(:valid_stream) do
"\xac\xed\x00\x05\x75\x72\x00\x02" +
"\x5b\x43\xb0\x26\x66\xb0\xe2\x5d" +
"\x84\xac\x02\x00\x00\x78\x70\x00" +
"\x00\x00\x02\x00\x61\x00\x62"
end
describe ".new" do
it "returns a JavaDeserializer instance" do
expect(deserializer).to be_a(JavaDeserializer)
end
it "initializes file to nil" do
expect(deserializer.file).to be_nil
end
end
describe "#run" do
context "when file is nil" do
it "returns nil" do
expect(deserializer.run).to be_nil
end
end
context "when file contains a valid stream" do
it "returns an Stream" do
expect(File).to receive(:new) do
contents = valid_stream
StringIO.new(contents)
end
deserializer.file = 'sample'
expect(deserializer.run).to be_an(Rex::Java::Serialization::Model::Stream)
end
end
context "when file contains an invalid stream" do
it "returns nil" do
expect(File).to receive(:new) do
contents = 'invalid_stream'
StringIO.new(contents)
end
deserializer.file = 'sample'
expect(deserializer.run).to be_nil
end
end
end
end