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/sip/response_spec.rb
Views: 1904
1
# -*- coding: binary -*-
2
3
RSpec.describe 'Rex::Proto::SIP::Response parsing' do
4
describe 'Parses valid responses correctly' do
5
specify do
6
resp = 'SIP/1.0 123 Sure, OK'
7
r = ::Rex::Proto::SIP::Response.parse(resp)
8
expect(r.status_line).to eq(resp)
9
expect(r.version).to eq('1.0')
10
expect(r.code).to eq('123')
11
expect(r.message).to eq('Sure, OK')
12
expect(r.headers).to be_nil
13
end
14
15
specify do
16
resp = "SIP/2.0 200 OK\r\nFoo: bar\r\nBlah: 0\r\nFoO: blaf\r\n"
17
r = ::Rex::Proto::SIP::Response.parse(resp)
18
expect(r.status_line).to eq('SIP/2.0 200 OK')
19
expect(r.version).to eq('2.0')
20
expect(r.code).to eq('200')
21
expect(r.message).to eq('OK')
22
expect(r.headers).to eq('Foo' => %w(bar), 'Blah' => %w(0), 'FoO' => %w(blaf))
23
expect(r.header('Foo')).to eq %w(bar blaf)
24
end
25
end
26
27
describe 'Parses invalid responses correctly' do
28
[
29
'',
30
'aldkjfakdjfasdf',
31
'SIP/foo 200 OK',
32
'SIP/2.0 foo OK'
33
].each do |r|
34
it 'Should fail to parse an invalid response' do
35
expect { ::Rex::Proto::SIP::Response.parse(r) }.to raise_error(ArgumentError, /status/)
36
end
37
end
38
end
39
end
40
41