使用Locust进行负载测试的OAuth登录

3
我正在使用Locust对一个应用进行负载测试。它有一个IP地址而不是网址,例如192.24.130.8080/app。
用户登录时,会被重定向到类似于KeyCloak认证服务的页面,如下所示: http://192.24.130.8080/auth/realms/project/protocol/openid-connect/auth?client_id=v5_prod&redirect_uri=http://192.24.130.8080/app/&response_type=code&scope=openid#/ 我有以下代码,使用用户名和登录密码。但是,当我在代码中更改密码(为错误密码)时,负载测试仍然运行。这表明我只是访问了重定向页面,而没有通过它。
最初的回答:您需要检查KeyCloak身份验证服务是否正确配置,并且您的代码是否正确处理了身份验证过程。建议您使用调试工具来跟踪请求和响应,以便更好地了解发生了什么问题。
from locust import HttpLocust, TaskSet, task


class UserBehavior(TaskSet):
    def on_start(self):
        """ on_start is called when a Locust start before any task is scheduled """
        self.login()

    def on_stop(self):
        """ on_stop is called when the TaskSet is stopping """
        self.logout()

    def login(self):
        self.client.post("/app/&response_type=code&scope=openid#/", {"user":"user100", "password":"sun"})

    def logout(self):
        self.client.post("/app/&response_type=code&scope=openid#/", {"user":"user100", "password":"sun"})


    @task(3)
    def app(self):
        self.client.get("/index/#/")

    @task(1)


      def app2(self):
            self.client.get("/account/932507")

    class UserWait(HttpLocust):
        task_set = UserBehavior
        #1000 ms = 1 second
        min_wait = 2000
        max_wait = 3000

我不确定如何通过Keycloak oauth。非常感谢您的任何帮助!

最初的回答:

1个回答

0

2
2.python-requests.org已经不存在了。requests v3的新等效版本是https://requests.readthedocs.io/en/latest/user/authentication/#oauth-2-and-openid-connect-authentication。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接