JMeter intermittently failing to parse URL variables while load testing - jmeter

While load testing with JMeter I am attempting to send 1000 requests in one second. The issue is that I need to send the access token aquired from each previous login. While doing so I am getting the following error:
java.net.URISyntaxException: Illegal character in path at index 67: https://greenback-api.com/api/subscribers/getSavings/${USER_ID}?access_token=${AUTH_TOKEN}
Typical under a low load JMETER has no problem transforming the variables into a valid url likeso:
api.com/api/subscribers/getSavings/4?access_token=443hrr4938rh9ghreughughtrugtrgt4
Is there a way to force JMETER to render the url variables before issuing a get request even under a high load?

It looks like sometimes ${USER_ID} and ${AUTH_TOKEN} are not returned by login (or whatever sets them). As a result JMeter will use the expression ${...} as is. And the characters {} are indeed invalid for URI (they have to be encoded).
Another option is that ${USER_ID} or ${AUTH_TOKEN} really contain some characters invalid for URI and that need to be encoded.
So you may need to
URL Encode your ${AUTH_TOKEN} (and possibly ${USER_ID})
Make stricter checking upon login completion (and any other operations that fill ${USER_ID} or ${AUTH_TOKEN}) to make sure they don't proceed to the following operations if the value was not returned.

Related

Jmeter 5.3: Extract run time 'code_challenge' URL parameter value from request URL which is not shown in any response

We have one URL parameter as "code_challenge" which gets generated at run time, this value we need to extract so that from next runs it can be handled. However since this code value is not captured in any previous requests/responses and need to extract at run time, unable to understand how to achieve.
Tried Regular Extractor choosing URL radio button, but it captures the value from recorded script.
Steps followed:
Record script using Blazmeter (Browse URL xx.com>Click Login)
Redirected to URL(s) in which one of the url has "code_Challenge" parameter with run time value)
First URL is: accounts-xx.com/oauth2/oidcdiscovery/.well-known/openid-configuration> The response doesn't have any parameter values
Second URL is:
https://accounts-xx.com/oauth2/authorize?response_type=code&client_id=zzzz&scope=ituytutut&redirect_uri=xx.com/callBack&code_challenge_method=ooo&**code_challenge=dsfsdlfhl**
In above 3rd point url, Code_challenge value is generated at run time when executed steps from browser.
However If replayed the recorded script which would have already generated code value hence other requests would fail. Due to this, need to get the code value fetched.
The code_challenge is generated from WS02 service.
Jmeter version: 5.3
Please suggest, or should we need to use Selenium webdriver integration.
Regular expression which would extract the value from recorded script:
As per Mitigating Authorization Code Interception Attacks article:
code_challenge The client creates and records a secret cryptographically random string (the code_verifier), which is then encoded using URL safe base64 encoding to transform it into the code_challenge.
As per PKCE in WSO2 IS server article:
1.Plain:
If a code_challenge method is mention as plain or not mention at all it will take this plain value. Then code_challenge will like:
code_challenge = code_verifier
2. SHA256:
To have the code_challenge as SHA256, we should mention this in request otherwise plain value will be assumed.For SHA256 code challenge will be like
code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
Here base64url is same as base64encoding(used so that all machine can identify as same value) but trailing “=” will be removed and “+” & “/” are placed by “-” & “_” to avoid unnecessary length in URL.(otherwise ‘+’ becomes ‘%2B’, ‘/’ becomes ‘%2F’ and ‘=’ becomes ‘%3D in URL)
As much as possible, it is better to select the code challenge method as SHA256 then the flow will become more secure and hard to guess(if someone try to brute force it)
So I think you need to add JSR223 PreProcessor and calculate/generate the code_challenge using the algorithm used by your server in Groovy language, store the value into a JMeter Variable and use it in the request.
You can leave the field value empty and then its value gets updated once the request is sent. But you won't see the value in the request.
I had a similar issue, it worked in my case.

Loadster capturing rule found no matches for variable __RequestVerificationToken

I'm trying to stress test my application with Loadster but every single Post method throw warning/error __RequestVerificationToken is empty or undefined as in the Get method it has the warning about capturing rule found no matches for variable __RequestVerificationToken.
This is the default way to capture in the Get method
I tried these two capture ways as well to capture
<input name="__RequestVerificationToken" type="hidden" value="
and
<input name="__RequestVerificationToken" value="
as you can see here
but still having the same warnings.
by the way, I do have this key in the HTML file.
Any clue?
After you record a script, Loadster automatically adds capturing rules for some server-generated tokens, including __RequestVerificationToken, when it sees them regurgitated from the client to the server in a subsequent request. It does this by backtracking the graph of recorded requests/responses until it finds where they originated.
When Loadster's recorder finds a match for one of these tokens, it will create a capturer on the originating step (where the value was first seen in a response) and a parameterized variable in the subsequent step(s) where the value is returned to the server.
The important thing to keep in mind is that the capturing rule is based solely on information available at the time of recording. If something is different at playback, the capturer may fail to find a value, and you'll get this error.
The most likely explanation is that an earlier step in your script failed to produce the expected state, and now the server isn't actually returning the page with the __RequestVerificationToken. For example, an earlier login in your script may have failed, and now when you request the form you're getting some kind of error page instead of the form you expected.
You can confirm this in Loadster using the Requests tab at the bottom of the script editor. After playing a script, a tree of all requests and responses appears in this section, and you can drill down to see the exact response that your server returned. Most likely you won't see a __RequestVerificationToken in this response (that's why capturing failed) but you will probably see something else that explains it. You may also need to backtrack in the tree to an earlier request/response to see where it went off the rails.
For me, the place Loadster attached the "Capture" from the recording was not correct. After recording, it attached the "Capture" rule to the POST request that resulted from the form submission. The token to be captured though was actually generated by the preceding GET request.
To correct this, I simply moved (retyped) the Capture csrfmiddlewaretoken from HTML input csrfmiddlewaretoken from the POST request to the preceding GET and it worked.
This isn't actually the case for the OP, but search results for this error are slim, so this seemed like a good place to put this.

How to get URL having ".../?where={'key1' : 'value1' , 'key2' : 'value2':.........}" in Jmeter http request

I need to load test one Python api in below URL format:
//IP:PORT/Sub_Part/?where={"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":"VALUE3"}
I tried to pass the key value pair through csv as well as directly in http request but getting error message.
java.net.URISyntaxException: Illegal character in query at index 47:
http://IP:PORT/Sub_Part/?where={"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":"VALUE3"}
Here key and value are dummy data I have placed here for easy understanding.
Please help me with correct syntax for this URL.
Thanks in advance for all your help.
In REST APIs, JSON objects are typically sent (POST) or returned in the body of the request. They are not typically encoded as part of the URL.
For a GET request, you can either pass the information as segments in the url or as querystring parameters.
For more details refer here, How to send a GET request with a "/" in the query
As per HTML URL Encoding Reference:
URLs can only be sent over the Internet using the ASCII character-set.
so you need to define the request in JMeter's HTTP Request sampler as follows:
Pay attention to URL Encode? checkbox, it has to be ticked otherwise the parameter will be sent "as is"
Another option is using __urlencode() function like:
http://IP:PORT/Sub_Part/?where=${__urlencode({"KEY1":"VALUE1"\,"KEY2":"VALUE2"\,"KEY3":"VALUE3"})}
which will generate an encoded sequence which you could use in the URL path:
%7B%22KEY1%22%3A%22VALUE1%22%2C%22KEY2%22%3A%22VALUE2%22%2C%22KEY3%22%3A%22VALUE3%22%7D
as you can see, all non-ASCII characters where removed.
Check out Apache JMeter Functions - An Introduction to learn more about JMeter Functions concept.

JMeter RegUx User Parameters not adding parameter

New to JMeter, and I'm probably missing some simple thing but I can't find it anywhere.
I'm trying to log into a web application so I send a GET request to the home page to retrieve the csrf token and then I use the regular expression extractor to retrieve it:
I then try to place the extracted token into the POST request:
But the extracted token doesn't show up in the request sent via the View Results Tree. Only the UserId and Password are passed which I manually defined:
My regular expression is finding a match as you can see here:
but even if it wasn't finding a match, it should still pass "NotFound" correct?
Any help is greatly appreciated!
Edit: Added a Debug Sampler and it is correctly showing the variable Token with it's correct value. So Token just isn't being added to the request via the RegEx User Parameter Pre Processor.
It's difficult to see what you're doing without seeing the LoginPage step, but you need to make sure you are adding the csrf token you've extracted in the right place.
Typically it could be as a query param, part of a post body or an http header.
As you can see the token has been extracted from your initial response in the Debug sampler, there must be something wrong in how or where the token is being applied to the LoginPage request. (As you say the RegEx User Parameter Pre Processor isn't adding it)
I've never used the PreProcessor and the Jmeter documentation explanation is a bit vague on what it does, but you can add the variables into your request without it using the variable saved for the capture groups - for input name this will be ${Token_g1} and for value it will be ${Token_g2} - which you will be able to see from the Debug Sampler. You'll need to add a Header or Cookie Manager to the Login Page element if this is where the token is.
By setting the template in the Extractor to $1$$2$ you create a variable with the name and value concatenated together. I'm not sure why you would need this, and I would guess that the name doesn't change - in which case you can just use capture group 2, or if you want to use the Variable name Token then update your template to be $2$

Jmeter is converting '#' in the Password into junk character

I am recording Login in Jmeter. Password has '#'. Jmeter recorded exact string but when i run the same, '#' is converted to '%40ss' and login is getting failed(login is failing even if i pass parameters through csv file). But if we pass parameters through jmeter Body Data, Login is successful. I dont want to pass through Body Data, i want to send parameters through CSV file. How to achieve this. Please find the attachments
Recorded and Response
My expectation is that it is only a matter of representation, i.e. when I run similar request using a sniffer tool like Wireshark I can see # sign as a part of form data.
Most probably your problem lies somewhere else, i.e. you haven't correlated this __RequestVerificationToken or haven't added HTTP Cookie Manager.
When it comes to load testing ASP.NET web applications you cannot just record and replay your test, you need to perform correlation of dynamic parameters, check out ASP.NET Login Testing with JMeter article for more details.
Lakshmikanth, when you are passing any special character in parameters values then JMeter converts that character into percent-encoding for eg. '#' converts to '%40', '!' converts to '%21'.
To overcome this issue you can pass your password as it is [say P#ssword] in the .csv file but in your request you need to uncheck the encode checkbox corresponding to your password parameter.

Resources