Location parameter was not display in response header for extract access token in JMeter - jmeter

The location field contains the token value for the next redirecting page. But I am unable to get that token value from the response header to navigate to the next page.
But while we run the browser manually we can see the location filed in the response header.
how can I get an access token without a location parameter else how to get the location parameter in JMeter response header?

If you're not getting the same response with JMeter comparing to the real browser it means that you're not sending the same request (or requests sequence)
Try playing with Redirect automatically / Follow redirects checkboxes, it might be the case JMeter is not properly redirecting you to the proper location
You need to compare the requests originating from JMeter and real browser using:
either browser developer tools and View Results Tree listener
or using a 3rd-party sniffer tool like Fiddler or Wireshark
Once you configure JMeter to behave exactly like the real browser you should get the same response including the Location header.

For Azure B2C login we need to follow the below steps:
Need to extract CSRF and State Properties from below endpoints
.........onmicrosoft.com/b2c_1_xxx_signup_signin_v2/oauth2/v2.0/authorize
Regex Expression Main sample only : "csrf":"([^"]+)","transId":"StateProperties=([^"]+)
Pass above value in below endpoints
............/B2C_1_xxx_SignUp_SignIn_V2/client/perftrace?tx=StateProperties=${csrf_sp_g2}&p=B2C_1_xxx_SignUp_SignIn_V2
3.Extract Code value from below endpoints Main and sub sample body : code=([^"]+)
....../B2C_1_xxx_SignUp_SignIn_V2/api/CombinedSigninAndSignup/confirmed
PAss above code value in below endpoints parameter
......../b2c_1_xxx_signup_signin_v2/oauth2/v2.0/token
You will find the token value in main sample only and also you will get location parameter in sub sample

Related

JMeter - Should I remove Redirect from recorded script?

I used the Blazemeter Chrome plug-in to record. When the UserID is checked, browser is redirected to another URL. This redirect is recorded in the script.
Want to ask:
I read that the redirect will occur during the UserID check if I have Follow Redirects checked ? Is this correct ? The reason I ask is that I saw some extra HTTP request generated but they are not the same URL as the redirect which was sent from the server.
So I can actually just remove the redirect URL recorded ?
Thanks.
Your JMeter test must generate the same network footpring as the real browser does
So you can use a sniffer tool like Wireshark or Fiddler to compare the number/nature of the requests which originate from JMeter and from the real browser, the requests must be exactly the same (apart from dynamic parameters which needs to be correlated)
If HTTP Request sampler redirects automatically and the next request basically duplicates the redirected one - remove the recorded one.
If automatic redirect is causing troubles and you're not able to extract dynamic elements because they're "hidden" in 2nd level of sub-results - disable redirection in the HTTP Request sampler and leave the recorded separate request which mimics redirection.

Azure AD authentication with Jmeter

I want to do performance testing of my site which uses the Azure AD authentication. In order to login to the site 3 requests are called.
in first request the clientid is passed
in the second request in the URL it is creating one parameter 'tx' and it has some value. Rest it creates the csrf token which I am extracting successfully.
But I am facing problem in extracting the value of 'tx'
I am checking the value in the previous requests response but I am not able to find it. Is there anything that I am missing? I checked it on Fidler too somehow I am not getting the value of the tx.
I would suggest that you perform the login action in Chrome (say) with Developer Tools > Network open - and on the second request (sending 'tx') get the value that is sent by the browser, then search for that value in the previous response - and find how that is represented as parameters in the downloaded data.
I had a similar requirement and ended up Writing PostProcessor (to extract a value and save in a variable) and PreProcessor (to inject the variable value into the posted parameter) - you may need to process HTML, javascript or embedded JSON in the initial response.
The fact is that (more-and-more) Web Applications are embedding functionality in client-side javascript and you need to set JMeter up to emulate this.

Can't get authorized response on requests in JMeter, while they have the same CSRF token and sessionID

I'm having trouble with getting my site normally loaded during the performance testing in Apache JMeter. Firstly I recorded the script (by BadBoy), containing authorization and visiting some pages, unavailable without login. Next, I exported it to JMeter, configured Regular Expression Extractor to get the csrftoken from the request right before the authorization request and it looks like it works just fine:
no errors in http-requests
But if to look at the tab "Response data" of every post-authorized request, the content isn't like correctly loaded page, it just starts page with the empty authorization form, i.e. in some way session is new though all the requests have the same session id and csrftoken in Cookie Data and in Set-Cookie (Sample result), appeared in authorization request result.
HTTP Cookie Manager is added.
Did anyone face this trouble?
UPDATE: I've conducted an experiment with transferring cookies from Chrome to Mozilla Firefox, copied 'csrftoken' and 'session id', and - voila! - it worked, I got the same authorized session in two browsers. Still have no idea what's wrong with JMeter
JMeter automatically treats HTTP Response Codes below 400 as successful, it doesn't perform any checks of response body. Most likely your Regular Expression Extractor failed, add a Debug Sampler and double check resulting variable value.
There could be also the following possible reasons:
You might need to send CSRF token in encoded/escaped form so using i.e. __urlEncode() function will be required. Or vice versa.
Application may expect the token in multiple locations, i.e. not only as a form parameter, but as an extra HTTP Header. In that case you will need to pass it via HTTP Header Manager
You might also want to try the new step-by-step debugger for JMeter to get to the bottom of the issue.
This is the default behavior of this token. 1. make sure where these tokens are passed. It might be passed multiple times. Check the header. Generally, "xref-token" is again passed.
It should be in exact format, decode it if required, also remove , or ; or /. You can also use fiddler.
The solution was found after recording a script by Blazemeter plugin in Chrome and further exporting it in '.JMX' format. Adding an HTTP Header Manager like this (with its special fields, of course) to each HTTP Request solved the problem.

How to authenticate user when testing REST API using Jmeter

I am trying to make a script to test REST services using Jmeter.
Till now I was using Chrome’s Advanced REST Client.
My authentication request was GET and it was something like this in Advanced REST:
https://username:password#URL:portnumber
its a GET request
Now when I am using Jmeter. I tried following ways:
I added HTTP Authorization Manager and mentioned Base URL and Username/password inside it.
When I am trying to do a request then its showing me “Unauthorized”
I also tried to login using normal https request but no success.
When accessed manually, a authorization popup window appears and username and password is submitted inside this window.
Please suggest me a way for how to login using Jmeter.
Few suggestions:
Most likely you have mismatch in URL you're trying hit and the one, specified in HTTP Authorization Manager, double check it.
Add View Results Tree listener and make sure that the header like:
Authorization: Basic xxxxxxxxxxxx=
is being sent along with the request and compare it with the one, sent by the real browser.
Try switching "Implementation" of your HTTP Request samplers to HttpClient3.1, the easiest way of doing this is using HTTP Request Defaults
And finally, you can use HTTP Header Manager to send the relevant header, it's name should be Authorization and value Basic and username:password encoded in Base64. There is base64Encode function available via JMeter Plugins.

Jmeter: How to handle CSRF token from child URL which is not avialable while recording

I have to use Jmeter to perform load testing for a website.For this I have to record the login page and play back with real loads from CSV file.The website uses CSRF token for login.
While play back the recorded URLS using HTTPs Script recorder,this "/xyz/j_spring_security_check" calls\spawns an URL,/xyz/login.html(This URL is not available in the recorded http requests but could see in the view results tree,that is why I termed this as "calls\spawns",Please correct me with right term ), which generates the CSRF token and session ID.
The /xyz/j_spring_security_check later uses the CSRF token,session token,Username and password to login.
Now the problem is since the URL is called internally,I couldn't postprocess CSRF token from the /xyz/login.html URL.
Please help me to know,how to get the CSRF token which is part of response body of internally called URL and not available in the recorded http requests.
p.s:I know how to extract the CSRF token from the request response.
I had a similar, I had included "HTTP URL Re-writing Modifier" and as well as removed off the Different call made on the Child Window. Just enabled the Save/Submit action of the Child window.
This worked for my scenario where a user had Search for a specific value in a child window.
I had this issue. It was due to view results tree size capacity. Increase the view results tree size in Jmeter properties like this:
view.results.tree.max_size = 0.
All the value you will start to see in view results tree listener. All the tokens and all will be printing.

Resources