Skip to content

Commit

Permalink
test: remove valid hostname check in test-dns.js
Browse files Browse the repository at this point in the history
Operating systems can and do return invalid hostnames if that's
what they have (for example) in /etc/hosts. Test passes if no
error is thrown and the hostname string is not empty.

Fixes: #2468
PR-URL: #2785
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
Trott authored and rvagg committed Sep 12, 2015
1 parent 5e93bc4 commit 1dad19b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
9 changes: 0 additions & 9 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,6 @@ exports.hasMultiLocalhost = function hasMultiLocalhost() {
return ret === 0;
};

exports.isValidHostname = function(str) {
// See http://stackoverflow.com/a/3824105
var re = new RegExp(
'^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])' +
'(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*$');

return !!str.match(re) && str.length <= 255;
};

exports.fileExists = function(pathname) {
try {
fs.accessSync(pathname);
Expand Down
6 changes: 4 additions & 2 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ TEST(function test_lookup_all_mixed(done) {
TEST(function test_lookupservice_ip_ipv4(done) {
var req = dns.lookupService('127.0.0.1', 80, function(err, host, service) {
if (err) throw err;
assert.ok(common.isValidHostname(host));
assert.equal(typeof host, 'string');
assert(host);

/*
* Retrieve the actual HTTP service name as setup on the host currently
Expand Down Expand Up @@ -604,7 +605,8 @@ TEST(function test_lookupservice_ip_ipv4(done) {
TEST(function test_lookupservice_ip_ipv6(done) {
var req = dns.lookupService('::1', 80, function(err, host, service) {
if (err) throw err;
assert.ok(common.isValidHostname(host));
assert.equal(typeof host, 'string');
assert(host);

/*
* Retrieve the actual HTTP service name as setup on the host currently
Expand Down

0 comments on commit 1dad19b

Please sign in to comment.