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/net/dns/rr/classes_spec.rb
Views: 11789
1
# -*- coding:binary -*-
2
require 'spec_helper'
3
4
require 'net/dns'
5
6
RSpec.describe Net::DNS::RR::Classes do
7
8
subject do
9
described_class.new
10
end
11
12
describe '#initialize' do
13
subject(:rr_class) do
14
described_class.allocate
15
end
16
17
it 'raises when initialized with no args' do
18
expect { rr_class.send(:initialize) }.to raise_error(ArgumentError)
19
end
20
21
it 'respects default RR class when initialized with a nil RR class' do
22
rr_class.send(:initialize, nil)
23
expect(rr_class.to_i).to eql(1)
24
expect(rr_class.to_s).to eql('IN')
25
end
26
27
# TODO: figure out why this doesn't work
28
skip 'respects configured default RR class' do
29
rr_class.send(:default=, 'NONE')
30
expect(rr_class.to_i).to eql(254)
31
expect(rr_class.to_s).to eql('NONE')
32
end
33
34
it 'initializes with a valid RR class Integer argument' do
35
rr_class.send(:initialize, 4)
36
expect(rr_class.to_i).to eql(4)
37
expect(rr_class.to_s).to eql('HS')
38
end
39
40
it 'raises when the supplied RR class Integer is invalid' do
41
expect { rr_class.send(:initialize, 123456) }.to raise_error(ClassArgumentError)
42
expect { rr_class.send(:initialize, -1) }.to raise_error(ClassArgumentError)
43
end
44
45
it 'initializes with a valid RR class String argument' do
46
rr_class.send(:initialize, 'CH')
47
expect(rr_class.to_i).to eql(3)
48
expect(rr_class.to_s).to eql('CH')
49
rr_class.send(:initialize, 'CLASS9')
50
expect(rr_class.to_i).to eql(9)
51
expect(rr_class.to_s).to eql('CLASS9')
52
rr_class.send(:initialize, 'CLASS1')
53
expect(rr_class.to_i).to eql(1)
54
expect(rr_class.to_s).to eql('IN')
55
end
56
57
it 'raises when the supplied RR class String is invalid' do
58
expect { rr_class.send(:initialize, 'cats') }.to raise_error(ClassArgumentError)
59
expect { rr_class.send(:initialize, 'CLASS123456') }.to raise_error(ClassArgumentError)
60
end
61
end
62
end
63
64