Visual Studio Web性能测试-OAuth 2.0 [英] Visual studio Web Performance tests - OAuth 2.0

查看:190
本文介绍了Visual Studio Web性能测试-OAuth 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为使用Identity Server 3的应用程序创建Web性能测试.我不知道如何模拟登录和获取令牌.

I am trying to create the Web Performance tests for an app that is using Identity Server 3. I can't figure out how to simulate login and get token.

例如,我使用的是myapp.com,身份服务器托管在identity.com上.我在myapp.com/api中的所有端点都是安全的,并且需要Bearer令牌. identity.com可以为我提供令牌,以换取用户名和密码. identity.com会将我重定向到myapp.com/tokenRedirect?token=***.如何捕获令牌并将其用作API请求的授权标头?

For example, I am using myapp.com and identity server is hosted on identity.com. All my endpoints in myapp.com/api are secured and require Bearer token. identity.com can provide me token in exchange for a username and password. identity.com will redirect me to a myapp.com/tokenRedirect?token=***. How can I catch the token and use it as an Authorization header for API requests?

JMeter有一些解决方案,但在VS 2017测试中找不到.

There are some solutions for JMeter but could not find any for VS 2017 tests.

推荐答案

默认情况下,重定向是在Visual Studio记录的测试中自动处理的,因此无法访问包含令牌的重定向响应.将请求的FollowRedirects属性设置为False允许包含重定向的响应通过常规提取规则和/或插件等进行访问.其中之一可用于查找令牌值并将其保存到上下文中参数(CP).关闭自动重定向处理后,应添加一个新请求(使用Insert request命令,不要使用Add dependent request),并且该请求应具有重定向所需的请求.因此,其url的格式应为myapp.com/tokenRedirect?token={{TheCPWithTheToken}}.

Redirections are handled automatically, by default, in a test recorded by Visual Studio and hence the redirection response containing the token is not accessible. Setting the FollowRedirects property of the request to False allows the response containing the redirection to be accessed by the usual extraction rules and/or plugins etc. One of them can be used to find the token value and save it to a context parameter (CP). Having turned off the automatic redirection handling, a new request should be added (use the Insert request command, do not use Add dependent request) and it should have the request that the redirection wants. Hence its url should be of the form myapp.com/tokenRedirect?token={{TheCPWithTheToken}}.

在以后的请求中,可以通过Add header命令添加带有令牌的CP,或者可以修改现有的标头字段以使用CP.

In later requests the CP with the token can be added via the Add header command, or an existing header field can be modified to use the CP.

这篇关于Visual Studio Web性能测试-OAuth 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆