Skip to content

Commit

Permalink
prefer create_request, use StringIO over custom slice operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Cook committed Aug 21, 2017
1 parent 2660a5b commit 2a1daa6
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions spec/lib/rex/post/meterpreter/packet_parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
# -*- coding:binary -*-
require 'rex/post/meterpreter/packet'
require 'rex/post/meterpreter/packet_parser'

require 'stringio'

RSpec.describe Rex::Post::Meterpreter::PacketParser do
subject(:parser){
Rex::Post::Meterpreter::PacketParser.new
}
before(:example) do
@req_packt = Rex::Post::Meterpreter::Packet.new(
Rex::Post::Meterpreter::PACKET_TYPE_REQUEST,
"test_method")
@raw = @req_packt.to_r
@sock = double('Socket')
allow(@sock).to receive(:read) do |arg|
@raw.slice!(0,arg)
end
end

it "should initialise with expected defaults" do
expect(parser.send(:raw)).to eq ""
expect(parser.send(:hdr_length_left)).to eq 12
expect(parser.send(:payload_length_left)).to eq 0
@request_packet = Rex::Post::Meterpreter::Packet.create_request("test_method")
@sock = StringIO.new(@request_packet.to_r)
end

it "should parse valid raw data into a packet object" do
while @raw.length >0
begin
parsed_packet = parser.recv(@sock)
end
end while parsed_packet.nil?
expect(parsed_packet).to be_a Rex::Post::Meterpreter::Packet
expect(parsed_packet.type).to eq Rex::Post::Meterpreter::PACKET_TYPE_REQUEST
expect(parsed_packet.method?("test_method")).to eq true
Expand Down

0 comments on commit 2a1daa6

Please sign in to comment.