Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
An easy way to test REST API responses with Mocha
elbow = mocha + superagent + jayschema + awesomeness
A sample test script:
var elbow = require("elbow");
describe("testing Http Responses", function() {
elbow.run(it, "http://localhost:9090/", __dirname + "/../schema", {
timeout: 5000,
});
});
See a sample schema.
See a sample test output.
⇒ npm install elbow --save-dev
var elbow = require("elbow");
Runs your tests.
it
(Function): it provided by Mocha.baseUrl
(String): base url of the server. This is used to resolve the relative urls (endpoints).schemaDir
(String): path to the directory holding your schemas.options
(Object): test configurations
options.timeout
(Integer): test-specific timeoutoptions.label
(Function):
it
labelfunction(method, schema)
Loads your schemas.
schemaDir
(String): path to the directory holding your schemas.callback
(Function):
callback(err, schemas)
schemas
(Array): array holding your schemasSchemas, as defined in its specification, are valid JSON documents.
All the schemas should be placed in a single directory. They should have the extension .json
.
A sample schema file would look like:
{
"$schema": "http://json-schema.org/schema#",
"endpoint": "/transactions/transfers/charges",
"description": "transfer charges",
"methods": ["get", "post"],
"params": {
"to": "registered",
"amount": 5000
},
"status": 200,
"type": "object",
"properties": {
"charge": {
"type": "string"
}
},
"required": ["charge"]
}
Required key-value pairs include:
endpoint
(String): endpoint to test. This will be resolved to an absolute url using the base url. e.g. /endpoint
description
(String): describes the significance of the http response. e.g. "creating a new resource object"
methods
(Array): all the http methods to use to test the endpoint
"get"
, "post"
, "put"
, "delete"
params
(Object): parameters to pass to endpoint. e.g. { "query": "name" }
Optional key-value pairs include:
status
(Number): response status code. e.g. 201
The rest of the document will be used as is in validation.
The test cases are created in the order of:
01-get.json
is used before 02-get.json
"methods"
in the schema. e.g. with ["post", "get"]
, "post"
is used before "get"
This allows you to use a sequence in your tests, without having to use any beforeEach
, any code, etc...
✓ GET /params (testing the sending of params) [/home/gocho/Repos/GochoMugo/github/elbow/test/schema/params.json] (60ms)
✓ POST /params (testing the sending of params) [/home/gocho/Repos/GochoMugo/github/elbow/test/schema/params.json]
✓ PUT /params (testing the sending of params) [/home/gocho/Repos/GochoMugo/github/elbow/test/schema/params.json]
✓ DELETE /params (testing the sending of params) [/home/gocho/Repos/GochoMugo/github/elbow/test/schema/params.json]
✓ GET /simple (testing the response body only) [/home/gocho/Repos/GochoMugo/github/elbow/test/schema/simple.json]
✓ POST /simple (testing the response body only) [/home/gocho/Repos/GochoMugo/github/elbow/test/schema/simple.json]
✓ PUT /simple (testing the response body only) [/home/gocho/Repos/GochoMugo/github/elbow/test/schema/simple.json]
✓ DELETE /simple (testing the response body only) [/home/gocho/Repos/GochoMugo/github/elbow/test/schema/simple.json]
The method and endpoint is shown for each test case. The description of the schema is shown between (
and )
. The absolute filepath of the schema file used in the test case is shown between [
and ]
.
Elbow is also available from your terminal.
If installed globally, the command elbow
will be readily available. Otherwise, elbow will be available at ./node_modules/.bin/elbow
.
To list your schemas with the respective descriptions.
⇒ elbow --list [absolutePathToSchemaDir]
The MIT License (MIT)
Copyright (c) 2015 GochoMugo mugo@forfuture.co.ke
FAQs
An easy way to test REST API responses with Mocha
The npm package elbow receives a total of 11 weekly downloads. As such, elbow popularity was classified as not popular.
We found that elbow 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.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.