Testing keycloak login/registration using JMeter - jmeter

We have an requirement to test Keycloak Login/Registration using Keycloak application. When I open portal and click on continue to Login/Registration, it is redirecting to the following URL and taking Query Parameter.
I am not aware how and from which section we can get the value of Query parameter to pass
https://keycloak..com/realms//protocol/openid-connect/auth?client_id=&redirect_uri=http***personal-information
state= f707ae75-4543-46a8-8204-538492251966
nonce= 03d80815-c174-4453-83d4-0324726b87df
code challenge= OpSGM55wKbL4suTi_-FJcyWIdD63UryMV8fX4Mu-dc4
code challenge method= S256
tab id= ub4Sj_h_Cho
Please help here, if possible
Thanks

You've mentioned you're redirected which means that one of the previous request responds with i.e. 302 HTTP Status Code and its Location header contains the keycloak URL and all these query parameters.
If you need to extract them for future use - go for Regular Expression Extractor or Boundary Extractor, just make sure to choose the relevant "Field to check"

Your app uses Authorization Code Flow with Proof Key for Code Exchange (PKCE), so you need to understand:
1.) OIDC auth request (client_id,redirect_uri,state parameters - they configured in your IDP/Keyclok usually): https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
2.) PKCE part (code_challenge,code_challenge parameters - they are generated usually): https://datatracker.ietf.org/doc/html/rfc7636

Related

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?

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.

How to test with jMeter against basic auth protected domain?

I am running a staging cluster of apache/nginx webservers where the domain has basic authentication restricted access. My goal is to test performance of the cluster with jmeter.
In order to pass the authentication I have added the HTTP Authentication controler of jmeter. This works, BUT every request shows two logentries at apache. One 200 and one 401. This is normal behavior as of the first request the user must be authenticated. Unfortunatelly, jmeter does this on every request.
How can I make sure that each thread/user only requests access once. Or even better, how could I grant jmeter access with without every user needing to authenticat. I believe that this will impact the test results.
Thank you for any hint on this.
It sounds like a JMeter bug as given proper "Authorization" header is provided there shouldn't be WWW-Authenticate challenge. If you could file it via JMeter Bugzilla or flag it via JMeter Users Mailing List that would be great
In the meantime you can work it around using one of the following approaches:
Inject credentials directly into URL - in case of JMeter into "Path" input field like:
http://username:password#host.domain/path
Use Beanshell Scripting to construct proper "Authorization" header on-the-fly. In order to do so:
Make sure that HTTP Header Manager is present. If not - add it on Test Plan level or as a child of the HTTP Request which needs to be authenticated
add Beanshell PreProcessor as a child of HTTP Request which needs to be authenticated
Provide username and password separated by space via "Parameters" input
Put the following code into the PreProcessor's "Script" area
import org.apache.jmeter.protocol.http.util.Base64Encoder;
import org.apache.jmeter.protocol.http.control.Header;
String encodedCredentials = Base64Encoder.encode(bsh.args[0] + ":" + bsh.args[1]);
sampler.getHeaderManager().add(new Header("Authorization", "Basic " + encodedCredentials));
You shouldn't be receiving any 401 codes anywhere anymore.

JMeter - Error in URL Redirection

I was trying to issue a https request through jmeter and observed am getting Error Page response data for login page (Post Method).
login page url redirecting to different url (i.e. Application Home Page) but my login page redirect to the Error page.
And for Post req sampler i got error code 302 - Object moved to here.
Any help in resolving this issue would be a great help.
Probable https server that does not give a certificate or certificate must specify clearly in jmeter
This sounds like you're not handling some dynamic authentication token which is required in the post data or in the HTTP header.
There is probably a dynamically generated auth token on the page of the form itself (or the HTTP header) which you need to use instead of a static value.
You can capture the dynamic value with a post processor regular expression and then pass it in to the next request with the updated value.
There is a JMeter webinar which also covers exactly this scenario and how to solve it:
https://www.youtube.com/watch?v=cv7KqxaLZd8
UPDATE 1:
Sound like you're testing an asp.net application. They can be very finicky with JMeter. Check out these articles and other SO solutions:
asp.net login testing with jmeter
http://wiki.apache.org/jmeter/JMeterTesting/ASPNETViewState
How to use JMeter for load testing ASP.net web applications implementing viewstate

Resources