JMeter: How to use the RESTful API key for authorization of the next set of API - jmeter

I am creating a jmeter load test plan for RESTful API request. I need to use the dynamic API key generated in my first sampler SignIn API in the next set of API requests I am going to create.
Can someone help out with how to pass the selected data parameters from response and input to the another api request in other required format for that post request.
Response Header
WebxxxHeader: {"UserName":"xxxxx","UserID":1,"ApiKey":"ea9a3572-de75-4a85-848a-8fed874f2269","ValidFrom":"2015-06-05 05:54:35","ValidTo":"2015-06-12 05:54:35","UserRole":null,"Password":null,"DeviceToken":null,"DeviceType":null,"IsRetina":false,"UniqueId":null}
Header to be posted in the next set of APIs
WebxxxHeader: {"UserName":"xxxxx","ApiKey":"ea9a3572-de75-4a85-848a-8fed874f2269"}
One more issue here is I have to pass the user email in the header instead of UserName.
Please share advanced JMeter blog references.
Thanks in advance for your suggestions.

I would suggest searching the web for something like "JMeter correlation" - that should give you the answers you're looking for.
Particular this API key bit can be handled via Regular Expression Extractor postprocessor.
Add Regular Expression Extractor as a child of the request which returns the API Key
Configure it as follows:
Field to check: Response Headers
Reference Name: anything meaningful, i.e. API_KEY
Regular Expression: "ApiKey":"(.+?)"
Template: $1$
Other fields can be left as is
Add HTTP Header Manager as a child of the second request and configure it as follows:
Name: WebxxxHeader
Value: `{"UserName":"xxxxx","ApiKey":"${API_KEY}"}
If you testing REST API I think that JSON Path Extractor available via JMeter Plugins could be extremely useful. See Using the XPath Extractor in JMeter guide (scroll to "Parsing JSON") for installation and usage instructions and some form of JSON Path language reference.

Related

In JMeter, how can I correlate/parameterize from HTTP Header Manager?

My HTTP Request has child HTTP Header Manager. The HTTP Header Manager has dynamic values, and other parameters depending on search on GUI application. See picture. The xsrf-token is dynamic, and auditlog varies depending on my search by vEnl. I am using JMeter 4.0. The HTTP Requests are GET, and therefore cannot use the checkbox "Use multipart/form-data for POST" either. How can I correlate/parameterize in this situation?
Use Regular Expression Extractor in the response of whatever request which has the right value for this Header Manager. Name it for example :testDynaVar
Then use ${testDynaVar} in auditlog's value. The parameter value will be passed to this header manager.
You need to extract this xsrf-token from the previous response using a suitable JMeter Post-Processor, save it into a JMeter Variable and substitute recorded hard-coded value with this variable in the HTTP Header Manager, check out How to Load Test CSRF-Protected Web Sites article for example implementation.
HTTP Header Manager can evaluate JMeter Variables in the runtime and substitute the placeholders with the respective values:
with regards to this auditlog header your question doesn't contain enough information to come up with the proper configuration, from the first glance you can parameterize this ctime argument using __time() function

Jmeter : getting 401 error

Does any one knows how to solve it with regular expression? here i am putting screen shot with valid access token and error response token.
thanks in advance.
Valid response token
invalid response token
and Regular expression exctracter
it is fine if you guys have any other solution for this unauthorized access thing.
Add JSON Extractor as a child of the authserver request and configure it as follows:
Variable Names: anything meaningful, i.e. token
JSON Path expressions: $.access_token
Add HTTP Header Manager as a child of the student request and configure it to send Authorization header with the value of Bearer ${token}
Going forward you can go for an alternative way of recording a JMeter test which is capable of exporting the recorded requests in SmartJMX mode with automatic correlation of dynamic parameters applied so you will be able to save your time for more creative work. See How to Cut Your JMeter Scripting Time by 80% article for more details.

Managing auto generated HTTP Authorization Manager in jmeter not working

I have recorded a native app in jmeter. It shows one auto-generated 'Authorization Manager' where username is appearing as '${Auth_Login}' and password as ${Auth_password}.
I am running the script but the response is appearing as :
"{"error":"No authorization header."}"
Please help me out to resolve this issue.
You should extract the token which returns from the first response using a post processor (i.e regular expression extractor).
Now add this token to the next request's header manager like this:
Name: Authorization
Value: ${Token}
Note: you should check the request header using traffic capturing tool i.e fiddler, because these names might not be the same also the token sometimes looks like this Bearer ${Token}
See using regex with jmeter for more information on regular expression extractor.

JMeter and CSRF

I am doing performance testing of one of the application.
Below are the specifications of Application.
1. It is based on sharepoint 2013.It uses
2. It uses JSON for interchanging data between the pages.
3. It uses NTLM authentication.
4. CSRF security fix is implemented in the application
Please fund below the problem description
When I am running the recorded script, one of my page is showing "{ : "d":false| CSRF attack" "
CSRF token it basically dynamic parameter, for Sharepoint it's usually called __RequestVerificationToken. You need to extract it from first page using one of the following PostProcessors:
Regular Expression Extractor
XPath Extractor
CSS/JQuery Extractor
and use extracted value in second request. See How to Load Test CSRF-Protected Web Sites article for comprehensive explanation and bypass example.
In order to deal with NTLM authentication use HTTP Authorization Manager
Use a Regular Expression Extractor, as Dmitri suggests.
The token must be there somewhere - CSRF works by sending a token as part of one request, then checking that the same token is received with the following request. Can you add an example of your JSON to your question?

Jmeter Login Request with cookies have wrong Response

I m new in jmeter i want to know if i send post request for login with cookies then in Response below information is displaying .
Request Error We’re sorry, there was a problem with your request.
Please make sure you have cookies enabled and try again.
What could be going wrong.?
It may be not about the missing or incorrect cookies.
You need to provide valid loginCsrfParam value as well, it needs to be extracted from previous response via one of the following PostProcessors:
Regular Expression Extractor
XPath Extractor
CSS/JQuery Extractor
converted into a JMeter Variable and used as a parameter in your login request.
See How to Load Test CSRF-Protected Web Sites guide for comprehensive information on bypassing CSRF protection in your JMeter test.

Resources