diff --git a/TESTS.md b/TESTS.md index 6637e6c..e10f693 100644 --- a/TESTS.md +++ b/TESTS.md @@ -126,4 +126,13 @@ $digcmd @$ns -p $port A doesntexist.a.example.com # should return NS records in ANSWER section, nothing else $digcmd @$ns -p $port NS a.example.com +# Test: +# wildcard record should match after static records +$digcmd @$ns -p $port ANY wild.example.com # no record +$digcmd @$ns -p $port ANY exists.wild.example.com # static record, before wildcard +$digcmd @$ns -p $port ANY foo.exists.wild.example.com # no record +$digcmd @$ns -p $port ANY doesntexist.wild.example.com # single-level wildcard +$digcmd @$ns -p $port ANY alsedoesntexist.wild.example.com # single-level wildcard +$digcmd @$ns -p $port ANY foo.doesntexist.wild.example.com # no second-level wildcard + ``` diff --git a/lib/dns-store.js b/lib/dns-store.js index 952ebf1..ef89016 100644 --- a/lib/dns-store.js +++ b/lib/dns-store.js @@ -29,13 +29,47 @@ function getRecords(db, qname, cb) { }); function checkCount() { + var ready; + count -= 1; - if (count <= 0) { - myRecords = myRecords.filter(function (r) { - return !delMe[r.id]; - }); - cb(null, myRecords); + ready = count <= 0; + + if (!ready) { + return; } + + myRecords = myRecords.filter(function (r) { + return !delMe[r.id]; + }); + + // There are a number of ways to interpret the wildcard rules + var hasWild = false; + var hasMatch = false; + myRecords.some(function (r) { + if (qname === r.name) { + hasMatch = true; + return true; + } + if ('*' === r.name[0]) { + hasWild = true; + } + }); + + if (hasMatch) { + myRecords = myRecords.filter(function (r) { + if ('*' !== r.name[0]) { return true; } + }); + } + /* + // no need to filter out records if wildcard is used + else { + records = records.filter(function (r) { + if ('*' === r.name[0]) { return true; } + }); + } + */ + + cb(null, myRecords); } function getRecord(r) {