Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
test-listen
Advanced tools
The 'test-listen' npm package is a utility that helps in testing HTTP servers by providing a way to start a server and get its URL. This is particularly useful for integration tests where you need to make HTTP requests to a server.
Start a server and get its URL
This feature allows you to start an HTTP server and get its URL, which can then be used for making HTTP requests in your tests.
const testListen = require('test-listen');
const http = require('http');
const server = http.createServer((req, res) => {
res.end('Hello World');
});
testListen(server).then(url => {
console.log(`Server is running at ${url}`);
});
Supertest is a popular library for testing HTTP servers. It provides a high-level abstraction for testing HTTP, making it easy to send requests and assert responses. Unlike 'test-listen', which focuses on starting a server and getting its URL, Supertest provides a more comprehensive set of tools for making assertions on HTTP responses.
Nock is a library for HTTP mocking and expectations. It allows you to intercept HTTP requests and provide predefined responses, making it useful for testing HTTP clients. While 'test-listen' is used for starting a server and getting its URL, Nock is used for mocking HTTP requests and responses.
http-server is a simple, zero-configuration command-line HTTP server. It is useful for serving static files and testing static websites. Unlike 'test-listen', which is used for starting a server programmatically and getting its URL, http-server is more focused on serving static content from the command line.
Little helper to produce URLs with ephemeral ports. async
/await
ready.
import http from 'http';
import listen from 'test-listen';
const srv = http.createServer((req, res) => res.end('1'));
const srv2 = http.createServer((req, res) => res.end('2'));
test('urls', async t => {
let url = await listen(srv);
t.ok(url == 'http://localhost:11401');
let url = await listen(srv2);
t.ok(url == 'http://localhost:42333');
});
FAQs
Produce URLs to test HTTP servers with ephemeral ports
The npm package test-listen receives a total of 377,564 weekly downloads. As such, test-listen popularity was classified as popular.
We found that test-listen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.