Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockServer Returns Invalid HTTP Status Code '0 U' Causing Parsing Errors and Timeouts #1932

Open
OrCAD-sys opened this issue Feb 20, 2025 · 0 comments

Comments

@OrCAD-sys
Copy link

Describe the issue
I am encountering an issue when trying to create an API simulation using MockServer that returns a status code of 0 for my POST request. Instead of a valid HTTP status code, the response is returning '0 U', which is causing an immediate invalid HTTP status error and resulting in timeouts when attempting to handle the response.

What you are trying to do
I am attempting to simulate an API that should return a status code of 0 for a specific POST request. However, MockServer seems to be responding with an improperly formatted status code ('0 U'), leading to parsing errors and connectivity issues.

MockServer version

{
    "artifactId": "mockserver-core",
    "groupId": "org.mock-server",
    "ports": [1080],
    "version": "5.14.0"
}

Deployment Configuration (Masked)

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: mock-server
    argocd.argoproj.io/instance: stg-mock-server
    chart: mock-server-5.14.1
    heritage: Helm
    release: mockserver
  name: mock-server
  namespace: mock-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mock-server
      release: mockserver
  template:
    metadata:
      labels:
        app: mock-server
        product: mock-server
        release: mockserver
    name: mock-server
    spec:
      containers:
      - env:
        - name: MOCKSERVER_LOG_LEVEL
          value: INFO
        - name: MOCKSERVER_FORWARD_PROXY_TLS_PRIVATE_KEY
          value: /org/mockserver/socket/private.pem
        - name: MOCKSERVER_FORWARD_PROXY_TLS_X509_CERTIFICATE_CHAIN
          value: /org/mockserver/socket/public.pem
        - name: SERVER_PORT
          value: '1080'
        image: 'mockserver/mockserver:mockserver-5.14.0'
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 10
          initialDelaySeconds: 10
          periodSeconds: 5
          successThreshold: 1
          tcpSocket:
            port: serviceport
        name: mock-server
        ports:
          - containerPort: 1080
            name: serviceport
            protocol: TCP
        readinessProbe:
          failureThreshold: 10
          initialDelaySeconds: 2
          periodSeconds: 2
          successThreshold: 1
          tcpSocket:
            port: serviceport
        securityContext:
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: false
          runAsUser: 65534
        volumeMounts:
        - mountPath: /config
          name: config-volume
        - mountPath: /libs
          name: libs-volume
        - mountPath: /org/mockserver/socket/private.pem
          name: private-key
          readOnly: true
          subPath: private.pem
        - mountPath: /org/mockserver/socket/public.pem
          name: public-key
          readOnly: true
          subPath: public.pem
      serviceAccountName: default
      volumes:
      - configMap:
          name: mockserver-config
          optional: true
        name: config-volume
      - configMap:
          name: mockserver-config
          optional: true
        name: libs-volume
      - name: public-key
        secret:
          items:
          - key: public-pem
            path: public.pem
          secretName: tls-keys
      - name: private-key
        secret:
          items:
          - key: private-pem
            path: private.pem
          secretName: tls-keys

ENTRYPOINT Configuration

ENTRYPOINT ["java", "-Dfile.encoding=UTF-8", "-cp", "/mockserver-netty-jar-with-dependencies.jar:/libs/*", "-Dmockserver.propertyFile=/config/mockserver.properties", "org.mockserver.cli.Main"]

To Reproduce
Steps to reproduce the issue:

  1. How you are running MockServer
    I am running MockServer in a Docker container deployed on Kubernetes using Helm.
    Example command for running locally:

    docker run -d -p 1080:1080 mockserver/mockserver
  2. Code used to create expectations

    new MockServerClient("localhost", 1080)
        .when(
            request()
                .withMethod("POST")
                .withPath("/v1/partners/test/transfers/funding")
                .withBody("{"funding_transfer":{"transfer_reference":"{{$guid}}"}}")
        )
        .respond(
            response()
                .withStatusCode(0)  // Attempting to return a status code of 0
                .withDelay(TimeUnit.MILLISECONDS, 1)  // Introducing a slight delay
        );

What error you saw
When I send the request using a client (such as Postman or RestSharp), I immediately receive the following error:

Request Details
Request Headers:

Content-Type: application/json;charset=UTF-8
Accept: application/json

Request Body:

{
    "funding_transfer": {
        "transfer_reference": "cd8f2ad5-177a-4085-8b1e-c75b18e2ebda"
    }
}

Error Message:

Received an invalid status code: '0 U'.

Expected behaviour
MockServer should return a valid HTTP status code (such as 200) instead of 0 or any invalid representation like '0 U' when a POST request with the specified body is made to /v1/partners/test/transfers/funding.

MockServer Log
Here’s the log message confirming that the expectation was created and the response being returned:

02-20 09:36:04.447 EXPECTATION_RESPONSE    
returning response:	
{
  "statusCode": 0,
  "delay": {
    "timeUnit": "MILLISECONDS",
    "value": 1
  }
}
for request:	
{
  "method": "POST",
  "path": "/v1/partners/test/transfers/funding",
  "body": {
    "funding_transfer": { ... }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant