@nictool/dns-resource-record 1.2.2 → 1.2.4
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.
- package/CHANGELOG.md +21 -2
- package/README.md +2 -13
- package/package.json +15 -9
- package/rr/a.js +1 -3
- package/rr/aaaa.js +6 -7
- package/rr/caa.js +13 -2
- package/rr/cname.js +1 -3
- package/rr/dname.js +1 -3
- package/rr/dnskey.js +38 -5
- package/rr/ds.js +13 -2
- package/rr/ipseckey.js +26 -10
- package/rr/key.js +14 -2
- package/rr/mx.js +1 -3
- package/rr/naptr.js +5 -1
- package/rr/rrsig.js +13 -2
- package/rr/smimea.js +29 -3
- package/rr/srv.js +1 -3
- package/rr/sshfp.js +20 -3
- package/rr/tlsa.js +29 -3
- package/rr.js +15 -6
- package/.codeclimate.yml +0 -25
- package/.github/FUNDING.yml +0 -3
- package/.github/workflows/ci.yml +0 -43
- package/.github/workflows/codeql.yml +0 -14
- package/.github/workflows/publish.yml +0 -16
- package/.gitmodules +0 -3
- package/.prettierrc.yml +0 -3
- package/DEVELOP.md +0 -9
- package/eslint.config.mjs +0 -41
- package/test/a.js +0 -75
- package/test/aaaa.js +0 -86
- package/test/base.js +0 -148
- package/test/caa.js +0 -111
- package/test/cert.js +0 -48
- package/test/cname.js +0 -40
- package/test/dname.js +0 -57
- package/test/dnskey.js +0 -45
- package/test/ds.js +0 -45
- package/test/fake.js +0 -34
- package/test/hinfo.js +0 -80
- package/test/https.js +0 -56
- package/test/ipseckey.js +0 -141
- package/test/key.js +0 -36
- package/test/loc.js +0 -75
- package/test/mx.js +0 -78
- package/test/naptr.js +0 -47
- package/test/ns.js +0 -56
- package/test/nsec.js +0 -37
- package/test/nsec3.js +0 -47
- package/test/nsec3param.js +0 -23
- package/test/nxt.js +0 -37
- package/test/openpgpkey.js +0 -85
- package/test/ptr.js +0 -56
- package/test/rr.js +0 -212
- package/test/smimea.js +0 -51
- package/test/soa.js +0 -99
- package/test/spf.js +0 -51
- package/test/srv.js +0 -101
- package/test/sshfp.js +0 -69
- package/test/svcb.js +0 -56
- package/test/tinydns.js +0 -163
- package/test/tlsa.js +0 -63
- package/test/txt.js +0 -82
- package/test/uri.js +0 -65
package/rr.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import util from 'node:util'
|
|
2
|
-
|
|
3
1
|
export default class RR extends Map {
|
|
4
2
|
constructor(opts) {
|
|
5
3
|
super()
|
|
@@ -21,7 +19,7 @@ export default class RR extends Map {
|
|
|
21
19
|
this.setClass(opts?.class)
|
|
22
20
|
|
|
23
21
|
for (const f of this.getFields('rdata')) {
|
|
24
|
-
const fnName = `set${this.
|
|
22
|
+
const fnName = `set${this.ucFirst(f)}`
|
|
25
23
|
if (this[fnName] === undefined)
|
|
26
24
|
this.throwHelp(`Missing ${fnName} in class ${this.get('type')}`)
|
|
27
25
|
this[fnName](opts[f])
|
|
@@ -30,7 +28,7 @@ export default class RR extends Map {
|
|
|
30
28
|
if (opts.comment) this.set('comment', opts.comment)
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
ucFirst(str) {
|
|
34
32
|
return str
|
|
35
33
|
.split(/\s/)
|
|
36
34
|
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
@@ -106,7 +104,7 @@ export default class RR extends Map {
|
|
|
106
104
|
this.throwHelp(`TTL must be numeric (${typeof t})`)
|
|
107
105
|
|
|
108
106
|
// RFC 1035, 2181
|
|
109
|
-
this.is32bitInt(this.
|
|
107
|
+
this.is32bitInt(this.get('type'), 'TTL', t)
|
|
110
108
|
|
|
111
109
|
this.set('ttl', t)
|
|
112
110
|
}
|
|
@@ -128,7 +126,7 @@ export default class RR extends Map {
|
|
|
128
126
|
if (this.constructor.name === 'RR') throw new Error(e)
|
|
129
127
|
|
|
130
128
|
const example = this.getCanonical
|
|
131
|
-
? `Example ${this.constructor.name}:\n${
|
|
129
|
+
? `Example ${this.constructor.name}:\n${JSON.stringify(this.getCanonical(), null, '\t')}\n\n`
|
|
132
130
|
: `${this.constructor.name} records have the fields: ${this.getFields().join(', ')}\n\n`
|
|
133
131
|
|
|
134
132
|
throw new Error(`${e}\n\n${example}${this.citeRFC()}\n`)
|
|
@@ -313,6 +311,17 @@ export default class RR extends Map {
|
|
|
313
311
|
)
|
|
314
312
|
}
|
|
315
313
|
|
|
314
|
+
isIPv4(string) {
|
|
315
|
+
// https://stackoverflow.com/questions/5284147/validating-ipv4-addresses-with-regexp
|
|
316
|
+
return /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/.test(string)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
isIPv6(string) {
|
|
320
|
+
return /^(?:(?:[a-fA-F\d]{1,4}:){7}(?:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,2}|:)|(?:[a-fA-F\d]{1,4}:){4}(?:(?::[a-fA-F\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,3}|:)|(?:[a-fA-F\d]{1,4}:){3}(?:(?::[a-fA-F\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,4}|:)|(?:[a-fA-F\d]{1,4}:){2}(?:(?::[a-fA-F\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,5}|:)|(?:[a-fA-F\d]{1,4}:){1}(?:(?::[a-fA-F\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$/gm.test(
|
|
321
|
+
string,
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
|
|
316
325
|
toBind(zone_opts) {
|
|
317
326
|
return `${this.getPrefix(zone_opts)}\t${this.getRdataFields()
|
|
318
327
|
.map((f) => this.getQuoted(f))
|
package/.codeclimate.yml
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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'
|
package/.github/FUNDING.yml
DELETED
package/.github/workflows/ci.yml
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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 }}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
package/.gitmodules
DELETED
package/.prettierrc.yml
DELETED
package/DEVELOP.md
DELETED
package/eslint.config.mjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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/test/a.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
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
|
-
}
|
package/test/caa.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import assert from 'assert'
|
|
2
|
-
|
|
3
|
-
import * as base from './base.js'
|
|
4
|
-
|
|
5
|
-
import CAA from '../rr/caa.js'
|
|
6
|
-
|
|
7
|
-
const validRecords = [
|
|
8
|
-
{
|
|
9
|
-
owner: 'ns1.example.com.',
|
|
10
|
-
ttl: 3600,
|
|
11
|
-
class: 'IN',
|
|
12
|
-
type: 'CAA',
|
|
13
|
-
flags: 0,
|
|
14
|
-
tag: 'issue',
|
|
15
|
-
value: 'http://letsencrypt.org',
|
|
16
|
-
testB: `ns1.example.com.\t3600\tIN\tCAA\t0\tissue\t"http://letsencrypt.org"\n`,
|
|
17
|
-
testT:
|
|
18
|
-
':ns1.example.com:257:\\000\\005issue"http\\072\\057\\057letsencrypt.org":3600::\n',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
owner: 'ns2.example.com.',
|
|
22
|
-
ttl: 3600,
|
|
23
|
-
class: 'IN',
|
|
24
|
-
type: 'CAA',
|
|
25
|
-
flags: 0,
|
|
26
|
-
tag: 'issue',
|
|
27
|
-
value: 'mailto:lets-crypt.org',
|
|
28
|
-
testB: `ns2.example.com.\t3600\tIN\tCAA\t0\tissue\t"mailto:lets-crypt.org"\n`,
|
|
29
|
-
testT:
|
|
30
|
-
':ns2.example.com:257:\\000\\005issue"mailto\\072lets-crypt.org":3600::\n',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
owner: 'example.net.',
|
|
34
|
-
ttl: 86400,
|
|
35
|
-
type: 'CAA',
|
|
36
|
-
flags: 0,
|
|
37
|
-
tag: 'issuewild',
|
|
38
|
-
value: 'https://letsencrypt.org',
|
|
39
|
-
testB:
|
|
40
|
-
'example.net.\t86400\tIN\tCAA\t0\tissuewild\t"https://letsencrypt.org"\n',
|
|
41
|
-
testT:
|
|
42
|
-
':example.net:257:\\000\\011issuewild"https\\072\\057\\057letsencrypt.org":86400::\n',
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
owner: 'certs.example.com.',
|
|
46
|
-
ttl: 86400,
|
|
47
|
-
type: 'CAA',
|
|
48
|
-
flags: 0,
|
|
49
|
-
tag: 'issue',
|
|
50
|
-
value: 'ca1.example.net',
|
|
51
|
-
testB: 'certs.example.com.\t86400\tIN\tCAA\t0\tissue\t"ca1.example.net"\n',
|
|
52
|
-
testT: ':certs.example.com:257:\\000\\005issue"ca1.example.net":86400::\n',
|
|
53
|
-
},
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
const invalidRecords = [
|
|
57
|
-
{
|
|
58
|
-
owner: 'example.com.',
|
|
59
|
-
type: 'CAA',
|
|
60
|
-
flags: 128,
|
|
61
|
-
tag: 'iodef',
|
|
62
|
-
value: 'letsencrypt.org', // missing iodef prefix
|
|
63
|
-
msg: /RFC/,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
owner: 'example.com.',
|
|
67
|
-
type: 'CAA',
|
|
68
|
-
flags: 128,
|
|
69
|
-
tag: 'invalid', // invalid
|
|
70
|
-
value: 'http://letsencrypt.org',
|
|
71
|
-
msg: /RFC/,
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
owner: 'example.com.',
|
|
75
|
-
type: 'CAA',
|
|
76
|
-
flags: 15, // invalid
|
|
77
|
-
tag: 'issue',
|
|
78
|
-
value: 'http://letsencrypt.org',
|
|
79
|
-
msg: /RFC/,
|
|
80
|
-
},
|
|
81
|
-
]
|
|
82
|
-
|
|
83
|
-
describe('CAA record', function () {
|
|
84
|
-
base.valid(CAA, validRecords)
|
|
85
|
-
base.invalid(CAA, invalidRecords, { ttl: 3600 })
|
|
86
|
-
|
|
87
|
-
base.getDescription(CAA)
|
|
88
|
-
base.getRFCs(CAA, validRecords[0])
|
|
89
|
-
base.getFields(CAA, ['flags', 'tag', 'value'])
|
|
90
|
-
base.getTypeId(CAA, 257)
|
|
91
|
-
|
|
92
|
-
base.toBind(CAA, validRecords)
|
|
93
|
-
base.toTinydns(CAA, validRecords)
|
|
94
|
-
|
|
95
|
-
base.fromBind(CAA, validRecords)
|
|
96
|
-
base.fromTinydns(CAA, validRecords)
|
|
97
|
-
|
|
98
|
-
for (const val of validRecords) {
|
|
99
|
-
it(`imports tinydns CAA (generic) record`, async function () {
|
|
100
|
-
const r = new CAA({ tinyline: val.testT })
|
|
101
|
-
if (process.env.DEBUG) console.dir(r)
|
|
102
|
-
for (const f of ['owner', 'flags', 'tag', 'value', 'ttl']) {
|
|
103
|
-
assert.deepStrictEqual(
|
|
104
|
-
r.get(f),
|
|
105
|
-
val[f],
|
|
106
|
-
`${f}: ${r.get(f)} !== ${val[f]}`,
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
})
|
package/test/cert.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import * as base from './base.js'
|
|
2
|
-
|
|
3
|
-
import CERT from '../rr/cert.js'
|
|
4
|
-
|
|
5
|
-
const validRecords = [
|
|
6
|
-
{
|
|
7
|
-
owner: 'mail.example.com.',
|
|
8
|
-
ttl: 86400,
|
|
9
|
-
class: 'IN',
|
|
10
|
-
type: 'CERT',
|
|
11
|
-
'cert type': 'PGP',
|
|
12
|
-
'key tag': 0,
|
|
13
|
-
algorithm: 0,
|
|
14
|
-
certificate: 'hexidecimalkeystring1',
|
|
15
|
-
testB:
|
|
16
|
-
'mail.example.com.\t86400\tIN\tCERT\tPGP\t0\t0\thexidecimalkeystring1\n',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
owner: 'smith.example.com.',
|
|
20
|
-
ttl: 86400,
|
|
21
|
-
class: 'IN',
|
|
22
|
-
type: 'CERT',
|
|
23
|
-
'cert type': 'PGP',
|
|
24
|
-
'key tag': 0,
|
|
25
|
-
algorithm: 0,
|
|
26
|
-
certificate: 'hexidecimalkeystring2',
|
|
27
|
-
testB:
|
|
28
|
-
'smith.example.com.\t86400\tIN\tCERT\tPGP\t0\t0\thexidecimalkeystring2\n',
|
|
29
|
-
},
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
const invalidRecords = []
|
|
33
|
-
|
|
34
|
-
describe('CERT record', function () {
|
|
35
|
-
base.valid(CERT, validRecords)
|
|
36
|
-
base.invalid(CERT, invalidRecords)
|
|
37
|
-
|
|
38
|
-
base.getDescription(CERT)
|
|
39
|
-
base.getRFCs(CERT, validRecords[0])
|
|
40
|
-
base.getFields(CERT, ['cert type', 'key tag', 'algorithm', 'certificate'])
|
|
41
|
-
base.getTypeId(CERT, 37)
|
|
42
|
-
|
|
43
|
-
base.toBind(CERT, validRecords)
|
|
44
|
-
// base.toTinydns(CERT, validRecords)
|
|
45
|
-
|
|
46
|
-
base.fromBind(CERT, validRecords)
|
|
47
|
-
// base.fromTinydns(CERT, validRecords)
|
|
48
|
-
})
|