CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/proto/thrift/thrift_struct_spec.rb
Views: 1904
1
# -*- coding: binary -*-
2
require 'spec_helper'
3
require 'rex/text'
4
5
RSpec.describe Rex::Proto::Thrift::ThriftStruct do
6
let(:text) { Rex::Text.rand_text_alphanumeric(10) }
7
let(:value) { [
8
{ field_id: 1, data_type: Rex::Proto::Thrift::ThriftDataType::T_UTF7, data_value: text },
9
{ data_type: Rex::Proto::Thrift::ThriftDataType::T_STOP }
10
] }
11
let(:binary_s) { [Rex::Proto::Thrift::ThriftDataType::T_UTF7, 1, text.length].pack('CnN') + text + "\x00".b }
12
13
describe '#to_binary_s' do
14
it 'should correctly encode' do
15
expect(described_class.new(value).to_binary_s).to eq binary_s
16
end
17
end
18
19
describe '.read' do
20
it 'should correctly decode' do
21
expect(described_class.read(binary_s)).to eq value
22
end
23
end
24
end
25
26