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.
msw-when-then
Advanced tools
MSW is a brilliant tool for mocking, but is missing a few things to make it perfect for testing. msw-when-then aims to help with that.
when-then
style Apinpm install msw-when-then
server
and rest
:import { whenThen, get, ok } from "msw-when-then";
const { when } = whenThen(server, rest);
when(get("https://some.url")).thenReturn(ok({ foo: "bar" }));
Familiar chaining pattern, the responses are return in order with the last response returned for all subsequent requests.
import { get, badRequest, ok } from "msw-when-then";
when(get("https://some.url"))
.thenReturn(badRequest({ response: "first request" }))
.thenReturn(ok({ response: "subsequent requests" }));
Sometimes you need to take things into your own hands. We expose the original MSW resolver function, so you can do whatever you like. See MSW Docs for more details.
import { get } from "msw-when-then";
when(get("https://some.url")).then((req, res, ctx) => {
// Any additional logic here
return res(ctx.status(400), ctx.json({ response: "last response" }));
});
Mocking APIs is great, but how can we ensure our app is sending the right data? We can do this by specifying the expected request data when mocking.
Note: The id
key in the withParams
here matches the :id
argument in the post
url
import { post, request, withBody, withHeaders, withParams, ok } from "msw-when-then";
when(post("https://some.url/:id")).thenReturnFor(
request(
withBody({ foo: "bar" }),
withHeaders({ "content-type": "application/json" }),
withParams({ id: "expected-id" })
),
ok({ response: "success" })
);
FAQs
A non-invasive 'when-then' style API for MSW
The npm package msw-when-then receives a total of 718 weekly downloads. As such, msw-when-then popularity was classified as not popular.
We found that msw-when-then demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.