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/thrift/thrift_header_spec.rb
Views: 11789
1
RSpec.describe Rex::Proto::Thrift::ThriftHeader do
2
let(:value) { { version: 0x8001, message_type: 1, method_name: '', sequence_id: 1 } }
3
let(:binary_s) { "\x80\x01\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01".b }
4
subject(:instance) { described_class.new }
5
6
it { should respond_to :version }
7
it { should respond_to :message_type }
8
it { should respond_to :method_name }
9
it { should respond_to :sequence_id }
10
11
it 'is big endian' do
12
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :big
13
end
14
15
it 'tracks the version in a Uint16 field' do
16
expect(instance.version).to be_a BinData::Uint16be
17
end
18
19
it 'tracks the message type in a ThriftMessageType field' do
20
expect(instance.message_type).to be_a Rex::Proto::Thrift::ThriftMessageType
21
end
22
23
it 'tracks the method name in a ThriftString field' do
24
expect(instance.method_name).to be_a Rex::Proto::Thrift::ThriftString
25
end
26
27
it 'tracks the sequence ID in a Uint32 field' do
28
expect(instance.sequence_id).to be_a BinData::Uint32be
29
end
30
31
it 'sets the version correctly by default' do
32
expect(instance.version).to eq 0x8001
33
end
34
35
describe '#to_binary_s' do
36
it 'should correctly encode' do
37
expect(described_class.new(value).to_binary_s).to eq binary_s
38
end
39
end
40
41
describe '.read' do
42
it 'should correctly decode' do
43
expect(described_class.read(binary_s)).to eq value
44
end
45
end
46
end
47
48