conpar 0.1.0

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 (47) hide show
  1. data/.gitignore +19 -0
  2. data/.travis.yml +7 -0
  3. data/Gemfile +4 -0
  4. data/Guardfile +24 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +43 -0
  7. data/Rakefile +25 -0
  8. data/conpar.gemspec +30 -0
  9. data/lib/conpar.rb +18 -0
  10. data/lib/conpar/_all.rb +9 -0
  11. data/lib/conpar/configuration.rb +19 -0
  12. data/lib/conpar/directive.rb +30 -0
  13. data/lib/conpar/directive/_all.rb +9 -0
  14. data/lib/conpar/directive/access_list.rb +33 -0
  15. data/lib/conpar/directive/access_list/_all.rb +11 -0
  16. data/lib/conpar/directive/access_list/base.rb +20 -0
  17. data/lib/conpar/directive/access_list/ether_type.rb +43 -0
  18. data/lib/conpar/directive/access_list/extended.rb +56 -0
  19. data/lib/conpar/directive/access_list/standard.rb +42 -0
  20. data/lib/conpar/directive/access_list/unknown_type.rb +16 -0
  21. data/lib/conpar/directive/access_list/web_type.rb +42 -0
  22. data/lib/conpar/directive/base.rb +52 -0
  23. data/lib/conpar/directive/comment.rb +13 -0
  24. data/lib/conpar/directive/empty.rb +12 -0
  25. data/lib/conpar/document.rb +24 -0
  26. data/lib/conpar/version.rb +3 -0
  27. data/spec/conpar_spec.rb +20 -0
  28. data/spec/lib/.keep +0 -0
  29. data/spec/lib/directive/access_list/base_spec.rb +5 -0
  30. data/spec/lib/directive/access_list/ether_type_spec.rb +32 -0
  31. data/spec/lib/directive/access_list/extended_spec.rb +71 -0
  32. data/spec/lib/directive/access_list/standard_spec.rb +32 -0
  33. data/spec/lib/directive/access_list/unknown_spec.rb +8 -0
  34. data/spec/lib/directive/access_list/web_type_spec.rb +27 -0
  35. data/spec/lib/directive/access_list_spec.rb +17 -0
  36. data/spec/lib/directive/base_spec.rb +46 -0
  37. data/spec/lib/directive/comment_spec.rb +13 -0
  38. data/spec/lib/directive/empty_spec.rb +13 -0
  39. data/spec/lib/directive_spec.rb +9 -0
  40. data/spec/lib/document_spec.rb +98 -0
  41. data/spec/samples/basic +3 -0
  42. data/spec/samples/sample2 +3 -0
  43. data/spec/samples/sample3 +4 -0
  44. data/spec/samples/sample4 +5 -0
  45. data/spec/samples/sample5 +8 -0
  46. data/spec/spec_helper.rb +7 -0
  47. metadata +247 -0
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conpar::Directive::Base do
4
+ context "::SIGNATURE" do
5
+ subject { Conpar::Directive::Base::SIGNATURE }
6
+ it "should not be nil" do
7
+ expect(subject).to_not be_nil, "::SIGNATURE is nil"
8
+ end
9
+ it "should be a Regexp" do
10
+ expect(subject).to be_a_kind_of(Regexp)
11
+ end
12
+ end
13
+
14
+ context "new instance" do
15
+ subject { Conpar::Directive::Base.new }
16
+
17
+ it "should not have a line number" do
18
+ expect(subject.line_number).to be_nil
19
+ end
20
+
21
+ it "should have a line span of 1" do
22
+ expect(subject.line_span).to eq(1)
23
+ end
24
+
25
+ it "should have no content" do
26
+ expect(subject.content).to eq("")
27
+ end
28
+
29
+ it "should have an empty sub_ilk" do
30
+ expect(subject.sub_ilk).to eq("")
31
+ end
32
+
33
+ it ".match_data should be nil" do
34
+ expect(subject.match_data).to be_nil
35
+ end
36
+
37
+ context 'with explicit content' do
38
+ subject { Conpar::Directive::Base.new("foobar") }
39
+ context ".content" do
40
+ it "should be 'foobar'" do
41
+ expect(subject.content).to eq('foobar')
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conpar::Directive::Comment do
4
+ context "::SIGNATURE" do
5
+ subject { Conpar::Directive::Comment::SIGNATURE }
6
+ it "should match ': no comment'" do
7
+ expect(": no comment").to match(subject)
8
+ end
9
+ it "should not match empty string" do
10
+ expect(" ").not_to match(subject)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conpar::Directive::Empty do
4
+ context "::SIGNATURE" do
5
+ subject { Conpar::Directive::Empty::SIGNATURE }
6
+ it "should match ''" do
7
+ expect("").to match(subject)
8
+ end
9
+ it "should match ' '" do
10
+ expect(" ").to match(subject)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conpar::Directive do
4
+ context ".new" do
5
+ it "should always return a type of Directive" do
6
+ expect(subject.new("").class.ancestors).to include(Conpar::Directive::Base)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conpar::Document do
4
+ subject { Conpar::Document }
5
+
6
+ it "should respond to #parse()" do
7
+ expect(subject).to respond_to(:parse)
8
+ end
9
+
10
+ describe ".parse" do
11
+ # 3 comments, nothing else
12
+ context "basic" do
13
+ let(:config) { File.read("spec/samples/basic") }
14
+
15
+ it "should read as a string" do
16
+ expect(config).to be_a_kind_of(String)
17
+ end
18
+
19
+ context "result" do
20
+ context "valid parse" do
21
+ let(:result) { subject.parse(config) }
22
+ it "should be an Array" do
23
+ expect(result).to be_a_kind_of(Array)
24
+ end
25
+ end#valid parse
26
+
27
+ context "invalid parse" do
28
+ it "should throw exception if fw_config argument is not a string" do
29
+ expect{ subject.parse(nil) }.to raise_exception(ArgumentError)
30
+ expect{ subject.parse(Object.new) }.to raise_exception(ArgumentError)
31
+ end
32
+ end#invalid parse
33
+ end#result
34
+ end
35
+
36
+ # 2 comments and 1 ACL
37
+ context 'sample2' do
38
+ let(:config) { File.read("spec/samples/sample2") }
39
+
40
+ context "result" do
41
+ let(:result) { subject.parse(config) }
42
+ it { expect(result.select{|r| r.ilk == :comment }).to have(2).items }
43
+ context "ACLs" do
44
+ let(:acls) do
45
+ result.select{|r| r.ilk == :access_list }
46
+ end
47
+ it { expect(acls).to have(1).item }
48
+ it "first acl should be on line #3" do
49
+ expect(acls.first.line_number).to eq(3)
50
+ end
51
+ end
52
+ # f
53
+ end
54
+ end
55
+
56
+ # 2 comments and 2 different ACLs
57
+ context 'sample3' do
58
+ let(:config) { File.read("spec/samples/sample3") }
59
+
60
+ context "result" do
61
+ let(:result) { subject.parse(config) }
62
+ it { expect(result.select{|r| r.ilk == :comment }).to have(2).items }
63
+ it { expect(result.select{|r| r.ilk == :access_list }).to have(2).items }
64
+ it { expect(result.select{|r| r.sub_ilk == "standard" }).to have(1).items }
65
+ it { expect(result.select{|r| r.sub_ilk == "extended" }).to have(1).items }
66
+ end
67
+ end
68
+
69
+ # 2 comments, 2 different known ACLs, 1 unknown ACL
70
+ context 'sample4' do
71
+ let(:config) { File.read("spec/samples/sample4") }
72
+
73
+ context "result" do
74
+ let(:result) { subject.parse(config) }
75
+ it { expect(result.select{|r| r.ilk == :comment }).to have(2).items }
76
+ it { expect(result.select{|r| r.ilk == :access_list }).to have(3).items }
77
+ it { expect(result.select{|r| r.sub_ilk == "standard" }).to have(1).items }
78
+ it { expect(result.select{|r| r.sub_ilk == "extended" }).to have(1).items }
79
+ it { expect(result.select{|r| r.sub_ilk == "unknown" }).to have(1).items }
80
+ end
81
+ end
82
+
83
+ # 3 comments, 2 different known ACLs, 1 unknown ACL, 2 other directives
84
+ context 'sample5' do
85
+ let(:config) { File.read("spec/samples/sample5") }
86
+
87
+ context "result" do
88
+ let(:result) { subject.parse(config) }
89
+ it { expect(result.select{|r| r.ilk == :comment }).to have(3).items }
90
+ it { expect(result.select{|r| r.ilk == :access_list }).to have(3).items }
91
+ it { expect(result.select{|r| r.sub_ilk == "standard" }).to have(1).items }
92
+ it { expect(result.select{|r| r.sub_ilk == "extended" }).to have(1).items }
93
+ it { expect(result.select{|r| r.sub_ilk == "unknown" }).to have(1).items }
94
+ it { expect(result.select{|r| r.ilk == :directive }).to have(2).items }
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,3 @@
1
+ : First Comment
2
+ : Second Comment
3
+ : Third Comment
@@ -0,0 +1,3 @@
1
+ : First Comment
2
+ : Second Comment
3
+ access-list foo-bar standard deny all
@@ -0,0 +1,4 @@
1
+ : First Comment
2
+ : Second Comment
3
+ access-list foo-bar standard deny all
4
+ access-list bang-biz extended permit ip any any
@@ -0,0 +1,5 @@
1
+ : First Comment
2
+ access-list foo-bar standard deny all
3
+ : Second Comment
4
+ access-list bang-biz extended permit ip any any
5
+ access-list dne blahtype permit all
@@ -0,0 +1,8 @@
1
+ : First Comment
2
+ access-list foo-bar standard deny all
3
+ : Second Comment
4
+ access-list bang-biz extended permit ip any any
5
+ access-list dne blahtype permit all
6
+ : additional directives
7
+ version 1.0.0
8
+ logging enable
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'conpar'
3
+
4
+
5
+ RSpec.configure do |config|
6
+ config.color_enabled = true
7
+ end
metadata ADDED
@@ -0,0 +1,247 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conpar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan A. Johnson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.4.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.4.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: redcarpet
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: pry
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Full-featured firewall configuration parser library.
143
+ email:
144
+ - ryan.johnson@rackspace.com
145
+ executables: []
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - .gitignore
150
+ - .travis.yml
151
+ - Gemfile
152
+ - Guardfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - conpar.gemspec
157
+ - lib/conpar.rb
158
+ - lib/conpar/_all.rb
159
+ - lib/conpar/configuration.rb
160
+ - lib/conpar/directive.rb
161
+ - lib/conpar/directive/_all.rb
162
+ - lib/conpar/directive/access_list.rb
163
+ - lib/conpar/directive/access_list/_all.rb
164
+ - lib/conpar/directive/access_list/base.rb
165
+ - lib/conpar/directive/access_list/ether_type.rb
166
+ - lib/conpar/directive/access_list/extended.rb
167
+ - lib/conpar/directive/access_list/standard.rb
168
+ - lib/conpar/directive/access_list/unknown_type.rb
169
+ - lib/conpar/directive/access_list/web_type.rb
170
+ - lib/conpar/directive/base.rb
171
+ - lib/conpar/directive/comment.rb
172
+ - lib/conpar/directive/empty.rb
173
+ - lib/conpar/document.rb
174
+ - lib/conpar/version.rb
175
+ - spec/conpar_spec.rb
176
+ - spec/lib/.keep
177
+ - spec/lib/directive/access_list/base_spec.rb
178
+ - spec/lib/directive/access_list/ether_type_spec.rb
179
+ - spec/lib/directive/access_list/extended_spec.rb
180
+ - spec/lib/directive/access_list/standard_spec.rb
181
+ - spec/lib/directive/access_list/unknown_spec.rb
182
+ - spec/lib/directive/access_list/web_type_spec.rb
183
+ - spec/lib/directive/access_list_spec.rb
184
+ - spec/lib/directive/base_spec.rb
185
+ - spec/lib/directive/comment_spec.rb
186
+ - spec/lib/directive/empty_spec.rb
187
+ - spec/lib/directive_spec.rb
188
+ - spec/lib/document_spec.rb
189
+ - spec/samples/basic
190
+ - spec/samples/sample2
191
+ - spec/samples/sample3
192
+ - spec/samples/sample4
193
+ - spec/samples/sample5
194
+ - spec/spec_helper.rb
195
+ homepage: ''
196
+ licenses:
197
+ - MIT
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ none: false
204
+ requirements:
205
+ - - ! '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ segments:
209
+ - 0
210
+ hash: -4307823525324721916
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ! '>='
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ segments:
218
+ - 0
219
+ hash: -4307823525324721916
220
+ requirements: []
221
+ rubyforge_project:
222
+ rubygems_version: 1.8.23
223
+ signing_key:
224
+ specification_version: 3
225
+ summary: Firewall CONfig PARser
226
+ test_files:
227
+ - spec/conpar_spec.rb
228
+ - spec/lib/.keep
229
+ - spec/lib/directive/access_list/base_spec.rb
230
+ - spec/lib/directive/access_list/ether_type_spec.rb
231
+ - spec/lib/directive/access_list/extended_spec.rb
232
+ - spec/lib/directive/access_list/standard_spec.rb
233
+ - spec/lib/directive/access_list/unknown_spec.rb
234
+ - spec/lib/directive/access_list/web_type_spec.rb
235
+ - spec/lib/directive/access_list_spec.rb
236
+ - spec/lib/directive/base_spec.rb
237
+ - spec/lib/directive/comment_spec.rb
238
+ - spec/lib/directive/empty_spec.rb
239
+ - spec/lib/directive_spec.rb
240
+ - spec/lib/document_spec.rb
241
+ - spec/samples/basic
242
+ - spec/samples/sample2
243
+ - spec/samples/sample3
244
+ - spec/samples/sample4
245
+ - spec/samples/sample5
246
+ - spec/spec_helper.rb
247
+ has_rdoc: