Add unit test for and correct parsing of NAT-PMP port map responses

bug/bundler_fix
Jon Hart 2014-08-22 12:41:35 -07:00
parent 246f021437
commit 5ad090e833
2 changed files with 15 additions and 1 deletions

View File

@ -37,7 +37,7 @@ module NATPMP
# Parse a NAT-PMP mapping response +resp+.
# Returns the decoded parts as an array.
def parse_map_port_response(resp)
resp.unpack("CCvVnnN")
resp.unpack("CCnNnnN")
end
end

View File

@ -31,4 +31,18 @@ describe Rex::Proto::NATPMP do
expect(addr).to eq('0.0.0.0')
end
end
describe '#parse_map_port_response' do
it 'should properly parse responses' do
data = "\x00\x82\x00\x00\x00\x33\x6f\xd8\x11\x5c\x15\xb3\x00\x36\xee\x80"
ver, opcode, result, epoch, internal, external, lifetime = subject.parse_map_port_response(data)
expect(ver).to eq(0)
expect(opcode).to eq(130)
expect(result).to eq(0)
expect(epoch).to eq(3370968)
expect(internal).to eq(4444)
expect(external).to eq(5555)
expect(lifetime).to eq(3600000)
end
end
end