usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
27.62k stars 1.28k forks source link

Javascript code to generate OTP code based on secrets is not working #3379

Open dougleenhouts opened 3 weeks ago

dougleenhouts commented 3 weeks ago

I have checked the following:

Describe the bug

I use this well-known script in Postman to generate a 6-digit OTP code in a pre-request script based on a variable for a secret key: https://gist.github.com/ptrstpp950/42660823675f6bf2f2d2f1503663553a

But when I try to run the same pre-request script in Bruno I get this error:

Error invoking remote method 'send-http-request': TypeError: Cannot read properties of undefined (reading 'length')

I don't see any equivalent to the Postman console to find any more details either.

.bru file to reproduce the bug

No response

Screenshots/Live demo link

https://github.com/user-attachments/assets/6de4ac96-5b6f-441f-97c0-93394917654a

sreelakshmi-bruno commented 2 weeks ago

Hi @dougleenhouts, I tried to run the script on our latest version(1.34.2) and it worked fine. I've attached the bruno collection here for you to try it out. Create an environment after you import it. Please let me know how it goes! Temp Test.json

dougleenhouts commented 1 week ago

Thanks @sreelakshmi-bruno , that attached collection works in safe mode, but in developer mode (on 1.34.0) it returns:

Error invoking remote method 'send-http-request': TypeError: X.jsSHA is not a constructor

Pragadesh44-Bruno commented 1 week ago

Hey @dougleenhouts,

In Bruno, we use two different runtimes for Safe and Dev modes: a browser-based runtime and a Node-based runtime. In the script above (line 2246), there is no need to export the module in the Node runtime code. If we fix that, it won’t be an issue. In the updated gist, we have removed the export logic.

PS: To understand the diff between the behavior try running the script in Node.js runtime and in browser

sreelakshmi-bruno commented 1 week ago

Hi @dougleenhouts, I've attached the collection we've created by removing that function. Please check it out and let us know how it goes.

Temp Test OTP.json