toxy
Advanced tools
Comparing version 0.3.7 to 0.3.8
const toxy = require('..') | ||
const proxy = toxy() | ||
const rules = proxy.rules | ||
const poisons = proxy.poisons | ||
const rules = toxy.rules | ||
const poisons = toxy.poisons | ||
@@ -7,0 +7,0 @@ proxy |
module.exports = function eachSeries(arr, iterator, cb) { | ||
cb = cb || function () {} | ||
if (!Array.isArray(arr) || !arr.length) return cb() | ||
var stack = arr.slice() | ||
@@ -3,0 +6,0 @@ var length = iterator.length |
@@ -9,5 +9,6 @@ module.exports = function slowClose(opts) { | ||
// Cache native methods | ||
var _end = res.end | ||
var _setHeader = res.setHeader | ||
var _writeHead = res.writeHead | ||
var proto = Object.getPrototypeOf(res) | ||
var _end = proto.end | ||
var _setHeader = proto.setHeader | ||
var _writeHead = proto.writeHead | ||
@@ -14,0 +15,0 @@ res.setHeader = function (header, value) { |
@@ -6,3 +6,3 @@ const helpers = require('../helpers') | ||
var threshold = +opts.threshold || 100 | ||
var delay = +opts.threshold || +opts.delay || 100 | ||
var chunkSize = +opts.bps || +opts.bytes || +opts.chunk || 1024 | ||
@@ -15,4 +15,5 @@ | ||
var _end = res.end | ||
var _write = res.write | ||
var proto = Object.getPrototypeOf(res) | ||
var _end = proto.end | ||
var _write = proto.write | ||
@@ -44,3 +45,3 @@ // Listen for connection close in both ends | ||
function writeDefer(chunk, next) { | ||
setTimeout(write, threshold) | ||
setTimeout(write, delay) | ||
@@ -47,0 +48,0 @@ function write() { |
{ | ||
"name": "toxy", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"description": "Hackable HTTP proxy to simulate server failure scenarios and network conditions", | ||
@@ -38,3 +38,3 @@ "repository": "h2non/toxy", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha --timeout 5000 --reporter spec --ui tdd test/* test/admin/*" | ||
"test": "./node_modules/.bin/mocha --timeout 5000 --bail --reporter spec --ui tdd test/* test/admin/*" | ||
}, | ||
@@ -41,0 +41,0 @@ "dependencies": { |
@@ -7,3 +7,3 @@ # toxy [![Build Status](https://api.travis-ci.org/h2non/toxy.svg?branch=master&style=flat)](https://travis-ci.org/h2non/toxy) [![Code Climate](https://codeclimate.com/github/h2non/toxy/badges/gpa.svg)](https://codeclimate.com/github/h2non/toxy) [![NPM](https://img.shields.io/npm/v/toxy.svg)](https://www.npmjs.org/package/toxy) | ||
It was mainly designed for fuzzing/evil testing purposes, when toxy becomes particularly useful to cover fault tolerance and resiliency capabilities of a system, especially [disruption-tolerant networks](https://en.wikipedia.org/wiki/Delay-tolerant_networking) and [service-oriented](http://microservices.io/patterns/index.html) architectures, where toxy may act as intermediate MitM proxy among services. | ||
It was mainly designed for fuzzing/evil testing purposes, when toxy becomes particularly useful to cover fault tolerance and resiliency capabilities of a system, especially in [disruption-tolerant networks](https://en.wikipedia.org/wiki/Delay-tolerant_networking) and [service-oriented](http://microservices.io/patterns/index.html) architectures, where toxy may act as MitM proxy among services. | ||
@@ -471,3 +471,3 @@ toxy allows you to plug in [poisons](#poisons), optionally filtered by [rules](#rules), which essentially can intercept and alter the HTTP flow as you need, performing multiple evil actions in the middle of that process, such as limiting the bandwidth, delaying TCP packets, injecting network jitter latency or replying with a custom error or status code. | ||
- **chunk** `number` - Packet chunk size in bytes. Default to `1024` | ||
- **threshold** `object` - Limit threshold time frame in miliseconds. Default to `1000` | ||
- **delay** `object` - Data chunk delay time frame in miliseconds. Default to `100` | ||
@@ -474,0 +474,0 @@ ```js |
@@ -6,3 +6,3 @@ const expect = require('chai').expect | ||
test('options', function (done) { | ||
// Workaround: timers in the event-loop are a bit inconsistent in Travis | ||
// Workaround: event-loop timers are a bit inconsistent in small machines (e.g: Travis) | ||
if (process.env.CI) return done() | ||
@@ -21,6 +21,6 @@ | ||
setTimeout(period(disabled), 75) | ||
setTimeout(period(enabled), 150) | ||
setTimeout(period(disabled), 200) | ||
setTimeout(period(enabled), 300) | ||
setTimeout(done, 350) | ||
setTimeout(period(enabled), 200) | ||
setTimeout(period(disabled), 250) | ||
setTimeout(period(enabled), 350) | ||
setTimeout(done, 500) | ||
@@ -27,0 +27,0 @@ function disabled(err, ignore) { |
@@ -43,2 +43,3 @@ const http = require('http') | ||
var spy = sinon.spy() | ||
var reqStub = { socket: {}, once: function () {} } | ||
@@ -66,7 +67,7 @@ proxy.poison(function delay(req, res, next) { | ||
proxy._inPoisons.run(null, null, function () { | ||
proxy._inPoisons.run(reqStub, {}, function () { | ||
expect(spy.calledOnce).to.be.true | ||
}) | ||
proxy._outPoisons.run(null, null, function () { | ||
proxy._outPoisons.run(reqStub, {}, function () { | ||
expect(spy.calledTwice).to.be.true | ||
@@ -73,0 +74,0 @@ |
156405
3797