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.
@unpourtous/mocker
Advanced tools
Mocker is a simple and lightweight library which is used for generating random js object as defined schema.
npm install @unpourtous/mocker --save
a) First, define your object, the object schema.
import { Types } from '@unpourtous/mocker'
const objectSchema = {
stringDate: Types.string('date'),
stringRange: Types.string().range(10, 100),
numberRange: Types.number().range(0, 100),
enum: Types.enum(['A', 'B', 'C']),
fixNumber: 520, // If a valid type was set, the valid type will be the value
fixString: 'this is a fixString',
plainObject: { // define a object array
far: Types.string(),
bar: Types.number()
},
stringArray: [Types.string()], // define a primary type array
objectArray: [{ // define a object array
far: Types.string(),
bar: Types.number()
}]
}
b) Secondly, use Mocker to generate a random object.
import { Mocker } from '@unpourtous/mocker'
const mockerObject = Mocker.mockObject(objectSchema)
// the mockerObject should like
// {
// stringDate: '1941-10-03',
// stringRange: 'PKlDGzTY10pMZjYDIMtEWThTlXGcQE1gp2rYcStO2n52vw',
// numberRange: 62.61,
// enum: 'B',
// default: 'GXvmNy',
// fixNumber: 520,
// fixString: 'this is a fixString',
// plainObject: { far: 'O0qBn', bar: 464255.58 },
// stringArray: [ 'X5iH5' ],
// objectArray: [ { far: '', bar: 574378.47 } ]
// }
API | Description |
---|---|
string() | Create a instance of TPString. |
range(min, max) | Set min and max length for string, this is only used if this string dose not set regExp |
regExp(regExp) | Set regExp for this string, if this is set, the generated string match this regexp. |
fixValue(fixValue) | Set fix value |
API | Description |
---|---|
number() | Create a instance of Number. |
range (min, max) | Set min value and max value for number |
format(format) | Set number format, get more detail from Numeral.js |
fixValue(fixValue) | Set fix value |
API | Description |
---|---|
enum(enumValues) | Create a instance of Enum. enumValues should be a array containers all possible value. |
API | Description |
---|---|
boolean() | Create a instance of Boolean. |
fixValue(fixValue) | Set fix value |
All test case was put in test/
.
Test result:
You can also clone it run the test by youself.
git clone https://github.com/UnPourTous/mocker.git
cd mocker
yarn
yarn run test
MIT
FAQs
Mocker data generator
We found that @unpourtous/mocker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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.