Giter Site home page Giter Site logo

testinggospels / camouflage Goto Github PK

View Code? Open in Web Editor NEW
253.0 3.0 26.0 11.38 MB

Camouflage is a backend mocking tool for HTTP, gRPC, Websockets and Thrift protocols, which helps you carry out your front end prototyping, unit testing, functional/performance testing in silos, in absence of one or more Microservices/APIs.

Home Page: https://testinggospels.github.io/camouflage/

License: MIT License

TypeScript 83.55% JavaScript 14.87% Python 0.84% Dockerfile 0.05% Gherkin 0.68%
service-virtualization testing camouflage grpc api-simulation camouflage-server mockserver stubbing microservices-testing mocks

camouflage's Introduction

camouflage.png

Camouflage

HTTP/gRPC Mocking tool





Support

Chat on Discord

What is Camouflage?

Camouflage is a service virtualization tool inspired by namshi/mockserver. Camouflage works on a file based endpoint configuration system, which means it allows you to create a mock endpoint by simply creating a set of directories and a mock file, using which necessary responses are generated when you call the endpoint.

Available Features

🔥 File based mocking support for HTTP, HTTPS, HTTP2, gRPC, Thrift and websockets. 🔥

⚡ Dynamic/realistic responses without having to write any code. ⚡

🧩 Flexibility to partially or fully code your responses. 🧩

🎯 Conditional responses based on request parameters. 🎯

🌟 Inbuilt Caching - In memory and redis. 🌟

🧮 Ability to fetch and condition the response using external data. Currently supported data sources are CSV and postgres. 🧮

⏳ Delay Simulation. ⏳

🔍 Inbuilt monitoring. 🔍

🦺 Inbuilt backup and restore mechanism. 🦺

⏩ Quick start with camouflage init and camouflage restore modules. ⏩

🎊 Deployable on standalone VMs, Dockers and Kubernetes. 🎊

📁 Comes with a file explorer UI that allows modification of mock files hosted remotely. 📁

✅ Validation of requests and responses using your OpenApi schema's. ✅

Getting Started

  1. Camouflage is an NPM package, therefore to install Camouflage, you'd need to install NodeJS (>v14) first, if you haven't already done so.
  2. Install Camouflage: npm install -g camouflage-server
  3. Run camouflage --version to validate the installation was successful.
  4. Create an empty directory anywhere in your machine and navigate to it in your terminal.
  5. For npm and yarn, execute command camouflage init, or use npx degit camouflagejs/init myproject irrespective of your pacakge manager, to initialize a Camouflage project.
  6. This creates a basic skeleton of the folders you'd need in order to get started. You can modify these folders as per your requirements.
  7. Start the Camouflage server by initializing it with a config.yml file: camouflage --config config.yml

Configuration Options / Sample Config yml File

loglevel: info
cpus: 1
monitoring:
  port: 5555
ssl:
  cert: "./certs/server.cert"
  key: "./certs/server.key"
  root_cert: "./certs/root.cert"
protocols:
  http:
    enable: true
    mocks_dir: "./mocks"
    port: 8080
  https:
    enable: false
    port: 8443
  http2:
    enable: false
    port: 8081
  ws:
    enable: false
    mocks_dir: "./ws_mocks"
    port: 8082
  grpc:
    enable: false
    host: 0.0.0.0
    port: 4312
    mocks_dir: "./grpc/mocks"
    protos_dir: "./grpc/protos"
    grpc_tls: false
  thrift:
    enable: false
    mocks_dir: "./thrift/mocks"
    services:
      - port: 9999
        service: "/opt/gen-nodejs/Calculator"
        handlers:
          - add
          - substract
          - ping
backup:
  enable: false
  cron: "0 * * * *" # Hourly Backup
cache:
  enable: false
  ttl_seconds: 300
injection:
  enable: false
validation:
  enable: true
  schemas:
    - type: OpenApi
      url: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json
origins:
  - http://localhost:3000
  - http://localhost:3001
  - http://localhost:5000
# ext_helpers: "./custom_handlebar.json"

Create your first mock

Camouflage uses a file based system to configure the endpoints. For example, to create a mock to the endpoint /hello-world:

  1. You start by creating a directory ${MOCKS_DIR}/hello-world
  2. Create a file GET.mock under ${MOCKS_DIR}/hello-world
  3. Paste following content:
HTTP/1.1 200 OK
X-Custom-Header: Custom-Value
Content-Type: application/json

{
    "greeting": "Hey! It works!"
}

Navigate to http://localhost:8080/hello-world

${MOCK_DIR} is defined in config.yaml as protocols.http.mocks_dir. Refer to docs for more details.

Contributing

All and any relevant contributions to the project are welcome. Easiest way to contribute to Camouflage is to 🌟 the project. You can also help find typos and grammatical mistakes in the documentation to earn a quick 🟩 for your Github profile.

If you'd like to get into technical nitty gritty, I have tried my best to provide relevant comments throughout the code base with a JSDocs available too. Since we are still in beta, there are frequent changes in the codebase, which might at times lead to outdated JSDocs, in which case, feel free to reach out via discussions or join us on discord.

Raise an issue if you think something is not working as expected, or if you'd like to request a new feature

Read the detailed contributing guide

Building from source

Camouflage is quickly approaching it's first release i.e. v1.0.0, however while it is still in beta, there might be some bugs, missed use cases, incorrect implementations of some functionalities. This is to be expected. But, the good news is that we are constantly evolving.

There might be times when latest changes have not gone to release yet. You can find such changes in the develop branch of the repository, which is the most updated version of Camouflage. If you'd like to get your hands on the upcoming release of Camouflage at any point, you can build it from the source. However, since this source might contain changes that are not tested yet and are not ready for use, you might want to proceed with caution.

  1. Clone the repository: git clone https://github.com/testinggospels/camouflage.git
  2. Checkout develop branch: git checkout develop
  3. Install dependencies: npm install
  4. Build the project: npm run build
  5. At this point you can run Camouflage using: node bin/camouflage.js --config ./config.yml
  6. However if you'd like to install Camouflage globally, execute: npm pack
  7. Install by running command: npm install -g camouflage-server-0.0.0-development.tgz or npm install -g camouflage-server-0.0.0-development.zip

License

MIT License

Copyright (c) 2021 testinggospels

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

camouflage's People

Contributors

ashanka-singh-qatalog avatar cat-ninja avatar dependabot[bot] avatar dnafication avatar kitofr avatar richardruiter avatar schmelto avatar shubhendumadhukar 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

camouflage's Issues

Bug: protofiles are imported to other protofiles, intermittently re-register same methods twice

Describe the bug
If any protofiles contain reference/imports to other protofiles and if imported protofile contain service/methods, same methods are registered twice leading to incorrect loading of protofiles.

To Reproduce
Steps to reproduce the behavior:

  1. Create protofile A.
  2. Import to protofile A to protofile B.
  3. Add Service/Method to protofile A.
  4. A warning should appear in logs, stating Not re-registering method. Already registered.

Expected behavior
Protofiles parsed as part of imports should not be parsed again individually.

Additional context
Add a file .protoignore similar to .gitignore or .npmignore to ignore protofiles that are used as imports. Camouflage will only parse such files as part of imports and not independently.

Add a GitHub action to automate release creation

Is your feature request related to a problem? Please describe.
Current process for creating a new GitHub release is to manually create a new tag from main branch and add the changelog to release which seems to be an inefficient way of creating releases.

Describe the solution you'd like
An automated GitHub Actions, which is triggered anytime a pull request to main is approved and merged, should create a new GitHub release with proper changelog and SemVer versioning.

Describe alternatives you've considered
Manual.

Additional context
NA

Write tests for automation

Is your feature request related to a problem? Please describe.
Currently specified tests in camouflage focus on functional/performance testing of the Mocks. However, a more robust test is required in order to certify new pull requests as part of the automation.

Describe the solution you'd like
To be updated

Describe alternatives you've considered
NA

Additional context
NA

Enable user to write a custom code to modify a response

Is your feature request related to a problem? Please describe.
Current {{#code}}{{/code}} helper, allows user to generate a complete response by writing a custom code which returns a response object. However there might be use cases where user doesn't want to write a code for whole response, instead user might just want to use custom code just for a part of the response. A new helper to return values by evaluating a javascript code, would be helpful

Describe the solution you'd like
Final implementation of this helper could look like {{#inject}}(()=>{ return somevalue; })(){{/inject}}

Describe alternatives you've considered
NA

Additional context
NA

Update Docs: Handlerbars' inbuilt if helper does not support comparisons.

Describe the bug
Since Handlebars' inbuilt if helper does not support comparisons, this section of docs need to be updated.

To Reproduce
NA

Expected behavior
Replace with a custom handlebar definition example which users can load externally via a JSON file.

Screenshots
NA

Desktop (please complete the following information):
NA

Additional context
NA

Generate mocks from OpenAPI document

OpenAPI is a description of HTTP-based APIs which are typically, RESTful APIs. It comes in the form of a YAML file or JSON, that describes the inputs and outputs of an API. OpenAPI is not the only way to describe a API, there is also RAML, API Blueprint, ... but it looks like OpenAPI is becoming the standard. More information can be found https://www.openapis.org/. https://spec.openapis.org/oas/v3.1.0

When using a Contract-First API Development approach, our first task is to describe an API with OpenAPI before starting to code. The next step would be to launch the API using a mock service/service virtualization. So consumers can already work with the service while it is under development.

The mock service/service virtualization is also used for running integration testing, so when we test a service, we use the mocks for the dependent services.

It would be great if we could use these documents to generate the necessary files and folders for Camouflage. Camouflage is very simple to use and I would be great to keep it this way. So maybe a solution would be to not include this feature inside camouflage but to provide a separate way to generate the necessary files.

The current version of OpenAPI is 3.1, which came out in 15 Feb 2021, but the tooling supporting OAS3.1 is still under development (a parser is probably needed). Most tooling supports up to OAS3.0.

There is also an example object which could be used to provide data for the mocks: https://spec.openapis.org/oas/v3.1.0#example-object

Note: There is also a spec for asynchronous APIs called AsyncAPI (which is heavily based on OpenAPI) and is used to describe for instance WebSocket communication.

Remove deprecated bodyParser

Describe the bug
Replace depracated bodyParser with inbuild express parser

To Reproduce
NA

Expected behavior
NA

Screenshots
NA

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
bodyParser.json() --> express.json
bodyParser.urlencoded({extended: true}) --> express.urlencoded({extended: true})

Enable user to write a custom code to generate a response

Is your feature request related to a problem? Please describe.
Though with handlebars, user has an extensive capability to write conditions, run loops etc without writing a code, there might be some complex use cases where the user would need to write a custom code to generate a desired response.

Describe the solution you'd like
This can be implemented using a custom handlebar helper which can evaluate the code passed in via mock files and generate a desired response. Final implementation could look like following in a mock file:

HTTP/1.1 200 OK
X-Static-Header: Static-Value

{{code}}
function (request, logger) {
    var name = request.query.name;
    return {
        status: 201,
        headers: {
            "X-Dynamic-Header": "Dynamic-Value"
        },
        body: `{'greeting': 'Hello ${name}'}`
    }
}
{{/code}}

Describe alternatives you've considered
NA

Additional context
NA

Startup failure when proto package doesn't contain service

Describe the bug
The following error is reported by the server upon startup when the proto file below is included in grpc/protos:

/usr/local/lib/node_modules/camouflage-server/dist/protocols/index.js:140
                    let methods = Object.keys(service);
                                         ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at /usr/local/lib/node_modules/camouflage-server/dist/protocols/index.js:140:42
    at Array.forEach (<anonymous>)
    at Protocols.initGrpc (/usr/local/lib/node_modules/camouflage-server/dist/protocols/index.js:122:22)
    at Object.start (/usr/local/lib/node_modules/camouflage-server/dist/index.js:171:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/camouflage-server/bin/camouflage.js:280:14)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10

To Reproduce
Steps to reproduce the behavior:

  1. Add the following file to grpc/protos:
syntax = "proto3";

package com.livongo.protobuf.grpc.internal_non_production.template;

import "google/protobuf/wrappers.proto";
import "google/api/annotations.proto";

/**
* HelloWorld++ service. Has unary and streaming APIs.
*/
service HelloWorld {
    /** Pass in your name and get back a clever, personalized greeting! */
    rpc SayHello (ToBeGreeted) returns (Greeting) {
        option (google.api.http) = {
            post: "/v1/sayhello"
          };
    }
    /** Pass in a message and have it echoed back with embellishments! */
    rpc SayAnything (Greeting) returns (Greeting) {
        option (google.api.http) = {
            post: "/v1/sayanything"
          };
    }
    /**
    * Optionally pass in a number N (defaults to 1), and it returns a stream of N random numbers.
    */
    rpc GenIntStream (google.protobuf.Int32Value) returns (stream google.protobuf.Int32Value) {
        option (google.api.http) = {
            post: "/v1/genIntStream"
          };
    }

    // Pass in a stream of numbers (e.g., output from GenIntStream), and it returns a stream of min/max messages,
    // with an updated message emitted whenever the min and/or max seen so far in the input changes.
    rpc IntStreamToStatsStream (stream google.protobuf.Int32Value) returns (stream MinMax) {
        option (google.api.http) = {
            post: "/v1/intStreamToStatsStream"
          };
    }
}

// This is doc for message
message ToBeGreeted {
    message Person {
        string name = 1;
    }

    // A greetee is a person
    Person person = 1;
    google.protobuf.StringValue msg = 2;
}

message Greeting {
    string message = 1;
}

message Nothing {
}

message MinMax {
    int32 min = 1;
    int32 max = 2;
}

Expected behavior
No error upon startup should happen due to the above proto file.

Desktop (please complete the following information):

  • OS: MacOS Catalina
  • camouflage-server 0.5.1

Additional context
The following patch to add a guard around the possibly undefined service variable fixes the problem:

137a138
>                 if (typeof service !== 'undefined') {
159c160,161
<             });
---
>                 }});

Here's the log output when the error happens:

2021-07-26 13:27:07 debug: Camouflage configuration:
========
mocks_dir | ws.mocks_dir | http.port | http.enable | https.enable | http2.enable | grpc.enable | ws.enable | cache.enable | injection.enable | origins | ssl.key | ssl.cert | https.port | http2.port | grpc.host | grpc.port | grpc.mocks_dir | grpc.protos_dir | loglevel | backup.enable | backup.cron | configFile | ext_helpers | cache.ttl_seconds
========
./mocks | ./ws_mocks | 8080 | false | false | false | true | false | false | false | http://localhost:3000/,http://localhost:3001/,http://localhost:5000/ | ./certs/server.key | ./certs/server.cert | 8443 | 8081 | 8082 | localhost | 4312 | ./grpc/mocks | ./grpc/protos | debug | false | 0 * * * * | config.yml | ./custom_handlebar.json | 300
========
 
2021-07-26 13:27:07 info: [41045] Master Started 
2021-07-26 13:27:07 info: Cluster metrics server listening to 5555, metrics exposed on http://localhost:5555/metrics 
(node:41045) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
2021-07-26 13:27:08 info: CORS enabled for http://localhost:3000/, http://localhost:3001/, http://localhost:5000/ 
2021-07-26 13:27:08 info: [41048] Worker started 
2021-07-26 13:27:08 info: Handlebar helpers registration started 
2021-07-26 13:27:08 warn: Code Injection is disabled. Handlebars such as code and inject and functionalities such as external helpers, will not work.  
2021-07-26 13:27:08 info: Handlebar helpers registration completed 
2021-07-26 13:27:08 debug: Registering Unary method: createBlog 
2021-07-26 13:27:08 debug: Registering Unary method: listBlogs 
2021-07-26 13:27:08 debug: Registering Unary method: SayHello 
2021-07-26 13:27:08 debug: Registering Unary method: SayAnything 
2021-07-26 13:27:08 debug: Registering method with server side streaming: GenIntStream 
2021-07-26 13:27:08 debug: Registering method with BIDI streaming: IntStreamToStatsStream 
/usr/local/lib/node_modules/camouflage-server/dist/protocols/index.js.orig:138
                let methods = Object.keys(service);
                                     ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at /usr/local/lib/node_modules/camouflage-server/dist/protocols/index.js.orig:138:38
    at Array.forEach (<anonymous>)
    at Protocols.initGrpc (/usr/local/lib/node_modules/camouflage-server/dist/protocols/index.js.orig:122:22)
    at Object.start (/usr/local/lib/node_modules/camouflage-server/dist/index.js:171:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/camouflage-server/bin/camouflage.js:280:14)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:816:12)
2021-07-26 13:27:08 warn: [41048] Worker Stopped Mon Jul 26 2021 13:27:08 GMT-0700 (Pacific Daylight Time) 

Add a injection flag to enable or disable code handlebar

Is your feature request related to a problem? Please describe.
Since code injection can potentially be an exploitable vulnerability, users should be able to enable or disable code injection at their discretion.

Describe the solution you'd like
Add a new boolean property "injection" in config.yml which controls if external code can be executed by Camouflage.

Describe alternatives you've considered
NA

Additional context
NA

Add GitHub Actions for build, publish and release

Is your feature request related to a problem? Please describe.
Currently following steps are being carried out manually:

  • Checkout code
  • Change version in package.json according to the release type
  • Run npm install
  • Run npm run build
  • Run npm publish
  • Create a new GitHub release with changelog

Describe the solution you'd like
Above steps could be automated using Github Actions

Describe alternatives you've considered
NA

Additional context
NA

Feature :: Graphql mocking support

Is your feature request related to a problem? Please describe.
NA

Describe the solution you'd like
Graphql mocking support similar to existing REST mocking complete with handlebars for data generation, request matching etc

Describe alternatives you've considered
NA

Additional context
NA

camouflage init returns exit code 1

Describe the bug
camouflage init in an empty directory returns an exit code of 1

To Reproduce
Steps to reproduce the behavior:

  1. Make an empty directory
  2. Initialize camouflage
$ camouflage init
$ echo $?

Exit code returned is 1. All directories are created correctly and without issue. But for some reason the exit code is 1.

Expected behavior
Exit Code should be 0 in the case of successful initialization

Desktop (please complete the following information):

  • OS: MacOS Catalina
  • Version: 0.5.8

Additional context
I'm trying to build a Docker image with camouflage installed. The final command is camouflage init which produces an exit code 1. Tried it on my computer and I see the same issue.

Add ability to connect to external data source: MySQL/Postgres

Is your feature request related to a problem? Please describe.
User should be able to connect to a database to fetch data for the mock file

Describe the solution you'd like
At times only random numbers are not enough for generating a valid response and a user might want to connect to an external data to read some rows and columns. A new helper which reads data from a database and loads it into a data object accessible to user would be an ideal solution.

In the context of current issue, we can consider mysql/sqlite db as a template, which can later be used by contributor to develop custom handlebars to be loaded into Camouflage as per the issue #31

Describe alternatives you've considered
Random Data

Additional context
NA

Add JSDocs

Is your feature request related to a problem? Please describe.
To help interested contributor a detailed JSDocs would be a good point to start at.

Describe the solution you'd like
Add JSDocs

Describe alternatives you've considered
NA

Additional context
NA

Needed a way to override default options used by proto-loader

Is your feature request related to a problem? Please describe.
Camouflage uses default values provided by proto-loader and currently provides no way to override this values.

Describe the solution you'd like
Need to optionally load a protoloader_config.json at the startup, to override the default options if required.

Describe alternatives you've considered
NA

Additional context
NA

Allow json like messages for WS

Describe the bug
When I make a request to mock file below, I get an error.
Allow json like messages for WebSocket. Now I have to stringify WS json message.

To Reproduce
Steps to reproduce the behavior:

  1. Mock File Content
    ws_mocks/message.mock
{
    "self": {
        "status": "OK",
        "result": {
            "service": {
                "abc": "123"
            }
        }
    }
}
  1. Error Stack Trace
  throw new ERR_INVALID_ARG_TYPE(
  ^

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object
    at new NodeError (node:internal/errors:371:5)
    at Function.from (node:buffer:322:9)
    at toBuffer (/usr/local/lib/node_modules/camouflage-server/node_modules/ws/lib/buffer-util.js:97:18)
    at Sender.send (/usr/local/lib/node_modules/camouflage-server/node_modules/ws/lib/sender.js:265:17)
    at WebSocket.send (/usr/local/lib/node_modules/camouflage-server/node_modules/ws/lib/websocket.js:421:18)
    at Timeout._onTimeout (/usr/local/lib/node_modules/camouflage-server/dist/parser/WebsocketParser.js:61:28)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Expected behavior
Expects above mock file to work as is.

Incompatible with NodeJS v16.x

I tried to install camouflage-server but it refused to be installed because of strict node version limit. Here's the terminal output:

[athaariq@ArchLinux-VM] ~/web/learn-vuex
$ yarn add -D camouflage-server
yarn add v1.22.15
[1/4] Resolving packages...
warning camouflage-server > @opuscapita/filemanager-server > pdf2json > [email protected]: Deprecated due to CVE-2021-21366 resolved in 0.5.0
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
error [email protected]: The engine "node" is incompatible with this module. Expected version ">=8 <=15". Got "16.11.1"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
[FAIL|1]

Please consider to update the dependency thru your package.json, thanks!

Inject and code with condition on request body does not work because of API caching

Describe the bug
Writing handlebars with conditional request body will always return the same response even though the request body had changed.

To Reproduce
Steps to reproduce the behavior:

  1. Mock File Content
HTTP/1.1 {{#inject}}(()=>{
    if (request.body['email']==='[email protected]' && request.body['password']==='Password123456') {
        return '200 OK';
    } else {
        return '404 Not Found';
    }
})();{{/inject}}
Content-Type: application/json; charset=utf-8

{{#inject}}(()=>{
    if (request.body['email']==='[email protected]' && request.body['password']==='Password123456') {
        return `
        {
           "full_name": "Kien Nguyen",
           "email": "[email protected]",
           "created": "2021-03-05T10:25:40.680Z",
           "updated": "2021-03-05T11:16:18.389Z",
        }
        `;
    } else {
        return `
        {
            "error_code": "USER_NOT_FOUND_ERROR",
            "message": "User not found"
        }
        `;
    }
})();{{/inject}}
  1. Folder Structure sessions/POST.mock
  2. Error Stack Trace
...

Expected behavior
Should return response base on the request body

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Attach camouflage.log file

Startup fails when a directory is introduced in grpc/protos

Describe the bug
Camouflage startup fails when I add a directory to the grpc/protos folder.
The error I see is:

2021-07-27 16:38:14 warn: [84661] Worker Stopped Tue Jul 27 2021 16:38:14 GMT-0700 (Pacific Daylight Time)
2021-07-27 16:38:15 info: CORS enabled for http://localhost:3000/, http://localhost:3001/, http://localhost:5000/
2021-07-27 16:38:15 info: [84664] Worker started
2021-07-27 16:38:15 info: Handlebar helpers registration started
2021-07-27 16:38:15 warn: Code Injection is enabled.
2021-07-27 16:38:15 error: Loading custom handlebar helpers from ./custom_handlebar.json failed. File not found.
2021-07-27 16:38:15 info: Handlebar helpers registration completed
/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/root.js:104
            throw err;
            ^

Error: EISDIR: illegal operation on a directory, read
    at Object.readSync (node:fs:720:3)
    at tryReadSync (node:fs:430:20)
    at Object.readFileSync (node:fs:476:19)
    at fetch (/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/root.js:172:34)
    at Root.load (/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/root.js:206:13)
    at Root.loadSync (/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/root.js:247:17)
    at Object.loadProtosWithOptionsSync (/usr/local/lib/node_modules/camouflage-server/node_modules/@grpc/proto-loader/build/src/util.js:66:29)
    at Object.loadSync (/usr/local/lib/node_modules/camouflage-server/node_modules/@grpc/proto-loader/build/src/index.js:191:31)
    at /usr/local/lib/node_modules/camouflage-server/dist/protocols/index.js:106:46
    at Array.forEach (<anonymous>) {
  errno: -21,
  syscall: 'read',
  code: 'EISDIR'
}

To Reproduce
Steps to reproduce the behavior:

  1. Create any directory under ${CAMOUFLAGE_DIR}/grpc/protos
  2. Start up camouflage % camouflage --config config.yml

Expected behavior
Startup without any issues

Desktop (please complete the following information):

  • OS: MacOS Catalina
  • Browser - N/A - using grpcurl for grpc requests
  • Version - 0.5.2

Additional context
Tried out a sample grpc mock (the todoService.readTodos) which worked as expected. Tried to add a grpc mock for our use case which contains a couple of protos organised in directories. But startup fails when a directory is introduced.

Add lint to CI workflow

To enforce stricter checks on the code quality, use eslint to perform lint activities one each pull request to main branch.

Installation error - gc-stats fails to build with node-gyp

During installation, an optional dependency on gc-stats fails to build on specific node versions. However, Camouflage functionalities work as expected with the exception of probably the metrics exposed by prom-client. Since this is used only for monitoring purposes, fixing it or looking for alternatives is not a priority. PRs are welcome nonetheless.

[Help wanted] Cannot resolve/handle imports within grpc/protos during startup

Describe the bug
I have a proto file protocolVersion.proto which has an import statement like

...
import "com/company/foo/package/types/semanticVersion.proto"
...

Both proto files A.proto and B.proto are in the grpc/protos directory but when I try to startup Camouflage I see this error:

/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/namespace.js:411
        throw Error("no such Type or Enum '" + path + "' in " + this);
        ^

Error: no such Type or Enum 'SemanticVersion' in Type .com.company.foo.package.types.ProtocolVersion
    at Type.lookupTypeOrEnum (/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/namespace.js:411:15)
    at Field.resolve (/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/field.js:268:94)
    at Type.set (/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/type.js:177:38)
    at Type.get (/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/type.js:155:45)
    at Field.resolve (/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/field.js:317:21)
    at Type.resolveAll (/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/type.js:304:21)
    at Namespace.resolveAll (/usr/local/lib/node_modules/camouflage-server/node_modules/protobufjs/src/namespace.js:308:25)

I tried putting semanticVersion.proto in its own folder structure but i still couldn't find it. Should I be doing something else instead?

To Reproduce
Steps to reproduce the behavior:

  1. Create proto file A, proto file B in some package. Import B in A
  2. Startup camouflage

Expected behavior
Imports can be resolved/starts up correctly

Desktop (please complete the following information):

  • OS: macOS Catalina
  • Version: 0.5.5

Add support for remaining HTTP Verbs

Is your feature request related to a problem? Please describe.
Currently support verbs in Camouflage have been carried from the first experimental release. Camouflage should now support all the available HTTP Verbs.

Describe the solution you'd like
Implementation for remaining HTTP Verbs:

  • GET
  • HEAD
  • POST
  • PUT
  • DELETE
  • CONNECT
  • OPTIONS
  • TRACE
  • PATCH

Describe alternatives you've considered
NA

Additional context
NA

Fix out of sync config.yml samples

Describe the bug
Following sections are out of sync from the actual config.yml

  • camouflage.js
  • README.md
  • docs/getting-started.md

To Reproduce
NA

Expected behavior
Update required

Screenshots
NA

Desktop (please complete the following information):
NA

Additional context
NA

Allow capture handlebar for websocket

Is your feature request related to a problem? Please describe.
Allow capture handlebar for websocket. For example: I need to take some id from incoming message and put it in mock response.

Allow users to disable cache.

Is your feature request related to a problem? Please describe.
Using cache, while proves useful while running a performance test, might produce unfavorable results at times, while testing mocks functionally. As an end user, I should be able to disable cache if needed.

Describe the solution you'd like
Add a new boolean property in config.yml which controls Camouflage's behavior of caching request.

Describe alternatives you've considered
NA

Additional context
NA

Add ability to send random responses for same endpoints

Is your feature request related to a problem? Please describe.
Camouflage currently supports single response per endpoint, or multiple conditional responses per endpoint. However, one use case can be considered for the scenario where the user might want to randomly send multiple responses for the same endpoint without any conditions.

Describe the solution you'd like
Provide the ability to design mocks in a way that multiple responses can be specified in the same .mock file separated by a delimiter. Camouflage would then pick one response from those files at random for each invocation.

Describe alternatives you've considered
Conditional Responses

Additional context
NA

Add capability to send a custom default response

Is your feature request related to a problem? Please describe.
In cases Camouflage can not find a mockfile for an invoked endpoint, it sends following default response

{
    "error": "Not Found"
}

User should, however, be able to override this default response with custom default responses at global level and at the API level.

Describe the solution you'd like
Implementation as follows:

  1. User invokes a GET call to /default/error/response
  2. Corresponding mock file is evaluated as ${MOCK_DIR}/default/error/response/GET.mock
  3. Camouflage can not find the mock file, however it finds a directory ${MOCK_DIR}/default
  4. Camouflage determines ${MOCK_DIR}/default/__/GET.mock as the closest match for the invoked API.
  5. Camouflage looks for an API level default response in the closest match.
  6. If above mock file too, is unavailable, Camouflage looks for a global default response ${MOCK_DIR}/__/GET.mock
  7. Finally, if all determined mock files are unavailable, Camouflage sends its inbuilt default response as shown above.

Describe alternatives you've considered
NA

Additional context
NA

Add the ability/template for contributors/end users to develop custom handlebars

Is your feature request related to a problem? Please describe.
In case of a very specific problem, Camouflage should not try to implement all the handlebars internally, instead it should have a capability to add a custom handlebars from an external source.

Describe the solution you'd like
Contributors and Users should have the ability to write custom handlebars.

Describe alternatives you've considered
NA

Additional context
NA

Bug: UI and Management endpoints not available

Describe the bug
If http/https/http2 protocols are disabled, Camouflage UI and management endpoints such as /ping and /restart are not available.

To Reproduce
Steps to reproduce the behavior:

  1. Disable http/https/http2 protocols via config.yml
  2. Start camouflage server.
  3. Access Camouflage Homepage. eg. http://localhost:8080/

Expected behavior
Even though aforementioned protocols are disabled, UI and management endpoints should still be available.

Add ability to disable HTTP

Is your feature request related to a problem? Please describe.
Currently there is no config file parameter that allows a user to disable HTTP Protocol.

Describe the solution you'd like

  • Add a new property enable under protocols -> http in config.yml. By default this would be true
  • Add a new input parameter to start function in src/index.ts as enableHttp: boolean
  • In index.ts, wrap protocols.initHttp() inside an if block. if(enableHttp){}
  • In bin/camouflage.js, add config.protocols.http.enable property in inputs array.

Describe alternatives you've considered
NA

Additional context
NA

Convert camouflage.start() inputs from array to JSON object.

Is your feature request related to a problem? Please describe.
Camouflage currently accepts the inputs as an array, which makes it mandatory for parameters to be present in config.yml even if they are not needed. For example, parameters related to https/http2 are not present in config.yml, Camouflage should understand that ssl cert and key would not be required. With input as an array, contributors need to maintain a specific order while populating the inputs array

Describe the solution you'd like
Converting inputs to JSON brings following benefits

  • Contributors would not need to maintain a specific order while providing the values.
  • A CamouflageOptions interface can be created to maintain the required JSON. (with required and optional parameters)
  • Non mandatory values will automatically be considered as undefined while destructuring.

Describe alternatives you've considered
NA

Additional context
NA

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Camouflage takes a long time to start up with a size-able number of proto files

Describe the bug
Camouflage takes a long time to start up with a size-able number of proto files - say about 25+ files

To Reproduce
Steps to reproduce the behavior:
Unsure if I can fully describe how. Our proto files are organised in multiple directories and sub-directories.

Expected behavior
Camouflage should start up in less time - a wait for 20 mins doesn't bode well especially when we wish to include it as a part of a CI/CD pipeline

Desktop (please complete the following information):

  • OS: MacOS Catalina
  • Version - 0.5.6

Feature: Improve caching feature

Is your feature request related to a problem? Please describe.
Caching functionality currently includes basic caching configurations. However the caching library, i.e. apicache provides different configuration options, like caching in redis instead of memory, blacklisting headers, including or excluding specific status codes from being cached.

Describe the solution you'd like
Configuration options can be provided to Camouflage by adding a customizable options object, while instantiate cache object. Configurable key/values should be available in config.yml for modifications.

ES Lint Error: File has too many lines

Describe the bug
While listing the project, ES Lint throws following error,
301:1 error File has too many lines (306). Maximum allowed is 300 max-lines

To Reproduce
Steps to reproduce the behavior:

  1. Run npm run lint

Expected behavior
HandleBarDefinition class should be broken down into subclasses, 1 per helper.
Expected out from lint - No errors

Screenshots
NA

Desktop (please complete the following information):
NA

Additional context
NA

Doesn't support grpc package names with "."

Describe the bug
When a grpc package name contains one or more periods, e.g. foo.package, the mock grpc server fails to find the mocks and returns the error "The server does not implement the method /foo.package.HelloWorld/SayAnything".

Replacing the . in the package name with _ works around it, but when needing to use this for real projects with such package names and clients that use them, that's a costly workaround.

To Reproduce
Steps to reproduce the behavior:

  1. Mock File Content
    grpc/mocks/foo.package/HelloWorld/SayAnything.mock:
{
  "message": "foobar!!!!!"
}
  1. Proto file
    grpc/protos/hw5.proto:
syntax = "proto3";

package foo.package;

service HelloWorld {
    rpc SayAnything (Greeting) returns (Greeting) {
    }
}

message Greeting {
    string message = 1;
}
  1. Error Stack Trace
    grpcurl -v -d '{"message":"foobar!!"}' -proto grpc/protos/hw5.proto -plaintext localhost:4312 foo.package.HelloWorld/SayAnything
Resolved method descriptor:
rpc SayAnything ( .foo.package.Greeting ) returns ( .foo.package.Greeting );

Request metadata to send:
(empty)

Response headers received:
content-type: application/grpc+proto
date: Fri, 23 Jul 2021 18:14:16 GMT
grpc-accept-encoding: identity

Response trailers received:
(empty)
Sent 1 request and received 0 responses
ERROR:
  Code: Unimplemented
  Message: The server does not implement the method /foo.package.HelloWorld/SayAnything

Expected behavior
It should work like it does when the package has no .:

grpcurl -v -d '{"message":"foobar!!"}' -proto grpc/protos/hw4.proto -plaintext localhost:4312 foo_package.HelloWorld/SayAnything

Resolved method descriptor:
rpc SayAnything ( .foo_package.Greeting ) returns ( .foo_package.Greeting );

Request metadata to send:
(empty)

Response headers received:
content-type: application/grpc+proto
date: Fri, 23 Jul 2021 18:16:01 GMT
grpc-accept-encoding: identity

Response contents:
{
  "message": "foobar!!!!!"
}

Response trailers received:
(empty)
Sent 1 request and received 1 response

Desktop (please complete the following information):

  • OS: MacOS Catalina
  • camouflage-server 0.5.1

** Log file **

2021-07-23 11:10:10 debug: Camouflage configuration:
========
mocks_dir | ws.mocks_dir | http.port | http.enable | https.enable | http2.enable | grpc.enable | ws.enable | cache.enable | injection.enable | origins | ssl.key | ssl.cert | https.port | http2.port | grpc.host | grpc.port | grpc.mocks_dir | grpc.protos_dir | loglevel | backup.enable | backup.cron | configFile | ext_helpers | cache.ttl_seconds
========
./mocks | ./ws_mocks | 8080 | false | false | false | true | false | false | false | http://localhost:3000/,http://localhost:3001/,http://localhost:5000/ | ./certs/server.key | ./certs/server.cert | 8443 | 8081 | 8082 | localhost | 4312 | ./grpc/mocks | ./grpc/protos | debug | false | 0 * * * * | config.yml | ./custom_handlebar.json | 300
========
 
2021-07-23 11:10:10 info: [33656] Master Started 
2021-07-23 11:10:10 info: Cluster metrics server listening to 5555, metrics exposed on http://localhost:5555/metrics 
(node:33656) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
2021-07-23 11:10:12 info: CORS enabled for http://localhost:3000/, http://localhost:3001/, http://localhost:5000/ 
2021-07-23 11:10:12 info: [33659] Worker started 
2021-07-23 11:10:12 info: Handlebar helpers registration started 
2021-07-23 11:10:12 warn: Code Injection is disabled. Handlebars such as code and inject and functionalities such as external helpers, will not work.  
2021-07-23 11:10:12 info: Handlebar helpers registration completed 
2021-07-23 11:10:12 debug: Registering Unary method: createBlog 
2021-07-23 11:10:12 debug: Registering Unary method: listBlogs 
2021-07-23 11:10:12 debug: Registering Unary method: SayHello 
2021-07-23 11:10:12 debug: Registering Unary method: SayAnything 
2021-07-23 11:10:12 debug: Registering method with server side streaming: GenIntStream 
2021-07-23 11:10:12 debug: Registering method with BIDI streaming: IntStreamToStatsStream 
2021-07-23 11:10:12 debug: Registering Unary method: SayAnything 
2021-07-23 11:10:12 debug: Registering Unary method: createTodo 
2021-07-23 11:10:12 debug: Registering Unary method: readTodo 
2021-07-23 11:10:12 debug: Registering method with server side streaming: readTodoStream 
2021-07-23 11:10:12 debug: Registering method with client side streaming: createTodoStream 
2021-07-23 11:10:12 debug: Registering method with BIDI streaming: createTodoBidiStream 
(node:33659) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
2021-07-23 11:10:12 info: Worker sharing gRPC server at localhost:4312 ⛳ 
2021-07-23 11:10:34 debug: Mock file path: grpc/mocks/foo_package/HelloWorld/SayAnything.mock 
2021-07-23 11:10:34 debug: Response: {
  "message": "foobar!!!!!"
}

startup fails with backup error; backup.enable config ignored

Describe the bug
With the default configuration (backup.enable: true), the server fails with this error at startup:

2021-07-26 13:43:05 debug: Creating a new back up. 
/usr/local/lib/node_modules/camouflage-server/node_modules/fs-extra/lib/util/stat.js:51
    throw new Error('Source and destination must not be the same.')
    ^

Error: Source and destination must not be the same.
    at Object.checkPathsSync (/usr/local/lib/node_modules/camouflage-server/node_modules/fs-extra/lib/util/stat.js:51:11)
    at copyDirItem (/usr/local/lib/node_modules/camouflage-server/node_modules/fs-extra/lib/copy-sync/copy-sync.js:121:29)
    at /usr/local/lib/node_modules/camouflage-server/node_modules/fs-extra/lib/copy-sync/copy-sync.js:115:39
    at Array.forEach (<anonymous>)
    at copyDir (/usr/local/lib/node_modules/camouflage-server/node_modules/fs-extra/lib/copy-sync/copy-sync.js:115:23)
    at onDir (/usr/local/lib/node_modules/camouflage-server/node_modules/fs-extra/lib/copy-sync/copy-sync.js:105:10)
    at getStats (/usr/local/lib/node_modules/camouflage-server/node_modules/fs-extra/lib/copy-sync/copy-sync.js:45:37)
    at startCopy (/usr/local/lib/node_modules/camouflage-server/node_modules/fs-extra/lib/copy-sync/copy-sync.js:38:10)
    at handleFilterAndCopy (/usr/local/lib/node_modules/camouflage-server/node_modules/fs-extra/lib/copy-sync/copy-sync.js:33:10)
    at Object.copySync (/usr/local/lib/node_modules/camouflage-server/node_modules/fs-extra/lib/copy-sync/copy-sync.js:26:10)
2021-07-26 13:43:05 warn: [42197] Worker Stopped Mon Jul 26 2021 13:43:05 GMT-0700 (Pacific Daylight Time) 

Since there's some problem w/ the backup implementation, I tried to disable backups by setting backup.enable: false in my config.yaml, but surprisingly still got the same startup error, indicating the backup enable config. was ignored.

To Reproduce
Steps to reproduce the behavior:

  1. Add any new .proto file to grpc/protos. In my case I added the one given in #73 .
  2. Start the server: camoflauge --config config.yml

Expected behavior

  1. Backup should not fail when enabled
  2. Configuring backup.enable: false should disable backup

Desktop (please complete the following information):

  • OS: MacOS Catalina
  • camouflage-server 0.5.1

Additional context
Here's a patch to camouflage-server/bin/camoflauge.js to stop ignoring the backup.enable config:

207c207
<   config.backup.enable || true,
---
>   config.backup.enable,

Allow users to configure list of hosts for CORS via config.yml

Is your feature request related to a problem? Please describe.
For security reasons, camouflage server should only accept requests from specific origins.

Describe the solution you'd like
Camouflage should accept an array of domains/hosts for which CORS is enabled.

Describe alternatives you've considered
NA

Additional context
NA

Add ability to proxy requests to a downstream application

Is your feature request related to a problem? Please describe.
Currently Camouflage only supports mocked responses. However a valid use case is that at times user might want to proxy the downstream applications.

Describe the solution you'd like
User should be able write conditions in the mock file for proxying.

e.g. if a header, X-Fetch-Response-From: Proxy, is present in the incoming request, response should be fetched from a configured downstream, else from the mock.

Note that example above is just one of the use cases, similar conditions can be applied on any request objects.

Though Camouflage allows users to write conditions, it however does not have proxying capabilities.

This can be implemented by creating a new custom helper. The final mock file could look something similar to:

HTTP/1.1 200 OK
X-Header-Key: Header-Value

{{proxy to='http://example.com'}}

Camouflage will use specified headers and protocol from the mock file and fetch required response body from downstream. Handlebar would then return response object to HttpParser which would then be used to override default values.

Describe alternatives you've considered
NA

Additional context
NA

Fix eslint errors

Describe the bug
Fix eslint errors

  • Run lint on ts files instead of compiled js files
  • Fix resulting ts lint errors

To Reproduce
Steps to reproduce the behavior:

  1. npm run lint

Expected behavior
No lint errors

Screenshots
NA

Desktop (please complete the following information):
NA

Additional context
NA

body parsing will fail if lines are not in windows format (crlf)

Describe the bug
If you want to write a .moc file, you have to pay attention to the line endings in the file. the parser looks for the platform-specific line endings or uses windows line endings (\r\n)
If you use in your editor lf (\n) you get a mystiric error about some json content that is unexpected ended.

To Reproduce

  1. create a file with line endings (lf) for me switching that is very easly with notepad++
  2. set Content-Type to "application/json"
  3. set the logger to debug level
  4. look in the log output, if you have done a request

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser chrome
  • Version latest (0.5.00)

Additional context
here a little snipped of the log, if the error accoured for me:

2021-06-30 19:56:28 �[32minfo�[39m: [14864] Master Started 2021-06-30 19:56:28 �[32minfo�[39m: Cluster metrics server listening to 5555, metrics exposed on http://localhost:5555/metrics 2021-06-30 19:56:30 �[32minfo�[39m: CORS enabled for http://localhost:1443/, http://localhost:1415/, http://localhost:5000/ 2021-06-30 19:56:30 �[32minfo�[39m: [22044] Worker started 2021-06-30 19:56:30 �[32minfo�[39m: Handlebar helpers registration started 2021-06-30 19:56:30 �[33mwarn�[39m: Code Injection is enabled. 2021-06-30 19:56:30 �[31merror�[39m: Loading custom handlebar helpers from ./custom_handlebar.json failed. File not found. 2021-06-30 19:56:30 �[32minfo�[39m: Handlebar helpers registration completed 2021-06-30 19:56:30 �[34mdebug�[39m: Creating a new back up. 2021-06-30 19:56:30 �[34mdebug�[39m: Finished creating a new back up. 2021-06-30 19:56:30 �[32minfo�[39m: Scheduled a backup cron job with specified cron: 0 * * * * 2021-06-30 19:56:30 �[32minfo�[39m: Worker sharing HTTP server at http://localhost:1412 ⛳ 2021-06-30 19:56:33 �[34mdebug�[39m: Response Status set to 200 2021-06-30 19:56:33 �[33mwarn�[39m: Unexpected end of JSON input 2021-06-30 19:56:33 �[34mdebug�[39m: Generated Response 2021-06-30 19:56:33 �[34mdebug�[39m: HTTP POST /xyz/abc :: Query Parameters: {"uuid":"c94dfc38f01989b87ac9a60c6bdb8caf","somesecret":"7777777777"} | Request Headers {"accept":"application/json, text/json, text/x-json, text/javascript, application/xml, text/xml","user-agent":"RestSharp/106.11.7.0","content-type":"application/x-www-form-urlencoded","host":"localhost:1412","content-length":"3309","accept-encoding":"gzip, deflate","connection":"Keep-Alive"} | Request Body ***secret ***

Code example does not return expected value

Describe the bug
While trying to test the inbuilt example for code, the response is always empty. Similar issue is seen with inject example where the response is incomplete and look like below

{
    "phone":
}

To Reproduce
Start the camouflage server and goto

http://localhost:8080/code/inject
http://localhost:8080/code

Expected behavior
It should return a valid JSON

Desktop (please complete the following information):

OS: MacOS Big Sur
Version - 11.6

Node version: 14.17.5

Error while restoring backed up project

Describe the bug
While restoring a backup, camouflage throws an error for the directories not present. This might be due to missing exception handling.

To Reproduce
Steps to reproduce the behavior:
3. Error Stack Trace

internal/validators.js:124
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)
    at Object.resolve (path.js:980:7)
    at Object.<anonymous> (/usr/local/lib/node_modules/camouflage-server/bin/camouflage.js:116:82)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_INVALID_ARG_TYPE'
}

Expected behavior
For missing directories, camouflage should not throw a fatal error. Instead, restore should log an error message and proceed to next directory.

Screenshots
NA

Desktop (please complete the following information):
NA

Additional context
NA

Add ability to connect to external data source: CSV

Is your feature request related to a problem? Please describe.
User should be able to connect to a CSV file to fetch data for the mock file

Describe the solution you'd like
At times only random numbers are not enough for generating a valid response and a user might want to connect to an external data to read some rows and columns. A new helper which reads data from a csv file and loads it into a data object accessible to user would be an ideal solution

Describe alternatives you've considered
Random Data

Additional context
NA

Fix/Replace vulnerable dependencies

Describe the bug

9 vulnerabilities (7 moderate, 1 high, 1 critical)

To Reproduce
Steps to reproduce the behavior:

  1. npm install -g camouflage-server
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142

added 17 packages, changed 390 packages, and audited 414 packages in 36s

17 packages are looking for funding
  run `npm fund` for details

9 vulnerabilities (7 moderate, 1 high, 1 critical)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

Expected behavior
No critical or high vulnerabilities

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.