1
+ require 'msf/core'
2
+
3
+ RSpec . describe Net ::DNS ::Names do
4
+ subject do
5
+ obj = Object . new
6
+ obj . extend ( described_class )
7
+ end
8
+
9
+ describe '#dn_expand' do
10
+ context 'when offset is great than packet length' do
11
+ let ( :packet ) do
12
+ 'AAAAA'
13
+ end
14
+
15
+ let ( :offset ) do
16
+ 10
17
+ end
18
+
19
+ it 'raises an ExpandError exception' do
20
+ expect { subject . dn_expand ( packet , offset ) } . to raise_exception ( ExpandError )
21
+ end
22
+ end
23
+
24
+ context 'when packet length is less than offset + INT16SZ' do
25
+ let ( :packet ) do
26
+ "\xc0 "
27
+ end
28
+
29
+ let ( :offset ) do
30
+ 0
31
+ end
32
+
33
+ it 'raises an ExpandError exception' do
34
+ expect { subject . dn_expand ( packet , offset ) } . to raise_exception ( ExpandError )
35
+ end
36
+ end
37
+
38
+ context 'when packet length is less than offset + packet length' do
39
+ let ( :packet ) do
40
+ 'AAAAA'
41
+ end
42
+
43
+ let ( :offset ) do
44
+ 4
45
+ end
46
+
47
+ it 'raises an ExpandError exception' do
48
+ expect { subject . dn_expand ( packet , offset ) } . to raise_exception ( ExpandError )
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#pack_name' do
54
+ context 'when name data size is larger than 255 bytes' do
55
+ let ( :name ) do
56
+ 'A' * ( 255 +1 )
57
+ end
58
+
59
+ it 'raises an ArgumentError exception' do
60
+ expect { subject . pack_name ( name ) } . to raise_exception ( ArgumentError )
61
+ end
62
+ end
63
+
64
+ context 'when label data is larger than 63 bytes' do
65
+ let ( :name ) do
66
+ 'A' * ( 63 +1 ) + '.'
67
+ end
68
+
69
+ it 'raises an ArgumentError exception' do
70
+ expect { subject . pack_name ( name ) } . to raise_exception ( ArgumentError )
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '#names_array' do
76
+ let ( :name ) do
77
+ "AAA.AAA"
78
+ end
79
+
80
+ it 'returns an Array' do
81
+ expect ( subject . names_array ( name ) ) . to be_kind_of ( Array )
82
+ end
83
+ end
84
+
85
+ describe '#dn_comp' do
86
+ let ( :name ) do
87
+ 'AAAA'
88
+ end
89
+
90
+ let ( :offset ) do
91
+ 0
92
+ end
93
+
94
+ let ( :compnames ) do
95
+ { }
96
+ end
97
+
98
+ it 'returns 3 values' do
99
+ v = subject . dn_comp ( name , offset , compnames )
100
+ expect ( v . length ) . to eq ( 3 )
101
+ expect ( v [ 0 ] ) . to be_kind_of ( String )
102
+ expect ( v [ 1 ] ) . to be_kind_of ( Fixnum )
103
+ expect ( v [ 2 ] ) . to be_kind_of ( Hash )
104
+ end
105
+ end
106
+
107
+ describe '#valid?' do
108
+ context 'when FQDN is valid' do
109
+ let ( :fqdn ) do
110
+ 'example.com'
111
+ end
112
+
113
+ it 'returns the FQDN' do
114
+ expect ( subject . valid? ( fqdn ) ) . to eq ( fqdn )
115
+ end
116
+
117
+ end
118
+
119
+ context 'when FQDN is not valid' do
120
+ let ( :fqdn ) do
121
+ 'INVALID'
122
+ end
123
+
124
+ it 'raises ArgumentError exception' do
125
+ expect { subject . valid? ( fqdn ) } . to raise_exception ( ArgumentError )
126
+ end
127
+ end
128
+ end
129
+ end
0 commit comments