Need to load certificate in K6

We are using k6 in testing, I want to import the certificate ( perm file & key ) in k6 , can you pls let me know how we can use the certificate in k6 run & postman-k6 command.

- export MTLS_PEM="$(Details")"

- echo $MTLS_PEM | sed 's/\\n/\n/g' > mtls.pem

- export MTLS_KEY="$(details")"

- echo $MTLS_KEY | sed 's/\\n/\n/g' > mtls.key

k6 run --summary-export=load-performance.json $file --config=src/test/performance/config.json;

postman-to-k6 -e /$POSTMAN_ENV-$API_NAME.postman_environment.json $file -o /$filename-k6-script.js ;

Hi @Hemant !

Welcome to the community forums! :wave:

Not sure if I got the question fully :thinking: But let me try to answer for the headline part. So if the question is how to set up the TLS Auth you can use the option Options reference.

Let me know if that answers,
Cheers!

Hi …

I need to import mtls.pem & mtls.key in below

k6 run --summary-export=load-performance.json $file --config=src/test/performance/config.json;

postman-to-k6 -e /$POSTMAN_ENV-$API_NAME.postman_environment.json $file -o /$filename-k6-script.js ;

I have check the link provided but not sure how i can add this in above script. Can you pls help.

Hi @Hemant

From the commands that you provided I see that you are trying to do 2 things:

  1. Conver an existing postman collection to a k6 script using the tool postman-to-k6
  2. Run the converted script using the k6

So what I’m saying is that after converting the postman collection you have to adjust the options inside the result script, and there put:

tlsAuth: [
    {
      domains: ['example.com'],
      cert: open('mtls.pem'),
      key: open('mtls.key'),
    },
  ]

Note that the mtls.key and mtls.pem should be placed in the same folder.

There is a nice blog post about this topic Load Testing Your API with Postman

Let me know if that answers,
Cheers!