node/test/parallel/test-net-server-listen-path.js
Bartosz Sosnowski 531b4bedca net: allow IPC servers be accessible by all
Adds mappings to uv_pipe_chmod call by adding two new options to
listen call. This allows the IPC server pipe to be made readable or
writable by all users.

Fixes: https://github.com/nodejs/node/issues/19154

PR-URL: https://github.com/nodejs/node/pull/19472
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-05-24 11:06:12 +02:00

72 lines
1.4 KiB
JavaScript

'use strict';
const common = require('../common');
const net = require('net');
const assert = require('assert');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
function closeServer() {
return common.mustCall(function() {
this.close();
});
}
let counter = 0;
// Avoid conflict with listen-handle
function randomPipePath() {
return `${common.PIPE}-listen-path-${counter++}`;
}
// Test listen(path)
{
const handlePath = randomPipePath();
net.createServer()
.listen(handlePath)
.on('listening', closeServer());
}
// Test listen({path})
{
const handlePath = randomPipePath();
net.createServer()
.listen({ path: handlePath })
.on('listening', closeServer());
}
// Test listen(path, cb)
{
const handlePath = randomPipePath();
net.createServer()
.listen(handlePath, closeServer());
}
// Test listen(path, cb)
{
const handlePath = randomPipePath();
net.createServer()
.listen({ path: handlePath }, closeServer());
}
// Test pipe chmod
{
const handlePath = randomPipePath();
const srv = net.createServer()
.listen({
path: handlePath,
readableAll: true,
writableAll: true
}, common.mustCall(() => {
if (process.platform !== 'win32') {
const mode = fs.statSync(handlePath).mode;
assert.ok(mode & fs.constants.S_IROTH !== 0);
assert.ok(mode & fs.constants.S_IWOTH !== 0);
}
srv.close();
}));
}