@@
Update: I realized that I need to setup my K6 repo as a trusted client for TLS to work.So I’m going to give that a try. But i wonder why skip tls option offered by K6 is not working.
K6_INSECURE_SKIP_TLS_VERIFY=false k6 run test.js
k6 run --insecure-skip-tls-verify eventstlsauth.js
these commands give this error
WARN[0000] Request Failed error=“Post "https://endpoint/token\”: remote error: tls: handshake failure"
@@
hey folks! I’m new to K6 and I have hit a wall in dealing with calling an endpoint that uses tls auth and I’m facing an error that says
WARN[0000] Request Failed error="Post \"https:endpointname\": tls: failed to verify certificate: x509: certificate signed by unknown authority"
Code that I use is below
import http from 'k6/http';
// tried this way of passing tls auth via options as suggested in k6 doc and it doesn't work
// So below is the second way of passing via request options
// export const options = {
// tlsAuth: [
// {
// // domains: ['mtls-api.dev.connectid.com.au'],
// cert: open('./transport.pem'),
// key: open('./transport.key'),
// },
// ],
// };
const cert = open('./transport2.pem');
const key = open('./transport2.key');
export function setup() {
// Define the request headers with mTLS client certificate and key
let headers = {
'Content-Type': 'application/x-www-form-urlencoded',
};
//
// Define the token endpoint URL
let tokenEndpoint = 'https://<mytlsendpoint>/token';
// Define the request body
const requestBody = 'param1=value1¶m2=valu2¶m3=value3'
const requestOptions = {
headers: headers,
tls: {
client_cert: cert,
client_key: key,
},
// tls_insecure_skip_verify: true, // Include this to skip TLS verification
};
// Perform a POST request to obtain the token
let response = http.post(tokenEndpoint, requestBody, requestOptions);
console.log(response.status);
// Check the response and extract the token
check(response, {
'Token Obtained': (r) => r.status === 200,
});
return response.json('access_token'); // Assuming the token is in the JSON response
}
export default function () {
}Preformatted text
Any help/pointers are appreciated.