Skip to content

Commit

Permalink
release 0.9.9 (#26)
Browse files Browse the repository at this point in the history
* feat: parser improvements
* README: remove some content to web links
* CAA: more robust fromBind parser
- SOA: leave $TTL and $ORIGIN to dns-zone
- test/base: improve invalid tests, check error message against expected
- test/rr: update tests with expected error messages
- DNSKEY,
- HINFO, os and cpu can also be quoted strings
- NAPTR: quoted fields can be single quoted (MaraDNS)
- SOA: export TTL too
- TLSA: improved parser
- TXT: improved parser
* HINFO: test update for node v14
* add test/openpgpkey
  • Loading branch information
msimerson committed Apr 15, 2022
1 parent ccd4dd0 commit 6d35389
Show file tree
Hide file tree
Showing 34 changed files with 313 additions and 267 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
node-version: [ 14.x, 16.x ]
node-version: [ 14, 16 ]
fail-fast: false

steps:
Expand All @@ -24,12 +24,11 @@ jobs:
with:
fetch-depth: 1

- uses: actions/setup-node@v1
name: Use Node.js ${{ matrix.node-version }}
- uses: actions/setup-node@v3
name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
with:
node-version: ${{ matrix.node-version }}

- run: npm install

- name: Run test suite
run: npm run test
- run: npm run test
9 changes: 5 additions & 4 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ name: Coverage

env:
CI: true
node_version: 14

jobs:

Expand All @@ -19,18 +20,18 @@ jobs:
with:
fetch-depth: 1

- name: Use Node.js 14
- name: Use Node.js ${{ env.node_version }}
uses: actions/setup-node@master
with:
node-version: 14
node-version: ${{ env.node_version }}

- name: npm install
run: |
npm install
npm install --no-save nyc codecov
npm install --no-save c8 codecov
- name: run coverage
run: npx nyc --reporter=lcovonly npm run test
run: npx c8 --reporter=lcovonly npm run test
env:
NODE_ENV: cov

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on: [ push ]

env:
CI: true
node_version: 14

jobs:

Expand All @@ -22,12 +23,11 @@ jobs:
with:
fetch-depth: 1

- uses: actions/setup-node@v2
name: Use Node.js ${{ matrix.node-version }}
- uses: actions/setup-node@v3
name: Use Node.js ${{ env.node_version }}
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ env.node_version }}

- run: npm install

- name: Lint
run: npm run lint
- run: npm run lint
14 changes: 6 additions & 8 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- master

env:
node_version: 14
CI: true
node_version: 14

jobs:

Expand All @@ -22,18 +22,16 @@ jobs:
fetch-depth: 0

- name: Setup node.js ${{ env.node_version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ env.node_version }}
registry-url: https://registry.npmjs.org/

- run: npm install

- name: Run tests
run: npm run test
- run: npm run test

- name: publish to NPM
run: npm publish --access public
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

Expand All @@ -43,8 +41,8 @@ jobs:

- name: run coverage
run: |
npm install --no-save nyc codecov
npx nyc --reporter=lcovonly npm run test
npm install --no-save c8 codecov
npx c8 --reporter=lcovonly npm run test
env:
NODE_ENV: cov

Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
#### 1.N.N - YYYY-MM-DD


#### 0.9.9 - 2022-04-14

- feat: parser improvements (DNSKEY, HINFO, NAPTR, SOA, TLSA, TXT)
- CAA: more robust fromBind parser
- SOA: leave $TTL and $ORIGIN to dns-zone
- test/base: improve invalid tests, check error message against expected
- test/rr: update tests with expected error messages
- README: move some content to web links


#### 0.9.8 - 2022-04-07

- url updates
Expand Down
37 changes: 6 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,35 +235,13 @@ PRs are welcome, especially PRs with tests.
- this library enforces duplicate suppression
- DNSSEC canonicalization (see RFC 4034)
- wire format for most RRs require it
- Master Zone File expansions exist at another level
- fromBIND is regex based and is naive. [dns-zone](https://github.com/NicTool/dns-zone) has a much more robust parser.
- Master Zone File expansions exist in [dns-zone](https://github.com/NicTool/dns-zone)
- to{Bind|MaraDNS} output can be influenced (suppress TTL, class, relative domain names) with an options object. See it in `bin/dns-zone` in the [dns-zone](https://github.com/NicTool/dns-zone) package.


## DEFINITIONS

- Resource Record: structured data associated with names / nodes
- format: owner ttl class type rdata
- example: www.example.com 3600 IN A 192.0.2.127
- owner [name]:
- a node in the domain name tree
- consists of a sequence of labels
- format: node.zone.tld.
- the right most label is null, aka the root
- the 2nd from right is the top level domain
- the 3rd from right is the [organizational] domain name
- label: character strings between the dots in a domain name
- ttl: time to live
- how long to cache this DNS resource record
- class: IN, internet.
- type: the type of rdata the follows
- examples: A, MX, SOA, PTR
- rdata: resource data. The contents vary widely by type
- examples: A records have an address, CNAME records bear a cname target, NS records point to nameservers (nsdname).


## SEE ALSO

- [Dictionary of DNS terms](https://nictool.github.io/web/Dictionary)
- [Wikipedia, List of DNS Record Types](https://en.wikipedia.org/wiki/List_of_DNS_record_types)


Expand All @@ -275,20 +253,17 @@ PRs are welcome, especially PRs with tests.
- [x] add defaults for empty values like TTL
- [x] DNSSEC RRs: DS, NSEC, NSEC3, NSEC3PARAM, RRSIG
- [x] CERT RRs: CERT, KEY, SIG, OPENPGPKEY
- [ ] APL, KX, DHCID, HIP, RP, SVCB/HTTPS
- [ ] add toWire, exports in wire/network format
- [x] RFC 4034: if the type of RR is NS, MD, MF, CNAME, SOA, MB,
MG, MR, PTR, HINFO, MINFO, MX, RP, AFSDB, RT, SIG, PX, NXT,
NAPTR, KX, SRV, DNAME, A6, RRSIG, or NSEC, all uppercase
letters in the DNS names contained within the RDATA are replaced by the lowercase letters;
- [ ] LOC record ingest/out isn't consistent with API
- [ ] handling unknown RR types: RFC 3597
- [x] LOC record ingest/out isn't consistent with API
- [ ] export a web page for each RR type


## DEVELOP

- this package has no dependencies. That's no accident.
- eventually this will be used a node.js app & a browser based app
- so, ESM, eventually
- CI tests are on linux, windows, and macos
- this will be used by a node.js app & a browser based app
- [x] ES6 modules, eventually
- [x] CI tests are on linux, windows, and macos
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dns-resource-record",
"version": "0.9.8",
"version": "0.9.9",
"description": "DNS Resource Records",
"main": "rr/index.js",
"scripts": {
Expand Down
15 changes: 10 additions & 5 deletions rr/caa.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ class CAA extends RR {
}

// check if val starts with one of iodefSchemes
const iodefSchemes = [ 'mailto:', 'http:', 'https:' ]
if (!iodefSchemes.filter(s => val.startsWith(s)).length) {
throw new Error(`CAA value must have valid iodefScheme prefix, ${this.citeRFC()}`)
if (this.get('tag') === 'iodef') {
const iodefSchemes = [ 'mailto:', 'http:', 'https:' ]
if (!iodefSchemes.filter(s => val.startsWith(s)).length) {
throw new Error(`CAA value must have valid iodefScheme prefix, ${this.citeRFC()}`)
}
}

this.set('value', val)
Expand Down Expand Up @@ -96,15 +98,18 @@ class CAA extends RR {

fromBind (str) {
// test.example.com 3600 IN CAA flags, tags, value
const [ owner, ttl, c, type, flags, tag ] = str.split(/\s+/)
const fields = str.match(/^([^\s]+)\s+([0-9]+)\s+(\w+)\s+(\w+)\s+([0-9]+)\s+(\w+)\s+("[^"]+"|[^\s]+?)\s*$/i)
if (!fields) throw new Error(`unable to parse: ${str}`)

const [ owner, ttl, c, type, flags, tag, value ] = fields.slice(1)
return new this.constructor({
owner,
ttl : parseInt(ttl, 10),
class: c,
type,
flags: parseInt(flags, 10),
tag,
value: str.split(/\s+/).slice(6).join(' ').trim(),
value,
})
}

Expand Down
7 changes: 5 additions & 2 deletions rr/dnskey.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ class DNSKEY extends RR {

fromBind (str) {
// test.example.com 3600 IN DNSKEY Flags Protocol Algorithm PublicKey
const [ owner, ttl, c, type, flags, protocol, algorithm ] = str.split(/\s+/)
const match = str.match(/^([^\s]+)\s+([0-9]+)\s+(\w+)\s+(\w+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+\s*(.*?)\s*$/)
if (!match) throw new Error(`unable to parse DNSKEY: ${str}`)
const [ owner, ttl, c, type, flags, protocol, algorithm, publickey ] = match.slice(1)

return new this.constructor({
owner,
ttl : parseInt(ttl, 10),
Expand All @@ -69,7 +72,7 @@ class DNSKEY extends RR {
flags : parseInt(flags, 10),
protocol : parseInt(protocol, 10),
algorithm: parseInt(algorithm, 10),
publickey: str.split(/\s+/).slice(7).join(' ').trim(),
publickey: publickey,
})
}

Expand Down
16 changes: 9 additions & 7 deletions rr/hinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class HINFO extends RR {
/****** Resource record specific setters *******/
setCpu (val) {
if (val.length > 255) throw new Error('HINFO cpu cannot exceed 255 chars')
this.set('cpu', val)
this.set('cpu', val.replace(/^["']|["']$/g, ''))
}

setOs (val) {
if (val.length > 255) throw new Error('HINFO os cannot exceed 255 chars')
this.set('os', val)
this.set('os', val.replace(/^["']|["']$/g, ''))
}

getDescription () {
Expand All @@ -38,13 +38,11 @@ class HINFO extends RR {
}

/****** IMPORTERS *******/
// fromTinydns (str) {
// // HINFO via generic, :fqdn:n:rdata:ttl:timestamp:lo
// }

fromBind (str) {
// test.example.com 3600 IN HINFO DEC-2060 TOPS20
const [ owner, ttl, c, type, cpu, os ] = str.split(/\s+/)
const match = str.match(/([^\s]+)\s+([0-9]+)\s+(IN)\s+(HINFO)\s+("[^"]+"|[^\s]+)\s+("[^"]+"|[^\s]+)/i)
if (!match) throw new Error(`unable to parse HINFO: ${str}`)
const [ owner, ttl, c, type, cpu, os ] = match.slice(1)

const bits = {
owner,
Expand All @@ -57,6 +55,10 @@ class HINFO extends RR {
return new this.constructor(bits)
}

// fromTinydns (str) {
// // HINFO via generic, :fqdn:n:rdata:ttl:timestamp:lo
// }

/****** EXPORTERS *******/
// toTinydns () {
// const rdata = '' // TODO
Expand Down
5 changes: 2 additions & 3 deletions rr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ class RR extends Map {

if (opts.default) this.default = opts.default

if (opts.tinyline) return this.fromTinydns(opts.tinyline)
if (opts.bindline) return this.fromBind(opts.bindline)
if (opts.tinyline) return this.fromTinydns(opts.tinyline)

// tinydns specific
this.setLocation(opts?.location)
this.setTimestamp(opts?.timestamp)

this.setOwner(opts?.owner)
this.setType (opts?.type)
this.setTtl (opts?.ttl)
this.setClass(opts?.class)
this.setType (opts?.type)

for (const f of this.getFields('rdata')) {
const fnName = `set${this.ucfirst(f)}`
Expand Down Expand Up @@ -283,7 +283,6 @@ class RR extends Map {
const type = this.get('type')
const supportedTypes = 'A PTR MX AAAA SRV NAPTR NS SOA TXT SPF RAW FQDN4 FQDN6 CNAME HINFO WKS LOC'.split(/\s+/g)
if (!supportedTypes.includes(type)) return this.toMaraGeneric()
// console.log(supportedTypes)
return `${this.get('owner')}\t+${this.get('ttl')}\t${type}\t${this.getRdataFields().map(f => this.getQuoted(f)).join('\t')} ~\n`
}

Expand Down
10 changes: 5 additions & 5 deletions rr/naptr.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class NAPTR extends RR {
}

setFlags (val) {
if (![ '', 'S', 'A', 'U', 'P' ].includes(val))
if (![ '', 'S', 'A', 'U', 'P' ].includes(val.toUpperCase()))
throw new Error (`NAPTR flags are invalid, ${this.citeRFC()}`)

this.set('flags', val)
this.set('flags', val.toUpperCase())
}

setService (val) {
Expand Down Expand Up @@ -113,9 +113,9 @@ class NAPTR extends RR {
type : type,
order : parseInt(order, 10),
preference : parseInt(preference, 10),
flags : flags.trim().replace(/^"|"$/g, ''),
service : service.trim().replace(/^"|"$/g, ''),
regexp : regexp.trim().replace(/^"|"$/g, ''),
flags : flags.trim().replace(/^['"]|['"]$/g, ''),
service : service.trim().replace(/^['"]|['"]$/g, ''),
regexp : regexp.trim().replace(/^['"]|['"]/g, ''),
replacement: replacement,
}
return new this.constructor(bits)
Expand Down

0 comments on commit 6d35389

Please sign in to comment.