iqeo-hostspec 0.1.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +7 -0
- data/Guardfile +13 -0
- data/LICENSE.txt +675 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/hostspec +131 -0
- data/iqeo-hostspec.gemspec +24 -0
- data/lib/iqeo/hostspec.rb +180 -0
- data/spec/hostspec_runner_spec.rb +109 -0
- data/spec/iqeo/hostspec_spec.rb +493 -0
- data/tmux +38 -0
- metadata +73 -0
@@ -0,0 +1,493 @@
|
|
1
|
+
require 'iqeo/hostspec'
|
2
|
+
|
3
|
+
describe Iqeo::Hostspec do
|
4
|
+
|
5
|
+
context '.new' do
|
6
|
+
|
7
|
+
it 'accepts a single argument only' do
|
8
|
+
expect { Iqeo::Hostspec.new }.to raise_error
|
9
|
+
expect { Iqeo::Hostspec.new "1.1.1.1" }.to_not raise_error
|
10
|
+
expect { Iqeo::Hostspec.new "1.1.1.1","2.2.2.2" }.to raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'does not require a mask length' do
|
14
|
+
expect { Iqeo::Hostspec.new "3.3.3.3" }.to_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'defaults to a host mask when none specified' do
|
18
|
+
hs = Iqeo::Hostspec.new "4.4.4.4"
|
19
|
+
hs.mask.should eq '255.255.255.255'
|
20
|
+
hs.mask_length.should eq 32
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'mask length' do
|
26
|
+
|
27
|
+
before(:all) do
|
28
|
+
@mask_integers = [ 0,
|
29
|
+
2147483648, 3221225472, 3758096384, 4026531840,
|
30
|
+
4160749568, 4227858432, 4261412864, 4278190080,
|
31
|
+
4286578688, 4290772992, 4292870144, 4293918720,
|
32
|
+
4294443008, 4294705152, 4294836224, 4294901760,
|
33
|
+
4294934528, 4294950912, 4294959104, 4294963200,
|
34
|
+
4294965248, 4294966272, 4294966784, 4294967040,
|
35
|
+
4294967168, 4294967232, 4294967264, 4294967280,
|
36
|
+
4294967288, 4294967292, 4294967294, 4294967295
|
37
|
+
]
|
38
|
+
|
39
|
+
@mask_strings = [ '0.0.0.0',
|
40
|
+
'128.0.0.0', '192.0.0.0', '224.0.0.0', '240.0.0.0',
|
41
|
+
'248.0.0.0', '252.0.0.0', '254.0.0.0', '255.0.0.0',
|
42
|
+
'255.128.0.0', '255.192.0.0', '255.224.0.0', '255.240.0.0',
|
43
|
+
'255.248.0.0', '255.252.0.0', '255.254.0.0', '255.255.0.0',
|
44
|
+
'255.255.128.0', '255.255.192.0', '255.255.224.0', '255.255.240.0',
|
45
|
+
'255.255.248.0', '255.255.252.0', '255.255.254.0', '255.255.255.0',
|
46
|
+
'255.255.255.128', '255.255.255.192', '255.255.255.224', '255.255.255.240',
|
47
|
+
'255.255.255.248', '255.255.255.252', '255.255.255.254', '255.255.255.255'
|
48
|
+
]
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'is specified numerically after /' do
|
53
|
+
expect { Iqeo::Hostspec.new "5.5.5.5/24" }.to_not raise_error
|
54
|
+
expect { Iqeo::Hostspec.new "5.5.5.5/" }.to raise_error
|
55
|
+
expect { Iqeo::Hostspec.new "5.5.5.5/xyz" }.to raise_error
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'is between 0 and 32' do
|
59
|
+
(0..32).each do |masklen|
|
60
|
+
hs = Iqeo::Hostspec.new "1.2.3.4/#{masklen}"
|
61
|
+
hs.mask_length.should eq masklen
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'cannot be > 32' do
|
66
|
+
[ 33, 100, 1000 ].each do |masklen|
|
67
|
+
expect { Iqeo::Hostspec.new "1.2.3.4/#{masklen}" }.to raise_error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'sets mask string' do
|
72
|
+
@mask_strings.each_with_index do |str,len|
|
73
|
+
hs = Iqeo::Hostspec.new "1.2.3.4/#{len}"
|
74
|
+
hs.mask.should eq str
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'host' do
|
81
|
+
|
82
|
+
before(:all) do
|
83
|
+
@octets = (0..255).to_a
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'cannot be empty' do
|
87
|
+
expect { Iqeo::Hostspec.new '' }.to raise_error
|
88
|
+
expect { Iqeo::Hostspec.new '/32' }.to raise_error
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'an IP address' do
|
92
|
+
|
93
|
+
it 'may specify a single host without a mask length' do
|
94
|
+
@octets.each_cons(4) do |octets|
|
95
|
+
address = octets.join('.')
|
96
|
+
hs = Iqeo::Hostspec.new address
|
97
|
+
hs.address_spec.collect(&:first).should eq octets
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'may specify address range with a classful mask length' do
|
102
|
+
slash_specs = {
|
103
|
+
'1.1.1.1/32' => [[1],[1],[1],[1]],
|
104
|
+
'1.1.1.1/24' => [[1],[1],[1],[0..255]],
|
105
|
+
'1.1.1.1/16' => [[1],[1],[0..255],[0..255]],
|
106
|
+
'1.1.1.1/8' => [[1],[0..255],[0..255],[0..255]],
|
107
|
+
'1.1.1.1/0' => [[0..255],[0..255],[0..255],[0..255]]
|
108
|
+
}
|
109
|
+
slash_specs.each do |spec_str,spec_data|
|
110
|
+
hs = Iqeo::Hostspec.new spec_str
|
111
|
+
hs.address_spec.should eq spec_data
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'may specify address range with any mask length' do
|
116
|
+
slash_specs = {
|
117
|
+
'0.0.0.0/32' => [[0],[0],[0],[0] ],
|
118
|
+
'0.0.0.0/31' => [[0],[0],[0],[0..1] ],
|
119
|
+
'0.0.0.0/30' => [[0],[0],[0],[0..3] ],
|
120
|
+
'0.0.0.0/29' => [[0],[0],[0],[0..7] ],
|
121
|
+
'0.0.0.0/28' => [[0],[0],[0],[0..15] ],
|
122
|
+
'0.0.0.0/27' => [[0],[0],[0],[0..31] ],
|
123
|
+
'0.0.0.0/26' => [[0],[0],[0],[0..63] ],
|
124
|
+
'0.0.0.0/25' => [[0],[0],[0],[0..127]],
|
125
|
+
'0.0.0.0/24' => [[0],[0],[0],[0..255]],
|
126
|
+
'0.0.0.0/23' => [[0],[0],[0..1] ,[0..255]],
|
127
|
+
'0.0.0.0/22' => [[0],[0],[0..3] ,[0..255]],
|
128
|
+
'0.0.0.0/21' => [[0],[0],[0..7] ,[0..255]],
|
129
|
+
'0.0.0.0/20' => [[0],[0],[0..15] ,[0..255]],
|
130
|
+
'0.0.0.0/19' => [[0],[0],[0..31] ,[0..255]],
|
131
|
+
'0.0.0.0/18' => [[0],[0],[0..63] ,[0..255]],
|
132
|
+
'0.0.0.0/17' => [[0],[0],[0..127],[0..255]],
|
133
|
+
'0.0.0.0/16' => [[0],[0],[0..255],[0..255]],
|
134
|
+
'0.0.0.0/15' => [[0],[0..1] ,[0..255],[0..255]],
|
135
|
+
'0.0.0.0/14' => [[0],[0..3] ,[0..255],[0..255]],
|
136
|
+
'0.0.0.0/13' => [[0],[0..7] ,[0..255],[0..255]],
|
137
|
+
'0.0.0.0/12' => [[0],[0..15] ,[0..255],[0..255]],
|
138
|
+
'0.0.0.0/11' => [[0],[0..31] ,[0..255],[0..255]],
|
139
|
+
'0.0.0.0/10' => [[0],[0..63] ,[0..255],[0..255]],
|
140
|
+
'0.0.0.0/9' => [[0],[0..127],[0..255],[0..255]],
|
141
|
+
'0.0.0.0/8' => [[0],[0..255],[0..255],[0..255]],
|
142
|
+
'0.0.0.0/7' => [[0..1] ,[0..255],[0..255],[0..255]],
|
143
|
+
'0.0.0.0/6' => [[0..3] ,[0..255],[0..255],[0..255]],
|
144
|
+
'0.0.0.0/5' => [[0..7] ,[0..255],[0..255],[0..255]],
|
145
|
+
'0.0.0.0/4' => [[0..15] ,[0..255],[0..255],[0..255]],
|
146
|
+
'0.0.0.0/3' => [[0..31] ,[0..255],[0..255],[0..255]],
|
147
|
+
'0.0.0.0/2' => [[0..63] ,[0..255],[0..255],[0..255]],
|
148
|
+
'0.0.0.0/1' => [[0..127],[0..255],[0..255],[0..255]],
|
149
|
+
'0.0.0.0/0' => [[0..255],[0..255],[0..255],[0..255]],
|
150
|
+
'127.127.127.127/32' => [[127],[127],[127],[127] ],
|
151
|
+
'127.127.127.127/31' => [[127],[127],[127],[126..127]],
|
152
|
+
'127.127.127.127/30' => [[127],[127],[127],[124..127]],
|
153
|
+
'127.127.127.127/29' => [[127],[127],[127],[120..127]],
|
154
|
+
'127.127.127.127/28' => [[127],[127],[127],[112..127]],
|
155
|
+
'127.127.127.127/27' => [[127],[127],[127],[96..127] ],
|
156
|
+
'127.127.127.127/26' => [[127],[127],[127],[64..127] ],
|
157
|
+
'127.127.127.127/25' => [[127],[127],[127],[0..127] ],
|
158
|
+
'127.127.127.127/24' => [[127],[127],[127],[0..255] ],
|
159
|
+
'127.127.127.127/23' => [[127],[127],[126..127],[0..255]],
|
160
|
+
'127.127.127.127/22' => [[127],[127],[124..127],[0..255]],
|
161
|
+
'127.127.127.127/21' => [[127],[127],[120..127],[0..255]],
|
162
|
+
'127.127.127.127/20' => [[127],[127],[112..127],[0..255]],
|
163
|
+
'127.127.127.127/19' => [[127],[127],[96..127] ,[0..255]],
|
164
|
+
'127.127.127.127/18' => [[127],[127],[64..127] ,[0..255]],
|
165
|
+
'127.127.127.127/17' => [[127],[127],[0..127] ,[0..255]],
|
166
|
+
'127.127.127.127/16' => [[127],[127],[0..255] ,[0..255]],
|
167
|
+
'127.127.127.127/15' => [[127],[126..127],[0..255],[0..255]],
|
168
|
+
'127.127.127.127/14' => [[127],[124..127],[0..255],[0..255]],
|
169
|
+
'127.127.127.127/13' => [[127],[120..127],[0..255],[0..255]],
|
170
|
+
'127.127.127.127/12' => [[127],[112..127],[0..255],[0..255]],
|
171
|
+
'127.127.127.127/11' => [[127],[96..127] ,[0..255],[0..255]],
|
172
|
+
'127.127.127.127/10' => [[127],[64..127] ,[0..255],[0..255]],
|
173
|
+
'127.127.127.127/9' => [[127],[0..127] ,[0..255],[0..255]],
|
174
|
+
'127.127.127.127/8' => [[127],[0..255] ,[0..255],[0..255]],
|
175
|
+
'127.127.127.127/7' => [[126..127],[0..255],[0..255],[0..255]],
|
176
|
+
'127.127.127.127/6' => [[124..127],[0..255],[0..255],[0..255]],
|
177
|
+
'127.127.127.127/5' => [[120..127],[0..255],[0..255],[0..255]],
|
178
|
+
'127.127.127.127/4' => [[112..127],[0..255],[0..255],[0..255]],
|
179
|
+
'127.127.127.127/3' => [[96..127] ,[0..255],[0..255],[0..255]],
|
180
|
+
'127.127.127.127/2' => [[64..127] ,[0..255],[0..255],[0..255]],
|
181
|
+
'127.127.127.127/1' => [[0..127] ,[0..255],[0..255],[0..255]],
|
182
|
+
'127.127.127.127/0' => [[0..255] ,[0..255],[0..255],[0..255]],
|
183
|
+
'128.128.128.128/32' => [[128],[128],[128],[128] ],
|
184
|
+
'128.128.128.128/31' => [[128],[128],[128],[128..129]],
|
185
|
+
'128.128.128.128/30' => [[128],[128],[128],[128..131]],
|
186
|
+
'128.128.128.128/29' => [[128],[128],[128],[128..135]],
|
187
|
+
'128.128.128.128/28' => [[128],[128],[128],[128..143]],
|
188
|
+
'128.128.128.128/27' => [[128],[128],[128],[128..159]],
|
189
|
+
'128.128.128.128/26' => [[128],[128],[128],[128..191]],
|
190
|
+
'128.128.128.128/25' => [[128],[128],[128],[128..255]],
|
191
|
+
'128.128.128.128/24' => [[128],[128],[128],[0..255] ],
|
192
|
+
'128.128.128.128/23' => [[128],[128],[128..129],[0..255]],
|
193
|
+
'128.128.128.128/22' => [[128],[128],[128..131],[0..255]],
|
194
|
+
'128.128.128.128/21' => [[128],[128],[128..135],[0..255]],
|
195
|
+
'128.128.128.128/20' => [[128],[128],[128..143],[0..255]],
|
196
|
+
'128.128.128.128/19' => [[128],[128],[128..159],[0..255]],
|
197
|
+
'128.128.128.128/18' => [[128],[128],[128..191],[0..255]],
|
198
|
+
'128.128.128.128/17' => [[128],[128],[128..255],[0..255]],
|
199
|
+
'128.128.128.128/16' => [[128],[128],[0..255] ,[0..255]],
|
200
|
+
'128.128.128.128/15' => [[128],[128..129],[0..255],[0..255]],
|
201
|
+
'128.128.128.128/14' => [[128],[128..131],[0..255],[0..255]],
|
202
|
+
'128.128.128.128/13' => [[128],[128..135],[0..255],[0..255]],
|
203
|
+
'128.128.128.128/12' => [[128],[128..143],[0..255],[0..255]],
|
204
|
+
'128.128.128.128/11' => [[128],[128..159],[0..255],[0..255]],
|
205
|
+
'128.128.128.128/10' => [[128],[128..191],[0..255],[0..255]],
|
206
|
+
'128.128.128.128/9' => [[128],[128..255],[0..255],[0..255]],
|
207
|
+
'128.128.128.128/8' => [[128],[0..255] ,[0..255],[0..255]],
|
208
|
+
'128.128.128.128/7' => [[128..129],[0..255],[0..255],[0..255]],
|
209
|
+
'128.128.128.128/6' => [[128..131],[0..255],[0..255],[0..255]],
|
210
|
+
'128.128.128.128/5' => [[128..135],[0..255],[0..255],[0..255]],
|
211
|
+
'128.128.128.128/4' => [[128..143],[0..255],[0..255],[0..255]],
|
212
|
+
'128.128.128.128/3' => [[128..159],[0..255],[0..255],[0..255]],
|
213
|
+
'128.128.128.128/2' => [[128..191],[0..255],[0..255],[0..255]],
|
214
|
+
'128.128.128.128/1' => [[128..255],[0..255],[0..255],[0..255]],
|
215
|
+
'128.128.128.128/0' => [[0..255] ,[0..255],[0..255],[0..255]],
|
216
|
+
'255.255.255.255/32' => [[255],[255],[255],[255] ],
|
217
|
+
'255.255.255.255/31' => [[255],[255],[255],[254..255]],
|
218
|
+
'255.255.255.255/30' => [[255],[255],[255],[252..255]],
|
219
|
+
'255.255.255.255/29' => [[255],[255],[255],[248..255]],
|
220
|
+
'255.255.255.255/28' => [[255],[255],[255],[240..255]],
|
221
|
+
'255.255.255.255/27' => [[255],[255],[255],[224..255]],
|
222
|
+
'255.255.255.255/26' => [[255],[255],[255],[192..255]],
|
223
|
+
'255.255.255.255/25' => [[255],[255],[255],[128..255]],
|
224
|
+
'255.255.255.255/24' => [[255],[255],[255],[0..255] ],
|
225
|
+
'255.255.255.255/23' => [[255],[255],[254..255],[0..255]],
|
226
|
+
'255.255.255.255/22' => [[255],[255],[252..255],[0..255]],
|
227
|
+
'255.255.255.255/21' => [[255],[255],[248..255],[0..255]],
|
228
|
+
'255.255.255.255/20' => [[255],[255],[240..255],[0..255]],
|
229
|
+
'255.255.255.255/19' => [[255],[255],[224..255],[0..255]],
|
230
|
+
'255.255.255.255/18' => [[255],[255],[192..255],[0..255]],
|
231
|
+
'255.255.255.255/17' => [[255],[255],[128..255],[0..255]],
|
232
|
+
'255.255.255.255/16' => [[255],[255],[0..255] ,[0..255]],
|
233
|
+
'255.255.255.255/15' => [[255],[254..255],[0..255],[0..255]],
|
234
|
+
'255.255.255.255/14' => [[255],[252..255],[0..255],[0..255]],
|
235
|
+
'255.255.255.255/13' => [[255],[248..255],[0..255],[0..255]],
|
236
|
+
'255.255.255.255/12' => [[255],[240..255],[0..255],[0..255]],
|
237
|
+
'255.255.255.255/11' => [[255],[224..255],[0..255],[0..255]],
|
238
|
+
'255.255.255.255/10' => [[255],[192..255],[0..255],[0..255]],
|
239
|
+
'255.255.255.255/9' => [[255],[128..255],[0..255],[0..255]],
|
240
|
+
'255.255.255.255/8' => [[255],[0..255] ,[0..255],[0..255]],
|
241
|
+
'255.255.255.255/7' => [[254..255],[0..255],[0..255],[0..255]],
|
242
|
+
'255.255.255.255/6' => [[252..255],[0..255],[0..255],[0..255]],
|
243
|
+
'255.255.255.255/5' => [[248..255],[0..255],[0..255],[0..255]],
|
244
|
+
'255.255.255.255/4' => [[240..255],[0..255],[0..255],[0..255]],
|
245
|
+
'255.255.255.255/3' => [[224..255],[0..255],[0..255],[0..255]],
|
246
|
+
'255.255.255.255/2' => [[192..255],[0..255],[0..255],[0..255]],
|
247
|
+
'255.255.255.255/1' => [[128..255],[0..255],[0..255],[0..255]],
|
248
|
+
'255.255.255.255/0' => [[0..255] ,[0..255],[0..255],[0..255]],
|
249
|
+
}
|
250
|
+
slash_specs.each do |spec_str,spec_data|
|
251
|
+
hs = Iqeo::Hostspec.new spec_str
|
252
|
+
hs.address_spec.should eq spec_data
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'a hostname' do
|
259
|
+
|
260
|
+
it 'is assumed when not a simple IP spec' do
|
261
|
+
Iqeo::Hostspec.new('localhost').hostname.should eq 'localhost'
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'is assumed when not a complex IP spec' do
|
265
|
+
expect { hs = Iqeo::Hostspec.new "1.2.3.100-300" }.to raise_error Resolv::ResolvError
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'resolves to a host IP address' do
|
269
|
+
hs = Iqeo::Hostspec.new('localhost')
|
270
|
+
hs.hostname.should eq 'localhost'
|
271
|
+
hs.address_spec.collect(&:first).should eq [127,0,0,1]
|
272
|
+
hs.mask.should eq '255.255.255.255'
|
273
|
+
hs.mask_length.should eq 32
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'may specify address range with a mask length' do
|
277
|
+
(0..32).each do |masklen|
|
278
|
+
hs = Iqeo::Hostspec.new("localhost/#{masklen}")
|
279
|
+
hs.mask_length.should eq masklen
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
context 'a complex IP address spec' do
|
286
|
+
|
287
|
+
it 'must not specify a mask length' do
|
288
|
+
(0..32).each do |masklen|
|
289
|
+
expect { hs = Iqeo::Hostspec.new "10.20,22,24.30-39.40/#{masklen}" }.to raise_error
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'may specify octet values with commas' do
|
294
|
+
hs = Iqeo::Hostspec.new '10,11,12.20,21,22.30,31,32.40,41,42'
|
295
|
+
hs.address_spec.should eq [[10,11,12],[20,21,22],[30,31,32],[40,41,42]]
|
296
|
+
end
|
297
|
+
|
298
|
+
context 'may specify octet value ranges with dashes' do
|
299
|
+
|
300
|
+
it 'in form "n-m"' do
|
301
|
+
hs = Iqeo::Hostspec.new '10-19.20-29.30-39.40-49'
|
302
|
+
hs.address_spec.should eq [[10..19],[20..29],[30..39],[40..49]]
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'in form "n-"' do
|
306
|
+
hs = Iqeo::Hostspec.new '10-.20-.30-.40-'
|
307
|
+
hs.address_spec.should eq [[10..255],[20..255],[30..255],[40..255]]
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'in form "-m"' do
|
311
|
+
hs = Iqeo::Hostspec.new '-19.-29.-39.-49'
|
312
|
+
hs.address_spec.should eq [[0..19],[0..29],[0..39],[0..49]]
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'in form "-"' do
|
316
|
+
hs = Iqeo::Hostspec.new '-.-.-.-'
|
317
|
+
hs.address_spec.should eq [[0..255],[0..255],[0..255],[0..255]]
|
318
|
+
end
|
319
|
+
|
320
|
+
end
|
321
|
+
|
322
|
+
it 'may mix octet specifications with dashes and commas' do
|
323
|
+
hs = Iqeo::Hostspec.new '1,10,100,200.13-247.23-.-99'
|
324
|
+
hs.address_spec.should eq [[1,10,100,200],[13..247],[23..255],[0..99]]
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'may combine octet specification with dashes and commas' do
|
328
|
+
hs = Iqeo::Hostspec.new '0,1,10,100-200,250,254,255.-50,99,200-.-33,44,55-66,77,88-.-'
|
329
|
+
hs.address_spec.should eq [[0,1,10,100..200,250,254,255],[0..50,99,200..255],[0..33,44,55..66,77,88..255],[0..255]]
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'may not specifiy a reversed range' do
|
333
|
+
expect { hs = Iqeo::Hostspec.new '1.1.1.20-10' }.to raise_error
|
334
|
+
end
|
335
|
+
|
336
|
+
end
|
337
|
+
|
338
|
+
end
|
339
|
+
|
340
|
+
context 'instance' do
|
341
|
+
|
342
|
+
before(:all) do
|
343
|
+
@octets = (0..255).to_a
|
344
|
+
@multi_spec_with_commas = '10,11,12.20,21,22.30,31,32.40,41,42'
|
345
|
+
@multi_spec_with_dashes = '10-12.20-22.30-32.40-42'
|
346
|
+
@multi_expected_addresses = [
|
347
|
+
'10.20.30.40','10.20.30.41','10.20.30.42','10.20.31.40','10.20.31.41','10.20.31.42','10.20.32.40','10.20.32.41','10.20.32.42',
|
348
|
+
'10.21.30.40','10.21.30.41','10.21.30.42','10.21.31.40','10.21.31.41','10.21.31.42','10.21.32.40','10.21.32.41','10.21.32.42',
|
349
|
+
'10.22.30.40','10.22.30.41','10.22.30.42','10.22.31.40','10.22.31.41','10.22.31.42','10.22.32.40','10.22.32.41','10.22.32.42',
|
350
|
+
'11.20.30.40','11.20.30.41','11.20.30.42','11.20.31.40','11.20.31.41','11.20.31.42','11.20.32.40','11.20.32.41','11.20.32.42',
|
351
|
+
'11.21.30.40','11.21.30.41','11.21.30.42','11.21.31.40','11.21.31.41','11.21.31.42','11.21.32.40','11.21.32.41','11.21.32.42',
|
352
|
+
'11.22.30.40','11.22.30.41','11.22.30.42','11.22.31.40','11.22.31.41','11.22.31.42','11.22.32.40','11.22.32.41','11.22.32.42',
|
353
|
+
'12.20.30.40','12.20.30.41','12.20.30.42','12.20.31.40','12.20.31.41','12.20.31.42','12.20.32.40','12.20.32.41','12.20.32.42',
|
354
|
+
'12.21.30.40','12.21.30.41','12.21.30.42','12.21.31.40','12.21.31.41','12.21.31.42','12.21.32.40','12.21.32.41','12.21.32.42',
|
355
|
+
'12.22.30.40','12.22.30.41','12.22.30.42','12.22.31.40','12.22.31.41','12.22.31.42','12.22.32.40','12.22.32.41','12.22.32.42',
|
356
|
+
]
|
357
|
+
@specs_with_slash = {
|
358
|
+
'10.20.30.40/28' => [
|
359
|
+
'10.20.30.32', '10.20.30.33', '10.20.30.34', '10.20.30.35', '10.20.30.36', '10.20.30.37', '10.20.30.38', '10.20.30.39',
|
360
|
+
'10.20.30.40', '10.20.30.41', '10.20.30.42', '10.20.30.43', '10.20.30.44', '10.20.30.45', '10.20.30.46', '10.20.30.47',
|
361
|
+
],
|
362
|
+
'10.20.30.40/27' => [
|
363
|
+
'10.20.30.32', '10.20.30.33', '10.20.30.34', '10.20.30.35', '10.20.30.36', '10.20.30.37', '10.20.30.38', '10.20.30.39',
|
364
|
+
'10.20.30.40', '10.20.30.41', '10.20.30.42', '10.20.30.43', '10.20.30.44', '10.20.30.45', '10.20.30.46', '10.20.30.47',
|
365
|
+
'10.20.30.48', '10.20.30.49', '10.20.30.50', '10.20.30.51', '10.20.30.52', '10.20.30.53', '10.20.30.54', '10.20.30.55',
|
366
|
+
'10.20.30.56', '10.20.30.57', '10.20.30.58', '10.20.30.59', '10.20.30.60', '10.20.30.61', '10.20.30.62', '10.20.30.63',
|
367
|
+
]
|
368
|
+
}
|
369
|
+
|
370
|
+
end
|
371
|
+
|
372
|
+
shared_examples "enumerates" do |method|
|
373
|
+
|
374
|
+
it 'a single address for host address' do
|
375
|
+
@octets.each_cons(4) do |octets|
|
376
|
+
address = octets.join('.')
|
377
|
+
hs = Iqeo::Hostspec.new address
|
378
|
+
address_count = 0
|
379
|
+
hs.send(method) do |address_str|
|
380
|
+
address_str.should eq address
|
381
|
+
address_count += 1
|
382
|
+
end
|
383
|
+
address_count.should eq 1
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
it 'multiple addresses for a spec with multiple octet values (commas)' do
|
388
|
+
hs = Iqeo::Hostspec.new @multi_spec_with_commas
|
389
|
+
address_count = 0
|
390
|
+
hs.send(method) do |address_str|
|
391
|
+
address_str.should eq @multi_expected_addresses[address_count]
|
392
|
+
address_count +=1
|
393
|
+
end
|
394
|
+
address_count.should eq @multi_expected_addresses.size
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'multiple addresses for a spec with octet ranges (dashes)' do
|
398
|
+
hs = Iqeo::Hostspec.new @multi_spec_with_dashes
|
399
|
+
address_count = 0
|
400
|
+
hs.send(method) do |address_str|
|
401
|
+
address_str.should eq @multi_expected_addresses[address_count]
|
402
|
+
address_count +=1
|
403
|
+
end
|
404
|
+
address_count.should eq @multi_expected_addresses.size
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'masked addresses for specs with a mask length' do
|
408
|
+
@specs_with_slash.each do |address_spec,expected_addresses|
|
409
|
+
hs = Iqeo::Hostspec.new address_spec
|
410
|
+
address_count = 0
|
411
|
+
hs.send(method) do |address_str|
|
412
|
+
address_str.should eq expected_addresses[address_count]
|
413
|
+
address_count += 1
|
414
|
+
end
|
415
|
+
address_count.should eq expected_addresses.size
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
end
|
420
|
+
|
421
|
+
context '.each_address enumerates' do
|
422
|
+
include_examples 'enumerates', :each_address
|
423
|
+
end
|
424
|
+
|
425
|
+
context '.each enumerates' do
|
426
|
+
include_examples 'enumerates', :each
|
427
|
+
end
|
428
|
+
|
429
|
+
context 'enumerable' do
|
430
|
+
|
431
|
+
it '.each returns an Enumerator' do
|
432
|
+
hs = Iqeo::Hostspec.new '10.20.30.40/24'
|
433
|
+
hs.each.class.should eq Enumerator
|
434
|
+
end
|
435
|
+
|
436
|
+
it 'responds to Enumerable methods' do
|
437
|
+
hs = Iqeo::Hostspec.new '10.20.30.40/24'
|
438
|
+
hs.all? { |i| i.start_with? '10' }.should be_true
|
439
|
+
hs.any? { |i| i.end_with? '255' }.should be_true
|
440
|
+
end
|
441
|
+
|
442
|
+
it 'can calculate size for simple specs' do
|
443
|
+
(0..32).each do |masklen|
|
444
|
+
hs = Iqeo::Hostspec.new "10.20.30.40/#{masklen}"
|
445
|
+
hs.size.should eq 2**(32-masklen)
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
it 'can calculate size for complex specs' do
|
450
|
+
hs = Iqeo::Hostspec.new @multi_spec_with_commas
|
451
|
+
hs.size.should eq @multi_expected_addresses.size
|
452
|
+
hs = Iqeo::Hostspec.new @multi_spec_with_dashes
|
453
|
+
hs.size.should eq @multi_expected_addresses.size
|
454
|
+
end
|
455
|
+
|
456
|
+
it 'Enumerator can make use of size' do
|
457
|
+
hs = Iqeo::Hostspec.new '1.1.1.1-10'
|
458
|
+
hs.size.should eq 10
|
459
|
+
enumerator = hs.each
|
460
|
+
enumerator.size.should eq 10
|
461
|
+
end
|
462
|
+
|
463
|
+
it 'has first (from enumerable)' do
|
464
|
+
hs = Iqeo::Hostspec.new '1.1.2-10.20-100'
|
465
|
+
hs.first.should eq '1.1.2.20'
|
466
|
+
end
|
467
|
+
|
468
|
+
it 'has last' do
|
469
|
+
hs = Iqeo::Hostspec.new '1.1.2-10.20-100'
|
470
|
+
hs.last.should eq '1.1.10.100'
|
471
|
+
end
|
472
|
+
|
473
|
+
it 'has min equals first' do
|
474
|
+
hs = Iqeo::Hostspec.new '1.1.2-10.20-100'
|
475
|
+
hs.min.should eq '1.1.2.20'
|
476
|
+
end
|
477
|
+
|
478
|
+
it 'has max equals last' do
|
479
|
+
hs = Iqeo::Hostspec.new '1.1.2-10.20-100'
|
480
|
+
hs.max.should eq '1.1.10.100'
|
481
|
+
end
|
482
|
+
|
483
|
+
it 'has minmax' do
|
484
|
+
hs = Iqeo::Hostspec.new '1.1.2-10.20-100'
|
485
|
+
hs.minmax.should eq ['1.1.2.20','1.1.10.100']
|
486
|
+
end
|
487
|
+
|
488
|
+
end
|
489
|
+
|
490
|
+
end
|
491
|
+
|
492
|
+
end
|
493
|
+
|