dns-zone 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ require 'dns/zone/test_case'
2
+
3
+ class RR_DNSKEY_Test < DNS::Zone::TestCase
4
+
5
+ # FIXME (lantins): algorithm can be integer _or_ mnemonic!
6
+
7
+ TEST_KEY = 'AQPSKmynfzW4kyBv015MUG2DeIQ3Cbl+BBZH4b/0PY1kxkmvHjcZc8nokfzj31GajIQKY+5CptLr3buXA10hWqTkF7H6RfoRqXQeogmMHfpftf6zMv1LyBUgia7za6ZEzOJBOztyvhjL742iU/TpPSEDhm2SNKLijfUppn1UaNvv4w=='
8
+
9
+ def test_build_rr__dnskey
10
+ rr = DNS::Zone::RR::DNSKEY.new
11
+ rr.label = 'example.com.'
12
+ rr.ttl = 86400
13
+ rr.flags = 256
14
+ rr.protocol = 3
15
+ rr.algorithm = 5
16
+ rr.key = TEST_KEY
17
+
18
+ assert_equal "example.com. 86400 IN DNSKEY 256 3 5 #{TEST_KEY}", rr.dump
19
+ end
20
+
21
+ def test_load_rr__dnskey
22
+ rr = DNS::Zone::RR::DNSKEY.new.load("example.com. IN DNSKEY 256 3 5 #{TEST_KEY}")
23
+ assert_equal 'example.com.', rr.label
24
+ assert_equal 'DNSKEY', rr.type
25
+ assert_equal 256, rr.flags
26
+ assert_equal 3, rr.protocol
27
+ assert_equal 5, rr.algorithm
28
+ assert_equal TEST_KEY, rr.key
29
+ end
30
+
31
+ end
@@ -0,0 +1,28 @@
1
+ require 'dns/zone/test_case'
2
+
3
+ class RR_DS_Test < DNS::Zone::TestCase
4
+
5
+ TEST_DIGEST = '2BB183AF5F22588179A53B0A98631FAD1A292118'
6
+
7
+ def test_build_rr__ds
8
+ rr = DNS::Zone::RR::DS.new
9
+ rr.label = 'dskey.example.com.'
10
+ rr.key_tag = 60485
11
+ rr.algorithm = 5
12
+ rr.digest_type = 1
13
+ rr.digest = TEST_DIGEST
14
+
15
+ assert_equal "dskey.example.com. IN DS 60485 5 1 #{TEST_DIGEST}", rr.dump
16
+ end
17
+
18
+ def test_load_rr__ds
19
+ rr = DNS::Zone::RR::DS.new.load("dskey.example.com. IN DS 60485 5 1 #{TEST_DIGEST}")
20
+ assert_equal 'dskey.example.com.', rr.label
21
+ assert_equal 'DS', rr.type
22
+ assert_equal 60485, rr.key_tag
23
+ assert_equal 5, rr.algorithm
24
+ assert_equal 1, rr.digest_type
25
+ assert_equal TEST_DIGEST, rr.digest
26
+ end
27
+
28
+ end
@@ -0,0 +1,60 @@
1
+ require 'dns/zone/test_case'
2
+
3
+ class RR_NAPTR_Test < DNS::Zone::TestCase
4
+
5
+ def test_build_rr__naptr
6
+ rr = DNS::Zone::RR::NAPTR.new
7
+ rr.order = 100
8
+ rr.pref = 10
9
+ rr.flags = ''
10
+ rr.service = ''
11
+ rr.regexp = '!^urn:cid:.+@([^\.]+\.)(.*)$!\2!i'
12
+ rr.replacement = '.'
13
+
14
+ assert_equal '@ IN NAPTR 100 10 "" "" "!^urn:cid:.+@([^\.]+\.)(.*)$!\2!i" .', rr.dump
15
+ end
16
+
17
+ def test_load_rr__naptr
18
+ rr = DNS::Zone::RR::NAPTR.new.load('@ IN NAPTR 100 10 "" "" "!^urn:cid:.+@([^\.]+\.)(.*)$!\2!i" .')
19
+ assert_equal '@', rr.label
20
+ assert_equal 'NAPTR', rr.type
21
+ assert_equal 100, rr.order
22
+ assert_equal 10, rr.pref
23
+ assert_equal '', rr.flags
24
+ assert_equal '', rr.service
25
+ assert_equal '!^urn:cid:.+@([^\\.]+\\.)(.*)$!\\2!i', rr.regexp
26
+ assert_equal '.', rr.replacement
27
+
28
+ rr = DNS::Zone::RR::NAPTR.new.load('example.com. IN NAPTR 100 50 "a" "z3950+N2L+N2C" "" cidserver.example.com.')
29
+ assert_equal 'example.com.', rr.label
30
+ assert_equal 'NAPTR', rr.type
31
+ assert_equal 100, rr.order
32
+ assert_equal 50, rr.pref
33
+ assert_equal 'a', rr.flags
34
+ assert_equal 'z3950+N2L+N2C', rr.service
35
+ assert_equal '', rr.regexp
36
+ assert_equal 'cidserver.example.com.', rr.replacement
37
+
38
+ rr = DNS::Zone::RR::NAPTR.new.load('example.com. IN NAPTR 100 60 "a" "rcds+N2C" "" cidserver.example.com.')
39
+ assert_equal 'example.com.', rr.label
40
+ assert_equal 'NAPTR', rr.type
41
+ assert_equal 100, rr.order
42
+ assert_equal 60, rr.pref
43
+ assert_equal 'a', rr.flags
44
+ assert_equal 'rcds+N2C', rr.service
45
+ assert_equal '', rr.regexp
46
+ assert_equal 'cidserver.example.com.', rr.replacement
47
+
48
+ rr = DNS::Zone::RR::NAPTR.new.load('example.com. IN NAPTR 300 50 "b" "http+N2L+N2C+N2R" "" www.example.com.')
49
+ assert_equal 'example.com.', rr.label
50
+ assert_equal 'NAPTR', rr.type
51
+ assert_equal 300, rr.order
52
+ assert_equal 50, rr.pref
53
+ assert_equal 'b', rr.flags
54
+ assert_equal 'http+N2L+N2C+N2R', rr.service
55
+ assert_equal '', rr.regexp
56
+ assert_equal 'www.example.com.', rr.replacement
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,33 @@
1
+ require 'dns/zone/test_case'
2
+
3
+ class RR_NSEC3_Test < DNS::Zone::TestCase
4
+
5
+ def test_build_rr__nsec3
6
+ rr = DNS::Zone::RR::NSEC3.new
7
+ rr.label = 'foo.example.com.'
8
+
9
+ rr.algorithm = 1
10
+ rr.flags = 0
11
+ rr.iterations = 12
12
+ rr.salt = 'aabbccdd'
13
+ rr.next_hashed_owner_name = 'ji6neoaepv8b5o6k4ev33abha8ht9fgc'
14
+ rr.rrset_types = 'A AAAA'
15
+
16
+ assert_equal "foo.example.com. IN NSEC3 1 0 12 aabbccdd ji6neoaepv8b5o6k4ev33abha8ht9fgc A AAAA", rr.dump
17
+
18
+ end
19
+
20
+ def test_load_rr__nsec3
21
+ rr = DNS::Zone::RR::NSEC3.new.load("foo.example.com. IN NSEC3 1 0 12 aabbccdd ji6neoaepv8b5o6k4ev33abha8ht9fgc A AAAA")
22
+ assert_equal 'foo.example.com.', rr.label
23
+ assert_equal 'NSEC3', rr.type
24
+
25
+ assert_equal 1, rr.algorithm
26
+ assert_equal 0, rr.flags
27
+ assert_equal 12, rr.iterations
28
+ assert_equal 'aabbccdd', rr.salt
29
+ assert_equal 'ji6neoaepv8b5o6k4ev33abha8ht9fgc', rr.next_hashed_owner_name
30
+ assert_equal 'A AAAA', rr.rrset_types
31
+ end
32
+
33
+ end
@@ -0,0 +1,29 @@
1
+ require 'dns/zone/test_case'
2
+
3
+ class RR_NSEC3PARAM_Test < DNS::Zone::TestCase
4
+
5
+ def test_build_rr__nsec3param
6
+ rr = DNS::Zone::RR::NSEC3PARAM.new
7
+ rr.label = 'foo.example.com.'
8
+
9
+ rr.algorithm = 1
10
+ rr.flags = 0
11
+ rr.iterations = 12
12
+ rr.salt = 'aabbccdd'
13
+
14
+ assert_equal "foo.example.com. IN NSEC3PARAM 1 0 12 aabbccdd", rr.dump
15
+
16
+ end
17
+
18
+ def test_load_rr__nsec3param
19
+ rr = DNS::Zone::RR::NSEC3PARAM.new.load("foo.example.com. IN NSEC3PARAM 1 0 12 aabbccdd")
20
+ assert_equal 'foo.example.com.', rr.label
21
+ assert_equal 'NSEC3PARAM', rr.type
22
+
23
+ assert_equal 1, rr.algorithm
24
+ assert_equal 0, rr.flags
25
+ assert_equal 12, rr.iterations
26
+ assert_equal 'aabbccdd', rr.salt
27
+ end
28
+
29
+ end
@@ -0,0 +1,24 @@
1
+ require 'dns/zone/test_case'
2
+
3
+ class RR_NSEC_Test < DNS::Zone::TestCase
4
+
5
+ def test_build_rr__nsec
6
+ rr = DNS::Zone::RR::NSEC.new
7
+ rr.label = 'alfa.example.com.'
8
+ rr.next_domain = 'host.example.com.'
9
+ rr.rrset_types = 'A MX RRSIG NSEC TYPE1234'
10
+
11
+ assert_equal "alfa.example.com. IN NSEC host.example.com. A MX RRSIG NSEC TYPE1234", rr.dump
12
+
13
+ end
14
+
15
+ def test_load_rr__nsec
16
+ rr = DNS::Zone::RR::NSEC.new.load("alfa.example.com. IN NSEC host.example.com. A MX RRSIG NSEC TYPE1234")
17
+ assert_equal 'alfa.example.com.', rr.label
18
+ assert_equal 'NSEC', rr.type
19
+
20
+ assert_equal 'host.example.com.', rr.next_domain
21
+ assert_equal 'A MX RRSIG NSEC TYPE1234', rr.rrset_types
22
+ end
23
+
24
+ end
@@ -0,0 +1,40 @@
1
+ require 'dns/zone/test_case'
2
+
3
+ class RR_RRSIG_Test < DNS::Zone::TestCase
4
+
5
+ TEST_SIGNATURE = 'oJB1W6WNGv+ldvQ3WDG0MQkg5IEhjRip8WTrPYGv07h108dUKGMeDPKijVCHX3DDKdfb+v6oB9wfuh3DTJXUAfI/M0zmO/zz8bW0Rznl8O3tGNazPwQKkRN20XPXV6nwwfoXmJQbsLNrLfkGJ5D6fwFm8nN+6pBzeDQfsS3Ap3o='
6
+
7
+ def test_build_rr__rrsig
8
+ rr = DNS::Zone::RR::RRSIG.new
9
+ rr.label = 'host.example.com.'
10
+ rr.type_covered = 'A'
11
+ rr.algorithm = 5
12
+ rr.labels = 3
13
+ rr.original_ttl = 86400
14
+ rr.signature_expiration = 20030322173103
15
+ rr.signature_inception = 20030220173103
16
+ rr.key_tag = 2642
17
+ rr.signer = 'example.com.'
18
+ rr.signature = TEST_SIGNATURE
19
+
20
+ assert_equal "host.example.com. IN RRSIG A 5 3 86400 20030322173103 20030220173103 2642 example.com. #{TEST_SIGNATURE}", rr.dump
21
+
22
+ end
23
+
24
+ def test_load_rr__rrsig
25
+ rr = DNS::Zone::RR::RRSIG.new.load("host.example.com. IN RRSIG A 5 3 86400 20030322173103 20030220173103 2642 example.com. #{TEST_SIGNATURE}")
26
+ assert_equal 'host.example.com.', rr.label
27
+ assert_equal 'RRSIG', rr.type
28
+
29
+ assert_equal 'A', rr.type_covered
30
+ assert_equal 5, rr.algorithm
31
+ assert_equal 3, rr.labels
32
+ assert_equal 86400, rr.original_ttl
33
+ assert_equal 20030322173103, rr.signature_expiration
34
+ assert_equal 20030220173103, rr.signature_inception
35
+ assert_equal 2642, rr.key_tag
36
+ assert_equal 'example.com.', rr.signer
37
+ assert_equal TEST_SIGNATURE, rr.signature
38
+ end
39
+
40
+ end
@@ -0,0 +1,24 @@
1
+ require 'dns/zone/test_case'
2
+
3
+ class RR_SSHFP_Test < DNS::Zone::TestCase
4
+
5
+ def test_build_rr__sshfp
6
+ rr = DNS::Zone::RR::SSHFP.new
7
+ rr.label = 'host.example.'
8
+ rr.algorithm_number = 2
9
+ rr.fingerprint_type = 1
10
+ rr.fingerprint = '123456789abcdef67890123456789abcdef67890'
11
+
12
+ assert_equal 'host.example. IN SSHFP 2 1 123456789abcdef67890123456789abcdef67890', rr.dump
13
+ end
14
+
15
+ def test_load_rr__sshfp
16
+ rr = DNS::Zone::RR::SSHFP.new.load('host.example. IN SSHFP 2 1 123456789abcdef67890123456789abcdef67890')
17
+ assert_equal 'host.example.', rr.label
18
+ assert_equal 'SSHFP', rr.type
19
+ assert_equal 2, rr.algorithm_number
20
+ assert_equal 1, rr.fingerprint_type
21
+ assert_equal '123456789abcdef67890123456789abcdef67890', rr.fingerprint
22
+ end
23
+
24
+ end
@@ -53,13 +53,31 @@ EOL
53
53
  ZONE_FILE_BASIC_EXAMPLE =<<-EOL
54
54
  @ IN SOA ns0.lividpenguin.com. luke.lividpenguin.com. ( 2013101406 12h 15m 3w 3h )
55
55
  @ IN NS ns0.lividpenguin.com.
56
+ @ IN MX 10 mail
57
+ @ IN MX 99 mx.fakemx.net.
56
58
  @ IN A 78.47.253.85
59
+ mail IN A 78.47.253.85
57
60
  EOL
58
61
 
59
62
  def test_create_new_instance
60
63
  assert DNS::Zone.new
61
64
  end
62
65
 
66
+ def test_programmatic_readme_example
67
+ zone = DNS::Zone.new
68
+ zone.origin = 'example.com.'
69
+ zone.ttl = '1d'
70
+ # quick access to SOA RR
71
+ zone.soa.nameserver = 'ns0.lividpenguin.com.'
72
+ zone.soa.email = 'hostmaster.lividpenguin.com.'
73
+ # create and add new record
74
+ rec = DNS::Zone::RR::A.new
75
+ rec.address = '127.0.0.1'
76
+ zone.records << rec
77
+
78
+ assert_equal 2, zone.records.length, "were expecting 2 records, including the SOA"
79
+ end
80
+
63
81
  def test_load_zone_basic
64
82
  # load zone file.
65
83
  zone = DNS::Zone.load(ZONE_FILE_BASIC_EXAMPLE)
@@ -69,6 +87,20 @@ EOL
69
87
  assert_equal ZONE_FILE_BASIC_EXAMPLE, dump, 'loaded zone file should match dumped zone file'
70
88
  end
71
89
 
90
+ def test_load_zone_with_origin_param
91
+ # --- zone without $ORIGIN directive
92
+
93
+ zone = DNS::Zone.load(ZONE_FILE_BASIC_EXAMPLE, 'lividpenguin.com.')
94
+ dump = zone.dump
95
+ assert_equal ZONE_FILE_BASIC_EXAMPLE, dump, 'loaded zone file should match dumped zone file'
96
+ assert_equal 'lividpenguin.com.', zone.origin, 'check origin matches example input'
97
+
98
+ # --- zone with $ORIGIN directive
99
+
100
+ zone = DNS::Zone.load(ZONE_FILE_EXAMPLE, 'ignore.this.origin.favor.zone.com.')
101
+ assert_equal 'lividpenguin.com.', zone.origin, 'origin should come from test zone, not passed param'
102
+ end
103
+
72
104
  def test_load_zone
73
105
  # load example dns master zone file.
74
106
  zone = DNS::Zone.load(ZONE_FILE_EXAMPLE)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns-zone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Antins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-21 00:00:00.000000000 Z
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.3'
89
+ version: '0.6'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.3'
96
+ version: '0.6'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-minitest
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '2.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '2.0'
125
125
  description: |
126
126
  A Ruby library for building and parsing DNS zone files for use with
127
127
  Bind and PowerDNS (with Bind backend) DNS servers.
@@ -132,7 +132,6 @@ extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
134
  - Gemfile
135
- - Guardfile
136
135
  - HISTORY.md
137
136
  - README.md
138
137
  - Rakefile
@@ -141,29 +140,51 @@ files:
141
140
  - lib/dns/zone/rr.rb
142
141
  - lib/dns/zone/rr/a.rb
143
142
  - lib/dns/zone/rr/aaaa.rb
143
+ - lib/dns/zone/rr/cdnskey.rb
144
+ - lib/dns/zone/rr/cds.rb
144
145
  - lib/dns/zone/rr/cname.rb
146
+ - lib/dns/zone/rr/dlv.rb
147
+ - lib/dns/zone/rr/dnskey.rb
148
+ - lib/dns/zone/rr/ds.rb
145
149
  - lib/dns/zone/rr/hinfo.rb
146
150
  - lib/dns/zone/rr/mx.rb
151
+ - lib/dns/zone/rr/naptr.rb
147
152
  - lib/dns/zone/rr/ns.rb
153
+ - lib/dns/zone/rr/nsec.rb
154
+ - lib/dns/zone/rr/nsec3.rb
155
+ - lib/dns/zone/rr/nsec3param.rb
148
156
  - lib/dns/zone/rr/ptr.rb
149
157
  - lib/dns/zone/rr/record.rb
158
+ - lib/dns/zone/rr/rrsig.rb
150
159
  - lib/dns/zone/rr/soa.rb
151
160
  - lib/dns/zone/rr/spf.rb
152
161
  - lib/dns/zone/rr/srv.rb
162
+ - lib/dns/zone/rr/sshfp.rb
153
163
  - lib/dns/zone/rr/txt.rb
154
164
  - lib/dns/zone/test_case.rb
155
165
  - lib/dns/zone/version.rb
156
166
  - test/rr/a_test.rb
157
167
  - test/rr/aaaa_test.rb
168
+ - test/rr/cdnskey_test.rb
169
+ - test/rr/cds_test.rb
158
170
  - test/rr/cname_test.rb
171
+ - test/rr/dlv_test.rb
172
+ - test/rr/dnskey_test.rb
173
+ - test/rr/ds_test.rb
159
174
  - test/rr/hinfo_test.rb
160
175
  - test/rr/mx_test.rb
176
+ - test/rr/naptr_test.rb
161
177
  - test/rr/ns_test.rb
178
+ - test/rr/nsec3_test.rb
179
+ - test/rr/nsec3param_test.rb
180
+ - test/rr/nsec_test.rb
162
181
  - test/rr/ptr_test.rb
163
182
  - test/rr/record_test.rb
183
+ - test/rr/rrsig_test.rb
164
184
  - test/rr/soa_test.rb
165
185
  - test/rr/spf_test.rb
166
186
  - test/rr/srv_test.rb
187
+ - test/rr/sshfp_test.rb
167
188
  - test/rr/txt_test.rb
168
189
  - test/rr_test.rb
169
190
  - test/version_test.rb
@@ -188,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
209
  version: '0'
189
210
  requirements: []
190
211
  rubyforge_project:
191
- rubygems_version: 2.4.1
212
+ rubygems_version: 2.4.2
192
213
  signing_key:
193
214
  specification_version: 4
194
215
  summary: A Ruby library for building and parsing DNS zone files.