
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Hapi plugin for mocking endpoints.
npm install hapi-mock
This plugin provides a simple way to mock your HAPI endpoints. It is experimental at this point of time.
Register the plugin with Hapi server like this:
const Hapi = require('@hapi/hapi');
const hapiMock = require('hapi-mock');
const server = new Hapi.Server({
port: 3000,
});
const mock = {
plugin: hapiMock,
options: {
baseDir: Path.join(__dirname, 'mocks'),
},
};
const provision = async () => {
await server.register([mock]);
// ...
await server.start();
};
provision();
Your route configuration may look like this:
server.route({
method: 'GET',
path: '/example/{id}',
options: {
// ...
plugins: {
'hapi-mock': { // activate mocking for this endpoint
file: './cases', // JS module relative to `baseDir`
},
},
},
handler: async (request, h) => {
// ...
}
});
The file
option refers to a JS module (e.g., cases.js
) containing your mock cases, e.g.,
module.exports = [{
condition: 'params.id == "4711"',
code: 418,
}, {
condition: 'query.id == "foo"',
type: 'application/json',
body: {
bar: true,
},
}, {
condition: 'headers["x-mock-case"] == 13',
code: 200, // this is the default
type: 'text/plain', // this is the default
body: 'case 13',
}];
condition
may refer to HAPI's route parameters headers
, params
, query
, payload
, method
(lowercase), and path
.
The result parameters of a mock case can be code
, type
, and body
.
And finally, you need to set the HTTP header x-hapi-mock: true
to a request to have a route use mocking rather than its real handler implementation.
You don't want to use this plug-in in production, of course. Have fun.
FAQs
A simple HAPI plug-in for mocking endpoints
The npm package hapi-mock receives a total of 2 weekly downloads. As such, hapi-mock popularity was classified as not popular.
We found that hapi-mock 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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.