CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/proto/http/packet_spec.rb
Views: 1904
1
2
require 'spec_helper'
3
4
RSpec.describe Rex::Proto::Http::Packet do
5
it_behaves_like "hash with insensitive keys"
6
7
describe "#parse" do
8
let :body do
9
"Super body"
10
end
11
subject do
12
s = described_class.new
13
s.parse packet_str
14
15
s
16
end
17
context "with a request packet" do
18
let :packet_str do
19
"GET / HTTP/1.0\r\n" \
20
"Foo: Bar\r\n" \
21
"Content-Length: #{body.length}\r\n" \
22
"\r\n" \
23
"#{body}"
24
end
25
26
it "should have correct headers" do
27
expect(subject["foo"]).to eq "Bar"
28
expect(subject["Content-Length"]).to eq body.length.to_s
29
expect(subject.cmd_string).to eq "GET / HTTP/1.0\r\n"
30
expect(subject.body).to eq body
31
end
32
end
33
34
context "with a response packet" do
35
let :packet_str do
36
"HTTP/1.0 200 OK\r\n" \
37
"Foo: Bar\r\n" \
38
"Content-Length: #{body.length}\r\n" \
39
"\r\n" \
40
"#{body}"
41
end
42
43
it "should have correct headers" do
44
expect(subject["foo"]).to eq "Bar"
45
expect(subject["Content-Length"]).to eq body.length.to_s
46
expect(subject.cmd_string).to eq "HTTP/1.0 200 OK\r\n"
47
expect(subject.body).to eq body
48
end
49
end
50
51
end
52
end
53
54