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/net/dns/names/names_spec.rb
Views: 11789
require 'net/dns'12RSpec.describe Net::DNS::Names do3subject do4obj = Object.new5obj.extend(described_class)6end78describe '#dn_expand' do9context 'when offset is great than packet length' do10let(:packet) do11'AAAAA'12end1314let(:offset) do151016end1718it 'raises an ExpandError exception' do19expect { subject.dn_expand(packet, offset) }.to raise_exception(ExpandError)20end21end2223context 'when packet length is less than offset + INT16SZ' do24let(:packet) do25"\xc0"26end2728let(:offset) do29030end3132it 'raises an ExpandError exception' do33expect { subject.dn_expand(packet, offset) }.to raise_exception(ExpandError)34end35end3637context 'when packet length is less than offset + packet length' do38let(:packet) do39'AAAAA'40end4142let(:offset) do43444end4546it 'raises an ExpandError exception' do47expect { subject.dn_expand(packet, offset) }.to raise_exception(ExpandError)48end49end50end5152describe '#pack_name' do53context 'when name data size is larger than 255 bytes' do54let(:name) do55'A' * (255+1)56end5758it 'raises an ArgumentError exception' do59expect { subject.pack_name(name) }.to raise_exception(ArgumentError)60end61end6263context 'when label data is larger than 63 bytes' do64let(:name) do65'A' * (63+1) + '.'66end6768it 'raises an ArgumentError exception' do69expect { subject.pack_name(name) }.to raise_exception(ArgumentError)70end71end72end7374describe '#names_array' do75let(:name) do76"AAA.AAA"77end7879it 'returns an Array' do80expect(subject.names_array(name)).to be_kind_of(Array)81end82end8384describe '#dn_comp' do85let(:name) do86'AAAA'87end8889let(:offset) do90091end9293let(:compnames) do94{}95end9697it 'returns 3 values' do98v = subject.dn_comp(name, offset, compnames)99expect(v.length).to eq(3)100expect(v[0]).to be_kind_of(String)101expect(v[1]).to be_kind_of(Integer)102expect(v[2]).to be_kind_of(Hash)103end104end105106describe '#valid?' do107context 'when FQDN is valid' do108let(:fqdn) do109'example.com'110end111112it 'returns the FQDN' do113expect(subject.valid?(fqdn)).to eq(fqdn)114end115116end117118context 'when FQDN is not valid' do119let(:fqdn) do120'INVALID'121end122123it 'raises ArgumentError exception' do124expect { subject.valid?(fqdn) }.to raise_exception(ArgumentError)125end126end127end128end129130131