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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +64 -3
  4. data/cisco_acl_intp.gemspec +2 -2
  5. data/lib/cisco_acl_intp/ace.rb +9 -286
  6. data/lib/cisco_acl_intp/ace_ip.rb +24 -22
  7. data/lib/cisco_acl_intp/ace_other_qualifiers.rb +23 -6
  8. data/lib/cisco_acl_intp/ace_port.rb +37 -182
  9. data/lib/cisco_acl_intp/ace_port_opr.rb +251 -0
  10. data/lib/cisco_acl_intp/ace_port_opr_base.rb +138 -0
  11. data/lib/cisco_acl_intp/ace_proto.rb +133 -328
  12. data/lib/cisco_acl_intp/ace_proto_base.rb +163 -0
  13. data/lib/cisco_acl_intp/ace_srcdst.rb +30 -40
  14. data/lib/cisco_acl_intp/ace_tcp_flags.rb +9 -3
  15. data/lib/cisco_acl_intp/acl.rb +1 -251
  16. data/lib/cisco_acl_intp/acl_base.rb +1 -1
  17. data/lib/cisco_acl_intp/acl_utils.rb +120 -0
  18. data/lib/cisco_acl_intp/extended_ace.rb +149 -0
  19. data/lib/cisco_acl_intp/mono_function_acl.rb +161 -0
  20. data/lib/cisco_acl_intp/parser.rb +237 -395
  21. data/lib/cisco_acl_intp/parser.ry +85 -243
  22. data/lib/cisco_acl_intp/parser_api.rb +2 -2
  23. data/lib/cisco_acl_intp/single_acl_base.rb +137 -0
  24. data/lib/cisco_acl_intp/standard_ace.rb +105 -0
  25. data/lib/cisco_acl_intp/version.rb +1 -1
  26. data/spec/cisco_acl_intp/ace_ip_spec.rb +63 -0
  27. data/spec/cisco_acl_intp/ace_other_qualifier_spec.rb +52 -1
  28. data/spec/cisco_acl_intp/ace_port_operator_spec.rb +340 -0
  29. data/spec/cisco_acl_intp/ace_port_spec.rb +67 -217
  30. data/spec/cisco_acl_intp/ace_proto_spec.rb +118 -41
  31. data/spec/cisco_acl_intp/ace_spec.rb +38 -547
  32. data/spec/cisco_acl_intp/ace_srcdst_spec.rb +115 -226
  33. data/spec/cisco_acl_intp/ace_tcp_flags_spec.rb +36 -4
  34. data/spec/cisco_acl_intp/acl_base_spec.rb +2 -2
  35. data/spec/cisco_acl_intp/extended_ace_spec.rb +411 -0
  36. data/spec/cisco_acl_intp/extended_acl_spec.rb +265 -0
  37. data/spec/cisco_acl_intp/scanner_spec.rb +13 -12
  38. data/spec/cisco_acl_intp/standard_ace_spec.rb +77 -0
  39. data/spec/cisco_acl_intp/standard_acl_spec.rb +245 -0
  40. data/spec/conf/scanner_spec_data.yml +32 -0
  41. data/spec/spec_helper.rb +2 -2
  42. metadata +20 -4
  43. data/spec/cisco_acl_intp/acl_spec.rb +0 -525
@@ -1,525 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'spec_helper'
4
-
5
- describe NamedExtAcl do
6
- describe '#add_entry' do
7
- before do
8
- @acl = NamedExtAcl.new 'test-ext-acl'
9
- end
10
-
11
- it 'should be zero when initialized' do
12
- @acl.size.should be_zero
13
- end
14
-
15
- it 'should be size 1 and matches aclstr when added a acl entry' do
16
- ea = ExtendedAce.new(
17
- action: 'permit',
18
- protocol: 'udp',
19
- src: {
20
- ipaddr: '192.168.3.3',
21
- wildcard: '0.0.0.127'
22
- },
23
- dst: {
24
- ipaddr: '192.168.4.4',
25
- wildcard: '0.0.0.255'
26
- }
27
- )
28
- @acl.add_entry ea
29
- @acl.size.should eq 1
30
- aclstr = <<'EOL'
31
- ip access-list extended test-ext-acl
32
- permit udp 192.168.3.0 0.0.0.127 192.168.4.0 0.0.0.255
33
- EOL
34
- @acl.to_s.should be_aclstr(aclstr)
35
- end
36
- end
37
-
38
- describe '#add_entry_by_params' do
39
- before do
40
- @acl = NamedExtAcl.new 'test-ext-acl2'
41
- @acl.add_entry_by_params(
42
- action: 'permit',
43
- protocol: 'udp',
44
- src: {
45
- ipaddr: '192.168.3.3',
46
- wildcard: '0.0.0.127'
47
- },
48
- dst: {
49
- ipaddr: '192.168.4.4',
50
- wildcard: '0.0.0.255'
51
- }
52
- )
53
- @acl.add_entry_by_params(
54
- action: 'deny',
55
- protocol: 'tcp',
56
- src: {
57
- ipaddr: '192.168.3.3',
58
- wildcard: '0.0.0.0'
59
- },
60
- dst: {
61
- ipaddr: '192.168.4.4',
62
- wildcard: '0.0.0.255',
63
- operator: 'gt',
64
- port: AceUdpProtoSpec.new(
65
- number: 32_768
66
- )
67
- }
68
- )
69
- end
70
-
71
- it 'should be size 2' do
72
- @acl.size.should eq 2
73
- end
74
-
75
- it 'mutches aclstr' do
76
- aclstr = <<'EOL'
77
- ip access-list extended test-ext-acl2
78
- permit udp 192.168.3.0 0.0.0.127 192.168.4.0 0.0.0.255
79
- deny tcp host 192.168.3.3 192.168.4.0 0.0.0.255 gt 32768
80
- EOL
81
- @acl.to_s.should be_aclstr(aclstr)
82
- end
83
-
84
- it 'mutches aclstr with remark' do
85
- rmk = RemarkAce.new ' this is remark!!'
86
- @acl.add_entry rmk
87
- aclstr = <<'EOL'
88
- ip access-list extended test-ext-acl2
89
- permit udp 192.168.3.0 0.0.0.127 192.168.4.0 0.0.0.255
90
- deny tcp host 192.168.3.3 192.168.4.0 0.0.0.255 gt 32768
91
- remark this is remark!!
92
- EOL
93
- @acl.to_s.should be_aclstr(aclstr)
94
- end
95
-
96
- end
97
-
98
- describe '#search_ace' do
99
- # for extended ace, it is same as named/numbered ace.
100
- # so that, tests only named-extended-ace
101
- # and omit numbered-extended-acl
102
- before do
103
- @acl = NamedExtAcl.new 'test-ext-acl2'
104
- @acl.add_entry_by_params(
105
- action: 'permit',
106
- protocol: 'udp',
107
- src: {
108
- ipaddr: '192.168.3.3',
109
- wildcard: '0.0.0.127'
110
- },
111
- dst: {
112
- ipaddr: '192.168.4.4',
113
- wildcard: '0.0.0.255'
114
- }
115
- )
116
- @acl.add_entry_by_params(
117
- action: 'deny',
118
- protocol: 'tcp',
119
- src: {
120
- ipaddr: '192.168.10.3',
121
- wildcard: '0.0.0.0'
122
- },
123
- dst: {
124
- ipaddr: '192.168.4.4',
125
- wildcard: '0.0.0.255',
126
- operator: 'gt',
127
- port: AceUdpProtoSpec.new(
128
- number: 32_768
129
- )
130
- }
131
- )
132
- @acl.add_entry_by_params(
133
- action: 'deny',
134
- protocol: 'ip',
135
- src: {
136
- ipaddr: '0.0.0.0',
137
- wildcard: '255.255.255.255'
138
- },
139
- dst: {
140
- ipaddr: '10.0.0.0',
141
- wildcard: '0.0.0.255'
142
- }
143
- )
144
- end
145
-
146
- it 'should be match 2nd entry' do
147
- ace = @acl.search_ace(
148
- protocol: 'tcp',
149
- src_ip: '192.168.10.3',
150
- src_port: 64_332,
151
- dst_ip: '192.168.4.5',
152
- dst_port: 32_889
153
- )
154
- ace.to_s.should be_aclstr(
155
- 'deny tcp host 192.168.10.3 192.168.4.0 0.0.0.255 gt 32768'
156
- )
157
- end
158
-
159
- it 'should be last entry' do
160
- ace = @acl.search_ace(
161
- protocol: 'udp',
162
- src_ip: '192.168.10.3',
163
- src_port: 64_332,
164
- dst_ip: '10.0.0.3',
165
- dst_port: 33_890
166
- )
167
- ace.to_s.should be_aclstr('deny ip any 10.0.0.0 0.0.0.255')
168
- end
169
-
170
- it 'should be nil if not found match entry' do
171
- @acl.search_ace(
172
- protocol: 'udp',
173
- src_ip: '192.168.10.3',
174
- src_port: 62_223,
175
- dst_ip: '11.0.0.3',
176
- dst_port: 33_333
177
- ).should be_nil
178
- end
179
- end
180
- end
181
-
182
- describe NumberedExtAcl do
183
- describe '#add_entry' do
184
- before do
185
- @acl = NumberedExtAcl.new 102
186
- end
187
-
188
- it 'should be zero when initialized' do
189
- @acl.size.should be_zero
190
- end
191
-
192
- it 'should be size 1 and matches aclstr when added a acl entry' do
193
- ea = ExtendedAce.new(
194
- action: 'permit',
195
- protocol: 'udp',
196
- src: {
197
- ipaddr: '192.168.3.3',
198
- wildcard: '0.0.0.127'
199
- },
200
- dst: {
201
- ipaddr: '192.168.4.4',
202
- wildcard: '0.0.0.255'
203
- }
204
- )
205
- @acl.add_entry ea
206
- @acl.size.should eq 1
207
- aclstr = <<'EOL'
208
- access-list 102 permit udp 192.168.3.0 0.0.0.127 192.168.4.0 0.0.0.255
209
- EOL
210
- @acl.to_s.should be_aclstr(aclstr)
211
- end
212
- end
213
-
214
- describe '#add_entry_by_params' do
215
- before do
216
- @acl = NumberedExtAcl.new 104
217
- @acl.add_entry_by_params(
218
- action: 'permit',
219
- protocol: 'udp',
220
- src: {
221
- ipaddr: '192.168.3.3',
222
- wildcard: '0.0.0.127'
223
- },
224
- dst: {
225
- ipaddr: '192.168.4.4',
226
- wildcard: '0.0.0.255'
227
- }
228
- )
229
- @acl.add_entry_by_params(
230
- action: 'deny',
231
- protocol: 'tcp',
232
- src: {
233
- ipaddr: '192.168.3.3',
234
- wildcard: '0.0.0.0'
235
- },
236
- dst: {
237
- ipaddr: '192.168.4.4',
238
- wildcard: '0.0.0.255',
239
- operator: 'gt',
240
- port: AceUdpProtoSpec.new(
241
- number: 32_768
242
- )
243
- }
244
- )
245
- end
246
-
247
- it 'should be size 2' do
248
- @acl.size.should eq 2
249
- end
250
-
251
- it 'mutches aclstr' do
252
- aclstr = <<'EOL'
253
- access-list 104 permit udp 192.168.3.0 0.0.0.127 192.168.4.0 0.0.0.255
254
- access-list 104 deny tcp host 192.168.3.3 192.168.4.0 0.0.0.255 gt 32768
255
- EOL
256
- @acl.to_s.should be_aclstr(aclstr)
257
- end
258
-
259
- it 'mutches aclstr with remark' do
260
- rmk = RemarkAce.new ' this is remark!!'
261
- @acl.add_entry rmk
262
- aclstr = <<'EOL'
263
- access-list 104 permit udp 192.168.3.0 0.0.0.127 192.168.4.0 0.0.0.255
264
- access-list 104 deny tcp host 192.168.3.3 192.168.4.0 0.0.0.255 gt 32768
265
- access-list 104 remark this is remark!!
266
- EOL
267
- @acl.to_s.should be_aclstr(aclstr)
268
- end
269
- end
270
- end
271
-
272
- describe NamedStdAcl do
273
- describe '#add_entry' do
274
- before do
275
- @acl = NamedStdAcl.new 'test-std-acl'
276
- end
277
-
278
- it 'should be zero when initialized' do
279
- @acl.size.should be_zero
280
- end
281
-
282
- it 'should be size 1 and matches aclstr when added a acl entry' do
283
- sa = StandardAce.new(
284
- action: 'permit',
285
- src: {
286
- ipaddr: '192.168.3.3',
287
- wildcard: '0.0.0.127'
288
- }
289
- )
290
- @acl.add_entry sa
291
- @acl.size.should eq 1
292
- aclstr = <<'EOL'
293
- ip access-list standard test-std-acl
294
- permit 192.168.3.0 0.0.0.127
295
- EOL
296
- @acl.to_s.should be_aclstr(aclstr)
297
- end
298
- end
299
-
300
- describe '#add_entry_by_params' do
301
- before do
302
- @acl = NamedStdAcl.new 'test-std-acl2'
303
- @acl.add_entry_by_params(
304
- action: 'permit',
305
- src: {
306
- ipaddr: '192.168.3.3',
307
- wildcard: '0.0.0.127'
308
- }
309
- )
310
- @acl.add_entry_by_params(
311
- action: 'deny',
312
- src: {
313
- ipaddr: '192.168.4.4',
314
- wildcard: '0.0.0.255'
315
- }
316
- )
317
- end
318
-
319
- it 'should be size 2' do
320
- @acl.size.should eq 2
321
- end
322
-
323
- it 'mutches aclstr' do
324
- aclstr = <<'EOL'
325
- ip access-list standard test-std-acl2
326
- permit 192.168.3.0 0.0.0.127
327
- deny 192.168.4.0 0.0.0.255
328
- EOL
329
- @acl.to_s.should be_aclstr(aclstr)
330
- end
331
-
332
- it 'mutches aclstr with remark' do
333
- rmk = RemarkAce.new ' this is remark!!'
334
- @acl.add_entry rmk
335
- aclstr = <<'EOL'
336
- ip access-list standard test-std-acl2
337
- permit 192.168.3.0 0.0.0.127
338
- deny 192.168.4.0 0.0.0.255
339
- remark this is remark!!
340
- EOL
341
- @acl.to_s.should be_aclstr(aclstr)
342
- end
343
- end
344
-
345
- describe '#search_ace' do
346
- # for standard ace, it is same as named/numbered ace.
347
- # so that, tests only named-standard-ace
348
- # and omit numbered-standard-acl
349
- before do
350
- @acl = NamedStdAcl.new 'test-stdacl3'
351
- @acl.add_entry_by_params(
352
- action: 'permit',
353
- src: {
354
- ipaddr: '192.168.3.3',
355
- wildcard: '0.0.0.127'
356
- }
357
- )
358
- @acl.add_entry_by_params(
359
- action: 'deny',
360
- src: {
361
- ipaddr: '192.168.10.3',
362
- wildcard: '0.0.0.0'
363
- }
364
- )
365
- @acl.add_entry_by_params(
366
- action: 'deny',
367
- src: {
368
- ipaddr: '10.0.0.0',
369
- wildcard: '0.0.0.255'
370
- }
371
- )
372
- end
373
-
374
- it 'should be match 2nd entry' do
375
- ace = @acl.search_ace(
376
- src_ip: '192.168.10.3',
377
- src_port: 64_332
378
- )
379
- ace.to_s.should be_aclstr('deny host 192.168.10.3')
380
- end
381
-
382
- it 'should be last entry' do
383
- ace = @acl.search_ace(
384
- src_ip: '10.0.0.3',
385
- src_port: 33_890
386
- )
387
- ace.to_s.should be_aclstr('deny 10.0.0.0 0.0.0.255')
388
- end
389
-
390
- it 'should be nil if not found match entry' do
391
- @acl.search_ace(
392
- protocol: 'udp',
393
- src_ip: '11.0.0.3',
394
- src_port: 33_333
395
- ).should be_nil
396
- end
397
-
398
- end
399
-
400
- end
401
-
402
- describe NumberedStdAcl do
403
- describe '#add_entry' do
404
- before do
405
- @acl = NumberedStdAcl.new 10
406
- end
407
-
408
- it 'should be zero when initialized' do
409
- @acl.size.should be_zero
410
- end
411
-
412
- it 'should be size 1 and matches aclstr when added a acl entry' do
413
- sa = StandardAce.new(
414
- action: 'permit',
415
- src: {
416
- ipaddr: '192.168.3.3',
417
- wildcard: '0.0.0.127'
418
- }
419
- )
420
- @acl.add_entry sa
421
- @acl.size.should eq 1
422
- aclstr = <<'EOL'
423
- access-list 10 permit 192.168.3.0 0.0.0.127
424
- EOL
425
- @acl.to_s.should be_aclstr(aclstr)
426
- end
427
- end
428
-
429
- describe '#add_entry_by_params' do
430
- before do
431
- @acl = NumberedStdAcl.new 14
432
- @acl.add_entry_by_params(
433
- action: 'permit',
434
- src: {
435
- ipaddr: '192.168.3.3',
436
- wildcard: '0.0.0.127'
437
- }
438
- )
439
- @acl.add_entry_by_params(
440
- action: 'deny',
441
- src: {
442
- ipaddr: '192.168.4.4',
443
- wildcard: '0.0.0.255'
444
- }
445
- )
446
- end
447
-
448
- it 'should be size 2' do
449
- @acl.size.should eq 2
450
- end
451
-
452
- it 'mutches aclstr' do
453
- aclstr = <<'EOL'
454
- access-list 14 permit 192.168.3.0 0.0.0.127
455
- access-list 14 deny 192.168.4.0 0.0.0.255
456
- EOL
457
- @acl.to_s.should be_aclstr(aclstr)
458
- end
459
-
460
- it 'mutches aclstr with remark' do
461
- rmk = RemarkAce.new ' this is remark!!'
462
- @acl.add_entry rmk
463
- aclstr = <<'EOL'
464
- access-list 14 permit 192.168.3.0 0.0.0.127
465
- access-list 14 deny 192.168.4.0 0.0.0.255
466
- access-list 14 remark this is remark!!
467
- EOL
468
- @acl.to_s.should be_aclstr(aclstr)
469
- end
470
- end
471
-
472
- context 'list operations' do
473
- before do
474
- @acl = NumberedStdAcl.new 15
475
- @acl.add_entry RemarkAce.new('entry 1')
476
- @acl.add_entry RemarkAce.new('entry 2')
477
- @acl.add_entry RemarkAce.new('entry 3')
478
- @acl.add_entry RemarkAce.new('entry 4')
479
- end
480
-
481
- describe '#renumber' do
482
- it 'should has seq number by add_entry' do
483
- @acl.renumber
484
- @acl.reduce(10) do |num, each|
485
- each.seq_number.should eq num
486
- num + 10
487
- end
488
- end
489
- end
490
-
491
- describe '#sort' do
492
- it 'should be sorted by seq number' do
493
- @acl.renumber # initialize seq number
494
-
495
- last_ace = @acl.pop
496
- last_ace.seq_number = 15
497
- @acl.add_entry last_ace
498
- acl_new = @acl.dup_with_list(@acl.sort)
499
-
500
- aclstr = <<'EOL'
501
- access-list 15 remark entry 1
502
- access-list 15 remark entry 2
503
- access-list 15 remark entry 3
504
- access-list 15 remark entry 4
505
- EOL
506
- aclstr_new = <<'EOL'
507
- access-list 15 remark entry 1
508
- access-list 15 remark entry 4
509
- access-list 15 remark entry 2
510
- access-list 15 remark entry 3
511
- EOL
512
- @acl.name.should eq acl_new.name
513
- @acl.acl_type.should eq acl_new.acl_type
514
- @acl.to_s.should be_aclstr(aclstr)
515
- acl_new.to_s.should be_aclstr(aclstr_new)
516
- end
517
- end
518
- end
519
- end
520
-
521
- ### Local variables:
522
- ### mode: Ruby
523
- ### coding: utf-8-unix
524
- ### indent-tabs-mode: nil
525
- ### End: