Socket
Socket
Sign inDemoInstall

toxy

Package Overview
Dependencies
32
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.10 to 0.3.11

100

index.js
const Toxy = require('./lib/toxy')
const rules = require('./lib/rules')
const poisons = require('./lib/poisons')
/**
* API factory
* Expose `Toxy` API factory
*
* @exports {Function}
*/

@@ -12,14 +12,60 @@

/**
* Expose internal modules as static members
* Exposes admin HTTP server constructor.
*
* @property {Function} admin
* @static
*/
Toxy.admin = require('./lib/admin')
/**
* Exposes Rule constructor.
*
* @property {Rule} Rule
* @static
*/
Toxy.Rule = require('./lib/rule')
/**
* Exposes Base object.
*
* @property {Object} Base
* @static
*/
Toxy.Base = require('./lib/base')
/**
* Exposes Poison constructor.
*
* @property {Poison} Poison
* @static
*/
Toxy.Poison = require('./lib/poison')
/**
* Exposes Directive constructor.
*
* @property {Directive} Directive
* @static
*/
Toxy.Directive = require('./lib/directive')
/**
* Exposes Rocky proxy constructor.
*
* @property {Rocky} Rocky
* @static
*/
Toxy.Rocky = require('rocky').Rocky
/**
* Expose current version
* Expose current version.
*
* @property {String} VERSION
* @static
*/

@@ -30,27 +76,25 @@

/**
* Expose built-in poisons
* Expose built-in poisons.
*
* @property {Object} rules
* @static
*/
Toxy.poisons = Toxy.prototype.poisons = Object.create(null)
Toxy.poisons = Toxy.prototype.poisons
poisons.forEach(function (poison) {
Toxy.poisons[poison.name] = function () {
return poison.apply(null, arguments)
}
})
/**
* Expose built-in rules
* Expose built-in rules.
*
* @property {Object} rules
* @static
*/
Toxy.rules = Toxy.prototype.rules = Object.create(null)
Toxy.rules = Toxy.prototype.rules
rules.forEach(function (rule) {
Toxy.rules[rule.name] = function () {
return rule.apply(null, arguments)
}
})
/**
* Extend built-in rules
* Attaches a new rule.
*
* @param {Function} poison
* @method addPoison
* @static
*/

@@ -61,3 +105,7 @@

/**
* Extend built-in poisons
* Attaches a new poison.
*
* @param {Function} poison
* @method addPoison
* @static
*/

@@ -68,3 +116,7 @@

/**
* Add directive helper
* Add directive helper.
*
* @param {String}
* @function addDirective
* @private
*/

@@ -71,0 +123,0 @@

@@ -7,2 +7,10 @@ const router = require('router')

/**
* Creates a new Admin HTTP server exposing a
* simple API to manage toxy servers.
*
* @param {Object} opts
* @class Admin
*/
function Admin (opts) {

@@ -9,0 +17,0 @@ this.stack = []

@@ -1,6 +0,4 @@

module.exports = Base
const Base = exports
function Base () {}
Base.prototype._getAll = function (mw) {
Base._getAll = function (mw) {
return mw.stack.map(function (fn) {

@@ -11,3 +9,3 @@ return fn.$of

Base.prototype._disableAll = function (mw) {
Base._disableAll = function (mw) {
mw.stack.forEach(function (fn) {

@@ -19,4 +17,4 @@ fn.$of.disable()

Base.prototype._remove = function (mw, name) {
const item = this._searchInStack(mw, name)
Base._remove = function (mw, name) {
const item = searchInStack(mw, name)
if (item) {

@@ -29,4 +27,4 @@ mw.remove(item)

Base.prototype._callMethod = function (mw, action, name) {
const item = this._searchInStack(mw, name)
Base._callMethod = function (mw, action, name) {
const item = searchInStack(mw, name)
if (item) return item.$of[action]()

@@ -36,4 +34,4 @@ return false

Base.prototype._getDirective = function (mw, name) {
const item = this._searchInStack(mw, name)
Base._getDirective = function (mw, name) {
const item = searchInStack(mw, name)
if (item) return item.$of || item

@@ -43,3 +41,3 @@ return null

Base.prototype._searchInStack = function (mw, name) {
function searchInStack (mw, name) {
const stack = mw.stack

@@ -46,0 +44,0 @@ for (var i = 0, l = stack.length; i < l; i += 1) {

@@ -5,2 +5,11 @@ const Rule = require('./rule')

/**
* Directive encapsulates a directive function providing convenient
* methods and abstractions used by toxy higher layers to manage and configure directives.
*
* @param {Function} directive
* @class Directive
* @extends Rule
*/
function Directive (directive) {

@@ -7,0 +16,0 @@ Rule.call(this)

@@ -5,2 +5,14 @@ const Directive = require('./directive')

/**
* Poison encapsulates an HTTP middleware function
* which is responsible to infect and alter a given HTTP flow.
*
* Inherits from Directive to provide convenient methods and abstractions
* to configure the directive.
*
* @param {Function} poison
* @class Poison
* @extends Directive
*/
function Poison (poison) {

@@ -7,0 +19,0 @@ Directive.call(this, poison)

@@ -8,2 +8,9 @@ const rocky = require('rocky')

/**
* Extends Rocky Base prototype chain with
* Toxy domain specific convenient methods.
*
* @class RockyBase
*/
const RockyBase = rocky.Base

@@ -84,2 +91,4 @@

RockyBase.prototype.ifRule =
RockyBase.prototype.whenRule =
RockyBase.prototype.withRule =

@@ -86,0 +95,0 @@ RockyBase.prototype.poisonRule =

@@ -6,2 +6,10 @@ const midware = require('midware')

/**
* Rule provides convenient methods to manage
* and configure rule directives.
*
* @class Rule
* @mixin Base
*/
function Rule () {

@@ -44,4 +52,4 @@ this._rules = midware()

Object.keys(Base.prototype).forEach(function (key) {
Rule.prototype[key] = Base.prototype[key]
Object.keys(Base).forEach(function (key) {
Rule.prototype[key] = Base[key]
})
const midware = require('midware')
const Proxy = require('./proxy')
const rules = require('./rules')
const poisons = require('./poisons')
const randomId = require('./helpers').randomId

@@ -7,2 +9,10 @@

/**
* Creates a new Toxy HTTP proxy.
*
* @param {Object} opts
* @class Toxy
* @extends Proxy
*/
function Toxy (opts) {

@@ -20,2 +30,9 @@ if (!(this instanceof Toxy)) return new Toxy(opts)

/**
* Default TCP port to listen.
*
* @property {Number} PORT
* @static
*/
Toxy.PORT = +process.env.PORT || 3000

@@ -25,2 +42,10 @@

/**
* Starts listening on the network in the given port and host.
*
* @param {Number} port
* @param {String} host
* @method listen
*/
Toxy.prototype.listen = function (port, host) {

@@ -33,2 +58,11 @@ this.host = host

/**
* Registers a new route in the proxy server.
*
* @param {String} method
* @param {String} path
* @return {Route}
* @method route
*/
Toxy.prototype.route = function (method, path) {

@@ -58,2 +92,11 @@ const route = Proxy.prototype.route.apply(this, arguments)

/**
* Finds and returns an already registered route in the router stack.
*
* @param {String} routeId
* @param {String} method
* @return {Route}
* @method findRoute
*/
Toxy.prototype.findRoute = function (routeId, method) {

@@ -71,2 +114,34 @@ if (method) routeId = randomId(method, routeId)

/**
* Expose built-in poisons.
*
* @property {Object} poisons
*/
Toxy.prototype.poisons = Object.create(null)
poisons.forEach(function (poison) {
Toxy.prototype.poisons[poison.name] = function () {
return poison.apply(null, arguments)
}
})
/**
* Expose built-in rules.
*
* @property {Object} rules
*/
Toxy.prototype.rules = Object.create(null)
rules.forEach(function (rule) {
Toxy.prototype.rules[rule.name] = function () {
return rule.apply(null, arguments)
}
})
/**
* Private helpers
*/
function finalHandler (route) {

@@ -73,0 +148,0 @@ var isFinalHandler = false

{
"name": "toxy",
"version": "0.3.10",
"version": "0.3.11",
"description": "Hackable HTTP proxy to simulate server failure scenarios and network conditions",

@@ -5,0 +5,0 @@ "repository": "h2non/toxy",

@@ -1056,3 +1056,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) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com)

#### toxy#withRule(rule)
Aliases: `poisonRule`, `poisonFilter`
Aliases: `ifRule`, `whenRule`, `poisonRule`, `poisonFilter`

@@ -1059,0 +1059,0 @@ Apply a new rule for the latest registered poison.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc