bind9mgr 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/lib/bind9mgr.rb +1 -1
- data/lib/resource_record.rb +13 -6
- data/lib/zone.rb +8 -1
- data/spec/resource_record_spec.rb +29 -0
- metadata +4 -4
data/History.txt
CHANGED
data/lib/bind9mgr.rb
CHANGED
data/lib/resource_record.rb
CHANGED
@@ -17,27 +17,34 @@ module Bind9mgr
|
|
17
17
|
def valid?
|
18
18
|
@errors = []
|
19
19
|
(@errors << "Base type_and_rdata_shouldnt_be_blank"; return false) unless @type && @rdata
|
20
|
-
(@errors << "Owner invalid") if @owner && ( !@owner.kind_of?(String) || (@owner.
|
20
|
+
(@errors << "Owner invalid") if @owner && ( !@owner.kind_of?(String) || (@owner.match(/^\d+$/)) || (@owner == 'localhost') )
|
21
21
|
(@errors << "Class invalid") if !klass.nil? && !KLASSES.include?( klass )
|
22
22
|
(@errors << "Type not_supported") unless ALLOWED_TYPES.include?( type )
|
23
23
|
|
24
24
|
validate_method_name = "validate_#{@type.downcase}"
|
25
|
-
|
26
|
-
self.
|
25
|
+
|
26
|
+
(self.send validate_method_name) if self.respond_to?(validate_method_name)
|
27
27
|
|
28
28
|
return @errors.size == 0
|
29
29
|
end
|
30
30
|
|
31
|
+
def validate_soa
|
32
|
+
(@errors << "Rdata should_be_an_array"; return false) unless @rdata.kind_of? Array
|
33
|
+
(@errors << "Rdata should_have_7_elements"; return false) unless @rdata.size == 7
|
34
|
+
(@errors << "Base a record validation is under construction") unless @rdata[0].match(/\.$/)
|
35
|
+
end
|
36
|
+
|
31
37
|
def validate_a
|
32
|
-
@errors << "
|
38
|
+
(@errors << "Rdata should_be_a_string"; return false) unless @rdata.kind_of? String
|
39
|
+
(@errors << "Rdata should_not_be_blank"; return false) if @rdata.length < 1
|
33
40
|
end
|
34
41
|
|
35
42
|
def validate_cname
|
36
|
-
@errors << "Base cname record validation is under construction"
|
43
|
+
# @errors << "Base cname record validation is under construction"
|
37
44
|
end
|
38
45
|
|
39
46
|
def validate_mx
|
40
|
-
@errors << "Base mx record validation is under construction"
|
47
|
+
# @errors << "Base mx record validation is under construction"
|
41
48
|
end
|
42
49
|
|
43
50
|
##
|
data/lib/zone.rb
CHANGED
@@ -72,11 +72,18 @@ module Bind9mgr
|
|
72
72
|
raise ArgumentError, "default_ttl not secified" unless @default_ttl
|
73
73
|
|
74
74
|
add_default_rrs
|
75
|
-
|
75
|
+
|
76
|
+
rrhash = @records.inject({}){|s, v| s[v.type] ||= []; s[v.type] << v; s}
|
77
|
+
|
76
78
|
cont = "; File is under automatic control. Edit with caution.\n"
|
77
79
|
cont << ";;; Zone #{@origin} ;;;" << "\n"
|
78
80
|
cont << "$ORIGIN #{@origin}" << "\n" if @origin
|
79
81
|
cont << "$TTL #{@default_ttl}" << "\n" if @default_ttl
|
82
|
+
|
83
|
+
rrhash.keys.each do |rr_type|
|
84
|
+
cont << ";;; #{rr_type} ;;;\n"
|
85
|
+
cont << rrhash[rr_type].map{ |r| r.gen_rr_string }.join
|
86
|
+
end
|
80
87
|
cont << @records.map{ |r| r.gen_rr_string }.join
|
81
88
|
|
82
89
|
cont
|
@@ -47,6 +47,35 @@ describe Bind9mgr::ResourceRecord do
|
|
47
47
|
expect { @rr.gen_rr_string }.not_to raise_error
|
48
48
|
end
|
49
49
|
|
50
|
+
describe "A records validation" do
|
51
|
+
subject { Bind9mgr::ResourceRecord }
|
52
|
+
|
53
|
+
it( "with normal data" ) { subject.new( 'sub', nil, 'IN', 'A', '192.168.1.1' ).should be_valid }
|
54
|
+
it( "without class" ) { subject.new( 'sub', nil, nil, 'A', '192.168.1.1' ).should be_valid }
|
55
|
+
it( "with blank owner" ) { subject.new( '', nil, 'IN', 'A', '192.168.1.1' ).should be_valid }
|
56
|
+
it( "with nil owner" ) { subject.new( nil, nil, 'IN', 'A', '192.168.1.1' ).should be_valid }
|
57
|
+
|
58
|
+
it( "with '1' in all fields" ) { subject.new( '1', '1', '1', 'A', '1' ).should_not be_valid }
|
59
|
+
it( "with digit in owner" ) { subject.new( '1', nil, 'IN', 'A', '192.168.1.1' ).should_not be_valid }
|
60
|
+
it( "with double digit in owner" ) { subject.new( '11', nil, 'IN', 'A', '192.168.1.1' ).should_not be_valid }
|
61
|
+
it( "with blank rdata" ) { subject.new( 'sub', nil, 'IN', 'A', '' ).should_not be_valid }
|
62
|
+
it( "with nil rdata" ) { subject.new( 'sub', nil, 'IN', 'A', nil ).should_not be_valid }
|
63
|
+
it( "with digit in rdata" ) { subject.new( '1', nil, 'IN', 'A', '1' ).should_not be_valid }
|
64
|
+
it( "with char in rdata" ) { subject.new( '1', nil, 'IN', 'A', 's' ).should_not be_valid }
|
65
|
+
it( "with punctuation in rdata" ) { subject.new( '1', nil, 'IN', 'A', ',;;;' ).should_not be_valid }
|
66
|
+
it( "with wrong class" ) { subject.new( 'sub', nil, 'IN222', 'A', '192.168.1.1' ).should_not be_valid }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "SOA records validation" do
|
70
|
+
subject { Bind9mgr::ResourceRecord }
|
71
|
+
|
72
|
+
it( "with normal data" ) { subject.new( '@', nil, 'IN', 'SOA', ['qwe.com.', 'support@qwe.com', '123', '123', '123', '123', '123'] ).should be_valid }
|
73
|
+
it( "with wrong origin in rdata" ) { subject.new( '@', nil, 'IN', 'SOA', ['qwe', 'qwe', '123', '123', '123', '123', '123'] ).should_not be_valid }
|
74
|
+
it( "with wrong rdata size" ) { subject.new( '@', nil, 'IN', 'SOA', ['123', '123', '123'] ).should_not be_valid }
|
75
|
+
it( "with wrong rdata kind" ) { subject.new( '@', nil, 'IN', 'SOA', 'qwe' ).should_not be_valid }
|
76
|
+
|
77
|
+
end
|
78
|
+
|
50
79
|
it "shoult have a list of allowed rr types" do
|
51
80
|
Bind9mgr::ALLOWED_TYPES.should be_kind_of(Array)
|
52
81
|
Bind9mgr::ALLOWED_TYPES.count.should > 0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bind9mgr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-14 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hoe
|
16
|
-
requirement: &
|
16
|
+
requirement: &17322180 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '2.12'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *17322180
|
25
25
|
description: This gem contains some classes to manage bind9 zone files
|
26
26
|
email:
|
27
27
|
- mikhail@mad-box.ru
|