Skip to content

Commit

Permalink
test: adds linux-only test for abstract sockets
Browse files Browse the repository at this point in the history
Introduce a new linux-only test for binding to an abstract unix socket
and then making an http request against that socket.

Refs: nodejs#49656
  • Loading branch information
ggoodman committed Sep 15, 2023
1 parent 1064baf commit 3bddba0
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/parallel/test-pipe-abstract-socket-http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');

if (!common.isLinux)
common.skip();

const abstractSocket = '\0abstract';

let resStatus;

const server = http.createServer((req, res) => {
assert.strictEqual(req.method, 'POST');

req.resume();

req.on('end', () => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end();
});
});
server.listen(abstractSocket);

server.on('listening', () => {
makeRequest();
});

function makeRequest() {
const req = http.request({
path: '/',
method: 'POST',
socketPath: abstractSocket,
});

req.end();

req.on('response', (res) => {
resStatus = res.statusCode;

res.resume();
res.on('end', () => {
server.close();
});
});
}

process.on('exit', () => {
assert.strictEqual(resStatus, 200);
});

0 comments on commit 3bddba0

Please sign in to comment.