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.
hubot-mock-adapter
Advanced tools
I've whacked together a couple of Hubot scripts, but then they started getting more complicated. TDD is really the ONLY way to do any kind of meaningful development. But even if you're not TDD'ing, you are testing, right? Right?
I couldn't find an existing method for writing unit tests for Hubot scripts.
After digging around under Hubot's hood, I figured out all I really needed was
an Adapter
implementation I could spy on. That is what you see here.
Let's assume you've got a really simple script, like this:
module.exports = function (robot) {
robot.hear(/Computer!/, function (msg) {
msg.reply("Why hello there! (ticker tape, ticker tape)");
});
};
Create a test file in a folder. e.g. index.test.mjs.
You'll need a Node version > 17.
Assuming your tests are in test/
or have .test.
before the file extension, just run node --test
. For less typing, in your package.json
, add a test
script:
"scripts": {
"test": "node --test"
}
Then you can use npm test
to run your tests!
Create a test file in a folder. e.g. index.js.
You'll need devDependencies
something like this in your package.json
:
"devDependencies": {
"coffeescript": "^2.7.0",
"chai": "^4.3.7",
"hubot-mock-adapter": "^1.x.x",
"mocha": "^10.2.0",
"hubot": "^7.x.x",
}
Assuming your tests are in test/
, just run node_modules/.bin/mocha --exit
. For less typing, in your package.json
, add a test
script:
"scripts": {
"test": "mocha --exit"
}
Then you can use npm test
to run your tests!
FAQs
A mock Adapter for unit testing Hubot scripts
We found that hubot-mock-adapter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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.