Skip to content

Commit a5c39db

Browse files
committed
Use mocks like a boss...
1 parent 0b671d5 commit a5c39db

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

spec/lib/msf/java/rmi/client_spec.rb

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@
55
require 'rex/proto/rmi'
66
require 'msf/java/rmi/client'
77

8-
class RmiStringIO < StringIO
9-
10-
def put(data)
11-
write(data)
12-
end
13-
14-
def get_once(length = -1, timeout = 10)
15-
read
16-
end
17-
end
18-
198
describe Msf::Java::Rmi::Client do
209
subject(:mod) do
2110
mod = ::Msf::Exploit.new
@@ -24,11 +13,11 @@ def get_once(length = -1, timeout = 10)
2413
mod
2514
end
2615

27-
let(:io) { RmiStringIO.new('', 'w+b') }
16+
let(:io) { StringIO.new('', 'w+b') }
2817
let(:protocol_not_supported) { "\x4f" }
29-
let(:protocol_not_supported_io) { RmiStringIO.new(protocol_not_supported) }
18+
let(:protocol_not_supported_io) { StringIO.new(protocol_not_supported) }
3019
let(:protocol_ack) { "\x4e\x00\x0e\x31\x37\x32\x2e\x31\x36\x2e\x31\x35\x38\x2e\x31\x33\x32\x00\x00\x06\xea" }
31-
let(:protocol_ack_io) { RmiStringIO.new(protocol_ack) }
20+
let(:protocol_ack_io) { StringIO.new(protocol_ack) }
3221
let(:return_data) do
3322
"\x51\xac\xed\x00\x05\x77\x0f\x01\xd2\x4f\xdf\x47\x00\x00\x01\x49" +
3423
"\xb5\xe4\x92\x78\x80\x15\x73\x72\x00\x12\x6a\x61\x76\x61\x2e\x72" +
@@ -49,7 +38,17 @@ def get_once(length = -1, timeout = 10)
4938
"\x04\x74\x69\x6d\x65\x49\x00\x06\x75\x6e\x69\x71\x75\x65\x70\x78" +
5039
"\x70\x80\x01\x00\x00\x01\x49\xb5\xf8\x00\xea\xe9\x62\xc1\xc0"
5140
end
52-
let(:return_io) { RmiStringIO.new(return_data) }
41+
let(:return_io) { StringIO.new(return_data) }
42+
43+
before(:each) do
44+
allow_any_instance_of(::StringIO).to receive(:put) do |io, data|
45+
io.write(data)
46+
end
47+
48+
allow_any_instance_of(::StringIO).to receive(:get_once) do |io, length, timeout|
49+
io.read
50+
end
51+
end
5352

5453
describe "#send_header" do
5554
it "returns the number of bytes sent" do

0 commit comments

Comments
 (0)