Giter Site home page Giter Site logo

naturalintelligence / stubmatic Goto Github PK

View Code? Open in Web Editor NEW
130.0 6.0 14.0 808 KB

Mock HTTP calls without coding. Designed specially for testing and testers.

Home Page: https://naturalintelligence.github.io/Stubmatic/

License: Other

JavaScript 99.78% Shell 0.22%
stub-server nodejs soap-services stub mock http https ssl rest soap

stubmatic's Introduction

Stubmatic

Mock HTTP calls without coding. Designed specially for testing and testers.

NPM quality Travis ci Build Status Gitter Known Vulnerabilities Coverage Status

Stubmatic donate button

Stubmatic logo

  1. Installation : $npm install stubmatic -g
  2. Set up repo : $stubmatic init [repo-name]
  3. Start server : $stubmatic [-d <repo-name>]
  4. Help : $stubmatic --help

Important links : Video Tutorial, Wiki, NPM, Demo application, issues, changelogs Stubmatic donate button

Users

Main features

  • Mock HTTP(s) calls. (Hence can mock REST/SOAP web services)
  • Inspect HTTP calls from CLI or log them for more detail.
  • No code. Designed specially for testing and testers.
  • Mock messagepack or Nimn (निम्न) response easily. Write in JSON parse in desirable format.
  • Support SSL certificates.
  • Optional configuration
  • Dynamic response
    • Use Regular Expressions to match a request, capture some part of the request, to decide response file at runtime, to change contents of response at runtime etc.
    • Use Expressions (functions and markers) to display dynamic dates, random number etc.
    • Devide your response into multiple files (called dumps) for readability, reusability, and consistency.
    • Create a response skeleton with DB sets and fill data as per matched request.
    • Delay response for fixed or random time.
  • Send response as a stream (downloadable file)
  • Compress response automatically.
  • Route requests to other server using proxy.
  • Memory and CPU efficient
  • Ready to be used in performance environment
  • And much more like short notations, multiple mapping files, file strategy etc.

Configuration

To install stubmatic, you need to install nodejs and npm first. It is recommanded to be on latest version of both. npm is bundeled with nodejs. Now follow above commands to install stubmatic and to set up a repo.

How to start

Stubmatic works on request response mappings specified in a yaml file. Response contents can be read from body or file attribute of a maping.

-  request:
      url: /stubs/(admin|staff|customer|security)/([0-9]+)/2

   response:
      body: >
        multiple line response
        another line

When a request reaches to stubmatic server, it matches the request against all mappings. Whichever mapping matches first(top to bottom), will be used to serve the response. A complete response can be built with multiple files. It can also have some placeholder to show dynamic data, like date, or some random number or some part from request itself. Stubmatic first process and build complete response then respond back to any HTTP(s) request.

Using regular expression, single mapping can be used to match multiple requests and serve response from different files.

Sample SOAP request mapping

-  request:
     method: POST
     url: /soap-simulator/services/ServiceName
     post: actionName[\s\S]*mobile.([0-9]+)
  response:
     headers:
           content-type: text/xml
     strategy: "first-found"
     files: ["stubs/<% post.1 %>/response.xml","stubs/ServiceName/actionName/default.xml"]

Sample REST request mapping

-  request:
     method: GET
     url: /rest-simulator/services/ServiceName/actionName/([0-9]+)
  response:
     headers:
           content-type: text/xml
     strategy: "first-found"
     files: ["stubs/<% url.1 %>/response.xml","stubs/ServiceName/actionName/default.xml"]

Our other projects and research you must try

  • BigBit standard :
    • Single text encoding to replace UTF-8, UTF-16, UTF-32 and more with less memory.
    • Single Numeric datatype alternative of integer, float, double, long, decimal and more without precision loss.
  • Cytorus: Now be specific and flexible while running E2E tests.
    • Run tests only for a particular User Story
    • Run tests for a route or from a route
    • Customizable reporting
    • Central dashboard for better monitoring
  • imglab : Web based tool to label images for object. So that they can be used to train dlib or other object detectors. You can integrate 3rd party libraries for fast labeling.

Supporters

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

[Become a sponsor] Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Please also share your detail so we can thankyou on SocialMedia.

Helpful articles and tutorials

stubmatic's People

Contributors

amitguptagwl avatar bhavayanand9 avatar dependabot[bot] avatar jawn avatar snyk-bot 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

stubmatic's Issues

direct debug HTTP roundtrip without any configuration or mocks

Currently stubmatic can be used to debug a HTTP request without setting up any workspace;

$ stubmatic -v --debug [-p XXXX]

It also supports proxy a request to other server.

-  request:
      url: /someurl/.*

   response:
      proxy: http://google.com:8003

The combined feature can be used to debug HTTP response;

$ stubmatic -v --debug [-p XXXX] --to http://google.com

Requirement : When a user runs stubmatic with argument to, it should ignore any request response mapping. and should work as a proxy. if the --debug parameter is passed then it should log everything to the console or output stream.

Different HTTP response for each request

Currently, a user can create the mapping to serve the response from random files or in a round-robin fashion. (wiki)

-  request:
      url: /stubs/employee/([0-9]+)

   response:
      strategy: random
      files: ["<% url.1 %>.xml","file2.xml","file3.xml"]

Or

-  request:
      url: /stubs/employee/([0-9]+)

   response:
      strategy: random
      files: ["<% url.1 %>.xml","file2.xml",{"name":"file3.xml","status":500}]

But what if a user wants the same behavior but without any response in the body? He can create an empty file and do a hack like this;

-  request:
      url: /stubs/employee/([0-9]+)

   response:
      strategy: random
      files: [{"name":"empty","status":500}, {"name":"empty","status":503}]

We're looking for some meaningful mapping

-  request:
      url: /stubs/employee/([0-9]+)

   response:
      strategy: random
      status: [ 500, 503 ]

Error when calling from java web service client

I have create a mock that work fine when its called from SoapUI, but fail when its called from a generated java web service client. I thing that the body is not recognizing propertly, because in the log, resolved is null.

Error Handling ??

Hi,

Can I perform error handling on the validation errors, aroused due to the wrong input of post data?

For example I created an endpoint in response.yaml which accepts XML and returns a set of XML file already saved in project path.Still, it was fine was and working as expected, but I wanted to perform validations also on XML post body provided and throw error respectively can I do such things stubmatic.

Regards.

Stubmatic 6

We're currently working on new features in Stubmatic. Your suggestion would help us to lead in the correct direction.

Targeted major features

  1. Single handler. We were previously using 3 different handlers to feed information to the dynamic response: <% url.1 %>, [[dumpspath:file1,file2]], {{ TODAY }}. Now we'll be using a single handler: {{ include("file1", "file2") }}. [ Done ]
  2. Record and Play. Now you'll be able to record the response of different servers and serve the same response without connecting to that server again. It also records the request-response mapping to reduce your work. [ Done ]
  3. Dashboard. We want to create a GUI where you can see all the mappings and recordings. So it'll be helpful to manage all the mappings, reset counters, or add the mappings on the fly. We're also targetting to test a mapping from the dashboard. This feature will surely take long time so we'll be launching partial features with the release of stubmatic 6. And will keep adding more features. [Not started yet]
  4. Request payload matching. Currently only regex support is provided to match and capture request payload. Sometimes regex become difficult to understand. Hence, we're working on xpath, and jsonpath in case of XML, JSON, YAML inputs. [In Progress]

Json body Validation

I want to create a rest API and I want to validate the request and respond with proper error message If a specific field is not available or empty or invalid .

Can I do this using Stubmatic ?

Node 10 breaks stubmatic dynamic features

After switching node version from 8.9.4 to 10.13.0, dynamic features (evaluating keys at the response) is not working well. What I got in the response is just the evaluated key, not the entire response.

After debugging, I found the problem in lib/expressions/engine.js line 30
expressions[i]=new Expression(match[match.length-2], match[1]);

The problem is that match.length is different with node.js 10 and node.js 8.
So for start index you get a string and not a number.
Please see attached screenshots.
node8
node10

Simplifying the use of regular expressions

Why

In current version of Stubmatic, we use regular expressions to match & catch HTTP request. Writing regular expression can be an easy task for a developer, but reading and understanding it later is complex.

What

To solve this we're planning to use named regular expressions. E.g.

\authorize\(admin|staff|user)

can be replaced with

\authorize\:role:

How

  1. Create a set of regular expressions a project may need. Save them in a file
role : (admin|staff|user)
  1. Load this file when the Stubmatic starts before loading the mappings
  2. Replace each named regular expression with actual regular expression in mapping loaded into the memory.

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.