Is it possible to have Locust pass a header command with a secure token to load test an API?
I am trying to test our api for an encoder with a header flag for a token as the server being tested has to receive a token with the request, ie.
curl -H “Authorization: Token token string” http://someserver
Yes, you can use:
token_string = "token string"
resp = self.client.post(
url="http://someserver",
data=json.dumps(data),
auth=None,
headers={"authorization": "Token " + token_string},
name="http://someserver",
)
If you want to use same headers for every request you can also set them to the client in the on_start
method. They will be automatically used with every client request.
class User(HttpUser):
def on_start(self):
self.client.headers = {'Authorization': 'my-auth-token'}
@task
def my_authenticated_task(self):
self.client.post('enspoint') # this will use headers we set earlier
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With