mock-server / mockserver-client-node

MockServer javascript client for browsers, Node.js or any grunt build
http://mock-server.com
Apache License 2.0
72 stars 34 forks source link

SSL Issue in the latest version #40

Closed calbertts closed 4 years ago

calbertts commented 4 years ago

Describe the issue I've been using mock-server successfully several months ago, but today, trying to upgrade to the latest version, I'm unable to load expectations.

What you are trying to do Load expectations with a NodeJS script.

MockServer version 5.6.1 -> Works! 5.9.0 -> Doesn't work

To Reproduce Run a mock-server in the 443 port with -serverPort

  1. How you are running MockServer: Docker
    
    export CONTAINER_NAME=my-mock-server
    export HOST_PORT=8243                       # your local port
    export CONTAINER_PORT=443              # port inside the container
    export DOCKER_IMAGE=jamesdbloom/mockserver:mockserver-5.9.0

docker run \ -u 0 \ --memory=1GB \ -d \ --name $CONTAINER_NAME \ -p $HOST_PORT:$CONTAINER_PORT \ $DOCKER_IMAGE -serverPort $CONTAINER_PORT


2. Code you used to create expectations
await mocksServer.mockAnyResponse({
  httpRequest: {
    method: 'POST',
    path:   '/my/url',
    headers: {
      'Authorization': [ 'Basic 1234' ]
    },
    body: {
      type: 'STRING',
      string: 'grant_type=client_credentials',
      contentType: 'application/x-www-form-urlencoded'
    }
  },
  httpResponse: {
    body: JSON.stringify({
      access_token: '1234',
      scope: 'default',
      token_type: 'Bearer',
      expires_in: 1113
    })
  }
})

3. What error you saw

Fetching { "protocol": "https:", "method": "GET", "host": "raw.githubusercontent.com", "path": "/mock-server/mockserver/master/mockserver-core/src/main/resources/org/mockserver/socket/CertificateAuthorityCertificate.pem", "port": 443 } failed with error Error: connect ETIMEDOUT 151.101.132.133:443



**Expected behaviour**
The expectation should be loaded

**MockServer Log**
No logs are shown.
calbertts commented 4 years ago

It turns out to be an issue with the client library only, with the latest docker image version works fine until mockserver-client@5.7.0

The issue starts from mockserver-client@5.7.1

jamesdbloom commented 4 years ago

I believe this is fixed in the latest version 5.11.0, I used the following code:

function createExpectation() {
    var mockServerClient = require('mockserver-client').mockServerClient;
    mockServerClient("localhost", 1080)
        .mockAnyResponse({
            "httpRequest": {
                "method": "GET",
                "path": "/view/cart",
                "queryStringParameters": {
                    "cartId": ["055CA455-1DF7-45BB-8535-4F83E7266092"]
                },
                "cookies": {
                    "session": "4930456C-C718-476F-971F-CB8E047AB349"
                }
            },
            "httpResponse": {
                "body": "some_response_body"
            }
        })
        .then(
            function () {
                console.log("expectation created");
            },
            function (error) {
                console.log(error);
            }
        );
}

createExpectation();

and got the following output:

Saved CertificateAuthorityCertificate.pem from {
  "protocol": "https:",
  "method": "GET",
  "host": "raw.githubusercontent.com",
  "path": "/mock-server/mockserver/master/mockserver-core/src/main/resources/org/mockserver/socket/CertificateAuthorityCertificate.pem",
  "port": 443
}
expectation created

Please try the latest version, I'm going to close this issue but if it is not fixed please comment here or create a new issue.

dbubenheim commented 3 years ago

Hi @jamesdbloom. Yesterday I wanted to update our mock-server setup to the latest version. We're using a mock-server docker installation and the mock-server-client-node for creating expectations. So we switched to 5.11.2 but unfortunately I faced the very same issue that was mentioned by @calbertts. Everything works fine with the mock-server-client up to 5.7.0, but all later versions result in the mentioned issue. In our setup we're not using any TLS/HTTPS communication at all. Do you have any idea, what could be the reason for that? What I've also noticed is, that communication via REST-API (curl) works fine as well.