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/pong_spec.rb
Views: 11789
1
# -*- coding: binary -*-
2
3
require 'spec_helper'
4
5
RSpec.describe Rex::Proto::Kademlia::Pong do
6
let(:port) { 12345 }
7
subject(:pong) do
8
described_class.new(port)
9
end
10
11
describe '#initialize' do
12
it 'constructs properly' do
13
expect(pong.type).to eq(Rex::Proto::Kademlia::PONG)
14
expect(pong.port).to eq(port)
15
end
16
end
17
18
describe '#to_str' do
19
it 'packs properly' do
20
expect(pong.to_str).to eq("\xE4\x61\x39\x30")
21
end
22
end
23
24
describe '#from_data' do
25
it 'unpacks supported valid pongs properly' do
26
unpacked = described_class.from_data("\xE4\x61\x9E\x86")
27
expect(unpacked.type).to eq(Rex::Proto::Kademlia::PONG)
28
expect(unpacked.port).to eq(34462)
29
end
30
31
it 'does not decode overly small pongs' do
32
expect(described_class.from_data("\xE4\x61\x01")).to eq(nil)
33
end
34
35
it 'does not decode overly large pongs' do
36
expect(described_class.from_data("\xE4\x61\x01\x02\x03")).to eq(nil)
37
end
38
end
39
end
40
41