Skip to content

Commit

Permalink
dns: add failure test for dns.resolveXXX
Browse files Browse the repository at this point in the history
test whether the various resolve functions cause ENOTFOUND when trying
to resolve a known invalid domain/hostname.

PR-URL: nodejs#4921
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Brian White <mscdex@mscdex.net>
  • Loading branch information
dturing authored and Michael Scovetta committed Apr 2, 2016
1 parent c88425b commit 8cabd9e
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ TEST(function test_resolveMx(done) {
checkWrap(req);
});

TEST(function test_resolveMx_failure(done) {
var req = dns.resolveMx('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');

assert.ok(result == undefined);

done();
});

checkWrap(req);
});

TEST(function test_resolveNs(done) {
var req = dns.resolveNs('rackspace.com', function(err, names) {
Expand All @@ -103,6 +115,18 @@ TEST(function test_resolveNs(done) {
checkWrap(req);
});

TEST(function test_resolveNs_failure(done) {
var req = dns.resolveNs('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');

assert.ok(result == undefined);

done();
});

checkWrap(req);
});

TEST(function test_resolveSrv(done) {
var req = dns.resolveSrv('_jabber._tcp.google.com', function(err, result) {
Expand All @@ -129,6 +153,19 @@ TEST(function test_resolveSrv(done) {
checkWrap(req);
});

TEST(function test_resolveSrv_failure(done) {
var req = dns.resolveSrv('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');

assert.ok(result == undefined);

done();
});

checkWrap(req);
});

TEST(function test_resolveNaptr(done) {
var req = dns.resolveNaptr('sip2sip.info', function(err, result) {
if (err) throw err;
Expand All @@ -154,6 +191,19 @@ TEST(function test_resolveNaptr(done) {
checkWrap(req);
});

TEST(function test_resolveNaptr_failure(done) {
var req = dns.resolveNaptr('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');

assert.ok(result == undefined);

done();
});

checkWrap(req);
});

TEST(function test_resolveSoa(done) {
var req = dns.resolveSoa('nodejs.org', function(err, result) {
if (err) throw err;
Expand Down Expand Up @@ -188,6 +238,19 @@ TEST(function test_resolveSoa(done) {
checkWrap(req);
});

TEST(function test_resolveSoa_failure(done) {
var req = dns.resolveSoa('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');

assert.ok(result == undefined);

done();
});

checkWrap(req);
});

TEST(function test_resolveCname(done) {
var req = dns.resolveCname('www.microsoft.com', function(err, names) {
if (err) throw err;
Expand All @@ -206,6 +269,19 @@ TEST(function test_resolveCname(done) {
checkWrap(req);
});

TEST(function test_resolveCname_failure(done) {
var req = dns.resolveCname('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');

assert.ok(result == undefined);

done();
});

checkWrap(req);
});


TEST(function test_resolveTxt(done) {
var req = dns.resolveTxt('google.com', function(err, records) {
Expand All @@ -219,6 +295,19 @@ TEST(function test_resolveTxt(done) {
checkWrap(req);
});

TEST(function test_resolveTxt_failure(done) {
var req = dns.resolveTxt('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');

assert.ok(result == undefined);

done();
});

checkWrap(req);
});


TEST(function test_lookup_failure(done) {
var req = dns.lookup('does.not.exist', 4, function(err, ip, family) {
Expand Down

0 comments on commit 8cabd9e

Please sign in to comment.