dns-zonefile 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,141 @@
1
+ require 'spec_helper'
2
+ require 'dns/zonefile'
3
+
4
+ describe "DNS::Zonefile" do
5
+ it "should be versioned" do
6
+ lambda {
7
+ DNS::Zonefile.const_get(:VERSION)
8
+ }.should_not raise_error
9
+ end
10
+
11
+ it "should be version 0.0.1" do
12
+ DNS::Zonefile::VERSION.should eql("0.0.1")
13
+ end
14
+
15
+ it "should have an origin" do
16
+ DNS::Zonefile.new.should respond_to(:origin)
17
+ end
18
+
19
+ it "should provide a way of parsing a string" do
20
+ DNS::Zonefile.should respond_to(:parse)
21
+ end
22
+
23
+ describe "parsing a zonefile string" do
24
+ before(:each) do
25
+ @zonefile =<<-ZONE
26
+ ; Hi! I'm an example zonefile.
27
+ $ORIGIN example.com.
28
+ $TTL 86400; expire in 1 day.
29
+ @ IN SOA ns.example.com. hostmaster.example.com. (
30
+ 2007120710 ; serial number of this zone file
31
+ 1d ; slave refresh (1 day)
32
+ 1d ; slave retry time in case of a problem (1 day)
33
+ 4w ; slave expiration time (4 weeks)
34
+ 1h ; minimum caching time in case of failed lookups (1 hour)
35
+ )
36
+ ; That's the SOA part done.
37
+
38
+ ; Let's start the resource records.
39
+ example.com. NS ns ; ns.example.com is the nameserver for example.com
40
+ example.com. NS ns.somewhere.com. ; ns.somewhere.com is a backup nameserver for example.co
41
+ example.com. A 10.0.0.1 ; ip address for "example.com"
42
+ ns A 10.0.0.2 ; ip address for "ns.example.com"
43
+ www CNAME ns ; "www.example.com" is an alias for "ns.example.com"
44
+ wwwtest CNAME www ; "wwwtest.example.com" is another alias for "www.example.com"
45
+
46
+ ; Email... that'll be fun then
47
+ example.com. MX 10 mail.example.com. ; mail.example.com is the mailserver for example.com
48
+ @ MX 20 mail2.example.com. ; Similar to above line, but using "@" to say "use $ORIGIN"
49
+ @ MX 50 mail3 ; Similar to above line, but using a host within this domain
50
+ ZONE
51
+ end
52
+
53
+ it "should set the origin correctly" do
54
+ zone = DNS::Zonefile.parse(@zonefile)
55
+ zone.origin.should eql('example.com.')
56
+ end
57
+
58
+ it "should set the zone variables correctly" do
59
+ zone = DNS::Zonefile.parse(@zonefile)
60
+ zone.variables['TTL'].should eql('86400')
61
+ zone.variables['ORIGIN'].should eql('example.com.')
62
+ end
63
+
64
+ it "should set the SOA correctly" do
65
+ zone = DNS::Zonefile.parse(@zonefile)
66
+ soa = zone.soa
67
+ soa.ns.to_s.should eql('ns.example.com.')
68
+ soa.rp.to_s.should eql('hostmaster.example.com.')
69
+ soa.serial.to_i.should eql(2007120710)
70
+ soa.refresh.to_i.should eql(86400)
71
+ soa.retry.to_i.should eql(86400)
72
+ soa.expiry.to_i.should eql(2419200)
73
+ soa.ttl.to_i.should eql(3600)
74
+ end
75
+
76
+ it "should build the correct number of resource records" do
77
+ zone = DNS::Zonefile.parse(@zonefile)
78
+ zone.rr.size.should be(9)
79
+ end
80
+
81
+ it "should build the correct NS records" do
82
+ zone = DNS::Zonefile.parse(@zonefile)
83
+ ns_records = zone.rr.select { |rr| rr.record_type == "NS" }
84
+ ns_records.size.should be(2)
85
+
86
+ ns_records.detect { |ns|
87
+ ns.host.to_s == "example.com." && ns.nameserver.to_s == "ns.example.com."
88
+ }.should_not be_nil
89
+
90
+ ns_records.detect { |ns|
91
+ ns.host.to_s == "example.com." && ns.nameserver.to_s == "ns.somewhere.com."
92
+ }.should_not be_nil
93
+ end
94
+
95
+ it "should build the correct A records" do
96
+ zone = DNS::Zonefile.parse(@zonefile)
97
+ a_records = zone.rr.select { |rr| rr.record_type == "A" }
98
+ a_records.size.should be(2)
99
+
100
+ a_records.detect { |a|
101
+ a.host.to_s == "example.com." && a.ip_address.to_s == "10.0.0.1"
102
+ }.should_not be_nil
103
+
104
+ a_records.detect { |a|
105
+ a.host.to_s == "ns.example.com." && a.ip_address.to_s == "10.0.0.2"
106
+ }.should_not be_nil
107
+ end
108
+
109
+ it "should build the correct CNAME records" do
110
+ zone = DNS::Zonefile.parse(@zonefile)
111
+ cname_records = zone.rr.select { |rr| rr.record_type == "CNAME" }
112
+ cname_records.size.should be(2)
113
+
114
+ cname_records.detect { |cname|
115
+ cname.alias.to_s == "www.example.com." && cname.host.to_s == "ns.example.com."
116
+ }.should_not be_nil
117
+
118
+ cname_records.detect { |cname|
119
+ cname.alias.to_s == "wwwtest.example.com." && cname.host.to_s == "www.example.com."
120
+ }.should_not be_nil
121
+ end
122
+
123
+ it "should build the correct MX records" do
124
+ zone = DNS::Zonefile.parse(@zonefile)
125
+ mx_records = zone.rr.select { |rr| rr.record_type == "MX" }
126
+ mx_records.size.should be(3)
127
+
128
+ mx_records.detect { |mx|
129
+ mx.host.to_s == "example.com." && mx.priority.to_i == 10 && mx.exchanger.to_s == 'mail.example.com.'
130
+ }.should_not be_nil
131
+
132
+ mx_records.detect { |mx|
133
+ mx.host.to_s == "example.com." && mx.priority.to_i == 20 && mx.exchanger.to_s == 'mail2.example.com.'
134
+ }.should_not be_nil
135
+
136
+ mx_records.detect { |mx|
137
+ mx.host.to_s == "example.com." && mx.priority.to_i == 50 && mx.exchanger.to_s == 'mail3.example.com.'
138
+ }.should_not be_nil
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,2 @@
1
+ require 'spec'
2
+ require 'dns/zonefile'
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dns-zonefile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Craig R Webster
8
+ autorequire: dns/zonefile
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-13 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Parse and manipulate with DNS zonefiles. Great for working with BIND.
17
+ email: craig@barkingiguana.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - Rakefile
24
+ - README
25
+ - TODO
26
+ - doc/example2.com.zone
27
+ - doc/example3.com.zone
28
+ - doc/zonefile.example
29
+ - doc/zonefile.treetop
30
+ files:
31
+ - lib/dns/zonefile.rb
32
+ - lib/dns/zonefile_parser.rb
33
+ - spec/dns/zonefile_spec.rb
34
+ - spec/spec_helper.rb
35
+ - Rakefile
36
+ - README
37
+ - TODO
38
+ - doc/example2.com.zone
39
+ - doc/example3.com.zone
40
+ - doc/zonefile.example
41
+ - doc/zonefile.treetop
42
+ has_rdoc: true
43
+ homepage: http://barkingiguana.com/
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --title
49
+ - DNS::Zonefile -- Work with zonefiles
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Parse and manipulate with DNS zonefiles.
71
+ test_files: []
72
+