CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/proto/natpmp/packet_spec.rb
Views: 11789
1
# -*- coding: binary -*-
2
require 'spec_helper'
3
4
RSpec.describe Rex::Proto::NATPMP do
5
subject do
6
mod = Module.new
7
mod.extend described_class
8
mod
9
end
10
11
describe '#parse_external_address_response' do
12
it 'should properly parse non-error responses' do
13
data = "\x00\x80\x00\x00\x00\x33\x50\x53\xc0\xa8\x01\x02"
14
subject.parse_external_address_response(data)
15
ver, opcode, result, epoch, addr = subject.parse_external_address_response(data)
16
expect(ver).to eq(0)
17
expect(opcode).to eq(128)
18
expect(result).to eq(0)
19
expect(epoch).to eq(3362899)
20
expect(addr).to eq('192.168.1.2')
21
end
22
it 'should properly parse error responses' do
23
data = "\x00\x80\x00\x03\x00\x00\x70\x90\x00\x00\x00\x00"
24
subject.parse_external_address_response(data)
25
ver, opcode, result, epoch, addr = subject.parse_external_address_response(data)
26
expect(ver).to eq(0)
27
expect(opcode).to eq(128)
28
expect(result).to eq(3)
29
expect(epoch).to eq(28816)
30
expect(addr).to eq('0.0.0.0')
31
end
32
end
33
34
describe '#parse_map_port_response' do
35
it 'should properly parse responses' do
36
data = "\x00\x82\x00\x00\x00\x33\x6f\xd8\x11\x5c\x15\xb3\x00\x36\xee\x80"
37
ver, opcode, result, epoch, internal, external, lifetime = subject.parse_map_port_response(data)
38
expect(ver).to eq(0)
39
expect(opcode).to eq(130)
40
expect(result).to eq(0)
41
expect(epoch).to eq(3370968)
42
expect(internal).to eq(4444)
43
expect(external).to eq(5555)
44
expect(lifetime).to eq(3600000)
45
end
46
end
47
end
48
49