Connection Tests for GUI-less Operating Systems

Blog from 2/13/2023

Installing and running Mockoon without a GUI

In certain server configurations, you do not have a GUI available for the connection test, but e. g. only SSH access. In such an environment, you need to run Mockoon or another mock tool as a command line version (mockoon-cli). This block article focuses on only on a Mockoon installation. For all other topics, such as performing tests for inbound connections or outbound connections, please refer to the corresponding block articles (e.g., Test Jira Connectivity on OS Level).

Installation

To obtain a command line version of Mockoon you have to install mockoon-cli. Please also refer https://mockoon.com/cli/ for details.

Installation with Node.js

Use the following instructions to install mockoon-cli using Node.js:

  1. Install Node.js on your server. See also https://nodejs.org/ for more details.

  2. Install Node Version Manager (nvm). See https://github.com/nvm-sh/nvm#installing-and-updating for details.

  3. Run the following commands to install mockoon

nvm install v14.21.2

nvm use 14.21.2

npm install -g @mockoon/cli

Installation with Docker

Use the following command to install mockoon-cli via Docker:

docker pull mockoon/cli

Create your Mockoon environment

Since mockoon-cli has no configuration GUI, the configuration has to be specified via a JSON file.

Create a file mockoon_environment.json with the following content:

 

{

    "uuid": "",

    "lastMigration": 13,

    "name": "connection-test",

    "endpointPrefix": "",

    "latency": 0,

    "servers": [

        {

            "url": "https://localhost:<PORT>/"

        }

    ],

    "tlsOptions": {

        "enabled": true,

        "type": "PFX",

        "pfxPath": "<PATH_TO_PFX_FILE>",

        "certPath": "",

        "keyPath": "",

        "caPath": "",

        "passphrase": "<PASSWORD_FOR_PFX_FILE>"

    },

    "routes": [

        {

            "uuid": "",

            "documentation": "Get a list of posts (JSON)",

            "method": "get",

            "endpoint": "get",

            "responses": [

                {

                    "uuid": "",

                    "body": "{ \"test_response\": \"GET OK\" }",

                    "latency": 0,

                    "statusCode": 200,

                    "label": "Success",

                    "headers": [

                        {

                            "key": "",

                            "value": ""

                        }

                    ],

                    "filePath": "",

                    "sendFileAsBody": false,

                    "rules": [],

                    "rulesOperator": "OR",

                    "disableTemplating": false

                }

            ],

            "enabled": true,

            "randomResponse": false

        },

        {

            "uuid": "",

            "documentation": "Create a user",

            "method": "post",

            "endpoint": "post",

            "responses": [

                {

                    "uuid": "",

                    "body": "{ \"test_response\": \"POST OK\" }",

                    "latency": 0,

                    "statusCode": 201,

                    "label": "Created",

                    "headers": [

                        {

                            "key": "",

                            "value": ""

                        }

                    ],

                    "filePath": "",

                    "sendFileAsBody": false,

                    "rules": [],

                    "rulesOperator": "OR",

                    "disableTemplating": false

                }

            ],

            "enabled": true,

            "randomResponse": false

        }

    ],

    "proxyMode": false,

    "proxyHost": "",

    "https": false,

    "cors": true,

    "headers": [

        {

            "key": "Content-Type",

            "value": "application/json"

        }

    ],

    "proxyReqHeaders": [

        {

            "key": "",

            "value": ""

        }

    ],

    "proxyResHeaders": [

        {

            "key": "",

            "value": ""

        }

    ]

}

 

Please replace <PORT>, <PATH_TO_PFX_FILE> and <PASSWORD_FOR_PFX_FILE> with the actual values.

When running under Node.js, <PATH_TO_PFX_FILE> can be an absolute path.

When running under Docker, <PATH_TO_PFX_FILE> needs to be a relative Unix path to the docker mountpoint you create in the next section.

Note: You can also provide a certificate file and a key file instead of the pfx file. In this case use "type": "CERT" in the config file and fill the corresponding fields certPath and keyPath.

Run mockoon-cli

Run under Node.js

Please use the following command to run the mockoon server when installed via Node.js:

mockoon-cli start –-data <PATH_TO_ENVIRONMENT_JSON>

Run under docker

Please use the following command to run the mockoon server when installed via Node.js:

docker run -d --mount type=bind,source=’<DOCKER_MOUNT_PATH>’,target=/data,readonly -p <PORT>:<PORT> mockoon/cli:latest --data data/mockoon_environment.json --port <PORT>

Notes:

Your <DOCKER_MOUNT_PATH> needs to contain the PFX file for HTTPS and the environment JSON file. Their relative paths to the mountpoint need to be specified on the command line and in the config JSON.

The occurrences of <PORT> need to be replaced with the port you specified in your environment JSON.

Endpoint URLs

Once mockoon-cli is running the following endpoints are exposed on the host:

  • For GET requests: https://<HOST>:<PORT>/get

  • For POST requests: https://<HOST>:<PORT>/post

The response body for the requests looks as follows:

  • { "test_response": "GET OK" }

  • { "test_response": "POST OK" }

NOTE: In some of our blogs the endpoints are specified as provided by the GUI version. If you are using the current blog here to perform your setup, please consider the different endpoints and results when running subsequent tests.