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.
noflo-wrapper
Advanced tools
NoFlo component/graph testing and embedding wrapper compatible with BDD/TDD/whatever
Wraps a component to provide a convenient interface for use in normal JavaScript code. It is compatible with any testing paradigm: TDD/BDD/whatever. Read also Embedding NoFlo.
Install noflo-wrapper
and add it to your project's dependecies:
npm install noflo-wrapper --save
Require it:
const Wrapper = require('noflo-wrapper');
Use methods described below and run the tests just as you do it normally with your favorite testing framework.
Explanations below contain examples in JavaScript using Mocha and Chai in BDD style. You can also write your tests using any other framework or style.
First you need to create a new Wrapper object to wrap your component or graph:
const t = new Wrapper('my-noflo-app/Multiplier');
The constructor accepts either a full component name (including namespace prefix), or a function returning an instantiated component object, or a NoFlo Graph instance.
In general, components are loaded and wired up asynchronously, so you need to start the wrapper like this (and resolve the Promise) before running any tests:
before(() => t.start());
Advanced options
If the component to be tested is a NoFlo graph, you can pass custom event handlers to the Wrapper constructor:
const t = new Wrapper('my-noflo-app/Multiplier', {
load: (err, instance) => {
// This is called after loading the graph
},
ready: (err, instance) => {
// This is called when the network is ready to be attached
},
});
A high-level receive
method listens on output ports for data and groups until a disconnect
event.
A high-level send
methods sends data followed by a disconnect to one or more input ports.
Here is an example that tests a simple multiplier component:
t.receive('xy', (data) => {
chai.expect(data).to.equal(30);
done();
});
t.send({
x: 5,
y: 6,
});
Note that receive
is called before send
, because it binds event handlers asynchronously, while send
is almost an instant operation.
Short syntax for send
method to send data and disconnect to just one inport looks like this:
t.send('x', 123);
In more complex test cases you might want to send IPs and handle particular events manually:
t.outs.xy.on('data', (data) => {
chai.expect(data).to.equal(24);
done();
});
t.ins.x.send(8);
t.ins.x.disconnect();
t.ins.y.send(3);
t.ins.y.disconnect()
Wrapper object provides ins
and outs
hashmaps of sockets attached to the component.
You can also access the NoFlo network directly via network
property:
if (t.network.getActiveProcesses().length) {
// Do something
});
As receive
is triggered by a disconnect
event, there might be multiple data
packets in the transmission and also some group
bracket IPs. In such case they are available as arrays and counts in the callback arguments:
t.receive('xy', (data, groups, dataCount, groupCount) => {
chai.expect(data).to.eql([4, 10, 18]);
chai.expect(dataCount).to.equal(3);
chai.expect(groups).to.eql(['foo', 'bar']);
chai.expect(groupCount).to.equal(2);
done();
});
Note that groupCount
counts only closed groups via endGroup
events, while groups
contains unique groups sent to the output.
If a component sends output to multiple ports at the same time and you need to test results from all of them at once, that may require some syncrhonization spaghetti in your specs. But receive
simplifies it by accepting a hashmap and returning a Promise that is resolved when results from all outputs in the map have been received:
let div = null;
let mod = null;
t.receive({
quotient: (data) => {
div = data;
},
remainder: (data) => {
mod = data;
},
})
.then(() => {
chai.expect(div).to.equal 3
chai.expect(mod).to.equal 2
done()
});
t.send({
dividend: 11,
divisor: 3,
});
The receive
method returns a Promise resolved when a transmission is received, so you can chain subsequent transmissions in a thenable way, e.g.:
t.receive('quotient', (data) => {
chai.expect(data).to.equal(5);
})
.then(() => {
t.receive('quotient', (data) =>
chai.expect(data).to.equal(8);
done()
});
t.send({
dividend: 56,
divisor: 7,
});
});
t.send({
dividend: 30,
divisor: 6,
});
noflo-wrapper supports capturing Flowtraces for your runs. This enables retroactive debugging of the data flow in tools like Flowhub.
You can enable this with:
const t = new Wrapper('my-noflo-app/Multiplier', {
debug: true,
});
If you want to manage your own Flowtraces, you can also pass in an instance instead:
const { Flowtrace } = new Flowtrace();
const myTrace = new Flowtrace();
const t = new Wrapper('my-noflo-app/Multiplier', {
flowtrace: myTrace,
});
Under Node.js you can save the captured Flowtrace into a file with:
const tracefile = await t.dumpTrace();
If you want to store it some other way, it can be accessed via t.tracer
.
See complete BDD-style examples in spec
folder.
The first thing to start developing this package is:
npm install
Then run bundled Mocha specs:
npm test
Then feel free to hack on the lib
and specs
.
start
method now returns a Promise when no callback is providednoflo.Graph
objectsFAQs
NoFlo component/graph testing and embedding wrapper compatible with BDD/TDD/whatever
We found that noflo-wrapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.