From 8c11e6047bc58f1252d1b3597aec16c18ec5afe2 Mon Sep 17 00:00:00 2001 From: jvazquez-r7 Date: Thu, 4 Dec 2014 16:33:33 -0600 Subject: [PATCH] Add specs for the JavaDeserializer tool --- spec/tools/java_deserializer_spec.rb | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 spec/tools/java_deserializer_spec.rb diff --git a/spec/tools/java_deserializer_spec.rb b/spec/tools/java_deserializer_spec.rb new file mode 100644 index 0000000000..8fd21b7da6 --- /dev/null +++ b/spec/tools/java_deserializer_spec.rb @@ -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 \ No newline at end of file