@nictool/dns-resource-record 1.1.7 → 1.2.1

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 (75) hide show
  1. package/CHANGELOG.md +26 -43
  2. package/README.md +48 -48
  3. package/index.js +83 -29
  4. package/lib/tinydns.js +68 -61
  5. package/package.json +1 -2
  6. package/rr/a.js +32 -23
  7. package/rr/aaaa.js +49 -35
  8. package/rr/caa.js +56 -44
  9. package/rr/cert.js +21 -19
  10. package/rr/cname.js +22 -23
  11. package/rr/dname.js +23 -23
  12. package/rr/dnskey.js +45 -43
  13. package/rr/ds.js +40 -40
  14. package/rr/hinfo.js +29 -28
  15. package/rr/https.js +62 -0
  16. package/rr/ipseckey.js +69 -50
  17. package/rr/key.js +23 -23
  18. package/rr/loc.js +71 -58
  19. package/rr/mx.js +41 -27
  20. package/rr/naptr.js +52 -53
  21. package/rr/ns.js +26 -23
  22. package/rr/nsec.js +24 -20
  23. package/rr/nsec3.js +59 -46
  24. package/rr/nsec3param.js +24 -26
  25. package/rr/nxt.js +65 -0
  26. package/rr/openpgpkey.js +18 -15
  27. package/rr/ptr.js +20 -21
  28. package/rr/rrsig.js +28 -23
  29. package/rr/sig.js +25 -20
  30. package/rr/smimea.js +36 -31
  31. package/rr/soa.js +56 -42
  32. package/rr/spf.js +21 -18
  33. package/rr/srv.js +45 -45
  34. package/rr/sshfp.js +30 -31
  35. package/rr/svcb.js +64 -0
  36. package/rr/tlsa.js +50 -45
  37. package/rr/tsig.js +56 -0
  38. package/rr/txt.js +42 -35
  39. package/rr/uri.js +33 -33
  40. package/rr/wks.js +45 -0
  41. package/rr.js +133 -87
  42. package/.codeclimate.yml +0 -25
  43. package/DEVELOP.md +0 -23
  44. package/test/a.js +0 -76
  45. package/test/aaaa.js +0 -79
  46. package/test/base.js +0 -138
  47. package/test/caa.js +0 -104
  48. package/test/cert.js +0 -48
  49. package/test/cname.js +0 -41
  50. package/test/dname.js +0 -53
  51. package/test/dnskey.js +0 -44
  52. package/test/ds.js +0 -44
  53. package/test/fake.js +0 -26
  54. package/test/hinfo.js +0 -75
  55. package/test/ipseckey.js +0 -115
  56. package/test/key.js +0 -37
  57. package/test/loc.js +0 -71
  58. package/test/mx.js +0 -75
  59. package/test/naptr.js +0 -40
  60. package/test/ns.js +0 -53
  61. package/test/nsec.js +0 -38
  62. package/test/nsec3.js +0 -40
  63. package/test/nsec3param.js +0 -26
  64. package/test/openpgpkey.js +0 -35
  65. package/test/ptr.js +0 -54
  66. package/test/rr.js +0 -196
  67. package/test/smimea.js +0 -45
  68. package/test/soa.js +0 -77
  69. package/test/spf.js +0 -48
  70. package/test/srv.js +0 -81
  71. package/test/sshfp.js +0 -62
  72. package/test/tinydns.js +0 -140
  73. package/test/tlsa.js +0 -54
  74. package/test/txt.js +0 -70
  75. package/test/uri.js +0 -61
package/test/key.js DELETED
@@ -1,37 +0,0 @@
1
-
2
- import * as base from './base.js'
3
-
4
- import KEY from '../rr/key.js'
5
-
6
- const validRecords = [
7
- {
8
- owner : 'example.com.',
9
- ttl : 3600,
10
- class : 'IN',
11
- type : 'KEY',
12
- flags : 256,
13
- protocol : 3,
14
- algorithm: 5,
15
- publickey: `( AQPSKmynfzW4kyBv015MUG2DeIQ3 Cbl+BBZH4b/0PY1kxkmvHjcZc8no kfzj31GajIQKY+5CptLr3buXA10h WqTkF7H6RfoRqXQeogmMHfpftf6z Mv1LyBUgia7za6ZEzOJBOztyvhjL 742iU/TpPSEDhm2SNKLijfUppn1U aNvv4w== )`,
16
- testB : 'example.com.\t3600\tIN\tKEY\t256\t3\t5\t( AQPSKmynfzW4kyBv015MUG2DeIQ3 Cbl+BBZH4b/0PY1kxkmvHjcZc8no kfzj31GajIQKY+5CptLr3buXA10h WqTkF7H6RfoRqXQeogmMHfpftf6z Mv1LyBUgia7za6ZEzOJBOztyvhjL 742iU/TpPSEDhm2SNKLijfUppn1U aNvv4w== )\n',
17
- },
18
- ]
19
-
20
- const invalidRecords = [
21
- ]
22
-
23
- describe('KEY record', function () {
24
- base.valid(KEY, validRecords)
25
- base.invalid(KEY, invalidRecords, { ttl: 3600 })
26
-
27
- base.getDescription(KEY)
28
- base.getRFCs(KEY, validRecords[0])
29
- base.getFields(KEY, [ 'flags', 'protocol', 'algorithm', 'publickey' ])
30
- base.getTypeId(KEY, 25)
31
-
32
- base.toBind(KEY, validRecords)
33
- // base.toTinydns(KEY, validRecords)
34
-
35
- base.fromBind(KEY, validRecords)
36
- // base.fromTinydns(KEY, validRecords)
37
- })
package/test/loc.js DELETED
@@ -1,71 +0,0 @@
1
-
2
- import assert from 'assert'
3
-
4
- import * as base from './base.js'
5
-
6
- import LOC from '../rr/loc.js'
7
-
8
- const defaults = { class: 'IN', ttl: 3600, type: 'LOC' }
9
-
10
- const validRecords = [
11
- {
12
- ...defaults,
13
- owner : 'loc.home.example.com.',
14
- address: '47 43 47 N 122 21 35 W 132m 100m 100m 2m',
15
- testB : `loc.home.example.com.\t3600\tIN\tLOC\t47 43 47 N 122 21 35 W 132m 100m 100m 2m\n`,
16
- testT : ':loc.home.example.com:29:\\000\\024\\024\\042\\212\\075\\337\\070\\145\\276\\224\\150\\000\\230\\312\\020:3600::\n',
17
- },
18
- {
19
- ...defaults,
20
- owner : 'cambridge-net.kei.com.',
21
- address: '42 21 54 N 71 6 18 W -24m 30m',
22
- testB : 'cambridge-net.kei.com.\t3600\tIN\tLOC\t42 21 54 N 71 6 18 W -24m 30m\n',
23
- testT : ':cambridge-net.kei.com:29:\\000\\063\\000\\000\\211\\027\\055\\320\\160\\276\\025\\360\\000\\230\\215\\040:3600::\n',
24
- },
25
- {
26
- ...defaults,
27
- owner : 'rwy04l.logan-airport.boston.',
28
- address: '42 21 28.764 N 71 0 51.617 W -44m 2000m',
29
- testB : 'rwy04l.logan-airport.boston.\t3600\tIN\tLOC\t42 21 28.764 N 71 0 51.617 W -44m 2000m\n',
30
- testT : ':rwy04l.logan-airport.boston:29:\\000\\045\\000\\000\\211\\026\\313\\074\\160\\303\\020\\337\\000\\230\\205\\120:3600::\n',
31
- },
32
- ]
33
-
34
- const invalidRecords = [
35
- {
36
- ...defaults,
37
- owner : 'server.example.com.',
38
- address: '', // empty
39
- msg : /address is required/,
40
- },
41
- ]
42
-
43
- describe('LOC record', function () {
44
- base.valid(LOC, validRecords)
45
- base.invalid(LOC, invalidRecords)
46
-
47
- base.getDescription(LOC)
48
- base.getRFCs(LOC, validRecords[0])
49
- base.getFields(LOC, [ 'address' ])
50
- base.getTypeId(LOC, 29)
51
-
52
- base.toBind(LOC, validRecords)
53
- base.toTinydns(LOC, validRecords)
54
-
55
- describe('toExponent', function () {
56
- const loc = new LOC(validRecords[0])
57
- it('converts a SIZE/PREC to exponent format', function () {
58
- assert.equal(loc.toExponent(100), 18)
59
- })
60
- })
61
-
62
- describe('fromExponent', function () {
63
- const loc = new LOC(validRecords[0])
64
- it('decodes an exponent format to SIZE/PREC', function () {
65
- assert.equal(loc.fromExponent(18), 100)
66
- })
67
- })
68
-
69
- base.fromTinydns(LOC, validRecords)
70
- base.fromBind(LOC, validRecords)
71
- })
package/test/mx.js DELETED
@@ -1,75 +0,0 @@
1
-
2
- import assert from 'assert'
3
-
4
- import * as base from './base.js'
5
-
6
- import MX from '../rr/mx.js'
7
-
8
- const defaults = { class: 'IN', ttl: 3600, type: 'MX', preference: 0 }
9
-
10
- const validRecords = [
11
- {
12
- ...defaults,
13
- owner : 'test.example.com.',
14
- preference: 0,
15
- exchange : 'mail.example.com.',
16
- testB : 'test.example.com.\t3600\tIN\tMX\t0\tmail.example.com.\n',
17
- testT : '@test.example.com::mail.example.com:0:3600::\n',
18
- },
19
- {
20
- ...defaults,
21
- owner : 'www.example.com.',
22
- ttl : 86400,
23
- preference: 0,
24
- exchange : '.', // null MX, RFC 7505
25
- testB : 'www.example.com.\t86400\tIN\tMX\t0\t.\n',
26
- testT : '@www.example.com::.:0:86400::\n',
27
- },
28
- ]
29
-
30
- const invalidRecords = [
31
- {
32
- ...defaults,
33
- owner : 'test.example.com.',
34
- exchange: 'not-full-qualified.example.com',
35
- msg : /exchange must be fully qualified/,
36
- },
37
- {
38
- ...defaults,
39
- owner : 'test.example.com.',
40
- exchange: '192.0.2.1',
41
- msg : /exchange must be a FQDN/,
42
- },
43
- {
44
- ...defaults,
45
- owner : 'test.example.com.',
46
- exchange: '-blah',
47
- msg : /exchange must be fully qualified/,
48
- },
49
- ]
50
-
51
- describe('MX record', function () {
52
- base.valid(MX, validRecords)
53
- base.invalid(MX, invalidRecords)
54
-
55
- base.getDescription(MX)
56
- base.getRFCs(MX, validRecords[0])
57
- base.getFields(MX, [ 'preference', 'exchange' ])
58
- base.getTypeId(MX, 15)
59
-
60
- base.toBind(MX, validRecords)
61
- base.toTinydns(MX, validRecords)
62
-
63
- base.fromBind(MX, validRecords)
64
- base.fromTinydns(MX, validRecords)
65
-
66
- for (const val of validRecords) {
67
- it.skip(`imports tinydns MX (@) record (${val.owner})`, async function () {
68
- const r = new MX({ tinyline: val.testT })
69
- if (process.env.DEBUG) console.dir(r)
70
- for (const f of [ 'owner', 'exchange', 'preference', 'ttl' ]) {
71
- assert.deepStrictEqual(r.get(f), val[f], `${f}: ${r.get(f)} !== ${val[f]}`)
72
- }
73
- })
74
- }
75
- })
package/test/naptr.js DELETED
@@ -1,40 +0,0 @@
1
-
2
- import * as base from './base.js'
3
-
4
- import NAPTR from '../rr/naptr.js'
5
-
6
- const validRecords = [
7
- {
8
- owner : 'cid.urn.arpa.',
9
- ttl : 86400,
10
- class : 'IN',
11
- type : 'NAPTR',
12
- order : 100,
13
- preference : 10,
14
- flags : '',
15
- service : '',
16
- regexp : '!^urn:cid:.+@([^\\.]+\\.)(.*)$!\x02!i',
17
- replacement: '.',
18
- testB : 'cid.urn.arpa.\t86400\tIN\tNAPTR\t100\t10\t""\t""\t"!^urn:cid:.+@([^\\.]+\\.)(.*)$!\x02!i"\t.\n',
19
- testT : ':cid.urn.arpa:35:\\000\\144\\000\\012\\000\\000\\040!^urn\\072cid\\072.+@([^\\134.]+\\134.)(.*)$!\x02!i\\001.\\000:86400::\n',
20
- },
21
- ]
22
-
23
- const invalidRecords = [
24
- ]
25
-
26
- describe('NAPTR record', function () {
27
- base.valid(NAPTR, validRecords)
28
- base.invalid(NAPTR, invalidRecords)
29
-
30
- base.getDescription(NAPTR)
31
- base.getRFCs(NAPTR, validRecords[0])
32
- base.getFields(NAPTR, [ 'order', 'preference', 'flags', 'service', 'regexp', 'replacement' ])
33
- base.getTypeId(NAPTR, 35)
34
-
35
- base.toBind(NAPTR, validRecords)
36
- base.toTinydns(NAPTR, validRecords)
37
-
38
- base.fromBind(NAPTR, validRecords)
39
- base.fromTinydns(NAPTR, validRecords)
40
- })
package/test/ns.js DELETED
@@ -1,53 +0,0 @@
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 DELETED
@@ -1,38 +0,0 @@
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 DELETED
@@ -1,40 +0,0 @@
1
-
2
- import * as base from './base.js'
3
-
4
- import NSEC3 from '../rr/nsec3.js'
5
-
6
- const defaults = { class: 'IN', ttl: 3600, type: 'NSEC3' }
7
-
8
- const validRecords = [
9
- {
10
- ...defaults,
11
- owner : 'test.example.com.',
12
- 'hash algorithm' : 1,
13
- flags : 1,
14
- iterations : 12,
15
- salt : 'aabbccdd',
16
- 'type bit maps' : 'A\tRRSIG',
17
- 'next hashed owner name': '2vptu5timamqttgl4luu9kg21e0aor3s',
18
- testB : 'test.example.com.\t3600\tIN\tNSEC3\t1\t1\t12\taabbccdd\t(2vptu5timamqttgl4luu9kg21e0aor3s\tA\tRRSIG)\n',
19
- testT : ':test.example.com:50:\\001\\001\\000\\014aabbccdd2vptu5timamqttgl4luu9kg21e0aor3sA\\011RRSIG:3600::\n',
20
- },
21
- ]
22
-
23
- const invalidRecords = [
24
- ]
25
-
26
- describe('NSEC3 record', function () {
27
- base.valid(NSEC3, validRecords)
28
- base.invalid(NSEC3, invalidRecords, { ttl: 3600 })
29
-
30
- base.getDescription(NSEC3)
31
- base.getRFCs(NSEC3, validRecords[0])
32
- base.getFields(NSEC3, [ 'hash algorithm', 'flags', 'iterations', 'salt', 'next hashed owner name', 'type bit maps' ])
33
- base.getTypeId(NSEC3, 50)
34
-
35
- base.toBind(NSEC3, validRecords)
36
- base.toTinydns(NSEC3, validRecords)
37
-
38
- base.fromBind(NSEC3, validRecords)
39
- // base.fromTinydns(NSEC3, validRecords)
40
- })
@@ -1,26 +0,0 @@
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
- })
@@ -1,35 +0,0 @@
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 DELETED
@@ -1,54 +0,0 @@
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 DELETED
@@ -1,196 +0,0 @@
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
- })