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.
Simplest require mocking
Hey there!
This is a simple module mocking tool for your super clever unit testing.
$ npm install --save-dev cuculus
The simple case:
var cuculus = require("cuculus");
cuculus.replace("fs", {
writeFile: function(path, contents) {
// ...
}
});
// now fs is your object
cuculus.restore("fs");
// now fs is original
Or:
var cuculus = require("cuculus"),
restorer;
restorer = cuculus.replace("fs", {
writeFile: function(path, contents) {
// ...
}
});
// now fs is your object
restorer();
// now fs is original
Complete case:
var cuculus = require("cuculus");
// mocking library
// feel free to use your favorite
var sinon = require("sinon");
cuculus.modify("fs", function(fs, onRestore) {
var stub;
stub = sinon.stub(fs, "writeFile", function(path, contents) {
// your actions here
});
// register restore middleware
onRestore.push(stub.restore.bind(stub));
return fs;
});
// your tests here
// and after all, or, between each test
cuculus.restore("fs");
// now fs is native and without stubs
Complete replace the module named name
with stub
. Returns function, that
simple proxy to cuculus.restore(name)
.
Modifies current module with replacer
function. If replacer
modifies object, then restore
method will not restore the changes, until you not register the backupers with onRestore
function.
Restores module name
. If it was modified multiple times, restores to the root, until the steps
limit is not given.
Drops the cached module from require
. name
should be a module name or a full path to the js file.
MIT © Sergey Kamardin
FAQs
Simplest require mocking
We found that cuculus 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.