Skip to content

Commit

Permalink
dns: serve TXT from root only if NS is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Feb 25, 2021
1 parent 56f4186 commit d2a31f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/dns/resource.js
Expand Up @@ -322,6 +322,13 @@ class Resource extends Struct {
res.authority = this.toNS(name);
res.additional = this.toGlue(name);
break;
case types.TXT:
if (!this.hasNS()) {
res.aa = true;
res.answer = this.toTXT(name);
key.signZSK(res.answer, types.TXT);
}
break;
case types.DS:
res.aa = true;
res.answer = this.toDS(name);
Expand Down
25 changes: 24 additions & 1 deletion test/resource-test.js
Expand Up @@ -106,14 +106,37 @@ describe('Resource', function() {
assert.strictEqual(synthAAAA.data.address, '::2');
});

it('should not return TXT from root zone', () => {
it('should not return TXT from root zone if NS is present', () => {
const res = Resource.fromJSON(json);
const msg = res.toDNS('hns.', types.TXT);

assert(msg.aa);
assert(msg.answer.length === 0);
});

it('should return TXT from root zone if NS is not present', () => {
const res = Resource.fromJSON({
records: [
{
type: 'TXT',
txt: ['hello world']
}
]
});
const msg = res.toDNS('hns.', types.TXT);

assert(msg.aa);
assert(msg.answer.length === 2);

const [txt, sig] = msg.answer;
assert.strictEqual(txt.type, types.TXT);
assert.strictEqual(txt.name, 'hns.');
assert.strictEqual(txt.data.txt.length, 1);
assert.strictEqual(txt.data.txt[0], 'hello world');
assert.strictEqual(sig.type, types.RRSIG);
assert.strictEqual(sig.name, 'hns.');
});

it('should synthesize an answer', () => {
const res = Resource.fromJSON(json);
const msg = res.toDNS('hns.', types.DS);
Expand Down

0 comments on commit d2a31f1

Please sign in to comment.