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
@@ -4,7 +4,7 @@ require 'yaml'
4
4
 
5
5
  describe 'Scanner' do
6
6
  describe '#scan_line' do
7
- before do
7
+ before(:all) do
8
8
  @s = Scanner.new
9
9
  end
10
10
 
@@ -16,20 +16,20 @@ ip access-list extended FA8-OUT
16
16
  EOL
17
17
  @s.scan_line(acl).should == [
18
18
  [:NAMED_ACL, 'ip access-list'],
19
- %w[extended extended],
19
+ %w(extended extended),
20
20
  [:STRING, 'FA8-OUT'],
21
21
  [:EOS, nil],
22
- %w[deny deny],
23
- %w[udp udp],
24
- %w[any any],
25
- %w[any any],
26
- %w[eq eq],
27
- %w[bootpc bootpc],
22
+ %w(deny deny),
23
+ %w(udp udp),
24
+ %w(any any),
25
+ %w(any any),
26
+ %w(eq eq),
27
+ %w(bootpc bootpc),
28
28
  [:EOS, nil],
29
- %w[permit permit],
30
- %w[ip ip],
31
- %w[any any],
32
- %w[any any],
29
+ %w(permit permit),
30
+ %w(ip ip),
31
+ %w(any any),
32
+ %w(any any),
33
33
  [:EOS, nil],
34
34
  [false, 'EOF']
35
35
  ]
@@ -48,6 +48,7 @@ EOL
48
48
  ]
49
49
  end
50
50
  end
51
+
51
52
  end # scan_line
52
53
 
53
54
  describe '#scan_file' do
@@ -0,0 +1,77 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe StandardAce do
5
+ describe '#to_s' do
6
+ context 'Normal case' do
7
+
8
+ it 'should be permit action and set ip/wildcard' do
9
+ sa = StandardAce.new(
10
+ action: 'permit',
11
+ src: { ipaddr: '192.168.15.15', wildcard: '0.0.7.6' }
12
+ )
13
+ sa.to_s.should be_aclstr('permit 192.168.8.9 0.0.7.6')
14
+ end
15
+
16
+ it 'should be deny action and set ip/wildcard' do
17
+ sa = StandardAce.new(
18
+ action: 'deny',
19
+ src: { ipaddr: '192.168.15.15', wildcard: '0.0.0.127' }
20
+ )
21
+ sa.to_s.should be_aclstr('deny 192.168.15.0 0.0.0.127')
22
+ end
23
+
24
+ it 'should be able set with AceSrcDstSpec object' do
25
+ asds = AceSrcDstSpec.new(
26
+ ipaddr: '192.168.3.144', wildcard: '0.0.0.127'
27
+ )
28
+ sa = StandardAce.new(action: 'permit', src: asds)
29
+ sa.to_s.should be_aclstr('permit 192.168.3.128 0.0.0.127')
30
+ end
31
+
32
+ end
33
+
34
+ context 'Argument error case' do
35
+
36
+ it 'should be rased exception when :action not specified' do
37
+ lambda do
38
+ StandardAce.new(
39
+ src: { ipaddr: '192.168.3.3', wildcard: '0.0.0.127' }
40
+ )
41
+ end.should raise_error(AclArgumentError)
42
+ end
43
+
44
+ end
45
+ end
46
+
47
+ describe '#contains?' do
48
+ before do
49
+ @sa = StandardAce.new(
50
+ action: 'permit',
51
+ src: { ipaddr: '192.168.15.15', wildcard: '0.0.7.6' }
52
+ )
53
+ @ip_match = StandardAce.new(
54
+ action: 'permit',
55
+ src: { ipaddr: '192.168.9.11', netmask: 32 }
56
+ )
57
+ @ip_unmatch = StandardAce.new(
58
+ action: 'permit',
59
+ src: { ipaddr: '192.168.9.12', netmask: 32 }
60
+ )
61
+ end
62
+
63
+ it 'shoud be true with match ip addr' do
64
+ @sa.contains?(@ip_match).should be_true
65
+ end
66
+
67
+ it 'should be false with unmatch ip addr' do
68
+ @sa.contains?(@ip_unmatch).should be_false
69
+ end
70
+ end
71
+ end
72
+
73
+ ### Local variables:
74
+ ### mode: Ruby
75
+ ### coding: utf-8-unix
76
+ ### indent-tabs-mode: nil
77
+ ### End:
@@ -0,0 +1,245 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe NamedStdAcl do
5
+ describe '#add_entry' do
6
+ before(:all) do
7
+ @acl = NamedStdAcl.new 'test-std-acl'
8
+ end
9
+
10
+ it 'should be zero when initialized' do
11
+ @acl.size.should be_zero
12
+ end
13
+
14
+ it 'should be size 1 and matches aclstr when added a acl entry' do
15
+ sa = StandardAce.new(
16
+ action: 'permit',
17
+ src: {
18
+ ipaddr: '192.168.3.3',
19
+ wildcard: '0.0.0.127'
20
+ }
21
+ )
22
+ @acl.add_entry sa
23
+ @acl.size.should eq 1
24
+ aclstr = <<'EOL'
25
+ ip access-list standard test-std-acl
26
+ permit 192.168.3.0 0.0.0.127
27
+ EOL
28
+ @acl.to_s.should be_aclstr(aclstr)
29
+ end
30
+ end
31
+
32
+ describe '#add_entry_by_params' do
33
+ before(:all) do
34
+ @acl = NamedStdAcl.new 'test-std-acl2'
35
+ @acl.add_entry_by_params(
36
+ action: 'permit',
37
+ src: {
38
+ ipaddr: '192.168.3.3',
39
+ wildcard: '0.0.0.127'
40
+ }
41
+ )
42
+ @acl.add_entry_by_params(
43
+ action: 'deny',
44
+ src: {
45
+ ipaddr: '192.168.4.4',
46
+ wildcard: '0.0.0.255'
47
+ }
48
+ )
49
+ end
50
+
51
+ it 'should be size 2' do
52
+ @acl.size.should eq 2
53
+ end
54
+
55
+ it 'mutches aclstr' do
56
+ aclstr = <<'EOL'
57
+ ip access-list standard test-std-acl2
58
+ permit 192.168.3.0 0.0.0.127
59
+ deny 192.168.4.0 0.0.0.255
60
+ EOL
61
+ @acl.to_s.should be_aclstr(aclstr)
62
+ end
63
+
64
+ it 'mutches aclstr with remark' do
65
+ rmk = RemarkAce.new ' this is remark!!'
66
+ @acl.add_entry rmk
67
+ aclstr = <<'EOL'
68
+ ip access-list standard test-std-acl2
69
+ permit 192.168.3.0 0.0.0.127
70
+ deny 192.168.4.0 0.0.0.255
71
+ remark this is remark!!
72
+ EOL
73
+ @acl.to_s.should be_aclstr(aclstr)
74
+ end
75
+ end
76
+
77
+ describe '#find_aces_contains' do
78
+ # for standard ace, it is same as named/numbered ace.
79
+ # so that, tests only named-standard-ace
80
+ # and omit numbered-standard-acl
81
+ before(:all) do
82
+ @acl = NamedStdAcl.new 'test-stdacl3'
83
+ @acl.add_entry_by_params(
84
+ action: 'permit',
85
+ src: { ipaddr: '192.168.3.3', wildcard: '0.0.0.127' }
86
+ )
87
+ @acl.add_entry_by_params(
88
+ action: 'deny',
89
+ src: { ipaddr: '192.168.10.3', wildcard: '0.0.0.0' }
90
+ )
91
+ @acl.add_entry_by_params(
92
+ action: 'deny',
93
+ src: { ipaddr: '10.0.0.0', wildcard: '0.0.0.255' }
94
+ )
95
+ end
96
+
97
+ it 'should be match 2nd entry' do
98
+ ace = @acl.find_aces_contains(
99
+ protocol: 'tcp',
100
+ src_operator: :eq, src_ip: '192.168.10.3', src_port: 64_332
101
+ )
102
+ ace.to_s.should be_aclstr('deny host 192.168.10.3')
103
+ end
104
+
105
+ it 'should be last entry' do
106
+ ace = @acl.find_aces_contains(
107
+ protocol: 'tcp',
108
+ src_operator: :eq, src_ip: '10.0.0.3', src_port: 33_890
109
+ )
110
+ ace.to_s.should be_aclstr('deny 10.0.0.0 0.0.0.255')
111
+ end
112
+
113
+ it 'should be nil if not found match entry' do
114
+ @acl.find_aces_contains(
115
+ protocol: 'udp',
116
+ src_operator: :eq, src_ip: '11.0.0.3', src_port: 33_333
117
+ ).should be_nil
118
+ end
119
+ end
120
+ end
121
+
122
+ describe NumberedStdAcl do
123
+ describe '#add_entry' do
124
+ before(:all) do
125
+ @acl = NumberedStdAcl.new 10
126
+ end
127
+
128
+ it 'should be zero when initialized' do
129
+ @acl.size.should be_zero
130
+ end
131
+
132
+ it 'should be size 1 and matches aclstr when added a acl entry' do
133
+ sa = StandardAce.new(
134
+ action: 'permit',
135
+ src: {
136
+ ipaddr: '192.168.3.3',
137
+ wildcard: '0.0.0.127'
138
+ }
139
+ )
140
+ @acl.add_entry sa
141
+ @acl.size.should eq 1
142
+ aclstr = <<'EOL'
143
+ access-list 10 permit 192.168.3.0 0.0.0.127
144
+ EOL
145
+ @acl.to_s.should be_aclstr(aclstr)
146
+ end
147
+ end
148
+
149
+ describe '#add_entry_by_params' do
150
+ before do
151
+ @acl = NumberedStdAcl.new 14
152
+ @acl.add_entry_by_params(
153
+ action: 'permit',
154
+ src: {
155
+ ipaddr: '192.168.3.3',
156
+ wildcard: '0.0.0.127'
157
+ }
158
+ )
159
+ @acl.add_entry_by_params(
160
+ action: 'deny',
161
+ src: {
162
+ ipaddr: '192.168.4.4',
163
+ wildcard: '0.0.0.255'
164
+ }
165
+ )
166
+ end
167
+
168
+ it 'should be size 2' do
169
+ @acl.size.should eq 2
170
+ end
171
+
172
+ it 'mutches aclstr' do
173
+ aclstr = <<'EOL'
174
+ access-list 14 permit 192.168.3.0 0.0.0.127
175
+ access-list 14 deny 192.168.4.0 0.0.0.255
176
+ EOL
177
+ @acl.to_s.should be_aclstr(aclstr)
178
+ end
179
+
180
+ it 'mutches aclstr with remark' do
181
+ rmk = RemarkAce.new ' this is remark!!'
182
+ @acl.add_entry rmk
183
+ aclstr = <<'EOL'
184
+ access-list 14 permit 192.168.3.0 0.0.0.127
185
+ access-list 14 deny 192.168.4.0 0.0.0.255
186
+ access-list 14 remark this is remark!!
187
+ EOL
188
+ @acl.to_s.should be_aclstr(aclstr)
189
+ end
190
+ end
191
+
192
+ context 'list operations' do
193
+ before do
194
+ @acl = NumberedStdAcl.new 15
195
+ @acl.add_entry RemarkAce.new('entry 1')
196
+ @acl.add_entry RemarkAce.new('entry 2')
197
+ @acl.add_entry RemarkAce.new('entry 3')
198
+ @acl.add_entry RemarkAce.new('entry 4')
199
+ end
200
+
201
+ describe '#renumber' do
202
+ it 'should has seq number by add_entry' do
203
+ @acl.renumber
204
+ @acl.reduce(10) do |num, each|
205
+ each.seq_number.should eq num
206
+ num + 10
207
+ end
208
+ end
209
+ end
210
+
211
+ describe '#sort' do
212
+ it 'should be sorted by seq number' do
213
+ @acl.renumber # initialize seq number
214
+
215
+ last_ace = @acl.pop
216
+ last_ace.seq_number = 15
217
+ @acl.add_entry last_ace
218
+ acl_new = @acl.dup_with_list(@acl.sort)
219
+
220
+ aclstr = <<'EOL'
221
+ access-list 15 remark entry 1
222
+ access-list 15 remark entry 2
223
+ access-list 15 remark entry 3
224
+ access-list 15 remark entry 4
225
+ EOL
226
+ aclstr_new = <<'EOL'
227
+ access-list 15 remark entry 1
228
+ access-list 15 remark entry 4
229
+ access-list 15 remark entry 2
230
+ access-list 15 remark entry 3
231
+ EOL
232
+ @acl.name.should eq acl_new.name
233
+ @acl.acl_type.should eq acl_new.acl_type
234
+ @acl.to_s.should be_aclstr(aclstr)
235
+ acl_new.to_s.should be_aclstr(aclstr_new)
236
+ end
237
+ end
238
+ end
239
+ end
240
+
241
+ ### Local variables:
242
+ ### mode: Ruby
243
+ ### coding: utf-8-unix
244
+ ### indent-tabs-mode: nil
245
+ ### End:
@@ -1,3 +1,13 @@
1
+ - :test_description: "numbered std acl header"
2
+ :test_symbol: numbered_std_acl
3
+ :test_data:
4
+ - :line: "access-list 13 permit icmp host 192.168.3.3"
5
+ :tokens:
6
+ - [ NUMD_STD_ACL, 13 ]
7
+ - permit
8
+ - icmp
9
+ - host
10
+ - [ IPV4_ADDR, 192.168.3.3 ]
1
11
  - :test_description: "named std acl header"
2
12
  :test_symbol: named_std_acl
3
13
  :test_data:
@@ -22,6 +32,13 @@
22
32
  - :test_description: "named ext acl header"
23
33
  :test_symbol: named_ext_acl
24
34
  :test_data:
35
+ - :line: "access-list 133 permit tcp any any"
36
+ :tokens:
37
+ - [ NUMD_EXT_ACL, 133 ]
38
+ - permit
39
+ - tcp
40
+ - any
41
+ - any
25
42
  - :line: "ip access-list extended GI0-IN"
26
43
  :tokens:
27
44
  - [ NAMED_ACL, "ip access-list" ] # acl header
@@ -118,3 +135,18 @@
118
135
  :tokens:
119
136
  - group-object
120
137
  - [ STRING, nested-obj-name ]
138
+ - :test_description: "unknown tokens"
139
+ :test_symbol: unknown_acl
140
+ :test_data:
141
+ - :line: "access-list 99999999 permit icmp host 192.168.3.3"
142
+ :tokens:
143
+ - [ UNKNOWN, 'access-list 99999999' ]
144
+ - permit
145
+ - icmp
146
+ - host
147
+ - [ IPV4_ADDR, 192.168.3.3 ]
148
+ - :line: "access-list 55 _pmit icmp host 192.168.3.3"
149
+ :tokens:
150
+ - [ NUMD_STD_ACL, 55 ]
151
+ - [ UNKNOWN, "_pmit icmp host 192.168.3.3" ]
152
+
data/spec/spec_helper.rb CHANGED
@@ -33,9 +33,9 @@ def _pph(hash)
33
33
  hash.each do | k, v |
34
34
  case v
35
35
  when String
36
- kv.push %Q{:#{k.to_s}=>"#{v.to_s}"}
36
+ kv.push %Q(:#{k}=>"#{v}")
37
37
  else
38
- kv.push %Q{:#{k.to_s}=>#{v.to_s}}
38
+ kv.push %Q(:#{k}=>#{v})
39
39
  end
40
40
  end
41
41
  kv.join(',')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cisco_acl_intp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - stereocat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-11 00:00:00.000000000 Z
11
+ date: 2014-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netaddr
@@ -79,29 +79,41 @@ files:
79
79
  - lib/cisco_acl_intp/ace_ip.rb
80
80
  - lib/cisco_acl_intp/ace_other_qualifiers.rb
81
81
  - lib/cisco_acl_intp/ace_port.rb
82
+ - lib/cisco_acl_intp/ace_port_opr.rb
83
+ - lib/cisco_acl_intp/ace_port_opr_base.rb
82
84
  - lib/cisco_acl_intp/ace_proto.rb
85
+ - lib/cisco_acl_intp/ace_proto_base.rb
83
86
  - lib/cisco_acl_intp/ace_srcdst.rb
84
87
  - lib/cisco_acl_intp/ace_tcp_flags.rb
85
88
  - lib/cisco_acl_intp/acl.rb
86
89
  - lib/cisco_acl_intp/acl_base.rb
90
+ - lib/cisco_acl_intp/acl_utils.rb
91
+ - lib/cisco_acl_intp/extended_ace.rb
92
+ - lib/cisco_acl_intp/mono_function_acl.rb
87
93
  - lib/cisco_acl_intp/parser.rb
88
94
  - lib/cisco_acl_intp/parser.ry
89
95
  - lib/cisco_acl_intp/parser_api.rb
90
96
  - lib/cisco_acl_intp/scanner.rb
91
97
  - lib/cisco_acl_intp/scanner_special_token_handler.rb
98
+ - lib/cisco_acl_intp/single_acl_base.rb
99
+ - lib/cisco_acl_intp/standard_ace.rb
92
100
  - lib/cisco_acl_intp/version.rb
93
101
  - spec/cisco_acl_intp/ace_ip_spec.rb
94
102
  - spec/cisco_acl_intp/ace_other_qualifier_spec.rb
103
+ - spec/cisco_acl_intp/ace_port_operator_spec.rb
95
104
  - spec/cisco_acl_intp/ace_port_spec.rb
96
105
  - spec/cisco_acl_intp/ace_proto_spec.rb
97
106
  - spec/cisco_acl_intp/ace_spec.rb
98
107
  - spec/cisco_acl_intp/ace_srcdst_spec.rb
99
108
  - spec/cisco_acl_intp/ace_tcp_flags_spec.rb
100
109
  - spec/cisco_acl_intp/acl_base_spec.rb
101
- - spec/cisco_acl_intp/acl_spec.rb
102
110
  - spec/cisco_acl_intp/cisco_acl_intp_spec.rb
111
+ - spec/cisco_acl_intp/extended_ace_spec.rb
112
+ - spec/cisco_acl_intp/extended_acl_spec.rb
103
113
  - spec/cisco_acl_intp/parser_spec.rb
104
114
  - spec/cisco_acl_intp/scanner_spec.rb
115
+ - spec/cisco_acl_intp/standard_ace_spec.rb
116
+ - spec/cisco_acl_intp/standard_acl_spec.rb
105
117
  - spec/conf/extacl_objgrp_token_seq.yml
106
118
  - spec/conf/extacl_token_seq.yml
107
119
  - spec/conf/extended_acl.yml
@@ -140,16 +152,20 @@ summary: Cisco IOS Access Control List Interpreter
140
152
  test_files:
141
153
  - spec/cisco_acl_intp/ace_ip_spec.rb
142
154
  - spec/cisco_acl_intp/ace_other_qualifier_spec.rb
155
+ - spec/cisco_acl_intp/ace_port_operator_spec.rb
143
156
  - spec/cisco_acl_intp/ace_port_spec.rb
144
157
  - spec/cisco_acl_intp/ace_proto_spec.rb
145
158
  - spec/cisco_acl_intp/ace_spec.rb
146
159
  - spec/cisco_acl_intp/ace_srcdst_spec.rb
147
160
  - spec/cisco_acl_intp/ace_tcp_flags_spec.rb
148
161
  - spec/cisco_acl_intp/acl_base_spec.rb
149
- - spec/cisco_acl_intp/acl_spec.rb
150
162
  - spec/cisco_acl_intp/cisco_acl_intp_spec.rb
163
+ - spec/cisco_acl_intp/extended_ace_spec.rb
164
+ - spec/cisco_acl_intp/extended_acl_spec.rb
151
165
  - spec/cisco_acl_intp/parser_spec.rb
152
166
  - spec/cisco_acl_intp/scanner_spec.rb
167
+ - spec/cisco_acl_intp/standard_ace_spec.rb
168
+ - spec/cisco_acl_intp/standard_acl_spec.rb
153
169
  - spec/conf/extacl_objgrp_token_seq.yml
154
170
  - spec/conf/extacl_token_seq.yml
155
171
  - spec/conf/extended_acl.yml