microservices-demo / load-test

A load-test script & container for Sock Shop
Apache License 2.0
50 stars 137 forks source link

How to simulate GET /login method with locust? #23

Open zecoo opened 4 years ago

zecoo commented 4 years ago

And I checked the client.js file of sock-shop, the corresponding part of login codes is:

beforeSend: function (xhr) {
            xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
        }

which means the operation of locust is correct, but why does it not work?

Besides, I have already change the "username: password" str to base64 bytes

NASA1nk commented 2 years ago

did you solve this problem

I don't understand why it can log in without specifying a user name and password

yuhang-lin commented 1 year ago

I had the same problem, but now it's solved. Please find my code below:

@task
    def login(self):
        username = 'user'
        password = 'password'
        headers = {"Authorization": "Basic " + base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("ascii")}
        response = self.client.get("/login", headers=headers)
        if response.status_code == 200:
            print("Login successful")
        else:
            print("Login failed with status code: ", response.status_code)