@nictool/dns-resource-record 1.2.1 → 1.2.2

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 (52) hide show
  1. package/.codeclimate.yml +25 -0
  2. package/.github/FUNDING.yml +3 -0
  3. package/.github/workflows/ci.yml +43 -0
  4. package/.github/workflows/codeql.yml +14 -0
  5. package/.github/workflows/publish.yml +16 -0
  6. package/.gitmodules +3 -0
  7. package/.prettierrc.yml +3 -0
  8. package/CHANGELOG.md +9 -0
  9. package/DEVELOP.md +9 -0
  10. package/README.md +3 -1
  11. package/eslint.config.mjs +41 -0
  12. package/package.json +12 -3
  13. package/rr/caa.js +5 -3
  14. package/rr/hinfo.js +5 -3
  15. package/rr/openpgpkey.js +3 -3
  16. package/rr/tlsa.js +5 -3
  17. package/rr/txt.js +3 -3
  18. package/test/a.js +75 -0
  19. package/test/aaaa.js +86 -0
  20. package/test/base.js +148 -0
  21. package/test/caa.js +111 -0
  22. package/test/cert.js +48 -0
  23. package/test/cname.js +40 -0
  24. package/test/dname.js +57 -0
  25. package/test/dnskey.js +45 -0
  26. package/test/ds.js +45 -0
  27. package/test/fake.js +34 -0
  28. package/test/hinfo.js +80 -0
  29. package/test/https.js +56 -0
  30. package/test/ipseckey.js +141 -0
  31. package/test/key.js +36 -0
  32. package/test/loc.js +75 -0
  33. package/test/mx.js +78 -0
  34. package/test/naptr.js +47 -0
  35. package/test/ns.js +56 -0
  36. package/test/nsec.js +37 -0
  37. package/test/nsec3.js +47 -0
  38. package/test/nsec3param.js +23 -0
  39. package/test/nxt.js +37 -0
  40. package/test/openpgpkey.js +85 -0
  41. package/test/ptr.js +56 -0
  42. package/test/rr.js +212 -0
  43. package/test/smimea.js +51 -0
  44. package/test/soa.js +99 -0
  45. package/test/spf.js +51 -0
  46. package/test/srv.js +101 -0
  47. package/test/sshfp.js +69 -0
  48. package/test/svcb.js +56 -0
  49. package/test/tinydns.js +163 -0
  50. package/test/tlsa.js +63 -0
  51. package/test/txt.js +82 -0
  52. package/test/uri.js +65 -0
@@ -0,0 +1,25 @@
1
+ checks:
2
+ return-statements:
3
+ enabled: false
4
+ similar-code:
5
+ enabled: false
6
+ file-lines:
7
+ config:
8
+ threshold: 500
9
+ method-lines:
10
+ config:
11
+ threshold: 50
12
+ method-complexity:
13
+ config:
14
+ threshold: 10
15
+
16
+ plugins:
17
+ eslint:
18
+ enabled: true
19
+ channel: 'eslint-8'
20
+ config:
21
+ config: '.eslintrc.yaml'
22
+
23
+ ratings:
24
+ paths:
25
+ - '**.js'
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: msimerson
@@ -0,0 +1,43 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ env:
8
+ CI: true
9
+
10
+ jobs:
11
+ lint:
12
+ uses: NicTool/.github/.github/workflows/lint.yml@main
13
+
14
+ coverage:
15
+ uses: NicTool/.github/.github/workflows/coverage.yml@main
16
+ secrets: inherit
17
+
18
+ test:
19
+ needs: get-lts
20
+ runs-on: ${{ matrix.os }}
21
+ strategy:
22
+ matrix:
23
+ os: [ubuntu-latest, windows-latest, macos-latest]
24
+ node-version: ${{ fromJson(needs.get-lts.outputs.active) }}
25
+ fail-fast: false
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - uses: actions/setup-node@v4
29
+ name: Node ${{ matrix.node-version }} on ${{ matrix.os }}
30
+ with:
31
+ node-version: ${{ matrix.node-version }}
32
+ - run: npm install
33
+ - run: npm test
34
+
35
+ get-lts:
36
+ needs: lint
37
+ runs-on: ubuntu-latest
38
+ steps:
39
+ - id: get
40
+ uses: msimerson/node-lts-versions@v1
41
+ outputs:
42
+ lts: ${{ steps.get.outputs.lts }}
43
+ active: ${{ steps.get.outputs.active }}
@@ -0,0 +1,14 @@
1
+ name: CodeQL
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ # The branches below must be a subset of the branches above
8
+ branches: [main]
9
+ schedule:
10
+ - cron: '18 7 * * 4'
11
+
12
+ jobs:
13
+ codeql:
14
+ uses: NicTool/.github/.github/workflows/codeql.yml@main
@@ -0,0 +1,16 @@
1
+ name: publish
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths:
8
+ - package.json
9
+
10
+ env:
11
+ CI: true
12
+
13
+ jobs:
14
+ publish:
15
+ uses: NicTool/.github/.github/workflows/publish.yml@main
16
+ secrets: inherit
package/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule ".release"]
2
+ path = .release
3
+ url = https://github.com/msimerson/.release
@@ -0,0 +1,3 @@
1
+ trailingComma: 'all'
2
+ semi: false
3
+ singleQuote: true
package/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ Notable changes to this project are documented in this file.
4
4
 
5
5
  #### Unreleased
6
6
 
7
+ ### [1.2.2] - 2024-11-17
8
+
9
+ - dep(eslint): update to v9 & config
10
+ - chore: tighten up fromBind regex
11
+ - packaging tweaks (#43)
12
+
7
13
  ### [1.2.1] - 2024-03-10
8
14
 
9
15
  - fix(nsec3param): fixed setHash fname typo
@@ -295,3 +301,6 @@ Notable changes to this project are documented in this file.
295
301
  [1.1.6]: https://github.com/NicTool/dns-resource-record/releases/tag/1.1.6
296
302
  [1.1.8]: https://github.com/NicTool/dns-resource-record/releases/tag/1.1.8
297
303
  [1.2.1]: https://github.com/NicTool/dns-resource-record/releases/tag/1.2.1
304
+ [1.2.2]: https://github.com/NicTool/dns-resource-record/releases/tag/v1.2.2
305
+ [1.1.7]: https://github.com/NicTool/dns-resource-record/releases/tag/1.1.7
306
+ [1.2.0]: https://github.com/NicTool/dns-resource-record/releases/tag/1.2.0
package/DEVELOP.md ADDED
@@ -0,0 +1,9 @@
1
+ # Release process
2
+
3
+ In your local repo:
4
+
5
+ ```sh
6
+ git submodule update --init --recursive
7
+ ```
8
+
9
+ Read and follow the instructions in .release/README.md
package/README.md CHANGED
@@ -20,7 +20,7 @@ This module is used to:
20
20
  | **MaraDNS** | | :white_check_mark: |
21
21
  | **JS** | :white_check_mark: | :white_check_mark: |
22
22
 
23
- This package intends to import and export RFC compliant DNS resource records. Please [raise an issue](https://github.com/NicTool/dns-resource-record/issues) if you a valid resource record fails to pass or an invalid resource record passes.
23
+ This package intends to import and export RFC compliant DNS resource records. Please [raise an issue](https://github.com/NicTool/dns-resource-record/issues) if a valid resource record fails to pass or an invalid resource record passes.
24
24
 
25
25
  This package is for working with _individual_ Resource Records. For working with zones of RRs, use [dns-zone](https://github.com/NicTool/dns-zone).
26
26
 
@@ -239,6 +239,8 @@ PRs are welcome, especially PRs with tests.
239
239
 
240
240
  - [Dictionary of DNS terms](https://nictool.github.io/web/Dictionary)
241
241
  - [Wikipedia, List of DNS Record Types](https://en.wikipedia.org/wiki/List_of_DNS_record_types)
242
+ - @nictool/[dns-zone](https://www.npmjs.com/package/@nictool/dns-zone)
243
+ - @nictool/[dns-nameserver](https://www.npmjs.com/package/@nictool/dns-nameserver)
242
244
 
243
245
  ## TODO
244
246
 
@@ -0,0 +1,41 @@
1
+ import globals from 'globals'
2
+ import path from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import js from '@eslint/js'
5
+ import { FlatCompat } from '@eslint/eslintrc'
6
+
7
+ const __filename = fileURLToPath(import.meta.url)
8
+ const __dirname = path.dirname(__filename)
9
+ const compat = new FlatCompat({
10
+ baseDirectory: __dirname,
11
+ recommendedConfig: js.configs.recommended,
12
+ allConfig: js.configs.all,
13
+ })
14
+
15
+ export default [
16
+ {
17
+ languageOptions: {
18
+ ecmaVersion: 'latest',
19
+ globals: {
20
+ ...globals.node,
21
+ ...globals.browser,
22
+ ...globals.mocha,
23
+ },
24
+ sourceType: 'module',
25
+ },
26
+
27
+ rules: {
28
+ // 'no-undef': [ 'warn' ],
29
+ 'no-unused-vars': [
30
+ 'error',
31
+ {
32
+ args: 'none',
33
+ },
34
+ ],
35
+
36
+ 'dot-notation': 'error',
37
+ 'prefer-const': 'warn',
38
+ },
39
+ },
40
+ js.configs.recommended,
41
+ ]
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@nictool/dns-resource-record",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "DNS Resource Records",
5
5
  "main": "index.js",
6
+ "file": [
7
+ "lib",
8
+ "rr",
9
+ "CHANGELOG.md",
10
+ "rr.js"
11
+ ],
6
12
  "type": "module",
7
13
  "scripts": {
8
14
  "format:check": "npm run prettier; npm run lint",
9
15
  "format": "npm run prettier -- --write && npm run lint --fix",
10
- "lint": "npx eslint **/*.js",
16
+ "lint": "npx eslint@9 **/*.js",
11
17
  "lint:fix": "npm run lint -- --fix",
12
18
  "prettier": "npx prettier --ignore-path .gitignore --check .",
13
19
  "prettier:fix": "npx prettier --ignore-path .gitignore --write .",
@@ -39,6 +45,9 @@
39
45
  },
40
46
  "homepage": "https://github.com/NicTool/dns-resource-record#readme",
41
47
  "devDependencies": {
42
- "mocha": "^10.3.0"
48
+ "@eslint/js": "^9.15.0",
49
+ "eslint": "^9.15.0",
50
+ "globals": "^15.12.0",
51
+ "mocha": "^10.8.2"
43
52
  }
44
53
  }
package/rr/caa.js CHANGED
@@ -108,9 +108,11 @@ export default class CAA extends RR {
108
108
 
109
109
  fromBind(opts) {
110
110
  // test.example.com 3600 IN CAA flags, tags, value
111
- const fields = opts.bindline.match(
112
- /^([^\s]+)\s+([0-9]+)\s+(\w+)\s+(\w+)\s+([0-9]+)\s+(\w+)\s+("[^"]+"|[^\s]+?)\s*$/i,
113
- )
111
+ const fields = opts.bindline
112
+ .trim()
113
+ .match(
114
+ /^([\S]+)\s+([0-9]{1,10})\s+(IN)\s+(CAA)\s+([0-9]+)\s+(\w+)\s+("[^"]+"|[\S]+?)$/i,
115
+ )
114
116
  if (!fields) this.throwHelp(`unable to parse: ${opts.bindline}`)
115
117
 
116
118
  const [owner, ttl, c, type, flags, tag, value] = fields.slice(1)
package/rr/hinfo.js CHANGED
@@ -41,9 +41,11 @@ export default class HINFO extends RR {
41
41
  /****** IMPORTERS *******/
42
42
  fromBind(opts) {
43
43
  // test.example.com 3600 IN HINFO DEC-2060 TOPS20
44
- const match = opts.bindline.match(
45
- /([^\s]+)\s+([0-9]+)\s+(IN)\s+(HINFO)\s+("[^"]+"|[^\s]+)\s+("[^"]+"|[^\s]+)/i,
46
- )
44
+ const match = opts.bindline
45
+ .trim()
46
+ .match(
47
+ /^([\S]+)\s+([0-9]{1,10})\s+(IN)\s+(HINFO)\s+("[^"]+"|[\S]+)\s+("[^"]+"|[\S]+)/i,
48
+ )
47
49
  if (!match) this.throwHelp(`unable to parse HINFO: ${opts.bindline}`)
48
50
  const [owner, ttl, c, type, cpu, os] = match.slice(1)
49
51
 
package/rr/openpgpkey.js CHANGED
@@ -30,9 +30,9 @@ export default class OPENPGPKEY extends RR {
30
30
  fromBind(obj) {
31
31
  // test.example.com 3600 IN OPENPGPKEY <base64 public key>
32
32
  // eslint-disable-next-line no-unused-vars
33
- const [ignore, owner, ttl, c, type, publickey] = obj.bindline.match(
34
- /^([\S]+)\s+(\d+)\s+(\w+)\s+(\w+)\s+([\W\w]*)$/,
35
- )
33
+ const [ignore, owner, ttl, c, type, publickey] = obj.bindline
34
+ .trim()
35
+ .match(/^([\S]+)\s+(\d{1,10})\s+(IN)\s+(OPENPGPKEY)\s+([\W\w]*)$/)
36
36
 
37
37
  return new OPENPGPKEY({
38
38
  owner,
package/rr/tlsa.js CHANGED
@@ -60,9 +60,11 @@ export default class TLSA extends RR {
60
60
 
61
61
  fromBind(opts) {
62
62
  // test.example.com 3600 IN TLSA, usage, selector, match, data
63
- const match = opts.bindline.split(
64
- /^([^\s]+)\s+([0-9]+)\s+(\w+)\s+(\w+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+(.*?)\s*$/,
65
- )
63
+ const match = opts.bindline
64
+ .trim()
65
+ .split(
66
+ /^([^\s]+)\s+([0-9]{1,10})\s+(IN)\s+(TLSA)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+(.*?)$/,
67
+ )
66
68
  if (!match) this.throwHelp(`unable to parse TLSA: ${opts.bindline}`)
67
69
  const [owner, ttl, c, type, usage, selector, matchtype, cad] =
68
70
  match.slice(1)
package/rr/txt.js CHANGED
@@ -70,9 +70,9 @@ export default class TXT extends RR {
70
70
 
71
71
  fromBind(opts) {
72
72
  // test.example.com 3600 IN TXT "..."
73
- const match = opts.bindline.split(
74
- /^([^\s]+)\s+([0-9]+)\s+(\w+)\s+(\w+)\s+?\s*(.*?)\s*$/,
75
- )
73
+ const match = opts.bindline
74
+ .trim()
75
+ .split(/^([\S]{1,255})\s+([0-9]{1,10})\s+(IN)\s+(\w{3})\s+?\s*(.*?)$/i)
76
76
  if (!match) this.throwHelp(`unable to parse TXT: ${opts.bindline}`)
77
77
  const [owner, ttl, c, type, rdata] = match.slice(1)
78
78
 
package/test/a.js ADDED
@@ -0,0 +1,75 @@
1
+ import A from '../rr/a.js'
2
+ import * as base from './base.js'
3
+
4
+ const defaults = { class: 'IN', ttl: 3600, type: 'A', address: '192.0.2.127' }
5
+
6
+ const validRecords = [
7
+ {
8
+ ...defaults,
9
+ owner: 'test.example.com.',
10
+ testB: 'test.example.com.\t3600\tIN\tA\t192.0.2.127\n',
11
+ testT: '+test.example.com:192.0.2.127:3600::\n',
12
+ },
13
+ {
14
+ ...defaults,
15
+ owner: 'test.example.com.',
16
+ ttl: 2147483647,
17
+ testB: 'test.example.com.\t2147483647\tIN\tA\t192.0.2.127\n',
18
+ testT: '+test.example.com:192.0.2.127:2147483647::\n',
19
+ },
20
+ {
21
+ ...defaults,
22
+ owner: 'a.',
23
+ ttl: 86400,
24
+ testB: 'a.\t86400\tIN\tA\t192.0.2.127\n',
25
+ testT: '+a:192.0.2.127:86400::\n',
26
+ },
27
+ {
28
+ ...defaults,
29
+ owner: '*.example.com.',
30
+ testB: '*.example.com.\t3600\tIN\tA\t192.0.2.127\n',
31
+ testT: '+*.example.com:192.0.2.127:3600::\n',
32
+ },
33
+ ]
34
+
35
+ const invalidRecords = [
36
+ { ...defaults, owner: '', msg: /RFC/ },
37
+ { ...defaults, owner: 'something*', msg: /fully/ },
38
+ { ...defaults, owner: 'some*thing', msg: /fully/ },
39
+ { ...defaults, owner: '*something', msg: /fully/ },
40
+ { ...defaults, owner: 'something.*', msg: /fully/ },
41
+ { ...defaults, address: 'hosts.not.valid.here', msg: /address must be IPv4/ },
42
+ { ...defaults, address: '', msg: /address is required/ },
43
+ { ...defaults, address: undefined, msg: /address is required/ },
44
+ { ...defaults, address: '1.x.2.3', msg: /address must be IPv4/ },
45
+ { ...defaults, address: '.1.2.3', msg: /address must be IPv4/ },
46
+ { ...defaults, type: '', msg: /type is required/ },
47
+ { ...defaults, type: undefined, msg: /type is required/ },
48
+ { ...defaults, ttl: '', msg: /TTL must be numeric/ },
49
+ { ...defaults, ttl: -299, msg: /TTL must be a 32-bit integer/ },
50
+ { ...defaults, ttl: 2147483648, msg: /TTL must be a 32-bit integer/ },
51
+ ]
52
+
53
+ // copy invalid properties to a valid object
54
+ for (let i = 0; i < invalidRecords.length; i++) {
55
+ const temp = JSON.parse(JSON.stringify(validRecords[0]))
56
+ Object.assign(temp, invalidRecords[i])
57
+ invalidRecords[i] = temp
58
+ }
59
+
60
+ describe('A record', function () {
61
+ base.valid(A, validRecords)
62
+ base.invalid(A, invalidRecords)
63
+
64
+ base.getDescription(A)
65
+ base.getRFCs(A, validRecords[0])
66
+ base.getRdataFields(A, ['address'])
67
+ base.getFields(A, ['address'])
68
+ base.getTypeId(A, 1)
69
+
70
+ base.toBind(A, validRecords)
71
+ base.toTinydns(A, validRecords)
72
+
73
+ base.fromBind(A, validRecords)
74
+ base.fromTinydns(A, validRecords)
75
+ })
package/test/aaaa.js ADDED
@@ -0,0 +1,86 @@
1
+ import assert from 'assert'
2
+
3
+ import * as base from './base.js'
4
+ import AAAA from '../rr/aaaa.js'
5
+
6
+ const defaults = { class: 'IN', ttl: 3600, type: 'AAAA' }
7
+
8
+ const validRecords = [
9
+ {
10
+ ...defaults,
11
+ owner: 'test.example.com.',
12
+ address: '2001:0db8:0020:000a:0000:0000:0000:0004',
13
+ testB: 'test.example.com.\t3600\tIN\tAAAA\t2001:db8:20:a::4\n',
14
+ testT:
15
+ ':test.example.com:28:\\040\\001\\015\\270\\000\\040\\000\\012\\000\\000\\000\\000\\000\\000\\000\\004:3600::\n',
16
+ },
17
+ ]
18
+
19
+ const invalidRecords = [
20
+ {
21
+ ...defaults,
22
+ owner: 'test.example.com.',
23
+ address: '192.0.2.204',
24
+ msg: /address must be IPv6/,
25
+ },
26
+ ]
27
+
28
+ describe('AAAA record', function () {
29
+ base.valid(AAAA, validRecords)
30
+ base.invalid(AAAA, invalidRecords)
31
+
32
+ base.getDescription(AAAA)
33
+ base.getRFCs(AAAA, validRecords[0])
34
+ base.getFields(AAAA, ['address'])
35
+ base.getTypeId(AAAA, 28)
36
+
37
+ base.toBind(AAAA, validRecords)
38
+ base.toTinydns(AAAA, validRecords)
39
+
40
+ base.fromBind(AAAA, validRecords)
41
+ base.fromTinydns(AAAA, validRecords)
42
+
43
+ for (const val of validRecords) {
44
+ it(`imports tinydns AAAA (generic) record (${val.owner})`, async function () {
45
+ const r = new AAAA({ tinyline: val.testT })
46
+ if (process.env.DEBUG) console.dir(r)
47
+ for (const f of ['owner', 'address', 'ttl']) {
48
+ assert.deepStrictEqual(
49
+ r.get(f),
50
+ val[f],
51
+ `${f}: ${r.get(f)} !== ${val[f]}`,
52
+ )
53
+ }
54
+ })
55
+ }
56
+
57
+ const tests = [
58
+ { e: '2001:0db8:0020:000a:0000:0000:0000:0004', c: '2001:db8:20:a::4' },
59
+ { e: '0000:0000:0000:0000:0000:0000:0000:0000', c: '::' },
60
+ { e: '0000:0000:0000:0000:0000:0000:0000:0001', c: '::1' },
61
+ { e: '2001:0db8:0000:0000:0000:0000:0002:0001', c: '2001:db8::2:1' },
62
+ { e: '2001:0db8:0000:0001:0001:0001:0001:0001', c: '2001:db8:0:1:1:1:1:1' },
63
+ {
64
+ e: '2001:0DB8:0000:0000:0008:0800:200C:417A',
65
+ c: '2001:DB8::8:800:200C:417A',
66
+ },
67
+ ]
68
+
69
+ describe('compress', function () {
70
+ const r = new AAAA(null)
71
+ for (const t of tests) {
72
+ it(`compresses IPv6 address (${t.e})`, function () {
73
+ assert.equal(r.compress(t.e), t.c)
74
+ })
75
+ }
76
+ })
77
+
78
+ describe('expand', function () {
79
+ const r = new AAAA(null)
80
+ for (const t of tests) {
81
+ it(`expands IPv6 address (${t.c})`, function () {
82
+ assert.equal(r.expand(t.c), t.e)
83
+ })
84
+ }
85
+ })
86
+ })
package/test/base.js ADDED
@@ -0,0 +1,148 @@
1
+ import assert from 'assert'
2
+
3
+ export function valid(type, validRecords, defaults) {
4
+ describe('valid', function () {
5
+ for (const val of validRecords) {
6
+ // console.log(val)
7
+ it(`parses record: ${val.owner}`, function () {
8
+ if (defaults) val.default = defaults
9
+ const r = new type(val)
10
+ if (defaults) delete val.default
11
+ if (process.env.DEBUG) console.dir(r)
12
+
13
+ for (const k of Object.keys(val)) {
14
+ if (/^test/.test(k)) continue
15
+ assert.strictEqual(
16
+ r.get(k),
17
+ val[k],
18
+ `${type.name} ${k} ${r.get(k)} !== ${val[k]}`,
19
+ )
20
+ }
21
+ })
22
+ }
23
+ })
24
+ }
25
+
26
+ export function invalid(type, invalidRecords, defaults) {
27
+ describe('invalid', function () {
28
+ for (const inv of invalidRecords) {
29
+ if (defaults) inv.default = defaults
30
+ it(`throws on record (${inv.owner})`, function () {
31
+ assert.throws(
32
+ () => {
33
+ new type(inv)
34
+ },
35
+ {
36
+ message: inv.msg,
37
+ },
38
+ )
39
+ })
40
+ }
41
+ })
42
+ }
43
+
44
+ export function toBind(type, validRecords) {
45
+ describe('toBind', function () {
46
+ for (const val of validRecords) {
47
+ it(`exports to BIND: ${val.owner}`, function () {
48
+ const r = new type(val).toBind()
49
+ if (process.env.DEBUG) console.dir(r)
50
+ assert.strictEqual(r, val.testB)
51
+ })
52
+ }
53
+ })
54
+ }
55
+
56
+ export function toTinydns(type, validRecords) {
57
+ describe('toTinydns', function () {
58
+ for (const val of validRecords) {
59
+ if (val.testT === undefined) continue
60
+ it(`exports to tinydns: ${val.owner}`, function () {
61
+ const r = new type(val).toTinydns()
62
+ if (process.env.DEBUG) console.dir(r)
63
+ assert.strictEqual(r, val.testT)
64
+ })
65
+ }
66
+ })
67
+ }
68
+
69
+ export function getDescription(type) {
70
+ describe('getDescription', function () {
71
+ const desc = new type(null).getDescription()
72
+ it(`gets description: ${desc}`, function () {
73
+ assert.ok(desc)
74
+ })
75
+ })
76
+ }
77
+
78
+ export function getRFCs(type, valid) {
79
+ describe('getRFCs', function () {
80
+ const r = new type(null)
81
+ const rfcs = r.getRFCs()
82
+ it(`can retrieve RFCs: ${rfcs.join(',')}`, function () {
83
+ assert.ok(rfcs.length)
84
+ })
85
+ })
86
+ }
87
+
88
+ function checkFromNS(type, validRecords, nsName, nsLineName) {
89
+ for (const val of validRecords) {
90
+ const testLine = nsLineName === 'bindline' ? val.testB : val.testT
91
+ if (testLine == undefined) continue
92
+ it(`imports ${nsName} record: ${val.owner}`, function () {
93
+ const r = new type({ [nsLineName]: testLine })
94
+ if (process.env.DEBUG) console.dir(r)
95
+ for (const f of r.getFields()) {
96
+ if (f === 'class') continue
97
+ let expected = val[f]
98
+ if (f === 'data' && Array.isArray(expected))
99
+ expected = expected.join('') // TXT
100
+ assert.deepStrictEqual(
101
+ r.get(f),
102
+ expected,
103
+ `${f}: ${r.get(f)} !== ${expected}`,
104
+ )
105
+ }
106
+ })
107
+ }
108
+ }
109
+
110
+ export function fromTinydns(type, validRecords) {
111
+ describe('fromTinydns', function () {
112
+ checkFromNS(type, validRecords, 'tinydns', 'tinyline')
113
+ })
114
+ }
115
+
116
+ export function fromBind(type, validRecords) {
117
+ describe('fromBind', function () {
118
+ checkFromNS(type, validRecords, 'BIND', 'bindline')
119
+ })
120
+ }
121
+
122
+ export function getRdataFields(type, rdataFields) {
123
+ describe('getRdataFields', function () {
124
+ const r = new type(null)
125
+ it(`can retrieve rdata fields: (${r.getRdataFields('rdata')})`, function () {
126
+ assert.deepEqual(r.getRdataFields('rdata'), rdataFields)
127
+ })
128
+ })
129
+ }
130
+
131
+ export function getFields(type, rdataFields) {
132
+ describe('getFields', function () {
133
+ const r = new type(null)
134
+ it(`can retrieve record fields`, function () {
135
+ assert.deepEqual(r.getFields('rdata'), rdataFields)
136
+ assert.deepEqual(r.getFields(), r.getFields('common').concat(rdataFields))
137
+ })
138
+ })
139
+ }
140
+
141
+ export function getTypeId(type, val) {
142
+ describe('getTypeId', function () {
143
+ const r = new type(null)
144
+ it(`can retrieve record type ID (${r.getTypeId()})`, function () {
145
+ assert.deepEqual(r.getTypeId(), val)
146
+ })
147
+ })
148
+ }