postman-to-k6
postman-to-k6 copied to clipboard
Can not use atob function because of different built-in libraries
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
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?
- Yes
- 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);
});