bind9mgr 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -61,3 +61,10 @@
61
61
  === 0.3.8 / 2011-10-15
62
62
 
63
63
  * NamedConf#add_zone returns Zone instance
64
+
65
+ === 0.3.9 / 2011-10-16
66
+
67
+ * CNAME validations
68
+ * MX validations
69
+ * A validations
70
+ * spec update
data/lib/bind9mgr.rb CHANGED
@@ -6,7 +6,7 @@ require File.join( File.dirname(__FILE__), 'resource_record' )
6
6
  require File.join( File.dirname(__FILE__), 'parser' )
7
7
 
8
8
  module Bind9mgr
9
- VERSION = '0.3.8'
9
+ VERSION = '0.3.9'
10
10
 
11
11
  ZONES_BIND_SUBDIR = 'primary'
12
12
 
@@ -17,6 +17,7 @@ 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 << "Rdata rdata_shouldnt_be_blank_string"; return false) if @rdata.kind_of?(String) && @rdata.length < 1
20
21
  (@errors << "Owner invalid") if @owner && ( !@owner.kind_of?(String) || (@owner.match(/^\d+$/)) || (@owner == 'localhost') )
21
22
  (@errors << "Class invalid") if !klass.nil? && !KLASSES.include?( klass )
22
23
  (@errors << "Type not_supported") unless ALLOWED_TYPES.include?( type )
@@ -29,22 +30,28 @@ module Bind9mgr
29
30
  end
30
31
 
31
32
  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
33
+ (@errors << "Rdata should_be_an_array"; return false) unless @rdata.kind_of? Array
34
+ (@errors << "Rdata should_have_7_elements"; return false) unless @rdata.size == 7
34
35
  (@errors << "Base a record validation is under construction") unless @rdata[0].match(/\.$/)
35
36
  end
36
37
 
37
38
  def validate_a
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
39
+ (@errors << "Rdata should_be_a_string"; return false) unless @rdata.kind_of? String
40
+ (@errors << "Rdata should_not_be_blank"; return false) if @rdata.length < 1 # TODO DRY it
40
41
  end
41
42
 
42
43
  def validate_cname
43
- # @errors << "Base cname record validation is under construction"
44
+ (@errors << "owner should_be_a_string"; return false) unless @owner.kind_of? String
45
+ (@errors << "owner should_not_contain_only_digits"; return false) if @owner.match(/^\d+$/)
44
46
  end
45
47
 
46
48
  def validate_mx
47
- # @errors << "Base mx record validation is under construction"
49
+ (@errors << "Rdata should_be_an_array"; return false) unless @rdata.kind_of? Array
50
+ (@errors << "Rdata should_contain_priority"; return false) unless @rdata[0].to_s.match(/^\d+$/) # TODO how about integer value
51
+ (@errors << "Rdata target_should_not_contain_only_digits"; return false) if @rdata[1].match(/^\d+$/)
52
+ end
53
+
54
+ def validate_txt
48
55
  end
49
56
 
50
57
  ##
data/lib/zone.rb CHANGED
@@ -158,6 +158,11 @@ zone "#{name}" {
158
158
  true
159
159
  end
160
160
 
161
+ def valid?
162
+ return false if @records.size < 1
163
+ @records.select{ |z| !z.valid? }.size == 0
164
+ end
165
+
161
166
  private
162
167
 
163
168
  def default_soa
data/spec/zone_spec.rb CHANGED
@@ -47,27 +47,44 @@ alias1 IN CNAME ns
47
47
  end
48
48
  pending "should generate zone entry content"
49
49
 
50
- it "should add default rrs before generate db content" do
51
- zone = Bind9mgr::Zone.new( 'example.com', 'example.com.db',
52
- { :main_ns => '192.168.1.1',
53
- :secondary_ns => '192.168.1.2',
54
- :main_server_ip => '192.168.1.3',
55
- :support_email => 'qwe@qwe.ru'
56
- })
57
- end
50
+ describe "records creation & validation" do
51
+ subject do
52
+ Bind9mgr::Zone.new( 'example.com', 'example.com.db',
53
+ { :main_ns => '192.168.1.1',
54
+ :secondary_ns => '192.168.1.2',
55
+ :main_server_ip => '192.168.1.3',
56
+ :support_email => 'qwe@qwe.ru'
57
+ })
58
+ end
58
59
 
59
- it "should add dot to zone name on creation unless there is no one" do
60
- zone = Bind9mgr::Zone.new( 'example.com', 'example.com.db',
61
- { :main_ns => '192.168.1.1',
62
- :secondary_ns => '192.168.1.2',
63
- :main_server_ip => '192.168.1.3',
64
- :support_email => 'qwe@qwe.ru'
65
- })
66
- zone.origin.should eql('example.com.')
67
- zone.name.should eql('example.com')
60
+ it "should add default rrs before generate db content" do
61
+ subject.gen_db_content
62
+ subject.records.size.should > 0
63
+ end
64
+
65
+ it "should add dot to zone name on creation unless there is no one" do
66
+ subject.origin.should eql('example.com.')
67
+ subject.name.should eql('example.com')
68
+ end
69
+
70
+ it "should not be valid without records" do
71
+ subject.should_not be_valid
72
+ end
73
+
74
+ it "should pass when there are default records and some valid ones" do
75
+ subject.add_default_rrs
76
+ subject.add_rr( 'qwe', nil, nil, 'CNAME', '@' )
77
+ subject.should be_valid
78
+ end
79
+
80
+ it "should not be valid with wrong records" do
81
+ subject.add_default_rrs
82
+ subject.add_rr( 'qwe', nil, nil, 'CNAME', '' )
83
+ subject.should_not be_valid
84
+ end
68
85
  end
69
86
 
70
- it "should raise error when undefined rr target added" do
87
+ pending "should raise error when undefined rr target added" do
71
88
  # examples
72
89
  # 1:
73
90
  # @ NS ns.example.com # here is no dot at the end of line -> error!
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.8
4
+ version: 0.3.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hoe
16
- requirement: &17488080 !ruby/object:Gem::Requirement
16
+ requirement: &24673600 !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: *17488080
24
+ version_requirements: *24673600
25
25
  description: This gem contains some classes to manage bind9 zone files
26
26
  email:
27
27
  - mikhail@mad-box.ru