Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Wiremock client for Node JS which promotes separation of dynamic mocking commands from test code logic.
npm install mock-cmdr
Mock Commander can be simply used as a Wiremock rest API client:
const mockCmdr = require('mock-cmdr');
mockCmdr.init({ baseUrl: 'http://wiremock' });
mockCmdr.createMapping({
request: {
method: 'GET',
urlPath: '/user/1',
},
response: {
jsonBody: {
id: 1
}
},
});
However, Mock Commander's real utility comes from defining templated Wiremock
commands. If the mapping definintion above is moved into
${__dirname}/mock/stub/get-user-by-id.js
then the same create mapping call
can be made by:
const user = { id: 1 };
await mockCmdr.stub.getUserById(user);
Commands are loaded by providing the cmdDir
option to mockCmdr.init()
:
const path = require('path');
const mockCmdr = require('mock-cmdr');
mockCmdr.init({
baseUrl: wiremockBaseUrl,
cmdDir: path.resolve(__dirname, 'mock'),
});
See the Mock Commander Cucumber Test Suite for a full example demonstrating how to define and use templated Wiremock commands with Cucumber.
The following example demonstrates the layout of a command dir:
[cmdDir]
|- stub
| |- user
| |- create.js
| |- get-by-id.js
|
|- find
|- user
|- create-by-email.js
The resulting commands after calling mockCmdr.init({ cmdDir })
will be:
mockCmdr.stub.user.create()
mockCmdr.stub.user.getById()
mockCmdr.find.user.createByEmail()
/**
* @returns {WiremockStubMapping}
*/
module.exports = function(user) {
return {
request: {
method: 'GET',
urlPath: `/user/${user.id}`,
},
response: {
jsonBody: user.toApiModel(),
},
};
};
/**
* @returns {WiremockRequestCriteria}
*/
module.exports = function(user) {
return {
method: 'GET',
urlPath: `/user/${user.id}`,
};
};
Initialize the Mock Commander session. If cmdDir
is specified then
loadCmds()
will also be called.
options:
http://wiremock:8080
.Define a templated mocking command that will be available via
mockCmdr.{type}.{path}
or mockCmdr.{type}.{name}
. When the command is
invoked then createMapping()
or findRequests()
will be called with the
output of the command's template function.
command:
"stub"
or "find"
.mockCmdr.stub
or mockCmdr.find
.{ path: [ name ] }
Load all "find" and "stub" mocking commands by searching recursively within baseDir.
The discovered commands will be passed to defineCmd()
using the camel
cased file names as the command path. Modules found within a "find"
directory are treated as "find" commands and modules found within a
"stub" directory are treated as "stub" commands. Modules not within a
"find" or "stub" directory are ignored.
Any intermediate directories other than "find" and "stub" will be treated as namespaces. Namespaces can be arbitrarily deep and are also camel cased. The "find" and "stub" dirs are excluded from the namespace and need not appear at the top level allowing related commands to be grouped appropriately.
async
Call the Wiremock Stub Mapping API.
async
Call the Wiremock Find Requests API.
Access to "stub" commands registered via mockCmdr.defineCmd()
.
Access to "find" commands registered via mockCmdr.defineCmd()
.
async
Remove stub mappings from the Wiremock server that have been created by the current session.
Copyright 2020 Nathan Jones. Licensed under the Apache License, Version 2.0.
FAQs
Wiremock Client
The npm package mock-cmdr receives a total of 10 weekly downloads. As such, mock-cmdr popularity was classified as not popular.
We found that mock-cmdr 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.