Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/rex/proto/kademlia/message_spec.rb
Views: 11789
# -*- coding: binary -*-1require 'spec_helper'23RSpec.describe Rex::Proto::Kademlia::Message do45context 'with a body' do6let(:type) { 1 }7let(:body) { 'test' }8let(:data) { "\xE4\x01test" }910subject(:message) do11described_class.new(type, body)12end1314describe '#initialize' do15it 'constructs properly' do16expect(message.type).to eq(type)17expect(message.body).to eq(body)18end19end2021describe '#to_str' do22it 'packs properly' do23expect(message.to_str).to eq(data)24end25end2627describe '#from_data' do28it 'unpacks supported messages properly' do29unpacked = described_class.from_data(data)30expect(unpacked.type).to eq(type)31expect(unpacked.body).to eq(body)32end3334it 'raises on compressed messages' do35expect do36described_class.from_data("\xE5\x01test")37end.to raise_error(NotImplementedError)38end39end4041describe '#==' do42it 'respects equality' do43expect(described_class.new(1, 'test')).to eq(described_class.new(1, 'test'))44expect(described_class.new(1, 'test')).not_to eq(described_class.new(1, 'not'))45expect(described_class.new(1, 'test')).not_to eq(described_class.new(2, 'test'))46expect(described_class.new(1, 'test')).not_to eq(described_class.new(2, 'not'))47end48end49end5051context 'without a body' do52let(:type) { 2 }53let(:body) { '' }54let(:data) { "\xE4\x02" }5556subject(:message) do57described_class.new(type, body)58end5960describe '#initialize' do61it 'constructs properly' do62expect(message.type).to eq(type)63expect(message.body).to eq(body)64end65end6667describe '#to_str' do68it 'packs properly' do69expect(message.to_str).to eq(data)70end71end7273describe '#from_data' do74it 'unpacks supported messages properly' do75unpacked = described_class.from_data(data)76expect(unpacked.type).to eq(type)77expect(unpacked.body).to eq(body)78end7980it 'raises on compressed messages' do81expect do82described_class.from_data("\xE5\x01")83end.to raise_error(NotImplementedError)84end85end86end87end888990