Code Monkey home page Code Monkey logo

frock's Introduction

frock

A plugin-based tool for running fake HTTP and socket services.

Build Status npm install js-standard-style

frock is a tool for running fake services and serving mock data. It's designed for developers who work in service-oriented architectures, and need to stand up fake services that approximate production services in their development environments.

frock itself is a host for running HTTP and socket services, and its HTTP router makes it simple to run multiple services on the same port. Outside of the core functions of starting services and routing to handlers, frock's functionality is implemented through plugins and middleware that you write.

There are some generic plugins provided for out-of-the-box functionality:

  • frock-static is a plugin for serving static content from files, directories, or URLs.
  • frock-proxy is a plugin for proxying requests from frock to a remote server.

For a quick overview of the functionality frock provides, see the example in this README.

Quick-Start Example

frock is a Node.js CLI utility, which loads a frockfile from your project directory. In the following example, we'll create a service that proxies requests to your local development server at http://localhost:8052, but intercepts some URLs to serve static content from a variety of sources.

In your working directory, create a frockfile.json:

{
  "servers": [
    {
      "port": 8080,
      "routes": [
        {
          "path": "/api/segments",
          "methods": ["GET"],
          "handler": "frock-static",
          "options": {
            "file": "fixtures/static/segments.json",
            "contentType": "application/json"
          }
        },
        {
          "path": "/api/remote",
          "methods": ["GET"],
          "handler": "frock-static",
          "options": {
            "url": "http://raw.githubusercontent.com/somewhere/something.json",
            "contentType": "application/json"
          }
        },
        {
          "path": "*",
          "methods": "any",
          "handler": "frock-proxy",
          "options": {
            "url": "http://localhost:8052"
          }
        }
      ]
    }
  ]
}

Install frock and the plugins you requested:

$ npm install frock frock-static frock-proxy

Then, run frock:

$ frock

This examples expects that your PATH is set to run Node.js packages from your project's installed node_modules; see the Understanding Packages section of the documentation for details.

Note: By default, frock only allows connections from localhost; see the docs on connection filtering for details.

Detailed Documentation

frock's documentation is split into several sections:

  • Using frock in your project/Understanding Packages is an overview of how frock is meant to sit alongside your project.
  • Implementing mocks/fakes:
    • Plugins: writing plugins, where you'll implement your fake services.
    • Middleware: writing middleware, which can augment your plugins' functionality.
    • Cores: writing cores, which can extend the core functionality of frock.
  • frockfile Reference, which explains the configuration file format that frock uses, the frockfile.json
  • Examples which provides detailed examples of using frock, and can help you understand how to implement your fake services.
  • API details the frock API, which can be used programatically rather than via the provided CLI. This also documents the frock singleton your plugins will be passed when they are instantiated.

CLI

The frock command will search upward from your current directory for a frockfile.json, and run it.

Use the built-in help to learn about other options:

$ frock --help

Some options can be set via environment variables; these provide defaults, which can still be overridden by explicitly passing CLI flags. Set these to any value besides an empty string to set the default to true:

  • FROCK_DEBUG set the log level to debug
  • FROCK_RAW_OUTPUT output the raw log JSON rather than pretty-printing
  • FROCK_UNSAFE_DISABLE_CONNECTION_FILTERING disable processing of whitelists/blacklists for connections, and allow any incoming connections

Testing

From the project directory:

$ npm test

Any test file that should be run must be required in the tests/index.js file.

License

Apache 2.0, see LICENSE for details.

frock's People

Contributors

dependabot[bot] avatar fardog avatar mintchaos avatar neruson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

frock's Issues

Add a CLI flag for bypassing the default whitelist

Currently, if you want to bypass the default whitelist, you'd need to add a connection key to your frockfile.json, as:

"connection": { "whitelist": ["0.0.0.0/0"] }

For some uses, it'd be best to have a CLI flag that could just override the whitelist, rather than needing it in your frockfile (since it's a bit of a run-time case, rather than a configuration case).

I'm proposing --disable-whitelist or perhaps --unsafe-disable-whitelist (since I think it's worth noting the safety of the command) for this purpose.

Create a Dockerfile example

Using docker for deploying frock is a common use; it'd be good to have an example of using frock with docker, including an example Dockerfile.

Whitelist all incoming requests

Hi,

I'm using frock to run some integration tests for a new project.
For that I created a Docker container like so:

FROM node:5

RUN npm install frock-static frock-proxy
RUN npm install -g frock
WORKDIR config
EXPOSE 8080

I built it with docker build -t urbanairship/frock .

To start the container I run

docker run -it --rm -v `pwd`:/config -p 8080:8080 urbanairship/frock frock

(The -v part is for mounting the frockfile.json from the README into the appropriate location inside my container)

After that I tested if it works with: curl docker.local:8080/api/segments where docker.local is the IP address of my docker host (I'm using boot2docker on OSX).

I got the following response:
info frock/core-httpsever: access from non-whitelisted, or from blacklisted address

After reading the documentation I found an option to circumvent this by putting the following inside my frockfile.json: "connection": { "whitelist": ["192.168.0.1/8"] }
This will whitelist all IP addresses as far as I can tell.
Since frock will only be visible to the linked containers this is okay and very useful for integration testing.

What do you think about these two friendly suggestions?

  1. Please add a Dockerfile to the project. It should be pretty similar to the one above. This way everybody can just run it right away without installing any node dependencies.
  2. Maybe add a comment in the docs on how to whitelist all IP addresses.

This would make it much easier for new users to get started.
Thanks for your tool. It's nicely done. Especially the auto-reloading of the config file. ๐Ÿ˜ƒ

Improve documentation around whitelisting and default whitelist

The default frock configuration whitelists connections to frock from localhost only; any other connections will be denied with a message:

info frock/core-httpsever: access from non-whitelisted, or from blacklisted address

It'd be good to improve documentation around this, along with examples for how to replace the default whitelist with your own. There are docs on this, but they're pretty buried: https://github.com/urbanairship/frock/blob/master/docs/frockfile.md#connection-object-optional

Along with this is #7 which would allow a CLI flag to bypass the default whitelist.

CVE for nested depedency commuter-2.0.0 >>> deep-extend-0.3.3

Hi,

It looks like there is a CVE out for one of the libraries frock is indirectly referencing

๐Ÿ”ด CVE-2018-3750 (CVSS3: 9.8) Severity: (HIGH)
Component: deep-extend-0.3.3 (Transitive)
Dependency path: frock-4.1.0 >>> commuter-2.0.0 >>> deep-extend-0.3.3
Fix: Upgrade to version 0.5.1

It looks like commuter hasn't been updated since 2015.

I'm not sure how exploitable the CVE is in the use case for frock, but it's listed as critical on nist.

https://nvd.nist.gov/vuln/detail/CVE-2018-3750

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.