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/kademlia/bootstrap_response_spec.rb
Views: 11789
1
# -*- coding: binary -*-
2
3
require 'spec_helper'
4
5
RSpec.describe Rex::Proto::Kademlia::BootstrapResponse do
6
describe '#from_data' do
7
it 'properly decodes real valid bootstrap responses' do
8
data = File.binread(File.join(File.dirname(__FILE__), 'kademlia_bootstrap_res.bin'))
9
response = described_class.from_data(data)
10
expect(response.peer_id).to eq('B54A83462529B21EF51FD54B956B07B0')
11
expect(response.tcp_port).to eq(4662)
12
expect(response.version).to eq(8)
13
# don't bother checking every peer
14
expect(response.peers.size).to eq(20)
15
peer = response.peers.first
16
expect(peer[:id]).to eq('B0A5518388D66BC211B0B9F75B3DCB10')
17
expect(peer[:ip]).to eq('149.91.116.59')
18
expect(peer[:tcp_port]).to eq(4882)
19
expect(peer[:udp_port]).to eq(4992)
20
expect(peer[:version]).to eq(8)
21
peer = response.peers.last
22
expect(peer[:id]).to eq('9B896000AEBE0B0A0ECB35457177A107')
23
expect(peer[:ip]).to eq('83.46.192.208')
24
expect(peer[:tcp_port]).to eq(3662)
25
expect(peer[:udp_port]).to eq(3672)
26
expect(peer[:version]).to eq(8)
27
end
28
29
it 'does not decode overly small bootstrap responses' do
30
expect(described_class.from_data('this is too small')).to eq(nil)
31
end
32
33
it 'does not decode malformed bootstrap responses' do
34
expect(described_class.from_data('this is large enough but truncated')).to eq(nil)
35
end
36
end
37
end
38
39