@nictool/dns-resource-record 1.1.3

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 (71) hide show
  1. package/.codeclimate.yml +25 -0
  2. package/CHANGELOG.md +253 -0
  3. package/DEVELOP.md +23 -0
  4. package/LICENSE +29 -0
  5. package/README.md +267 -0
  6. package/index.js +67 -0
  7. package/lib/tinydns.js +186 -0
  8. package/package.json +40 -0
  9. package/rr/a.js +65 -0
  10. package/rr/aaaa.js +137 -0
  11. package/rr/caa.js +129 -0
  12. package/rr/cert.js +75 -0
  13. package/rr/cname.js +76 -0
  14. package/rr/dname.js +74 -0
  15. package/rr/dnskey.js +117 -0
  16. package/rr/ds.js +104 -0
  17. package/rr/hinfo.js +84 -0
  18. package/rr/ipseckey.js +159 -0
  19. package/rr/key.js +73 -0
  20. package/rr/loc.js +216 -0
  21. package/rr/mx.js +86 -0
  22. package/rr/naptr.js +146 -0
  23. package/rr/ns.js +74 -0
  24. package/rr/nsec.js +61 -0
  25. package/rr/nsec3.js +99 -0
  26. package/rr/nsec3param.js +84 -0
  27. package/rr/openpgpkey.js +44 -0
  28. package/rr/ptr.js +65 -0
  29. package/rr/rrsig.js +101 -0
  30. package/rr/sig.js +100 -0
  31. package/rr/smimea.js +73 -0
  32. package/rr/soa.js +140 -0
  33. package/rr/spf.js +54 -0
  34. package/rr/srv.js +122 -0
  35. package/rr/sshfp.js +86 -0
  36. package/rr/tlsa.js +106 -0
  37. package/rr/txt.js +122 -0
  38. package/rr/uri.js +95 -0
  39. package/rr.js +291 -0
  40. package/test/a.js +76 -0
  41. package/test/aaaa.js +79 -0
  42. package/test/base.js +138 -0
  43. package/test/caa.js +104 -0
  44. package/test/cert.js +48 -0
  45. package/test/cname.js +41 -0
  46. package/test/dname.js +53 -0
  47. package/test/dnskey.js +44 -0
  48. package/test/ds.js +44 -0
  49. package/test/fake.js +26 -0
  50. package/test/hinfo.js +75 -0
  51. package/test/ipseckey.js +115 -0
  52. package/test/key.js +37 -0
  53. package/test/loc.js +71 -0
  54. package/test/mx.js +75 -0
  55. package/test/naptr.js +40 -0
  56. package/test/ns.js +53 -0
  57. package/test/nsec.js +38 -0
  58. package/test/nsec3.js +26 -0
  59. package/test/nsec3param.js +26 -0
  60. package/test/openpgpkey.js +35 -0
  61. package/test/ptr.js +54 -0
  62. package/test/rr.js +196 -0
  63. package/test/smimea.js +45 -0
  64. package/test/soa.js +77 -0
  65. package/test/spf.js +48 -0
  66. package/test/srv.js +81 -0
  67. package/test/sshfp.js +62 -0
  68. package/test/tinydns.js +140 -0
  69. package/test/tlsa.js +54 -0
  70. package/test/txt.js +70 -0
  71. package/test/uri.js +61 -0
package/test/ns.js ADDED
@@ -0,0 +1,53 @@
1
+
2
+ import assert from 'assert'
3
+
4
+ import * as base from './base.js'
5
+
6
+ import NS from '../rr/ns.js'
7
+
8
+ const defaults = { class: 'IN', ttl: 3600, type: 'NS' }
9
+
10
+ const validRecords = [
11
+ {
12
+ ...defaults,
13
+ owner: 'example.com.',
14
+ dname: 'ns1.example.com.',
15
+ testB: 'example.com.\t3600\tIN\tNS\tns1.example.com.\n',
16
+ testT: '&example.com::ns1.example.com:3600::\n',
17
+ },
18
+ ]
19
+
20
+ const invalidRecords = [
21
+ {
22
+ ...defaults,
23
+ owner: 'example.com.',
24
+ dname: '1.2.3.4', // FQDN required
25
+ msg : /dname must be fully qualified/,
26
+ },
27
+ ]
28
+
29
+ describe('NS record', function () {
30
+ base.valid(NS, validRecords)
31
+ base.invalid(NS, invalidRecords)
32
+
33
+ base.getDescription(NS)
34
+ base.getRFCs(NS, validRecords[0])
35
+ base.getFields(NS, [ 'dname' ])
36
+ base.getTypeId(NS, 2)
37
+
38
+ base.toBind(NS, validRecords)
39
+ base.toTinydns(NS, validRecords)
40
+
41
+ base.fromBind(NS, validRecords)
42
+ base.fromTinydns(NS, validRecords)
43
+
44
+ for (const val of validRecords) {
45
+ it.skip(`imports tinydns NS (&) record (${val.owner})`, async function () {
46
+ const r = new NS({ tinyline: val.testT })
47
+ if (process.env.DEBUG) console.dir(r)
48
+ for (const f of [ 'owner', 'dname', 'ttl' ]) {
49
+ assert.deepStrictEqual(r.get(f), val[f], `${f}: ${r.get(f)} !== ${val[f]}`)
50
+ }
51
+ })
52
+ }
53
+ })
package/test/nsec.js ADDED
@@ -0,0 +1,38 @@
1
+
2
+ import * as base from './base.js'
3
+
4
+ import NSEC from '../rr/nsec.js'
5
+
6
+ const validRecords = [
7
+ {
8
+ owner : 'alfa.example.com.',
9
+ ttl : 86400,
10
+ class : 'IN',
11
+ type : 'NSEC',
12
+ 'next domain' : 'host.example.com.',
13
+ 'type bit maps': 'A MX RRSIG NSEC TYPE1234',
14
+ testB : `alfa.example.com.\t86400\tIN\tNSEC\thost.example.com.\tA MX RRSIG NSEC TYPE1234\n`,
15
+ // testT : '\n',
16
+ },
17
+ ]
18
+
19
+ const invalidRecords = [
20
+ // {
21
+ // },
22
+ ]
23
+
24
+ describe('NSEC record', function () {
25
+ base.valid(NSEC, validRecords)
26
+ base.invalid(NSEC, invalidRecords, { ttl: 3600 })
27
+
28
+ base.getDescription(NSEC)
29
+ base.getRFCs(NSEC, validRecords[0])
30
+ base.getFields(NSEC, [ 'next domain', 'type bit maps' ])
31
+ base.getTypeId(NSEC, 47)
32
+
33
+ base.toBind(NSEC, validRecords)
34
+ // base.toTinydns(NSEC, validRecords)
35
+
36
+ base.fromBind(NSEC, validRecords)
37
+ // base.fromTinydns(NSEC, validRecords)
38
+ })
package/test/nsec3.js ADDED
@@ -0,0 +1,26 @@
1
+
2
+ import * as base from './base.js'
3
+
4
+ import NSEC3 from '../rr/nsec3.js'
5
+
6
+ const validRecords = [
7
+ ]
8
+
9
+ const invalidRecords = [
10
+ ]
11
+
12
+ describe('NSEC3 record', function () {
13
+ base.valid(NSEC3, validRecords)
14
+ base.invalid(NSEC3, invalidRecords, { ttl: 3600 })
15
+
16
+ base.getDescription(NSEC3)
17
+ base.getRFCs(NSEC3, validRecords[0])
18
+ base.getFields(NSEC3, [ 'hash algorithm', 'flags', 'iterations', 'salt', 'next hashed owner name', 'type bit maps' ])
19
+ base.getTypeId(NSEC3, 50)
20
+
21
+ // base.toBind(NSEC3, validRecords)
22
+ // base.toTinydns(NSEC3, validRecords)
23
+
24
+ // base.fromBind(NSEC3, validRecords)
25
+ // base.fromTinydns(NSEC3, validRecords)
26
+ })
@@ -0,0 +1,26 @@
1
+
2
+ import * as base from './base.js'
3
+
4
+ import NSEC3PARAM from '../rr/nsec3param.js'
5
+
6
+ const validRecords = [
7
+ ]
8
+
9
+ const invalidRecords = [
10
+ ]
11
+
12
+ describe('NSEC3PARAM record', function () {
13
+ base.valid(NSEC3PARAM, validRecords)
14
+ base.invalid(NSEC3PARAM, invalidRecords, { ttl: 3600 })
15
+
16
+ base.getDescription(NSEC3PARAM)
17
+ base.getRFCs(NSEC3PARAM, validRecords[0])
18
+ base.getFields(NSEC3PARAM, [ 'hash algorithm', 'flags', 'iterations', 'salt' ])
19
+ base.getTypeId(NSEC3PARAM, 51)
20
+
21
+ // base.toBind(NSEC3PARAM, validRecords)
22
+ // base.toTinydns(NSEC3PARAM, validRecords)
23
+
24
+ // base.fromBind(NSEC3PARAM, validRecords)
25
+ // base.fromTinydns(NSEC3PARAM, validRecords)
26
+ })
@@ -0,0 +1,35 @@
1
+
2
+ import * as base from './base.js'
3
+
4
+ import OPENPGPKEY from '../rr/openpgpkey.js'
5
+
6
+ const validRecords = [
7
+ // {
8
+ // owner : 'example.com.',
9
+ // ttl : 3600,
10
+ // class : 'IN',
11
+ // type : 'OPENPGPKEY',
12
+ // 'public key': ``,
13
+ // testB : '',
14
+ // testT : '',
15
+ // },
16
+ ]
17
+
18
+ const invalidRecords = [
19
+ ]
20
+
21
+ describe('OPENPGPKEY record', function () {
22
+ base.valid(OPENPGPKEY, validRecords)
23
+ base.invalid(OPENPGPKEY, invalidRecords, { ttl: 3600 })
24
+
25
+ base.getDescription(OPENPGPKEY)
26
+ base.getRFCs(OPENPGPKEY)
27
+ base.getFields(OPENPGPKEY, [ 'public key' ])
28
+ base.getTypeId(OPENPGPKEY, 61)
29
+
30
+ base.toBind(OPENPGPKEY, validRecords)
31
+ // base.toTinydns(OPENPGPKEY, validRecords)
32
+
33
+ base.fromBind(OPENPGPKEY, validRecords)
34
+ // base.fromTinydns(OPENPGPKEY, validRecords)
35
+ })
package/test/ptr.js ADDED
@@ -0,0 +1,54 @@
1
+
2
+ import assert from 'assert'
3
+
4
+ import * as base from './base.js'
5
+
6
+ import PTR from '../rr/ptr.js'
7
+
8
+ const defaults = { class: 'IN', ttl: 86400, type: 'PTR' }
9
+
10
+ const validRecords = [
11
+ {
12
+ ...defaults,
13
+ owner: '2.2.0.192.in-addr.arpa.',
14
+ dname: 'dhcp.example.com.',
15
+ testB: '2.2.0.192.in-addr.arpa.\t86400\tIN\tPTR\tdhcp.example.com.\n',
16
+ testT: '^2.2.0.192.in-addr.arpa:dhcp.example.com:86400::\n',
17
+ },
18
+ ]
19
+
20
+ const invalidRecords = [
21
+ {
22
+ ...defaults,
23
+ owner: 'example.com.',
24
+ dname: '192.0.2.4', // FQDN required
25
+ msg : /dname must be fully qualified/,
26
+ },
27
+ ]
28
+
29
+ describe('PTR record', function () {
30
+ base.valid(PTR, validRecords)
31
+ base.invalid(PTR, invalidRecords)
32
+
33
+ base.getDescription(PTR)
34
+ base.getRFCs(PTR, validRecords[0])
35
+ base.getFields(PTR, [ 'dname' ])
36
+ base.getTypeId(PTR, 12)
37
+
38
+ base.toBind(PTR, validRecords)
39
+ base.toTinydns(PTR, validRecords)
40
+
41
+ base.fromBind(PTR, validRecords)
42
+ base.fromTinydns(PTR, validRecords)
43
+
44
+ for (const val of validRecords) {
45
+
46
+ it.skip(`imports tinydns PTR (^) record (${val.owner})`, async function () {
47
+ const r = new PTR({ tinyline: val.testT })
48
+ if (process.env.DEBUG) console.dir(r)
49
+ for (const f of [ 'owner', 'dname', 'ttl' ]) {
50
+ assert.deepStrictEqual(r.get(f), val[f], `${f}: ${r.get(f)} !== ${val[f]}`)
51
+ }
52
+ })
53
+ }
54
+ })
package/test/rr.js ADDED
@@ -0,0 +1,196 @@
1
+
2
+ import assert from 'assert'
3
+
4
+ import RR from '../rr.js'
5
+ import A from '../rr/a.js'
6
+
7
+ const cases = [
8
+ // { name: 'RR class' , obj: RR , expect: [ 'owner', 'ttl', 'class', 'type' ] },
9
+ { name: 'RR instance', obj: new RR(null), expect: [ 'owner', 'ttl', 'class', 'type' ] },
10
+ // { name: 'A class' , obj: A , expect: [ 'owner', 'ttl', 'class', 'type', 'address' ] },
11
+ { name: 'A instance' , obj: new A(null) , expect: [ 'owner', 'ttl', 'class', 'type', 'address' ] },
12
+ ]
13
+
14
+ for (const c of cases) {
15
+ describe(`${c.name}`, function () {
16
+ describe('getFields', function () {
17
+ it('gets expected fields', async function () {
18
+ assert.deepStrictEqual(c.obj.getFields(), c.expect)
19
+ })
20
+ })
21
+ })
22
+ }
23
+
24
+ describe('RR', function () {
25
+ const r = new RR(null)
26
+
27
+ describe('setTtl', function () {
28
+ const invalid = [ -1, -4, -299, 2147483648, undefined ]
29
+ for (const i of invalid) {
30
+ it(`throws on invalid TTL: ${i}`, async function () {
31
+ try {
32
+ assert.deepStrictEqual(r.setTtl(i), false)
33
+ }
34
+ catch (e) {
35
+ assert.ok(e.message)
36
+ console.error(e.message)
37
+ }
38
+ })
39
+ }
40
+ })
41
+
42
+ describe('setClass', function () {
43
+ for (const i of [ 'IN', 'CH', 'ANY', 'NONE' ]) {
44
+ it(`accepts valid class: ${i}`, async function () {
45
+ r.setClass(i)
46
+ assert.deepEqual(r.get('class'), i)
47
+ })
48
+ }
49
+
50
+ for (const i of [ 'matt', 'in', 0 ]) {
51
+ it(`throws on invalid class: ${i}`, async function () {
52
+ try {
53
+ assert.strictEqual(r.setClass(i), false)
54
+ }
55
+ catch (e) {
56
+ assert.ok(e.message)
57
+ }
58
+ })
59
+ }
60
+ })
61
+
62
+ describe('fullyQualify', function () {
63
+ it('does nothing to empty hostname', async () => {
64
+ assert.equal(r.fullyQualify(''), '')
65
+ })
66
+
67
+ it('fully qualifies a valid hostname', async () => {
68
+ assert.equal(r.fullyQualify('example.com'), 'example.com.')
69
+ })
70
+ })
71
+
72
+ describe('getFQDN', function () {
73
+ it('adds a period to hostnames', async () => {
74
+ const rr = new RR(null)
75
+ rr.set('owner', 'www.example.com') // bypass FQ check
76
+ assert.equal(rr.getFQDN('owner'), 'www.example.com.')
77
+ })
78
+
79
+ it('reduces origin on request', async () => {
80
+ const rr = new RR(null)
81
+ const zone_opts = { origin: 'example.com.', hide: { origin: true } }
82
+ rr.setOwner('www.example.com.')
83
+ assert.equal(rr.getFQDN('owner', zone_opts), 'www')
84
+ })
85
+ })
86
+
87
+ describe('isFullyQualified', function () {
88
+ it('should detect FQDNs', async function () {
89
+ assert.deepEqual(r.isFullyQualified('$type', '$field', 'host.example.com.'), true)
90
+
91
+ try {
92
+ assert.deepEqual(r.isFullyQualified('$type', '$field', 'host.example.com'), false)
93
+ }
94
+ catch (e) {
95
+ assert.deepEqual(e.message, '$type: $field must be fully qualified')
96
+ }
97
+ })
98
+ })
99
+
100
+ describe('is8bitInt', function () {
101
+ const valid = [ 1, 2, 255 ]
102
+ const invalid = [ -1, 'a', new Date(), undefined, 256 ]
103
+
104
+ for (const i of valid) {
105
+ it(`returns true for valid int: ${i}`, async function () {
106
+ assert.strictEqual(r.is8bitInt('test', 'field', i), true)
107
+ })
108
+ }
109
+
110
+ for (const i of invalid) {
111
+ it(`throws on invalid int: ${i}`, async function () {
112
+ try {
113
+ assert.strictEqual(r.is8bitInt('test', 'field', i), false)
114
+ }
115
+ catch (e) {
116
+ assert.strictEqual(e.message, 'test field must be a 8-bit integer (in the range 0-255)')
117
+ }
118
+ })
119
+ }
120
+ })
121
+
122
+ describe('is16bitInt', function () {
123
+ const valid = [ 0, 1, 2, 55555, 65535 ]
124
+ const invalid = [ 'a', new Date(), undefined, 65536 ]
125
+
126
+ for (const i of valid) {
127
+ it(`returns true for valid int: ${i}`, async function () {
128
+ assert.strictEqual(r.is16bitInt('test', 'field', i), true)
129
+ })
130
+ }
131
+
132
+ for (const i of invalid) {
133
+ it(`throws on invalid int: ${i}`, async function () {
134
+ try {
135
+ assert.strictEqual(r.is16bitInt('test', 'field', i), false)
136
+ }
137
+ catch (e) {
138
+ assert.strictEqual(e.message, 'test field must be a 16-bit integer (in the range 0-65535)')
139
+ }
140
+ })
141
+ }
142
+ })
143
+
144
+ describe('is32bitInt', function () {
145
+ const valid = [ 1, 2, 55555, 2147483647 ]
146
+ const invalid = [ 'a', new Date(), undefined, 2147483648 ]
147
+
148
+ for (const i of valid) {
149
+ it(`returns true for valid int: ${i}`, async function () {
150
+ assert.strictEqual(r.is32bitInt('test', 'field', i), true)
151
+ })
152
+ }
153
+
154
+ for (const i of invalid) {
155
+ it(`throws on invalid int: ${i}`, async function () {
156
+ try {
157
+ assert.strictEqual(r.is32bitInt('test', 'field', i), false)
158
+ }
159
+ catch (e) {
160
+ assert.strictEqual(e.message, 'test field must be a 32-bit integer (in the range 0-2147483647)')
161
+ }
162
+ })
163
+ }
164
+ })
165
+
166
+ describe('getQuoted', function () {
167
+ it('returns a quoted string', async () => {
168
+ r.set('cpu', '"already quoted"')
169
+ assert.equal(r.get('cpu'), '"already quoted"')
170
+ assert.equal(r.getQuoted('cpu'), '"already quoted"') // doesn't double quote
171
+ })
172
+
173
+ it('doesn\'t double quote a quoted string', async () => {
174
+ r.set('cpu', '"already quoted"')
175
+ assert.equal(r.getQuoted('cpu'), '"already quoted"')
176
+ })
177
+ })
178
+
179
+ describe('isQuoted', function () {
180
+ it('detects a quoted strings', async function () {
181
+ assert.deepEqual(r.isQuoted('"yes, this is"'), true)
182
+ })
183
+
184
+ it('detects non-quoted strings', async function () {
185
+ assert.deepEqual(r.isQuoted('nope, not quoted'), false)
186
+ })
187
+ })
188
+
189
+ describe('isValidHostname', function () {
190
+ for (const n of [ 'x', '2x', '*', '*.something' ]) {
191
+ it(`passes name: ${n}`, async function () {
192
+ assert.deepEqual(r.isValidHostname(n), true)
193
+ })
194
+ }
195
+ })
196
+ })
package/test/smimea.js ADDED
@@ -0,0 +1,45 @@
1
+
2
+ import * as base from './base.js'
3
+
4
+ import SMIMEA from '../rr/smimea.js'
5
+
6
+ const defaults = { class: 'IN', ttl: 3600, type: 'SMIMEA' }
7
+
8
+ const validRecords = [
9
+ {
10
+ ...defaults,
11
+ owner : '_443._tcp.www.example.com.',
12
+ ttl : 3600,
13
+ 'certificate usage' : 0,
14
+ selector : 0,
15
+ 'matching type' : 1,
16
+ 'certificate association data': '( d2abde240d7cd3ee6b4b28c54df034b9 7983a1d16e8a410e4561cb106618e971 )',
17
+ testB : '_443._tcp.www.example.com.\t3600\tIN\tSMIMEA\t0\t0\t1\t( d2abde240d7cd3ee6b4b28c54df034b9 7983a1d16e8a410e4561cb106618e971 )\n',
18
+ // testT : '',
19
+ },
20
+ ]
21
+
22
+ const invalidRecords = [
23
+ {
24
+ ...defaults,
25
+ owner : 'test.example.com.',
26
+ selector: 6, // invalid
27
+ msg : /certificate usage invalid/,
28
+ },
29
+ ]
30
+
31
+ describe('SMIMEA record', function () {
32
+ base.valid(SMIMEA, validRecords)
33
+ base.invalid(SMIMEA, invalidRecords)
34
+
35
+ base.getDescription(SMIMEA)
36
+ base.getRFCs(SMIMEA, validRecords[0])
37
+ base.getFields(SMIMEA, [ 'certificate usage', 'selector', 'matching type', 'certificate association data' ])
38
+ base.getTypeId(SMIMEA, 53)
39
+
40
+ base.toBind(SMIMEA, validRecords)
41
+ // base.toTinydns(SMIMEA, validRecords)
42
+
43
+ base.fromBind(SMIMEA, validRecords)
44
+ // base.fromTinydns(SMIMEA, validRecords)
45
+ })
package/test/soa.js ADDED
@@ -0,0 +1,77 @@
1
+
2
+ import assert from 'assert'
3
+
4
+ import * as base from './base.js'
5
+
6
+ import SOA from '../rr/soa.js'
7
+
8
+ const defaults = { class: 'IN', ttl: 3600, type: 'SOA' }
9
+
10
+ const validRecords = [
11
+ {
12
+ ...defaults,
13
+ owner : 'example.com.',
14
+ mname : 'ns1.example.com.',
15
+ rname : 'matt.example.com.',
16
+ serial : 1,
17
+ refresh: 7200,
18
+ retry : 3600,
19
+ expire : 1209600,
20
+ minimum: 3600,
21
+ testB : `example.com.\t3600\tIN\tSOA\tns1.example.com.\tmatt.example.com.\t1\t7200\t3600\t1209600\t3600\n`,
22
+ testT : 'Zexample.com:ns1.example.com:matt.example.com:1:7200:3600:1209600:3600:3600::\n',
23
+ },
24
+ {
25
+ ...defaults,
26
+ owner : '2.example.com.',
27
+ mname : 'ns2.example.com.',
28
+ rname : 'matt.example.com.',
29
+ serial : 1,
30
+ refresh: 7200,
31
+ retry : 3600,
32
+ expire : 1209600,
33
+ minimum: 3600,
34
+ testB : `2.example.com.\t3600\tIN\tSOA\tns2.example.com.\tmatt.example.com.\t1\t7200\t3600\t1209600\t3600\n`,
35
+ testT : 'Z2.example.com:ns2.example.com:matt.example.com:1:7200:3600:1209600:3600:3600::\n',
36
+ },
37
+ ]
38
+
39
+ const invalidRecords = [
40
+ {
41
+ ...defaults,
42
+ owner : 'example.com.',
43
+ mname : 'ns1.example.com.',
44
+ rname : 'matt.example.com.',
45
+ serial : 4294967296,
46
+ refresh: 7200,
47
+ retry : 3600,
48
+ expire : 1209600,
49
+ msg : /serial must be a 32-bit integer/,
50
+ },
51
+ ]
52
+
53
+ describe('SOA record', function () {
54
+ base.valid(SOA, validRecords)
55
+ base.invalid(SOA, invalidRecords)
56
+
57
+ base.getDescription(SOA)
58
+ base.getRFCs(SOA, validRecords[0])
59
+ base.getFields(SOA, [ 'mname', 'rname', 'serial', 'refresh', 'retry', 'expire', 'minimum' ])
60
+ base.getTypeId(SOA, 6)
61
+
62
+ base.toBind(SOA, validRecords)
63
+ base.toTinydns(SOA, validRecords)
64
+
65
+ base.fromBind(SOA, validRecords)
66
+ base.fromTinydns(SOA, validRecords)
67
+
68
+ for (const val of validRecords) {
69
+ it.skip(`imports tinydns SOA (Z) record (${val.owner})`, async function () {
70
+ const r = new SOA({ tinyline: val.testT })
71
+ if (process.env.DEBUG) console.dir(r)
72
+ for (const f of [ 'owner', 'mname', 'rname', 'serial', 'refresh', 'retry', 'expire', 'ttl' ]) {
73
+ assert.deepStrictEqual(r.get(f), val[f], `${f}: ${r.get(f)} !== ${val[f]}`)
74
+ }
75
+ })
76
+ }
77
+ })
package/test/spf.js ADDED
@@ -0,0 +1,48 @@
1
+
2
+ import assert from 'assert'
3
+
4
+ import * as base from './base.js'
5
+
6
+ import SPF from '../rr/spf.js'
7
+
8
+ const defaults = { class: 'IN', ttl: 86400, type: 'SPF' }
9
+
10
+ const validRecords = [
11
+ {
12
+ ...defaults,
13
+ owner: 'example.com.',
14
+ data : 'v=spf1 mx a include:mx.example.com -all',
15
+ testB: 'example.com.\t86400\tIN\tSPF\t"v=spf1 mx a include:mx.example.com -all"\n',
16
+ testT: ':example.com:99:v=spf1 mx a include\\072mx.example.com -all:86400::\n',
17
+ },
18
+ ]
19
+
20
+ const invalidRecords = [
21
+
22
+ ]
23
+
24
+ describe('SPF record', function () {
25
+ base.valid(SPF, validRecords)
26
+ base.invalid(SPF, invalidRecords)
27
+
28
+ base.getDescription(SPF)
29
+ base.getRFCs(SPF, validRecords[0])
30
+ base.getFields(SPF, [ 'data' ])
31
+ base.getTypeId(SPF, 99)
32
+
33
+ base.toBind(SPF, validRecords)
34
+ base.toTinydns(SPF, validRecords)
35
+
36
+ base.fromBind(SPF, validRecords)
37
+ base.fromTinydns(SPF, validRecords)
38
+
39
+ for (const val of validRecords) {
40
+ it.skip(`imports tinydns SPF (generic) record`, async function () {
41
+ const r = new SPF({ tinyline: val.testT })
42
+ if (process.env.DEBUG) console.dir(r)
43
+ for (const f of [ 'owner', 'data', 'ttl' ]) {
44
+ assert.deepStrictEqual(r.get(f), val[f], `${f}: ${r.get(f)} !== ${val[f]}`)
45
+ }
46
+ })
47
+ }
48
+ })
package/test/srv.js ADDED
@@ -0,0 +1,81 @@
1
+
2
+ import assert from 'assert'
3
+
4
+ import * as base from './base.js'
5
+
6
+ import SRV from '../rr/srv.js'
7
+
8
+ const defaults = { class: 'IN', ttl: 3600, type: 'SRV' }
9
+
10
+ const validRecords = [
11
+ {
12
+ ...defaults,
13
+ owner : '_imaps._tcp.example.com.',
14
+ priority: 1,
15
+ weight : 0,
16
+ port : 993,
17
+ target : 'mail.example.com.',
18
+ testB : '_imaps._tcp.example.com.\t3600\tIN\tSRV\t1\t0\t993\tmail.example.com.\n',
19
+ testT : ':_imaps._tcp.example.com:33:\\000\\001\\000\\000\\003\\341\\004mail\\007example\\003com\\000:3600::\n',
20
+ },
21
+ {
22
+ ...defaults,
23
+ owner : '_sip._tls.example.com.',
24
+ priority: 100,
25
+ weight : 1,
26
+ port : 443,
27
+ target : 'sipdir.online.lync.com.',
28
+ testB : '_sip._tls.example.com.\t3600\tIN\tSRV\t100\t1\t443\tsipdir.online.lync.com.\n',
29
+ testT : ':_sip._tls.example.com:33:\\000\\144\\000\\001\\001\\273\\006sipdir\\006online\\004lync\\003com\\000:3600::\n',
30
+ },
31
+ ]
32
+
33
+ const invalidRecords = [
34
+ {
35
+ ...defaults,
36
+ owner : 'test.example.com.',
37
+ target: 'not-full-qualified.example.com',
38
+ msg : /must be a 16-bit integer/,
39
+ },
40
+ {
41
+ ...defaults,
42
+ owner : 'test.example.com.',
43
+ target: '192.168.0.1',
44
+ msg : /must be a 16-bit integer/,
45
+ },
46
+ ]
47
+
48
+ describe('SRV record', function () {
49
+ base.valid(SRV, validRecords)
50
+ base.invalid(SRV, invalidRecords)
51
+
52
+ base.getDescription(SRV)
53
+ base.getRFCs(SRV, validRecords[0])
54
+ base.getFields(SRV, [ 'priority', 'weight', 'port', 'target' ])
55
+ base.getTypeId(SRV, 33)
56
+
57
+ base.toBind(SRV, validRecords)
58
+ base.toTinydns(SRV, validRecords)
59
+
60
+ base.fromBind(SRV, validRecords)
61
+ base.fromTinydns(SRV, validRecords)
62
+
63
+ for (const val of validRecords) {
64
+ it(`imports tinydns SRV (generic) record (${val.owner})`, async function () {
65
+ const r = new SRV({ tinyline: val.testT })
66
+ if (process.env.DEBUG) console.dir(r)
67
+ for (const f of [ 'owner', 'target', 'priority', 'weight', 'port', 'ttl' ]) {
68
+ assert.deepStrictEqual(r.get(f), val[f], `${f}: ${r.get(f)} !== ${val[f]}`)
69
+ }
70
+ })
71
+ }
72
+
73
+ it(`imports tinydns SRV (S) record`, async function () {
74
+ const val = validRecords[0]
75
+ const r = new SRV({ tinyline: 'S_imaps._tcp.example.com:mail.example.com:993:1:0:3600::' })
76
+ if (process.env.DEBUG) console.dir(r)
77
+ for (const f of [ 'owner', 'target', 'priority', 'weight', 'port', 'ttl' ]) {
78
+ assert.deepStrictEqual(r.get(f), val[f], `${f}: ${r.get(f)} !== ${val[f]}`)
79
+ }
80
+ })
81
+ })