From 5d8eaaf3c07d7483c728fe8fb2f9ca204e69751f Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Tue, 19 Apr 2022 23:08:53 -0700 Subject: [PATCH 1/6] enabled macos & windows testing --- .github/workflows/ci-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 99b0e09..6430cdf 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: - os: [ ubuntu-latest, macos-latest ] + os: [ ubuntu-latest, macos-latest, windows-latest ] node-version: [ 14, 16 ] fail-fast: false From c3bd11600cf566e94ea89693db9f73a0246302b6 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 29 Apr 2022 10:40:59 -0700 Subject: [PATCH 2/6] add some debug logging --- lib/bind.js | 7 ++++++- test/bind.js | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/bind.js b/lib/bind.js index f4f6dc9..b6583f9 100644 --- a/lib/bind.js +++ b/lib/bind.js @@ -39,7 +39,7 @@ export async function parseZoneFile (str, implicitOrigin) { if (isDirective(line, res)) continue line = dz.stripComment(line, '"', ';') - +console.log(line) if (Object.keys(rrWIP).length) { // a continuation started resumeContinuation(line, rrWIP, res); continue } @@ -65,9 +65,11 @@ export async function parseZoneFile (str, implicitOrigin) { } // the start of a continuation was seen, remove it +console.log(`removing opening (`) iterRR.rdata = dz.removeChar(iterRR.rdata, '"', '(').trim() if (dz.hasUnquoted(iterRR.rdata, '"', ')')) { + // this is a single line continuation, see also resumeContinuation iterRR.rdata = dz.removeChar(iterRR.rdata, '"', ')').trim() res.push(parseRR(iterRR)) continue @@ -97,7 +99,10 @@ function resumeContinuation (line, rrWIP, res) { // within a zone file, new lines are ignored within parens. A paren was // opened, the closing paren will end the RR's rdata if (dz.hasUnquoted(line, '"', ')')) { // last line of this RR +console.log(`removing closing )`) rrWIP.rdata += dz.removeChar(line, '"', ')') + rrWIP.rdata = rrWIP.rdata.replace(/[\s]+/g, ' ') // flatten whitespace +console.log(rrWIP.rdata) res.push(parseRR(rrWIP)) Object.keys(rrWIP).map(k => delete rrWIP[k]) } diff --git a/test/bind.js b/test/bind.js index 31fcef6..f4100f0 100644 --- a/test/bind.js +++ b/test/bind.js @@ -61,14 +61,14 @@ describe('bind', function () { assert.deepStrictEqual(r[0], { $TTL: 86400 }) }) - it(`parses SOA`, async () => { + it.only(`parses SOA`, async () => { const r = await bind.parseZoneFile(`example.com. 86400 IN SOA ns1.example.com. hostmaster.example.com. ( 2021102100 ; serial 16384 ; refresh 2048 ; retry 604800 ; expiry 2560 ; minimum - )${os.EOL}`) + ) ${os.EOL}`) // console.dir(r, { depth: null }) assert.deepStrictEqual(r[0], new RR.SOA({ From 8cc2081c4560b1c4685a15eb4fb5e790aee87e51 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 29 Apr 2022 11:12:21 -0700 Subject: [PATCH 3/6] replace \n chars with os.EOL in multiline test --- lib/bind.js | 2 +- test/bind.js | 8 +------- test/index.js | 56 ++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/lib/bind.js b/lib/bind.js index b6583f9..2fe4163 100644 --- a/lib/bind.js +++ b/lib/bind.js @@ -45,7 +45,7 @@ console.log(line) } const match = line.match(re.zoneRR) - if (!match) throw new Error(`parse failure during line:\n\t${line}`) + if (!match) throw new Error(`parse failure during line:${os.EOL}\t${line}`) const [ owner, ttl, c, type, rdata ] = match.slice(1) const iterRR = { diff --git a/test/bind.js b/test/bind.js index f4100f0..b247a42 100644 --- a/test/bind.js +++ b/test/bind.js @@ -62,13 +62,7 @@ describe('bind', function () { }) it.only(`parses SOA`, async () => { - const r = await bind.parseZoneFile(`example.com. 86400 IN SOA ns1.example.com. hostmaster.example.com. ( - 2021102100 ; serial - 16384 ; refresh - 2048 ; retry - 604800 ; expiry - 2560 ; minimum - ) ${os.EOL}`) + const r = await bind.parseZoneFile(`example.com. 86400 IN SOA ns1.example.com. hostmaster.example.com. (${os.EOL}\t\t2021102100 ; serial${os.EOL}\t\t16384 ; refresh${os.EOL}\t\t2048 ; retry${os.EOL}\t\t604800 ; expiry${os.EOL}\t\t2560 ; minimum${os.EOL}\t\t) ${os.EOL}`) // console.dir(r, { depth: null }) assert.deepStrictEqual(r[0], new RR.SOA({ diff --git a/test/index.js b/test/index.js index 2cdd738..f73bbbe 100644 --- a/test/index.js +++ b/test/index.js @@ -1,5 +1,6 @@ import assert from 'assert' +import os from 'os' import * as dz from '../index.js' @@ -18,18 +19,53 @@ describe('dns-zone', function () { }) }) - const cases = { - '1w2d3h4m5s': 788645, - '1w1d' : 691200, - '1w' : 604800, - '1d' : 86400, - '2h' : 7200, - '1m' : 60, - '3600' : 3600, - '4500s' : 4500, - } + describe('removeChar', function () { + const removeCases = [ + [ 'this ( has opening paran', '"', '(', 'this has opening paran' ], + [ 'this ) has closing paran', '"', ')', 'this has closing paran' ], + ] + + for (const c of removeCases) { + it(`removes unquoted chacter ${c[2]}`, function () { + assert.equal(dz.removeChar(c[0], c[1], c[2]), c[3]) + }) + } + + const remainCases = [ + [ 'this "(" quoted open remains', '"', '(', 'this "(" quoted open remains' ], + [ 'this ")" quoted open remains', '"', ')', 'this ")" quoted open remains' ], + ] + + for (const c of remainCases) { + it(`retains quoted char ${c[2]}`, function () { + assert.equal(dz.removeChar(c[0], c[1], c[2]), c[3]) + }) + } + }) + + describe('stripCommment', function () { + it('removes a trailing comment', async function () { + assert.equal(dz.stripComment('This line has a ; trailing comment', '"', ';'), 'This line has a ') + }) + + it('removes multiline comments', async function () { + assert.equal(dz.stripComment(`This line has a ; trailing comment${os.EOL}and so too does ;this one${os.EOL}`, '"', ';'), 'This line has a ') + }) + + }) describe('toSeconds', function () { + const cases = { + '1w2d3h4m5s': 788645, + '1w1d' : 691200, + '1w' : 604800, + '1d' : 86400, + '2h' : 7200, + '1m' : 60, + '3600' : 3600, + '4500s' : 4500, + } + for (const c in cases) { it(`converts ${c} to ${cases[c]} seconds`, function () { assert.equal(dz.toSeconds(c), cases[c]) From a4d3a05114857082f55ab1aefd4e06187ca39ccd Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 29 Apr 2022 11:28:16 -0700 Subject: [PATCH 4/6] remove debugging --- lib/bind.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/bind.js b/lib/bind.js index 2fe4163..95a8422 100644 --- a/lib/bind.js +++ b/lib/bind.js @@ -39,7 +39,7 @@ export async function parseZoneFile (str, implicitOrigin) { if (isDirective(line, res)) continue line = dz.stripComment(line, '"', ';') -console.log(line) + if (Object.keys(rrWIP).length) { // a continuation started resumeContinuation(line, rrWIP, res); continue } @@ -65,7 +65,6 @@ console.log(line) } // the start of a continuation was seen, remove it -console.log(`removing opening (`) iterRR.rdata = dz.removeChar(iterRR.rdata, '"', '(').trim() if (dz.hasUnquoted(iterRR.rdata, '"', ')')) { @@ -99,10 +98,8 @@ function resumeContinuation (line, rrWIP, res) { // within a zone file, new lines are ignored within parens. A paren was // opened, the closing paren will end the RR's rdata if (dz.hasUnquoted(line, '"', ')')) { // last line of this RR -console.log(`removing closing )`) rrWIP.rdata += dz.removeChar(line, '"', ')') rrWIP.rdata = rrWIP.rdata.replace(/[\s]+/g, ' ') // flatten whitespace -console.log(rrWIP.rdata) res.push(parseRR(rrWIP)) Object.keys(rrWIP).map(k => delete rrWIP[k]) } From de023cc19387771460250629b3ae052e69b97eb6 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 29 Apr 2022 11:30:37 -0700 Subject: [PATCH 5/6] unleash the rest of the tests --- test/bind.js | 2 +- test/index.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/bind.js b/test/bind.js index b247a42..35db0da 100644 --- a/test/bind.js +++ b/test/bind.js @@ -61,7 +61,7 @@ describe('bind', function () { assert.deepStrictEqual(r[0], { $TTL: 86400 }) }) - it.only(`parses SOA`, async () => { + it(`parses SOA`, async () => { const r = await bind.parseZoneFile(`example.com. 86400 IN SOA ns1.example.com. hostmaster.example.com. (${os.EOL}\t\t2021102100 ; serial${os.EOL}\t\t16384 ; refresh${os.EOL}\t\t2048 ; retry${os.EOL}\t\t604800 ; expiry${os.EOL}\t\t2560 ; minimum${os.EOL}\t\t) ${os.EOL}`) // console.dir(r, { depth: null }) diff --git a/test/index.js b/test/index.js index f73bbbe..05cd9e7 100644 --- a/test/index.js +++ b/test/index.js @@ -51,7 +51,6 @@ describe('dns-zone', function () { it('removes multiline comments', async function () { assert.equal(dz.stripComment(`This line has a ; trailing comment${os.EOL}and so too does ;this one${os.EOL}`, '"', ';'), 'This line has a ') }) - }) describe('toSeconds', function () { From 4bfd68882a4b3cf3309b40f26416917941b2fb27 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 29 Apr 2022 15:24:48 -0700 Subject: [PATCH 6/6] update CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae5d24e..56b1dcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ #### 1.N.N - YYYY-MM-DD +- test: add windows CI testing +- test(bind): replace implicit \n with os.EOL +- test(index): add tests for removeChar, stripComment + + #### 1.0.0 - 2022-04-25 - fix(dns-zone): update import syntax for ESM RR