yaade icon indicating copy to clipboard operation
yaade copied to clipboard

Question: How to test an API with credentials?

Open jhjacobs81 opened this issue 1 year ago • 3 comments

Is it possible to test an api with credentials? so i can post my login details to /api/login and have it saved for future testing?

Or maybe i am overlooking something?

jhjacobs81 avatar Nov 06 '24 09:11 jhjacobs81

What kind of authentication system do you use? If you use something token based than you can simply store the token in an environment.

jonrosner avatar Nov 06 '24 14:11 jonrosner

hello Jon, thank you for responding :)

currently i do this: curl -c cookies.txt -X POST http://127.0.0.1:8080/login -H "Content-Type: application/json" -d '{ "Username": "user", "Password": "password" }'

which will generate a cookies.txt like this: 127.0.0.1:8080 FALSE / TRUE 1733555692 AppName MTczMDk2MzY5M3xEWDhFQVFMX2dBQUJFQUVRQUFBZl80QUFBUVp6ZEhKcGJtY01DUUFIZFhObGNsOXBaQVIxYVc1MEJnSUFHQT09fLtMohuQTYQ_xjDYdRxghTX1E_2NRVIyfgtvCnppCpbW

and then on subsequent request i do this: curl -b cookies.txt -X POST http://127.0.0.1:8080/create -H "Content-Type: application/json" -d '{ "Username": "user1", "Password": "userpass" }'

its a session based webapp

jhjacobs81 avatar Nov 07 '24 07:11 jhjacobs81

you can put a response script on the login request to set an env var wit the token that the login endpoint gives you

And make other requests use the token stored on the environment env var

progsoftpack avatar Feb 17 '25 16:02 progsoftpack