tjfontaine / node-dns

Replacement dns module in pure javascript for node.js
MIT License
585 stars 154 forks source link

Update README to indicate array type for TXT RRs #73

Closed SaltwaterC closed 9 years ago

SaltwaterC commented 10 years ago

The ResourceRecord from the documentation lists the data element of the answer to be a string for TXT queries. However, the answer contains an array of strings. This goes even against the records that use round robin (such as the A record) which contains an array of objects for each address. I made A and MX queries for comparison.

node dns-native.js google.com A
[ { name: 'google.com',
    type: 1,
    class: 1,
    ttl: 194,
    address: '173.194.70.101' },
  { name: 'google.com',
    type: 1,
    class: 1,
    ttl: 194,
    address: '173.194.70.113' },
  { name: 'google.com',
    type: 1,
    class: 1,
    ttl: 194,
    address: '173.194.70.102' },
  { name: 'google.com',
    type: 1,
    class: 1,
    ttl: 194,
    address: '173.194.70.139' },
  { name: 'google.com',
    type: 1,
    class: 1,
    ttl: 194,
    address: '173.194.70.138' },
  { name: 'google.com',
    type: 1,
    class: 1,
    ttl: 194,
    address: '173.194.70.100' } ]

node dns-native.js google.com MX
[ { name: 'google.com',
    type: 15,
    class: 1,
    ttl: 599,
    priority: 40,
    exchange: 'alt3.aspmx.l.google.com' },
  { name: 'google.com',
    type: 15,
    class: 1,
    ttl: 599,
    priority: 10,
    exchange: 'aspmx.l.google.com' },
  { name: 'google.com',
    type: 15,
    class: 1,
    ttl: 599,
    priority: 50,
    exchange: 'alt4.aspmx.l.google.com' },
  { name: 'google.com',
    type: 15,
    class: 1,
    ttl: 599,
    priority: 30,
    exchange: 'alt2.aspmx.l.google.com' },
  { name: 'google.com',
    type: 15,
    class: 1,
    ttl: 599,
    priority: 20,
    exchange: 'alt1.aspmx.l.google.com' } ]

node dns-native.js google.com TXT
[ { name: 'google.com',
    type: 16,
    class: 1,
    ttl: 3369,
    data: [ 'v=spf1 include:_spf.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all' ] } ]

The dns-native.js script is the following:

var dns = require('native-dns');

var request = dns.Request({
    question: dns.Question({
        name: process.argv[2],
        type: process.argv[3]
    }),
    server: {
        address: '8.8.8.8'
    },
    timeout: 1000
});

request.on('message', function (err, answer) {
    if (err) {
        console.error(err);
        process.exit(1);
    }
    console.log(answer.answer);
});

request.send();

Am I missing something for having predictable behaviour per documentation or this is an actual bug?

taoeffect commented 10 years ago

Which documentation are you referring to? From what you're saying this seems more just like an API that isn't accurately documented, but everything works OK otherwise, correct?

SaltwaterC commented 10 years ago

I am referring to the README file where ResourceRecord is defined. This document states that for the TXT type, the answer of the query should be into the data property of the RR object, having a typeof string.

I made a some TXT records on one of my domains for testing purposes.

dig txt saltwaterc.eu
[...]
;; ANSWER SECTION:
saltwaterc.eu.      300 IN  TXT "txt value 2"
saltwaterc.eu.      300 IN  TXT "txt value 1"
[...]

node dns-native.js saltwaterc.eu TXT
[ { name: 'saltwaterc.eu',
    type: 16,
    class: 1,
    ttl: 299,
    data: [ 'txt value 1' ] },
  { name: 'saltwaterc.eu',
    type: 16,
    class: 1,
    ttl: 299,
    data: [ 'txt value 2' ] } ]

Besides, that array for data is useless since the answer follows the same rules as any other RR that has multiple values for the same domain aka it returns an array of RR objects.

taoeffect commented 10 years ago

According to RFC 1035:

TXT-DATA        One or more <character-string>s.

Sounds like it needs to be an array, so closing.

SaltwaterC commented 10 years ago

Thanks, it makes sense now. Added a secondary string to a TXT record to check the behaviour. However, the README needs an update to reflect the fact that data for the TXT RR is an array, not a string.

dig txt saltwaterc.eu
[...]
;; ANSWER SECTION:
saltwaterc.eu.      299 IN  TXT "txt value 2"
saltwaterc.eu.      299 IN  TXT "txt value 1" "txt value 2"
[...]

node dns-native.js saltwaterc.eu TXT
[ { name: 'saltwaterc.eu',
    type: 16,
    class: 1,
    ttl: 284,
    data: [ 'txt value 2' ] },
  { name: 'saltwaterc.eu',
    type: 16,
    class: 1,
    ttl: 284,
    data: [ 'txt value 1', 'txt value 2' ] } ]
taoeffect commented 10 years ago

K, that can be done, I've changed the title to reflect that and have reopened the issue.

coolaj86 commented 9 years ago

bump

just got bit by this myself

taoeffect commented 9 years ago

Thanks @coolaj86! Merged your PR.