cisco_acl_intp 0.0.2 → 0.0.3
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 +4 -4
- data/Gemfile +1 -1
- data/README.md +64 -3
- data/cisco_acl_intp.gemspec +2 -2
- data/lib/cisco_acl_intp/ace.rb +9 -286
- data/lib/cisco_acl_intp/ace_ip.rb +24 -22
- data/lib/cisco_acl_intp/ace_other_qualifiers.rb +23 -6
- data/lib/cisco_acl_intp/ace_port.rb +37 -182
- data/lib/cisco_acl_intp/ace_port_opr.rb +251 -0
- data/lib/cisco_acl_intp/ace_port_opr_base.rb +138 -0
- data/lib/cisco_acl_intp/ace_proto.rb +133 -328
- data/lib/cisco_acl_intp/ace_proto_base.rb +163 -0
- data/lib/cisco_acl_intp/ace_srcdst.rb +30 -40
- data/lib/cisco_acl_intp/ace_tcp_flags.rb +9 -3
- data/lib/cisco_acl_intp/acl.rb +1 -251
- data/lib/cisco_acl_intp/acl_base.rb +1 -1
- data/lib/cisco_acl_intp/acl_utils.rb +120 -0
- data/lib/cisco_acl_intp/extended_ace.rb +149 -0
- data/lib/cisco_acl_intp/mono_function_acl.rb +161 -0
- data/lib/cisco_acl_intp/parser.rb +237 -395
- data/lib/cisco_acl_intp/parser.ry +85 -243
- data/lib/cisco_acl_intp/parser_api.rb +2 -2
- data/lib/cisco_acl_intp/single_acl_base.rb +137 -0
- data/lib/cisco_acl_intp/standard_ace.rb +105 -0
- data/lib/cisco_acl_intp/version.rb +1 -1
- data/spec/cisco_acl_intp/ace_ip_spec.rb +63 -0
- data/spec/cisco_acl_intp/ace_other_qualifier_spec.rb +52 -1
- data/spec/cisco_acl_intp/ace_port_operator_spec.rb +340 -0
- data/spec/cisco_acl_intp/ace_port_spec.rb +67 -217
- data/spec/cisco_acl_intp/ace_proto_spec.rb +118 -41
- data/spec/cisco_acl_intp/ace_spec.rb +38 -547
- data/spec/cisco_acl_intp/ace_srcdst_spec.rb +115 -226
- data/spec/cisco_acl_intp/ace_tcp_flags_spec.rb +36 -4
- data/spec/cisco_acl_intp/acl_base_spec.rb +2 -2
- data/spec/cisco_acl_intp/extended_ace_spec.rb +411 -0
- data/spec/cisco_acl_intp/extended_acl_spec.rb +265 -0
- data/spec/cisco_acl_intp/scanner_spec.rb +13 -12
- data/spec/cisco_acl_intp/standard_ace_spec.rb +77 -0
- data/spec/cisco_acl_intp/standard_acl_spec.rb +245 -0
- data/spec/conf/scanner_spec_data.yml +32 -0
- data/spec/spec_helper.rb +2 -2
- metadata +20 -4
- data/spec/cisco_acl_intp/acl_spec.rb +0 -525
@@ -0,0 +1,340 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'AcePortOpAny' do
|
5
|
+
describe '#contains' do
|
6
|
+
before(:all) do
|
7
|
+
@aclop = AcePortOpAny.new
|
8
|
+
@port1 = AceTcpProtoSpec.new(10)
|
9
|
+
@port2 = AceTcpProtoSpec.new('www')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should be true all conditions' do
|
13
|
+
@aclop.contains?(AcePortOpAny.new).should be_true
|
14
|
+
@aclop.contains?(AcePortOpStrictAny.new).should be_true
|
15
|
+
@aclop.contains?(AcePortOpEq.new(@port1)).should be_true
|
16
|
+
@aclop.contains?(AcePortOpNeq.new(@port1)).should be_true
|
17
|
+
@aclop.contains?(AcePortOpLt.new(@port1)).should be_true
|
18
|
+
@aclop.contains?(AcePortOpGt.new(@port1)).should be_true
|
19
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port2)).should be_true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'AcePortOpStrictAny' do
|
25
|
+
describe '#contains' do
|
26
|
+
before(:all) do
|
27
|
+
@aclop = AcePortOpStrictAny.new
|
28
|
+
@port1 = AceTcpProtoSpec.new(10)
|
29
|
+
@port2 = AceTcpProtoSpec.new('www')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should be true when only ANY conditions' do
|
33
|
+
@aclop.contains?(AcePortOpAny.new).should be_true
|
34
|
+
@aclop.contains?(AcePortOpStrictAny.new).should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should be false with other operators' do
|
38
|
+
@aclop.contains?(AcePortOpEq.new(@port1)).should be_false
|
39
|
+
@aclop.contains?(AcePortOpNeq.new(@port1)).should be_false
|
40
|
+
@aclop.contains?(AcePortOpLt.new(@port1)).should be_false
|
41
|
+
@aclop.contains?(AcePortOpGt.new(@port1)).should be_false
|
42
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port2)).should be_false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'AcePortOpEq' do
|
48
|
+
describe '#contains' do
|
49
|
+
before(:all) do
|
50
|
+
@port1 = AceTcpProtoSpec.new(10)
|
51
|
+
@port2 = AceTcpProtoSpec.new('www')
|
52
|
+
@aclop = AcePortOpEq.new(@port1)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should be true with ANY' do
|
56
|
+
@aclop.contains?(AcePortOpAny.new).should be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should be false with STRICT_ANY' do
|
60
|
+
@aclop.contains?(AcePortOpStrictAny.new).should be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should be true when same eq/port operator' do
|
64
|
+
@aclop.contains?(AcePortOpEq.new(@port1)).should be_true
|
65
|
+
@aclop.contains?(AcePortOpEq.new(@port2)).should be_false
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should be false with other operator' do
|
69
|
+
@aclop.contains?(AcePortOpNeq.new(@port1)).should be_false
|
70
|
+
@aclop.contains?(AcePortOpLt.new(@port1)).should be_false
|
71
|
+
@aclop.contains?(AcePortOpGt.new(@port1)).should be_false
|
72
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port2)).should be_false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'AcePortOpNeq' do
|
78
|
+
describe '#contains' do
|
79
|
+
before(:all) do
|
80
|
+
@port1 = AceTcpProtoSpec.new(10)
|
81
|
+
@port2 = AceTcpProtoSpec.new('www')
|
82
|
+
@port3 = AceTcpProtoSpec.new(443)
|
83
|
+
@aclop = AcePortOpNeq.new(@port2)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should be true with ANY' do
|
87
|
+
@aclop.contains?(AcePortOpAny.new).should be_true
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should be false with STRICT_ANY' do
|
91
|
+
@aclop.contains?(AcePortOpStrictAny.new).should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should be checked with EQUAL' do
|
95
|
+
@aclop.contains?(AcePortOpEq.new(@port1)).should be_true
|
96
|
+
@aclop.contains?(AcePortOpEq.new(@port2)).should be_false
|
97
|
+
@aclop.contains?(AcePortOpEq.new(@port3)).should be_true
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should be checked with NOT_EQUAL' do
|
101
|
+
@aclop.contains?(AcePortOpNeq.new(@port1)).should be_false
|
102
|
+
@aclop.contains?(AcePortOpNeq.new(@port2)).should be_true
|
103
|
+
@aclop.contains?(AcePortOpNeq.new(@port3)).should be_false
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should be checked with LOWER_THAN' do
|
107
|
+
@aclop.contains?(AcePortOpLt.new(@port1)).should be_true
|
108
|
+
@aclop.contains?(AcePortOpLt.new(@port2)).should be_true
|
109
|
+
@aclop.contains?(AcePortOpLt.new(@port3)).should be_false
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should be checked with GRATER_THAN' do
|
113
|
+
@aclop.contains?(AcePortOpGt.new(@port1)).should be_false
|
114
|
+
@aclop.contains?(AcePortOpGt.new(@port2)).should be_true
|
115
|
+
@aclop.contains?(AcePortOpGt.new(@port3)).should be_true
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should be checked with RANGE' do
|
119
|
+
port2a = AceTcpProtoSpec.new(79)
|
120
|
+
port2b = AceTcpProtoSpec.new(81)
|
121
|
+
@aclop.contains?(AcePortOpRange.new(@port1, port2a)).should be_true
|
122
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port2)).should be_false
|
123
|
+
@aclop.contains?(AcePortOpRange.new(@port2, @port3)).should be_false
|
124
|
+
@aclop.contains?(AcePortOpRange.new(port2b, @port3)).should be_true
|
125
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port3)).should be_false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'AcePortOpLt' do
|
131
|
+
describe '#contains' do
|
132
|
+
before(:all) do
|
133
|
+
@port1 = AceTcpProtoSpec.new(10)
|
134
|
+
@port2 = AceTcpProtoSpec.new('www')
|
135
|
+
@port3 = AceTcpProtoSpec.new(443)
|
136
|
+
@port_max = AceTcpProtoSpec.new(65_535)
|
137
|
+
@aclop = AcePortOpLt.new(@port2)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should be true with ANY' do
|
141
|
+
@aclop.contains?(AcePortOpAny.new).should be_true
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should be false with STRICT_ANY' do
|
145
|
+
@aclop.contains?(AcePortOpStrictAny.new).should be_true
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should be checked with EQUAL' do
|
149
|
+
@aclop.contains?(AcePortOpEq.new(@port1)).should be_true
|
150
|
+
@aclop.contains?(AcePortOpEq.new(@port2)).should be_false
|
151
|
+
@aclop.contains?(AcePortOpEq.new(@port3)).should be_false
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should be checked with NOT_EQUAL(1)' do
|
155
|
+
@aclop.contains?(AcePortOpNeq.new(@port1)).should be_false
|
156
|
+
@aclop.contains?(AcePortOpNeq.new(@port2)).should be_false
|
157
|
+
@aclop.contains?(AcePortOpNeq.new(@port3)).should be_false
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should be checked with NOT_EQUAL(2)' do
|
161
|
+
aclop = AcePortOpLt.new(@port_max)
|
162
|
+
aclop.contains?(AcePortOpNeq.new(@port_max)).should be_true
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should be checked with LOWER_THAN' do
|
166
|
+
@aclop.contains?(AcePortOpLt.new(@port1)).should be_true
|
167
|
+
@aclop.contains?(AcePortOpLt.new(@port2)).should be_true
|
168
|
+
@aclop.contains?(AcePortOpLt.new(@port3)).should be_false
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should be checked with GRATER_THAN' do
|
172
|
+
@aclop.contains?(AcePortOpGt.new(@port1)).should be_false
|
173
|
+
@aclop.contains?(AcePortOpGt.new(@port2)).should be_false
|
174
|
+
@aclop.contains?(AcePortOpGt.new(@port3)).should be_false
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should be checked with RANGE' do
|
178
|
+
port2a = AceTcpProtoSpec.new(79)
|
179
|
+
port2b = AceTcpProtoSpec.new(81)
|
180
|
+
@aclop.contains?(AcePortOpRange.new(@port1, port2a)).should be_true
|
181
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port2)).should be_false
|
182
|
+
@aclop.contains?(AcePortOpRange.new(@port2, @port3)).should be_false
|
183
|
+
@aclop.contains?(AcePortOpRange.new(port2b, @port3)).should be_false
|
184
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port3)).should be_false
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe 'AcePortOpGt' do
|
190
|
+
describe '#contains' do
|
191
|
+
before(:all) do
|
192
|
+
@port1 = AceTcpProtoSpec.new(10)
|
193
|
+
@port2 = AceTcpProtoSpec.new('www')
|
194
|
+
@port3 = AceTcpProtoSpec.new(443)
|
195
|
+
@port_min = AceTcpProtoSpec.new(0)
|
196
|
+
@aclop = AcePortOpGt.new(@port2)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should be true with ANY' do
|
200
|
+
@aclop.contains?(AcePortOpAny.new).should be_true
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'should be false with STRICT_ANY' do
|
204
|
+
@aclop.contains?(AcePortOpStrictAny.new).should be_true
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'should be checked with EQUAL' do
|
208
|
+
@aclop.contains?(AcePortOpEq.new(@port1)).should be_false
|
209
|
+
@aclop.contains?(AcePortOpEq.new(@port2)).should be_false
|
210
|
+
@aclop.contains?(AcePortOpEq.new(@port3)).should be_true
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should be checked with NOT_EQUAL(1)' do
|
214
|
+
@aclop.contains?(AcePortOpNeq.new(@port1)).should be_false
|
215
|
+
@aclop.contains?(AcePortOpNeq.new(@port2)).should be_false
|
216
|
+
@aclop.contains?(AcePortOpNeq.new(@port3)).should be_false
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should be checked with NOT_EQUAL(2)' do
|
220
|
+
aclop = AcePortOpGt.new(@port_min)
|
221
|
+
aclop.contains?(AcePortOpNeq.new(@port_min)).should be_true
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'should be checked with LOWER_THAN' do
|
225
|
+
@aclop.contains?(AcePortOpLt.new(@port1)).should be_false
|
226
|
+
@aclop.contains?(AcePortOpLt.new(@port2)).should be_false
|
227
|
+
@aclop.contains?(AcePortOpLt.new(@port3)).should be_false
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'should be checked with GRATER_THAN' do
|
231
|
+
@aclop.contains?(AcePortOpGt.new(@port1)).should be_false
|
232
|
+
@aclop.contains?(AcePortOpGt.new(@port2)).should be_true
|
233
|
+
@aclop.contains?(AcePortOpGt.new(@port3)).should be_true
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'should be checked with RANGE' do
|
237
|
+
port2a = AceTcpProtoSpec.new(79)
|
238
|
+
port2b = AceTcpProtoSpec.new(81)
|
239
|
+
@aclop.contains?(AcePortOpRange.new(@port1, port2a)).should be_false
|
240
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port2)).should be_false
|
241
|
+
@aclop.contains?(AcePortOpRange.new(@port2, @port3)).should be_false
|
242
|
+
@aclop.contains?(AcePortOpRange.new(port2b, @port3)).should be_true
|
243
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port3)).should be_false
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe 'AcePortOpRange' do
|
249
|
+
describe '#contains' do
|
250
|
+
before(:all) do
|
251
|
+
@port1 = AceTcpProtoSpec.new(10)
|
252
|
+
@port2 = AceTcpProtoSpec.new('www')
|
253
|
+
@port3 = AceTcpProtoSpec.new(443)
|
254
|
+
@port4 = AceTcpProtoSpec.new(8080)
|
255
|
+
|
256
|
+
@port2a = AceTcpProtoSpec.new(79)
|
257
|
+
@port2b = AceTcpProtoSpec.new(81)
|
258
|
+
@port3a = AceTcpProtoSpec.new(442)
|
259
|
+
@port3b = AceTcpProtoSpec.new(444)
|
260
|
+
|
261
|
+
@port_max = AceTcpProtoSpec.new(65_535)
|
262
|
+
@port_min = AceTcpProtoSpec.new(0)
|
263
|
+
|
264
|
+
@aclop = AcePortOpRange.new(@port2, @port3)
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should be true with ANY' do
|
268
|
+
@aclop.contains?(AcePortOpAny.new).should be_true
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'should be false with STRICT_ANY' do
|
272
|
+
@aclop.contains?(AcePortOpStrictAny.new).should be_true
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'should be checked with EQUAL' do
|
276
|
+
@aclop.contains?(AcePortOpEq.new(@port1)).should be_false
|
277
|
+
@aclop.contains?(AcePortOpEq.new(@port2)).should be_true
|
278
|
+
@aclop.contains?(AcePortOpEq.new(@port3)).should be_true
|
279
|
+
@aclop.contains?(AcePortOpEq.new(@port4)).should be_false
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'should be checked with NOT_EQUAL(1)' do
|
283
|
+
@aclop.contains?(AcePortOpNeq.new(@port1)).should be_false
|
284
|
+
@aclop.contains?(AcePortOpNeq.new(@port2)).should be_false
|
285
|
+
@aclop.contains?(AcePortOpNeq.new(@port3)).should be_false
|
286
|
+
@aclop.contains?(AcePortOpNeq.new(@port4)).should be_false
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'should be checked with NOT_EQUAL(2)' do
|
290
|
+
aclop = AcePortOpRange.new(@port_min, @port_max)
|
291
|
+
aclop.contains?(AcePortOpNeq.new(@port_min)).should be_true
|
292
|
+
aclop.contains?(AcePortOpNeq.new(@port_max)).should be_true
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'should be checked with LOWER_THAN(1)' do
|
296
|
+
@aclop.contains?(AcePortOpLt.new(@port1)).should be_false
|
297
|
+
@aclop.contains?(AcePortOpLt.new(@port2)).should be_false
|
298
|
+
@aclop.contains?(AcePortOpLt.new(@port3)).should be_false
|
299
|
+
@aclop.contains?(AcePortOpLt.new(@port4)).should be_false
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'should be checked with LOWER_THAN(2)' do
|
303
|
+
aclop = AcePortOpRange.new(@port_min, @port3)
|
304
|
+
aclop.contains?(AcePortOpLt.new(@port3a)).should be_true
|
305
|
+
aclop.contains?(AcePortOpLt.new(@port3)).should be_false
|
306
|
+
aclop.contains?(AcePortOpLt.new(@port3b)).should be_false
|
307
|
+
end
|
308
|
+
|
309
|
+
it 'should be checked with GRATER_THAN(1)' do
|
310
|
+
@aclop.contains?(AcePortOpGt.new(@port1)).should be_false
|
311
|
+
@aclop.contains?(AcePortOpGt.new(@port2)).should be_false
|
312
|
+
@aclop.contains?(AcePortOpGt.new(@port3)).should be_false
|
313
|
+
@aclop.contains?(AcePortOpGt.new(@port4)).should be_false
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'should be checked with GRATER_THAN(2)' do
|
317
|
+
aclop = AcePortOpRange.new(@port2, @port_max)
|
318
|
+
aclop.contains?(AcePortOpGt.new(@port2a)).should be_false
|
319
|
+
aclop.contains?(AcePortOpGt.new(@port2)).should be_false
|
320
|
+
aclop.contains?(AcePortOpGt.new(@port2b)).should be_true
|
321
|
+
end
|
322
|
+
|
323
|
+
it 'should be checked with RANGE' do
|
324
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port2a)).should be_false
|
325
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port2)).should be_false
|
326
|
+
@aclop.contains?(AcePortOpRange.new(@port2, @port3a)).should be_true
|
327
|
+
@aclop.contains?(AcePortOpRange.new(@port2, @port3)).should be_true
|
328
|
+
@aclop.contains?(AcePortOpRange.new(@port2, @port3b)).should be_false
|
329
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port3)).should be_false
|
330
|
+
@aclop.contains?(AcePortOpRange.new(@port2, @port4)).should be_false
|
331
|
+
@aclop.contains?(AcePortOpRange.new(@port1, @port4)).should be_false
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
### Local variables:
|
337
|
+
### mode: Ruby
|
338
|
+
### coding: utf-8-unix
|
339
|
+
### indent-tabs-mode: nil
|
340
|
+
### End:
|
@@ -3,11 +3,16 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe AcePortSpec do
|
5
5
|
describe '#new' do
|
6
|
+
before(:all) do
|
7
|
+
@port1 = AceTcpProtoSpec.new('bgp') # 179
|
8
|
+
@port2 = AceTcpProtoSpec.new(333)
|
9
|
+
end
|
10
|
+
|
6
11
|
it 'shoud be error with unknown operator' do
|
7
12
|
lambda do
|
8
13
|
AcePortSpec.new(
|
9
14
|
operator: 'equal',
|
10
|
-
port:
|
15
|
+
port: @port1
|
11
16
|
)
|
12
17
|
end.should raise_error(AclArgumentError)
|
13
18
|
end
|
@@ -16,17 +21,17 @@ describe AcePortSpec do
|
|
16
21
|
lambda do
|
17
22
|
AcePortSpec.new(
|
18
23
|
operator: 'range',
|
19
|
-
begin_port:
|
20
|
-
end_port:
|
24
|
+
begin_port: @port2,
|
25
|
+
end_port: @port1
|
21
26
|
)
|
22
27
|
end.should raise_error(AclArgumentError)
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
26
31
|
describe '#to_s' do
|
27
|
-
before do
|
28
|
-
@p1 = AceTcpProtoSpec.new(
|
29
|
-
@p2 = AceTcpProtoSpec.new(
|
32
|
+
before(:all) do
|
33
|
+
@p1 = AceTcpProtoSpec.new(22)
|
34
|
+
@p2 = AceTcpProtoSpec.new('www')
|
30
35
|
end
|
31
36
|
|
32
37
|
context 'Normal case' do
|
@@ -97,237 +102,82 @@ describe AcePortSpec do
|
|
97
102
|
end
|
98
103
|
end
|
99
104
|
|
100
|
-
describe '#
|
101
|
-
before do
|
102
|
-
@p1 = AceTcpProtoSpec.new(
|
103
|
-
@p2 = AceTcpProtoSpec.new(
|
104
|
-
|
105
|
-
@any = AcePortSpec.new(
|
106
|
-
|
107
|
-
)
|
108
|
-
@
|
109
|
-
|
110
|
-
)
|
111
|
-
@
|
112
|
-
|
113
|
-
)
|
114
|
-
@lt1 = AcePortSpec.new(
|
115
|
-
operator: 'lt', port: @p1
|
116
|
-
)
|
117
|
-
@gt1 = AcePortSpec.new(
|
118
|
-
operator: 'gt', port: @p1
|
119
|
-
)
|
105
|
+
describe '#contains?' do
|
106
|
+
before(:all) do
|
107
|
+
@p1 = AceTcpProtoSpec.new(22)
|
108
|
+
@p2 = AceTcpProtoSpec.new(32_768)
|
109
|
+
|
110
|
+
@any = AcePortSpec.new(operator: 'any')
|
111
|
+
@s_any = AcePortSpec.new(operator: :strict_any)
|
112
|
+
@eq1 = AcePortSpec.new(operator: 'eq', begin_port: @p1)
|
113
|
+
@eq2 = AcePortSpec.new(operator: 'eq', begin_port: @p2)
|
114
|
+
@neq1 = AcePortSpec.new(operator: 'neq', port: @p1)
|
115
|
+
@lt1 = AcePortSpec.new(operator: 'lt', port: @p1)
|
116
|
+
@lt2 = AcePortSpec.new(operator: 'lt', port: @p2)
|
117
|
+
@gt1 = AcePortSpec.new(operator: 'gt', port: @p1)
|
118
|
+
@gt2 = AcePortSpec.new(operator: 'gt', port: @p2)
|
120
119
|
@range = AcePortSpec.new(
|
121
120
|
operator: 'range',
|
122
121
|
port: @p1, end_port: @p2
|
123
122
|
)
|
124
123
|
end
|
125
124
|
|
126
|
-
it '
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
@
|
131
|
-
@
|
132
|
-
@
|
133
|
-
@
|
134
|
-
@any.matches?(65_535).should be_true
|
135
|
-
lambda do
|
136
|
-
@any.matches?(65_536)
|
137
|
-
end.should raise_error(AclArgumentError)
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'match correct number by op:eq' do
|
141
|
-
lambda do
|
142
|
-
@eq1.matches?(-1)
|
143
|
-
end.should raise_error(AclArgumentError)
|
144
|
-
@eq1.matches?(0).should be_false
|
145
|
-
@eq1.matches?(21).should be_false
|
146
|
-
@eq1.matches?(22).should be_true
|
147
|
-
@eq1.matches?(23).should be_false
|
148
|
-
@eq1.matches?(65_535).should be_false
|
149
|
-
lambda do
|
150
|
-
@eq1.matches?(65_536)
|
151
|
-
end.should raise_error(AclArgumentError)
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'match correct number by op:neq' do
|
155
|
-
lambda do
|
156
|
-
@neq1.matches?(-1)
|
157
|
-
end.should raise_error(AclArgumentError)
|
158
|
-
@neq1.matches?(0).should be_true
|
159
|
-
@neq1.matches?(21).should be_true
|
160
|
-
@neq1.matches?(22).should be_false
|
161
|
-
@neq1.matches?(23).should be_true
|
162
|
-
@neq1.matches?(65_535).should be_true
|
163
|
-
lambda do
|
164
|
-
@neq1.matches?(65_536)
|
165
|
-
end.should raise_error(AclArgumentError)
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'match lower number by op:lt' do
|
169
|
-
lambda do
|
170
|
-
@lt1.matches?(-1)
|
171
|
-
end.should raise_error(AclArgumentError)
|
172
|
-
@lt1.matches?(0).should be_true
|
173
|
-
@lt1.matches?(21).should be_true
|
174
|
-
@lt1.matches?(22).should be_false
|
175
|
-
@lt1.matches?(23).should be_false
|
176
|
-
@lt1.matches?(65_535).should be_false
|
177
|
-
lambda do
|
178
|
-
@lt1.matches?(65_536)
|
179
|
-
end.should raise_error(AclArgumentError)
|
125
|
+
it 'should be true when contained case' do
|
126
|
+
@any.contains?(@eq1).should be_true
|
127
|
+
@s_any.contains?(@any).should be_true
|
128
|
+
@eq1.contains?(@eq1).should be_true
|
129
|
+
@neq1.contains?(@eq2).should be_true
|
130
|
+
@lt2.contains?(@lt1).should be_true
|
131
|
+
@gt1.contains?(@gt2).should be_true
|
132
|
+
@range.contains?(@eq1).should be_true
|
180
133
|
end
|
181
134
|
|
182
|
-
it '
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
@
|
187
|
-
@
|
188
|
-
@
|
189
|
-
@gt1.matches?(23).should be_true
|
190
|
-
@gt1.matches?(65_535).should be_true
|
191
|
-
lambda do
|
192
|
-
@gt1.matches?(65_536)
|
193
|
-
end.should raise_error(AclArgumentError)
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'match lower number by op:range' do
|
197
|
-
lambda do
|
198
|
-
@range.matches?(-1)
|
199
|
-
end.should raise_error(AclArgumentError)
|
200
|
-
@range.matches?(0).should be_false
|
201
|
-
@range.matches?(21).should be_false
|
202
|
-
@range.matches?(22).should be_true
|
203
|
-
@range.matches?(23).should be_true
|
204
|
-
@range.matches?(32_767).should be_true
|
205
|
-
@range.matches?(32_768).should be_true
|
206
|
-
@range.matches?(32_769).should be_false
|
207
|
-
@range.matches?(65_535).should be_false
|
208
|
-
lambda do
|
209
|
-
@range.matches?(65_536)
|
210
|
-
end.should raise_error(AclArgumentError)
|
135
|
+
it 'should be false when not contained case' do
|
136
|
+
@s_any.contains?(@eq1).should be_false
|
137
|
+
@eq1.contains?(@eq2).should be_false
|
138
|
+
@neq1.contains?(@eq1).should be_false
|
139
|
+
@lt1.contains?(@lt2).should be_false
|
140
|
+
@gt2.contains?(@lt1).should be_false
|
141
|
+
@range.contains?(@neq1).should be_false
|
211
142
|
end
|
212
143
|
end
|
213
|
-
end
|
214
144
|
|
215
|
-
describe
|
216
|
-
|
217
|
-
|
218
|
-
@
|
219
|
-
@
|
220
|
-
|
221
|
-
)
|
222
|
-
@p2 = AceTcpProtoSpec.new(number: 19)
|
223
|
-
@eq2 = AceTcpPortSpec.new(
|
224
|
-
operator: 'eq', port: @p2
|
225
|
-
)
|
226
|
-
@any = AceTcpPortSpec.new(
|
227
|
-
operator: 'any'
|
228
|
-
)
|
145
|
+
describe '#==' do
|
146
|
+
before(:all) do
|
147
|
+
@p1a = AceTcpProtoSpec.new(179)
|
148
|
+
@p1b = AceTcpProtoSpec.new('bgp')
|
149
|
+
@p2 = AceTcpProtoSpec.new(33)
|
150
|
+
@pu1 = AceUdpProtoSpec.new(179)
|
229
151
|
end
|
230
152
|
|
231
|
-
it 'should be true
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
@eq2.matches?(19).should be_true
|
237
|
-
@eq2.matches?('19').should be_true
|
238
|
-
@eq2.matches?('chargen').should be_true
|
239
|
-
|
240
|
-
@any.matches?(3).should be_true
|
241
|
-
@any.matches?('55').should be_true
|
242
|
-
@any.matches?('www').should be_true
|
153
|
+
it 'should be true when same operator, same protocol' do
|
154
|
+
a = AcePortSpec.new(operator: 'eq', port: @p1a)
|
155
|
+
b = AcePortSpec.new(operator: 'eq', port: @p1b)
|
156
|
+
(a == b).should be_true
|
243
157
|
end
|
244
158
|
|
245
|
-
it 'should be false
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
@eq2.matches?(18).should be_false
|
250
|
-
@eq2.matches?('18').should be_false
|
159
|
+
it 'should be false when different protocol' do
|
160
|
+
a = AcePortSpec.new(operator: 'eq', port: @p1a)
|
161
|
+
b = AcePortSpec.new(operator: 'eq', port: @p2)
|
162
|
+
(a == b).should be_false
|
251
163
|
end
|
252
164
|
|
253
|
-
it 'should be
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
lambda do
|
259
|
-
@eq2.matches?('chargem').should be_false
|
260
|
-
end.should raise_error(AclArgumentError)
|
261
|
-
|
262
|
-
lambda do
|
263
|
-
@any.matches?('hogehoge')
|
264
|
-
end.should raise_error(AclArgumentError)
|
165
|
+
it 'should be false when different operator' do
|
166
|
+
a = AcePortSpec.new(operator: 'eq', port: @p2)
|
167
|
+
b = AcePortSpec.new(operator: 'lt', port: @p2)
|
168
|
+
(a == b).should be_false
|
265
169
|
end
|
266
170
|
|
267
|
-
it 'should be
|
268
|
-
|
269
|
-
|
270
|
-
|
171
|
+
it 'should be false when different protocol' do
|
172
|
+
a = AcePortSpec.new(operator: 'eq', port: @p1a)
|
173
|
+
b = AcePortSpec.new(operator: 'eq', port: @pu1)
|
174
|
+
(a == b).should be_false
|
271
175
|
end
|
272
176
|
end
|
273
177
|
end
|
274
178
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
operator: 'eq', port: @p1
|
281
|
-
)
|
282
|
-
@p2 = AceUdpProtoSpec.new(number: 9)
|
283
|
-
@eq2 = AceUdpPortSpec.new(
|
284
|
-
operator: 'eq', port: @p2
|
285
|
-
)
|
286
|
-
@any = AceUdpPortSpec.new(
|
287
|
-
operator: 'any'
|
288
|
-
)
|
289
|
-
end
|
290
|
-
|
291
|
-
it 'should be true by correct String arg' do
|
292
|
-
@eq1.matches?(512).should be_true
|
293
|
-
@eq1.matches?('512').should be_true
|
294
|
-
@eq1.matches?('biff').should be_true
|
295
|
-
|
296
|
-
@eq2.matches?(9).should be_true
|
297
|
-
@eq2.matches?('9').should be_true
|
298
|
-
@eq2.matches?('discard').should be_true
|
299
|
-
|
300
|
-
@any.matches?(3).should be_true
|
301
|
-
@any.matches?('55').should be_true
|
302
|
-
@any.matches?('snmp').should be_true
|
303
|
-
end
|
304
|
-
|
305
|
-
it 'should be false by wrong String arg' do
|
306
|
-
@eq1.matches?(513).should be_false
|
307
|
-
@eq1.matches?('513').should be_false
|
308
|
-
|
309
|
-
@eq2.matches?(10).should be_false
|
310
|
-
@eq2.matches?('8').should be_false
|
311
|
-
end
|
312
|
-
|
313
|
-
it 'should be raise error by unknown arg' do
|
314
|
-
lambda do
|
315
|
-
@eq1.matches?('bifff').should be_false
|
316
|
-
end.should raise_error(AclArgumentError)
|
317
|
-
|
318
|
-
lambda do
|
319
|
-
@eq2.matches?('dixcard').should be_false
|
320
|
-
end.should raise_error(AclArgumentError)
|
321
|
-
|
322
|
-
lambda do
|
323
|
-
@any.matches?('hogehoge')
|
324
|
-
end.should raise_error(AclArgumentError)
|
325
|
-
end
|
326
|
-
|
327
|
-
it 'should be raise error by udp protocol name' do
|
328
|
-
lambda do
|
329
|
-
@any.matches?('www')
|
330
|
-
end.should raise_error(AclArgumentError)
|
331
|
-
end
|
332
|
-
end
|
333
|
-
end
|
179
|
+
### Local variables:
|
180
|
+
### mode: Ruby
|
181
|
+
### coding: utf-8-unix
|
182
|
+
### indent-tabs-mode: nil
|
183
|
+
### End:
|