
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Wrestle enables you to unit test and automatically document your API from the command line or the browser by specifying intuitive, unit tests for each route.
Install Wrestle with npm.
$ npm install wrestle -g
Defining tests with Wrestle is as simple as defining the route, the HTTP method and the expected JSON response.
wrestle.describe("Get user named 'foo'")
.get("/user/foo").expect({
username: "foo",
id: /\w{6}/
});
wrestle.post("/user", {
username: "bar"
}).expect(200, {
success: true
});
Wrestle tests can be executed from the command line by simple supplying the file to the wrestle test
command then run the tests.
$ wrestle test path/to/tests.js
Wrestle tests can also be run in the browser. Define your tests and include index.js
, browser/interface.js
and the test file.
There are a couple of caveats however due to the Cross-Origin Resource Sharing (CORS) policy which doesn't allow cross-domain requests (or in fact any requests from a static page) so the following options to enable testing in the browser.
--disable-web-security
flag to disable the CORS security.wrestle -- Simple REST API testing
help Shows this help.
test <file> Run a test file.
--simple Simple output report
--report Just output report
--i x..y Run tests numbers x through to y
--i x, y, z Run tests x, y, z only
doc <file> Output API documentation
--theme <theme> Output documentation with theme from doc/theme/
--output <path> Specify output path for documentation. Defaults to test file directory.
Describe a test case. This is the description
variable in the documentation generator
wrestle.describe("Generate a random username")
.post("/username").expect({
username: String
});
Create a test case for a GET, PUT, POST or DELETE HTTP method. path
can contain variables expanded by wrestle.format
. data
is the request data to be passed along to the server. Data specified alongside the GET method will be converted to URL parameters.
wrestle.get("/user/foo").expect({
username: "foo",
email: String
});
Define the response schema for a test. code
is the expected HTTP status code. responseSchema
is the schema for the JSON response, see wrestle.schema
for a full description on defining schemas.
wrestle.get("/404").expect(404);
wrestle.get("/user/foo").expect({
id: Number,
name: String,
gender: /male|female/
});
Define a schema for request data or JSON response that matches either the request method, HTTP status code or both. A schema is an object that defines a set of rules another a request or response object must conform to. Wrestle loops over the object and tests if the property exists in the schema and that the property's value is of the same type as the schema or matches a regular expression. Schemas can contain variables which will be replaced by values when the request is executed (variables are defined using wrestle.define
).
wrestle.response.schema(200, {
meta: {
code: 200,
url: String,
error: Boolean
}
});
wrestle.request.schema("post", {
session: ":session",
auth: {
username: "admin",
password: "root"
}
});
Define a variable for use within schemas or paths which can be accessed using the :
prefix.
Add an event listener to the test suite using .on
or .addEventListener
. Below is a list of events and the details sent to them.
Name | Description | Parameters |
---|---|---|
test | A new test has begun testing. | test |
begin | Testing has begun. | |
end | All tests have been completed. | report |
paused | Testing has been paused | |
error | An error has occured. |
Below is the list of events sent to a test. These can be binded to the test sent when the test
event above is called.
Name | Description | Parameters |
---|---|---|
start | A new test has started. | |
pass | A test has passed. | status, response |
fail | A test has failed. | err, status, response |
finish | A test has been completed. | err, status, response |
Begin testing. Optionally pass in array of test indexs or bound to only run selected tests.
Pause testing.
Resume testing.
Wrestle can compile your API spec into some pretty informative documentation. It does this with a Mustache templating system. As is matures, more complex data will be passed into the documentation and maybe even a selection of templating engines but for now, it's fairly basic. Below is a table of all the variables passed into the theme. See the Mustache.js documentation for some help in theme formatting.
Variable Name | Description |
rules | Array of API rules. |
rule.method | API rule HTTP method. |
rule.path | Path with emphasis on variables. |
rule.description | Description of the API rule. |
rule.parameters | Parameters sent along with request to the server. |
rule.response | Respone recieved from request. |
version | The current version of wrestle |
FAQs
A REST API testing library.
We found that wrestle 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
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.