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 compatible with any testing paradigm: TDD/BDD/whatever. Also useful to embed NoFlo graphs into existing applications.
Install noflo-wrapper
and add it to your project's dev dependecies:
npm install --save-dev noflo-wrapper
Require it in your specs/tests:
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 CoffeeScript using Mocha and Chai in BDD style. You can also write your tests in JavaScript, using any other framework or style.
First you need to create a new Wrapper object to wrap your component or graph:
t = new Wrapper 'my-noflo-app/Multiplier'
The constructor accepts either a full component name (including namespace prefix), or an already instantiated component object, or a function returning such an object.
In general, components are loaded and wired up asynchronously, so you need to start the wrapper like this before running any tests:
before (done) ->
t.start (err, instance) ->
return done err if err # Error handling, optional
# instance contains a ready to use component
done()
Advanced options
If the component to be tested is a NoFlo graph, you can pass custom event handlers to the Wrapper constructor:
t = new Wrapper 'my-noflo-app/Multiplier',
load: (err, instance) ->
# This is call 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 component directly via c
property:
if t.c.outPorts.error.isAttached()
# 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:
div = null
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
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
.
FAQs
NoFlo component/graph testing and embedding wrapper compatible with BDD/TDD/whatever
The npm package noflo-wrapper receives a total of 0 weekly downloads. As such, noflo-wrapper popularity was classified as not popular.
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.