|
@ -1,11 +1,9 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
var common = require('../common'); |
|
|
const common = require('../common'); |
|
|
var fs = require('fs'); |
|
|
const fs = require('fs'); |
|
|
var net = require('net'); |
|
|
const net = require('net'); |
|
|
var path = require('path'); |
|
|
const path = require('path'); |
|
|
var assert = require('assert'); |
|
|
const assert = require('assert'); |
|
|
|
|
|
|
|
|
var accessErrorFired = false; |
|
|
|
|
|
|
|
|
|
|
|
// Test if ENOTSOCK is fired when trying to connect to a file which is not
|
|
|
// Test if ENOTSOCK is fired when trying to connect to a file which is not
|
|
|
// a socket.
|
|
|
// a socket.
|
|
@ -28,8 +26,7 @@ if (common.isWindows) { |
|
|
try { |
|
|
try { |
|
|
fs.unlinkSync(emptyTxt); |
|
|
fs.unlinkSync(emptyTxt); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
if (e.code != 'ENOENT') |
|
|
assert.strictEqual(e.code, 'ENOENT'); |
|
|
throw e; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
process.on('exit', cleanup); |
|
|
process.on('exit', cleanup); |
|
@ -38,7 +35,7 @@ if (common.isWindows) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var notSocketClient = net.createConnection(emptyTxt, function() { |
|
|
var notSocketClient = net.createConnection(emptyTxt, function() { |
|
|
assert.ok(false); |
|
|
common.fail('connection callback should not run'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
notSocketClient.on('error', common.mustCall(function(err) { |
|
|
notSocketClient.on('error', common.mustCall(function(err) { |
|
@ -49,39 +46,30 @@ notSocketClient.on('error', common.mustCall(function(err) { |
|
|
|
|
|
|
|
|
// Trying to connect to not-existing socket should result in ENOENT error
|
|
|
// Trying to connect to not-existing socket should result in ENOENT error
|
|
|
var noEntSocketClient = net.createConnection('no-ent-file', function() { |
|
|
var noEntSocketClient = net.createConnection('no-ent-file', function() { |
|
|
assert.ok(false); |
|
|
common.fail('connection to non-existent socket, callback should not run'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
noEntSocketClient.on('error', common.mustCall(function(err) { |
|
|
noEntSocketClient.on('error', common.mustCall(function(err) { |
|
|
assert.equal(err.code, 'ENOENT'); |
|
|
assert.strictEqual(err.code, 'ENOENT'); |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// On Windows or when running as root, a chmod has no effect on named pipes
|
|
|
// On Windows or when running as root, a chmod has no effect on named pipes
|
|
|
if (!common.isWindows && process.getuid() !== 0) { |
|
|
if (!common.isWindows && process.getuid() !== 0) { |
|
|
// Trying to connect to a socket one has no access to should result in EACCES
|
|
|
// Trying to connect to a socket one has no access to should result in EACCES
|
|
|
var accessServer = net.createServer(function() { |
|
|
const accessServer = net.createServer(function() { |
|
|
assert.ok(false); |
|
|
common.fail('server callback should not run'); |
|
|
}); |
|
|
}); |
|
|
accessServer.listen(common.PIPE, function() { |
|
|
accessServer.listen(common.PIPE, common.mustCall(function() { |
|
|
fs.chmodSync(common.PIPE, 0); |
|
|
fs.chmodSync(common.PIPE, 0); |
|
|
|
|
|
|
|
|
var accessClient = net.createConnection(common.PIPE, function() { |
|
|
var accessClient = net.createConnection(common.PIPE, function() { |
|
|
assert.ok(false); |
|
|
common.fail('connection should get EACCES, callback should not run'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
accessClient.on('error', function(err) { |
|
|
accessClient.on('error', common.mustCall(function(err) { |
|
|
assert.equal(err.code, 'EACCES'); |
|
|
assert.strictEqual(err.code, 'EACCES'); |
|
|
accessErrorFired = true; |
|
|
|
|
|
accessServer.close(); |
|
|
accessServer.close(); |
|
|
}); |
|
|
})); |
|
|
}); |
|
|
})); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assert that all error events were fired
|
|
|
|
|
|
process.on('exit', function() { |
|
|
|
|
|
if (!common.isWindows && process.getuid() !== 0) { |
|
|
|
|
|
assert.ok(accessErrorFired); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|