2013-01-17 22:05:49 +00:00
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require 'rex/proto/http/packet'
|
|
|
|
|
2015-10-16 20:57:04 +00:00
|
|
|
RSpec.describe Rex::Proto::Http::Packet do
|
2013-01-17 22:05:49 +00:00
|
|
|
it_behaves_like "hash with insensitive keys"
|
|
|
|
|
|
|
|
describe "#parse" do
|
|
|
|
let :body do
|
|
|
|
"Super body"
|
|
|
|
end
|
|
|
|
subject do
|
|
|
|
s = described_class.new
|
|
|
|
s.parse packet_str
|
|
|
|
|
|
|
|
s
|
|
|
|
end
|
|
|
|
context "with a request packet" do
|
|
|
|
let :packet_str do
|
|
|
|
"GET / HTTP/1.0\r\n" \
|
|
|
|
"Foo: Bar\r\n" \
|
|
|
|
"Content-Length: #{body.length}\r\n" \
|
|
|
|
"\r\n" \
|
|
|
|
"#{body}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should have correct headers" do
|
2015-10-20 16:30:38 +00:00
|
|
|
expect(subject["foo"]).to eq "Bar"
|
|
|
|
expect(subject["Content-Length"]).to eq body.length.to_s
|
|
|
|
expect(subject.cmd_string).to eq "GET / HTTP/1.0\r\n"
|
|
|
|
expect(subject.body).to eq body
|
2013-01-17 22:05:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a response packet" do
|
|
|
|
let :packet_str do
|
|
|
|
"HTTP/1.0 200 OK\r\n" \
|
|
|
|
"Foo: Bar\r\n" \
|
|
|
|
"Content-Length: #{body.length}\r\n" \
|
|
|
|
"\r\n" \
|
|
|
|
"#{body}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should have correct headers" do
|
2015-10-20 16:30:38 +00:00
|
|
|
expect(subject["foo"]).to eq "Bar"
|
|
|
|
expect(subject["Content-Length"]).to eq body.length.to_s
|
|
|
|
expect(subject.cmd_string).to eq "HTTP/1.0 200 OK\r\n"
|
|
|
|
expect(subject.body).to eq body
|
2013-01-17 22:05:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|