aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2014-05-21 22:13:09 -0400
committerTrevor Norris <trev.norris@gmail.com>2014-08-04 16:57:18 -0700
commit430678640c52868c571e1d71ce8ad1501866bafc (patch)
treed44f5a74399045c5ca2558e8062bd4a53e6e2033 /test
parent7da63a10ac5e3f4c63ed9b2fa6dfdbfa32df4063 (diff)
downloadandroid-node-v8-430678640c52868c571e1d71ce8ad1501866bafc.tar.gz
android-node-v8-430678640c52868c571e1d71ce8ad1501866bafc.tar.bz2
android-node-v8-430678640c52868c571e1d71ce8ad1501866bafc.zip
net: don't prefer IPv4 addresses during resolution
Currently the address resolution family defaults to IPv4. Instead remove the preference and instead resolve to a family suitable for the host. Expose the getaddrinfo flags and allow them to be passed. Add documentation about new flags. Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/internet/test-dns.js60
-rw-r--r--test/simple/test-dns.js62
2 files changed, 113 insertions, 9 deletions
diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js
index 6165b30a3a..902545c175 100644
--- a/test/internet/test-dns.js
+++ b/test/internet/test-dns.js
@@ -337,6 +337,36 @@ TEST(function test_lookup_ipv4_implicit(done) {
});
+TEST(function test_lookup_ipv4_explicit_object(done) {
+ var req = dns.lookup('www.google.com', {
+ family: 4
+ }, function(err, ip, family) {
+ if (err) throw err;
+ assert.ok(net.isIPv4(ip));
+ assert.strictEqual(family, 4);
+
+ done();
+ });
+
+ checkWrap(req);
+});
+
+
+TEST(function test_lookup_ipv4_hint_addrconfig(done) {
+ var req = dns.lookup('www.google.com', {
+ hint: dns.ADDRCONFIG
+ }, function(err, ip, family) {
+ if (err) throw err;
+ assert.ok(net.isIPv4(ip));
+ assert.strictEqual(family, 4);
+
+ done();
+ });
+
+ checkWrap(req);
+});
+
+
TEST(function test_lookup_ipv6_explicit(done) {
var req = dns.lookup('ipv6.google.com', 6, function(err, ip, family) {
if (err) throw err;
@@ -365,6 +395,36 @@ TEST(function test_lookup_ipv6_implicit(done) {
*/
+TEST(function test_lookup_ipv6_explicit_object(done) {
+ var req = dns.lookup('ipv6.google.com', {
+ family: 6
+ }, function(err, ip, family) {
+ if (err) throw err;
+ assert.ok(net.isIPv6(ip));
+ assert.strictEqual(family, 6);
+
+ done();
+ });
+
+ checkWrap(req);
+});
+
+
+TEST(function test_lookup_ipv6_hint(done) {
+ var req = dns.lookup('ipv6.google.com', {
+ hint: dns.V4MAPPED
+ }, function(err, ip, family) {
+ if (err) throw err;
+ assert.ok(net.isIPv6(ip));
+ assert.strictEqual(family, 6);
+
+ done();
+ });
+
+ checkWrap(req);
+});
+
+
TEST(function test_lookup_failure(done) {
var req = dns.lookup('does.not.exist', 4, function(err, ip, family) {
assert.ok(err instanceof Error);
diff --git a/test/simple/test-dns.js b/test/simple/test-dns.js
index e7dce4b2ee..48f7d5f40a 100644
--- a/test/simple/test-dns.js
+++ b/test/simple/test-dns.js
@@ -27,6 +27,8 @@ var dns = require('dns');
var existing = dns.getServers();
assert(existing.length);
+function noop() {}
+
var goog = [
'8.8.8.8',
'8.8.4.4',
@@ -61,12 +63,54 @@ assert.deepEqual(dns.getServers(), portsExpected);
assert.doesNotThrow(function () { dns.setServers([]); });
assert.deepEqual(dns.getServers(), []);
-assert.throws(
- function() {
- dns.resolve('test.com', [], new Function);
- },
- function(err) {
- return !(err instanceof TypeError);
- },
- "Unexpected error"
-);
+assert.throws(function() {
+ dns.resolve('test.com', [], noop);
+}, function(err) {
+ return !(err instanceof TypeError);
+}, 'Unexpected error');
+
+assert.throws(function() {
+ dns.lookup('www.google.com', { hints: 1 }, noop);
+});
+
+assert.throws(function() {
+ dns.lookup('www.google.com');
+}, 'invalid arguments: callback must be passed');
+
+assert.throws(function() {
+ dns.lookup('www.google.com', 4);
+}, 'invalid arguments: callback must be passed');
+
+assert.doesNotThrow(function() {
+ dns.lookup('www.google.com', 6, noop);
+});
+
+assert.doesNotThrow(function() {
+ dns.lookup('www.google.com', {}, noop);
+});
+
+assert.doesNotThrow(function() {
+ dns.lookup('www.google.com', {
+ family: 4,
+ hints: 0
+ }, noop);
+});
+
+assert.doesNotThrow(function() {
+ dns.lookup('www.google.com', {
+ family: 6,
+ hints: dns.ADDRCONFIG
+ }, noop);
+});
+
+assert.doesNotThrow(function() {
+ dns.lookup('www.google.com', {
+ hints: dns.V4MAPPED
+ }, noop);
+});
+
+assert.doesNotThrow(function() {
+ dns.lookup('www.google.com', {
+ hints: dns.ADDRCONFIG | dns.V4MAPPED
+ }, noop);
+});