Visual studio Web Performance tests - OAuth 2.0

人走茶凉 提交于 2019-12-11 17:14:52

问题


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.

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?

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


回答1:


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}}.

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.



来源:https://stackoverflow.com/questions/57715996/vs-webtest-extraction-rule-parameter-is-not-added-into-the-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!