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/header_spec.rb
Views: 1904
1
2
require 'spec_helper'
3
4
RSpec.describe Rex::Proto::Http::Packet::Header do
5
6
it_behaves_like "hash with insensitive keys"
7
8
let :original_str do
9
"POST /foo HTTP/1.0\r\n" \
10
"Content-Length: 0\r\n" \
11
"Foo: Bar\r\n" \
12
"Bar: Baz\r\n" \
13
"Combine-me: one\r\n" \
14
"Combine-me: two\r\n" \
15
"\r\n"
16
end
17
18
describe "#from_s" do
19
subject(:headers) do
20
h = described_class.new
21
h.from_s(original_str)
22
h
23
end
24
25
it "should create keys and values for each header" do
26
expect(headers['Foo']).to eq "Bar"
27
expect(headers['Content-Length']).to eq "0"
28
end
29
30
it "should combine headers" do
31
expect(headers['Combine-me']).to eq "one, two"
32
end
33
34
context "with folding" do
35
let :original_str do
36
"POST /foo HTTP/1.0\r\n" \
37
"Spaces:\r\n" \
38
" Bar\r\n" \
39
"Tabs:\r\n" \
40
"\tBar\r\n" \
41
"\r\n"
42
end
43
it "should recognize spaces" do
44
expect(headers['Spaces']).to eq "Bar"
45
end
46
it "should recognize tabs" do
47
expect(headers['Tabs']).to eq "Bar"
48
end
49
end
50
51
end
52
53
describe "#to_s" do
54
subject(:header_string) do
55
h = described_class.new
56
h.from_s(original_str)
57
h.to_s
58
end
59
60
context "without combining" do
61
let :original_str do
62
"POST /foo HTTP/1.0\r\n" \
63
"Foo: Bar\r\n" \
64
"Bar: Baz\r\n" \
65
"\r\n"
66
end
67
68
it "should return the same string" do
69
expect(header_string).to eq original_str
70
end
71
end
72
context "with combining" do
73
let :original_str do
74
"POST /foo HTTP/1.0\r\n" \
75
"Foo: Bar\r\n" \
76
"Foo: Baz\r\n" \
77
"Foo: Bab\r\n" \
78
"\r\n"
79
end
80
it "should produce an equivalent string" do
81
#pending "who knows"
82
combined = "Foo: Bar, Baz, Bab\r\n\r\n"
83
expect(header_string).to eq combined
84
end
85
end
86
end
87
88
end
89
90