Martin Jönsson
Martin Jönsson

Reputation: 1

K6 Get request result in error against specific endpoint URL

I am new to K6 and am trying to use the tool to perform a Get request by verifying an API. When the script is executed I get a warning that terminates the scrip. As far as my understanding is that this error is somewhat related to Go (if I have understood it correctly).

The result that I want to achieve is to be able to execute the Get request to the endpoint URL, but would appreciate any kind of feedback if I have done any incorrectly or should try an other approach.

Script:

import http from "k6/http";
import { check } from "k6";

export default function () {
  var url =
    "https://endpoint.example.to.cloud/api/reports/v1/SMOKETESTC6KP6NWX";

  var headerParam = {
    headers: {
      "Content-Type": "application/json",
    },
  };

  const response = http.get(url, headerParam);

  check(response, {
    "Response status reciving a 200 response ": (r) => r.status === 200,
  });

  let body = JSON.parse(response.body);
}

Output:

WARN[0000] Request Failed error="Get \"https://endpoint.example.to.cloud/api/reports/v1/SMOKETESTC6KP6NWX\": x509: certificate relies on legacy Common Name field, use SANs or temporarily enable Common Name matching with GODEBUG=x509ignoreCN=0"

Changing URL endpoint: If i change the URL endpoint (mockup url) like below, there will be no errors:

...
var url = "https://run.mocky.io/v3/16fa8113-57e0-4e47-99b9-b5c55da93d71";
...

Updated solution to run this locally:

In order to run this locally i had to add the certification and key: Example:

export let options = {
    ...
  
    tlsAuth: [
      {
        cert: open(`${__ENV.Certificate}`),
        key: open(`${__ENV.Key}`),
      },
    ],
  };

In addition populate the execute command with --insecure-skip-tls-verify

Example:

k6 run -e Certificate=/home/cert/example_certification.crt -e Key=/home/cert/certification/example_key.key -e example.js --insecure-skip-tls-verify

Upvotes: 0

Views: 1577

Answers (1)

na--
na--

Reputation: 1106

k6 is written in Go, and the latest versions of Go have a breaking change in how they handle X.509 certificates: https://golang.org/doc/go1.15#commonname

As it says in the error message, you can temporarily allow the old behavior by setting a GODEBUG=x509ignoreCN=0 environment variable, but that will likely stop working in a few months with Go 1.17. Using the insecureSkipTLSVerify k6 option might also work, I haven't checked, but as the name implies, that stops any TLS verification and is insecure.

So the real solution is to re-generate your server-side certificate properly.

Upvotes: 2

Related Questions