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/ldap/dn_binary_spec.rb
Views: 11789
require 'securerandom'12RSpec.describe Rex::Proto::LDAP::DnBinary do3let(:dn) do4'CN=User,CN=Users,DC=msf,DC=local'5end67let(:data) do8'abc123'9end1011let(:sample) do12described_class.new(dn, data)13end1415it 'encodes to the expected value' do16expect(sample.encode).to eq('B:12:616263313233:CN=User,CN=Users,DC=msf,DC=local')17end1819it 'encodes an empty value' do20initial = described_class.new(dn, '')21encoded = initial.encode22expect(encoded).to eq('B:0::CN=User,CN=Users,DC=msf,DC=local')23decoded = described_class.decode(encoded)24expect(decoded.data).to eq('')25end2627it 'throws exception with completely wrong format' do28expect { described_class.decode('definitely not a DN string') }.to raise_error(ArgumentError)29end3031it 'throws exception without DN' do32expect { described_class.decode('B:12:616263313233') }.to raise_error(ArgumentError)33end3435it 'throws exception on odd number of hex chars' do36expect { described_class.decode('B:11:61626331323:the_dn') }.to raise_error(ArgumentError)37end3839it 'throws exception on inconsistent number of hex chars' do40expect { described_class.decode('B:12:626331323:the_dn') }.to raise_error(ArgumentError)41end4243it 'reversibly decodes a random value' do44data = SecureRandom.bytes((SecureRandom.rand * 100).to_i + 1)45initial = described_class.new(dn, data)46encoded = initial.encode47decoded = described_class.decode(encoded)48expect(decoded.dn).to eq(initial.dn)49expect(decoded.data).to eq(initial.data)50end51end525354