
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
pptr-mock-server
Advanced tools
Tiny library for backendless testing using Puppeteer.
This library allows to define mock backend responses when testing web app with Puppeteer.
Internally it works purely via Puppeteer API using built-in
setRequestInterception
mechanism. It doesn't set up any servers and doesn't
modify any window APIs like XMLHttpRequest
. This provides great flexibility
and performance when handling requests, since it operates on browser internal
level.
NOTE: we use this library heavily in automated tests for Dock and related projects, but api surface is minimalistic, so it may not fit your needs. Contributions are welcome, so we can make this library more flexible and cover more usage scenarios.
Recommended reading: Automated UI Testing at Dock.
yarn add -D pptr-mock-server
import puppeteer from 'puppeteer';
import mockServer from 'pptr-mock-server';
// typically your global test setup
const browser = await puppeteer.launch();
const page = await browser.newPage();
const baseAppUrl = 'http://localhost';
this.mockRequest = await mockServer.init(page, {
baseAppUrl,
baseApiUrl: baseAppUrl + '/api/'
});
Once you have an instance of MockRequest you can pass it to your tests for registering mock responses:
const responseConfig = {body: {result: 'ok'}};
this.mockRequest.on('GET', 'http://localhost/api/account', 200, responseConfig);
But since you provided baseApiUrl
as http://localhost/api, you can use relative endpoint name. Also you can use .get()
shorthand method instead of .on()
:
const responseConfig = {body: {result: 'ok'}};
this.mockRequest.get('account', 200, responseConfig);
When your app performs request to the specified resource, it will respond with the mock response provided.
Once you setup a mock request handler, every matching request will be responded with it. However it's a common scenario when you need to mock a sequence of requests, when over time the same request produces different results. Recommended way to do it is to replace previously registered mock response using new one:
const responseConfig = {body: {result: 'ok'}};
this.mockRequest.get('account', 200, responseConfig); // returns 200 on each request
// test deleting account logic here
// after account is deleted we want to return 401 instead of 200
this.mockRequest.get('account', 401); // replaces existing handler
FAQs
Tiny library for backendless testing using Puppeteer
The npm package pptr-mock-server receives a total of 153 weekly downloads. As such, pptr-mock-server popularity was classified as not popular.
We found that pptr-mock-server demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.