postman-to-k6 icon indicating copy to clipboard operation
postman-to-k6 copied to clipboard

Can not use atob function because of different built-in libraries

Open fourcolor opened this issue 2 years ago • 2 comments

I use many atob function in my postman collection; indeed, it not work in k6 script. However I found that I can easily fix it by using the k6/encoding module.

import { b64decode } from "k6/encoding";
const atob = (str) => {
  return b64decode(str, "rawstd", "s");
};

I want to ask is there any plan to support this kind of problem? e.g. crypto-js -> k6/crypto

fourcolor avatar Sep 29 '22 16:09 fourcolor

hi @fourcolor,

Do I understand correctly, that you want to add the atob() function when it is detected in the Postman collection?

Do you have an example of a Postman collection where you used the atob function?

thim81 avatar Nov 12 '22 19:11 thim81

  1. Yes
  2. Here is the example
pm.test("Living JWT token", function () {
    let jsonData = pm.response.json();
    let Playload = JSON.parse(atob(jsonData.JWT.split(".")[1]));
    let iat = new Number(Playload.iat);
    let exp = new Number(Playload.exp);
    let dateToSecond = Math.ceil(Date.now()/1000);
    //check JWT token was issued in the past and expire in the future which means it is an effect token for now
    pm.expect(dateToSecond).to.be.within(iat,exp);
});

fourcolor avatar Nov 28 '22 16:11 fourcolor