Question: How to test an API with credentials?
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?
What kind of authentication system do you use? If you use something token based than you can simply store the token in an environment.
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
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