Hi,
When I make an mTLS call using K6 I end up getting a 401 Not Authorized - likely due to certificates . Not sure where I am making a mistake . This is the code that I have
import http from ‘k6/http’;
import encoding from 'k6/encoding';
import { check } from ‘k6’;
export const options = {
// … other options …
insecureSkipTLSVerify: true,
tlsAuth: [
{
domains: [‘ldomain1’, ‘domain2’], // Replace with your target domain(s)
cert: open(‘cert.cer’), // Path to your client certificate
key: open(‘key.key’), // Path to your client private key
},
// You can add more objects for different domains/certificates if needed
\],
};
const baseUrl = ‘https:///xxxxxxxx’;
const evurl = ‘https:///xxxxxx’;
const token_headers = {
“Content-Type”:“application/x-www-form-urlencoded”,
“User-Agent”:“PostmanRuntime”
}
const params_token = {
grant_type: ‘client_credentials’,
client_id: ‘>’
};
const params_ev = {
<redacted>>: "xxx",
<redacted>: "<redacted>",
<redacted>: "1",
<redacted>: "<redacted>"
}
export default function()
{
const res = http.post(baseUrl,params_token,token_headers);
console.log(`Response status: ${res.status}`);
console.log(`Response body: ${res.body}`);
const access_token = res.json().access_token;
const ev_headers = {
“User-Agent”: “PostmanRuntime7.50.0”,
“Authorization”: "Bearer "+ access_token,
//“Authorization”: hardtoken,
“”: “”,
“”: “”,
“”: “”,
“”: “”,
} ;
console.log(“linebreak”);
console.log(ev_headers);
console.log(params_ev);
const res_ev = http.get(evurl,params_ev,ev_headers);
console.log(`Response status: ${res_ev.status}`);
console.log(`Response body: ${res_ev.body}`);
console.log(`Response body: ${JSON.stringify(res_ev.headers)}`);
The first call to domain 1 goes through but the second call to domain 2 does not go through. However the same paraneters / headers / certs work in postman