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/acpp/message_spec.rb
Views: 11788
# -*- coding:binary -*-1require 'spec_helper'234RSpec.describe Rex::Proto::ACPP::Message do56subject(:message) do7described_class.new8end910# retrieve_public.bin has the contents of a message type 20 (retrieve11# settings) message with a password of public. There is no payload.12let(:retrieve_public_bin) do13File.binread(File.join(File.dirname(__FILE__), 'retrieve_public.bin'))14end1516let(:retrieve_public_message) do17message.password = 'public'18message.type = 2019message20end2122describe '#==' do23it 'considers two different objects composed of equal parts equal' do24message2 = described_class.new25message2.password = 'public'26message2.type = 2027expect(message2).to eq(retrieve_public_message)28end29it 'considers two different objects composed of different parts unequal' do30message3 = described_class.new31message3.type = 132message3.password = 'private'33expect(message3).not_to eq(retrieve_public_message)34end35end3637describe '#to_s' do38it 'encodes properly' do39expect(retrieve_public_bin).to eq(retrieve_public_message.to_s)40end41end4243describe '#decode' do44it 'fails to decode if the message is the wrong size' do45small = Rex::Text.rand_text_alpha(100)46large = Rex::Text.rand_text_alpha(200)47expect { described_class.decode(small) }.to raise_error(/size #{small.size}/i)48expect { described_class.decode(large) }.to raise_error(/size #{large.size}/i)49end50it 'fails to decode if the required header is incorrect' do51retrieve_public_bin[0,4] = 'blah'52expect { described_class.decode(retrieve_public_bin) }.to raise_error(/header/i)53end54it 'decodes properly when the required checksum is correct' do55expect(retrieve_public_message).to eq(described_class.decode(retrieve_public_bin))56expect(retrieve_public_message).to eq(described_class.decode(retrieve_public_bin, true))57end58it 'decodes properly when the non-required checksum is correct' do59expect(retrieve_public_message).to eq(described_class.decode(retrieve_public_bin, false))60end61it 'decodes properly when the message checksum is incorrect' do62retrieve_public_bin[7,4] = "\x01\x02\x03\x04"63expect { described_class.decode(retrieve_public_bin) }.to raise_error(/message checksum/i)64expect { described_class.decode(retrieve_public_bin, true) }.to raise_error(/message checksum/i)65expect(retrieve_public_message).to eq(described_class.decode(retrieve_public_bin, false))66end67end6869describe '#successful?' do70it 'is successful when 0' do71message = described_class.new72message.status = 073expect(message.successful?).to be true74end75it 'is successful when !0' do76message = described_class.new77message.status = 178expect(message.successful?).to be false79end80end81end828384