
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Finally, a solution to node.js dependency injection
npm install injectr
. Boom.
var injectr = require('injectr');
var myScript = injectr('../lib/myScript.js', {
fs : mockFs,
crypto : mockCrypto
});
Now when you require('fs')
or require('crypto')
in myScript.js, what you
get is mockFs
or mockCrypto
.
Treat injectr like require
for your tests, with a second argument to pass
in your mocks.
Paths are now relative to the current file, just like require. Please update your tests if you are upgrading from v0.4 or below.
injectr gives you access to the context of the injectr'd file via an optional third argument. Provide an object, and injectr will modify it as necessary and use that as the context.
var myScript = injectr('../lib/myScript.js', {}, {
Date : mockDate,
setTimeout : mockSetTimeout
});
As of version 0.4, injectr doesn't create a full node.js context for you to use. Instead, it isolates your script in its own sandbox, allowing you to include mocks of only the bits that your script needs.
injectr compiles any *.coffee files for you, so you can test your
CoffeeScript too. The default settings can be changed by overwriting the
injectr.onload
function. It takes the filename and file contents as
arguments, and returns the compiled script.
injectr is under the MIT License. Fork it. Modify it. Pass it around.
FAQs
Finally, a solution to node.js dependency injection
The npm package injectr receives a total of 1,361 weekly downloads. As such, injectr popularity was classified as popular.
We found that injectr 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
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.