Skip to content

Commit c4ab861

Browse files
dturingsilverwind
authored andcommitted
dns: add failure test for dns.resolveXXX
test whether the various resolve functions cause ENOTFOUND when trying to resolve a known invalid domain/hostname. PR-URL: #4921 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent 76bc4c7 commit c4ab861

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

test/internet/test-dns.js

+89
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ TEST(function test_resolveMx(done) {
8484
checkWrap(req);
8585
});
8686

87+
TEST(function test_resolveMx_failure(done) {
88+
var req = dns.resolveMx('something.invalid', function(err, result) {
89+
assert.ok(err instanceof Error);
90+
assert.strictEqual(err.errno, 'ENOTFOUND');
91+
92+
assert.ok(result == undefined);
93+
94+
done();
95+
});
96+
97+
checkWrap(req);
98+
});
8799

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

118+
TEST(function test_resolveNs_failure(done) {
119+
var req = dns.resolveNs('something.invalid', function(err, result) {
120+
assert.ok(err instanceof Error);
121+
assert.strictEqual(err.errno, 'ENOTFOUND');
122+
123+
assert.ok(result == undefined);
124+
125+
done();
126+
});
127+
128+
checkWrap(req);
129+
});
106130

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

156+
TEST(function test_resolveSrv_failure(done) {
157+
var req = dns.resolveSrv('something.invalid', function(err, result) {
158+
assert.ok(err instanceof Error);
159+
assert.strictEqual(err.errno, 'ENOTFOUND');
160+
161+
assert.ok(result == undefined);
162+
163+
done();
164+
});
165+
166+
checkWrap(req);
167+
});
168+
132169
TEST(function test_resolveNaptr(done) {
133170
var req = dns.resolveNaptr('sip2sip.info', function(err, result) {
134171
if (err) throw err;
@@ -154,6 +191,19 @@ TEST(function test_resolveNaptr(done) {
154191
checkWrap(req);
155192
});
156193

194+
TEST(function test_resolveNaptr_failure(done) {
195+
var req = dns.resolveNaptr('something.invalid', function(err, result) {
196+
assert.ok(err instanceof Error);
197+
assert.strictEqual(err.errno, 'ENOTFOUND');
198+
199+
assert.ok(result == undefined);
200+
201+
done();
202+
});
203+
204+
checkWrap(req);
205+
});
206+
157207
TEST(function test_resolveSoa(done) {
158208
var req = dns.resolveSoa('nodejs.org', function(err, result) {
159209
if (err) throw err;
@@ -188,6 +238,19 @@ TEST(function test_resolveSoa(done) {
188238
checkWrap(req);
189239
});
190240

241+
TEST(function test_resolveSoa_failure(done) {
242+
var req = dns.resolveSoa('something.invalid', function(err, result) {
243+
assert.ok(err instanceof Error);
244+
assert.strictEqual(err.errno, 'ENOTFOUND');
245+
246+
assert.ok(result == undefined);
247+
248+
done();
249+
});
250+
251+
checkWrap(req);
252+
});
253+
191254
TEST(function test_resolveCname(done) {
192255
var req = dns.resolveCname('www.microsoft.com', function(err, names) {
193256
if (err) throw err;
@@ -206,6 +269,19 @@ TEST(function test_resolveCname(done) {
206269
checkWrap(req);
207270
});
208271

272+
TEST(function test_resolveCname_failure(done) {
273+
var req = dns.resolveCname('something.invalid', function(err, result) {
274+
assert.ok(err instanceof Error);
275+
assert.strictEqual(err.errno, 'ENOTFOUND');
276+
277+
assert.ok(result == undefined);
278+
279+
done();
280+
});
281+
282+
checkWrap(req);
283+
});
284+
209285

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

298+
TEST(function test_resolveTxt_failure(done) {
299+
var req = dns.resolveTxt('something.invalid', function(err, result) {
300+
assert.ok(err instanceof Error);
301+
assert.strictEqual(err.errno, 'ENOTFOUND');
302+
303+
assert.ok(result == undefined);
304+
305+
done();
306+
});
307+
308+
checkWrap(req);
309+
});
310+
222311

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

0 commit comments

Comments
 (0)