Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Introduce knowledge of FreeBSD jails #1167

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@ exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);

var opensslCli = null;

Object.defineProperty(exports, 'inFreeBSDJail', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the return value of these should be cached? In test-net-local-address-port.js already you're using localhost_ipv4 twice and it's easy to forget that dynamic properties are lazy. See opensslCli for an already cached property.

get: function() {
if (process.platform === 'freebsd' &&
child_process.execSync('sysctl -n security.jail.jailed').toString() ===
'1\n') {
return true;
} else {
return false;
}
}
});

Object.defineProperty(exports, 'localhost_ipv4', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be localhostIPv4 to be consistent, we don't have any exports with _ and there's already exports.hasIPv6.

get: function() {
if (exports.inFreeBSDJail) {
// Jailed network interfaces are a bit special - since we need to jump
// through loops, as well as this being an exception case, assume the
// user will provide this instead.
if (process.env.LOCALHOST)
return process.env.LOCALHOST;

console.error('Looks like we\'re in a FreeBSD Jail. ' +
'Please provide your default interface address ' +
'as LOCALHOST or expect some tests to fail.');
}
return '127.0.0.1';
}
});

// opensslCli defined lazily to reduce overhead of spawnSync
Object.defineProperty(exports, 'opensslCli', {get: function() {
if (opensslCli !== null) return opensslCli;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var assert = require('assert');
var dgram = require('dgram');

// IPv4 Test
var localhost_ipv4 = '127.0.0.1';
var localhost_ipv4 = common.localhost_ipv4;
var socket_ipv4 = dgram.createSocket('udp4');
var family_ipv4 = 'IPv4';

Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-dgram-bind-default-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ var common = require('../common');
var assert = require('assert');
var dgram = require('dgram');

// skip test in FreeBSD jails since 0.0.0.0 will resolve to default interface
if (common.inFreeBSDJail) {
console.log('1..0 # Skipped: In a FreeBSD jail');
process.exit();
}

dgram.createSocket('udp4').bind(common.PORT + 0, common.mustCall(function() {
assert.equal(this.address().port, common.PORT + 0);
assert.equal(this.address().address, '0.0.0.0');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-dgram-udp4.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ server = dgram.createSocket('udp4');
server.on('message', function(msg, rinfo) {
console.log('server got: ' + msg +
' from ' + rinfo.address + ':' + rinfo.port);
assert.strictEqual(rinfo.address, '127.0.0.1');
assert.strictEqual(rinfo.address, common.localhost_ipv4);
assert.strictEqual(msg.toString(), message_to_send.toString());
server.send(msg, 0, msg.length, rinfo.port, rinfo.address);
});
Expand All @@ -22,7 +22,7 @@ server.on('listening', function() {
client.on('message', function(msg, rinfo) {
console.log('client got: ' + msg +
' from ' + rinfo.address + ':' + address.port);
assert.strictEqual(rinfo.address, '127.0.0.1');
assert.strictEqual(rinfo.address, common.localhost_ipv4);
assert.strictEqual(rinfo.port, server_port);
assert.strictEqual(msg.toString(), message_to_send.toString());
client.close();
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-net-local-address-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ var conns = 0, conns_closed = 0;

var server = net.createServer(function(socket) {
conns++;
assert.equal('127.0.0.1', socket.localAddress);
assert.equal(common.localhost_ipv4, socket.localAddress);
assert.equal(socket.localPort, common.PORT);
socket.on('end', function() {
server.close();
});
socket.resume();
});

server.listen(common.PORT, '127.0.0.1', function() {
var client = net.createConnection(common.PORT, '127.0.0.1');
server.listen(common.PORT, common.localhost_ipv4, function() {
var client = net.createConnection(common.PORT, common.localhost_ipv4);
client.on('connect', function() {
client.end();
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-net-remote-address-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var net = require('net');

var conns = 0, conns_closed = 0;

var remoteAddrCandidates = [ '127.0.0.1'];
var remoteAddrCandidates = [ common.localhost_ipv4 ];
if (common.hasIPv6) remoteAddrCandidates.push('::ffff:127.0.0.1');

var remoteFamilyCandidates = ['IPv4'];
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-net-server-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var assert = require('assert');
var net = require('net');

// Test on IPv4 Server
var localhost_ipv4 = '127.0.0.1';
var localhost_ipv4 = common.localhost_ipv4;
var family_ipv4 = 'IPv4';
var server_ipv4 = net.createServer();

Expand Down