JMeter, authenticity token has been encoded, how to decode - jmeter

My script get an authenticity token from first page, then pass it to the second page I got this error when running the test:
{"errors":{"error:":["ActionController::InvalidAuthenticityToken"]}}
I checked the token variable, apparently the string such as /, = has been encoded into %2F and %3D etc..
On my second page's HTTP request window, I have NOT selected "encoded" for token variable defined in the "Send parameters with the request" section.
Apparently the problem is I did not asked for encoded variable, JMeter just encode it. Is it a known bug or I should do something to decode it or is there a work around on this issue?

Did you pass token in POST data?
I'v faced the same problem and just pass body data as work around, to do it you need:
Select you HTTP sampler
Switch from "Parameter" to "Body Data" tab (you have to delete all parameters to do it)
Write body data (variable substitution works)
Body data example:
username=Some_name&token=AbRaCaDaBrA
NB, if something need to be encoded, you'll have to do it manually.

Related

Power Automate Escape '#' character

In Power Automate, I am using an HTTP activity with the following parameters:
Method: POST
Uri: Example.com
Body:
{
"Username":"MyName",
"Password":"#mycode",
"PrivateKey":"1234"
}
This request works fine in Postman, but in Power Automate, it returns an error which says The power flow's logic app flow template was invalid. Unable to parse template language expression 'mycode': expected token 'LeftParenthesis' and actual 'EndOfData'. Which seems to me like it's unable to read the "#" sign because the password is supposed to be #mycode, not mycode
Is there an escape character I can use for this? Unfortunately I'm not able to change the password.
In Power Automate, special characters are always escpaed if you write them twice.
In your case it would look like this: "##mycode"
You can initialise a variable and store your data in it later pass in "send http action".
‘Send http action’
Screenshot link
Source video link

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.

after recording using fiddler can we check whether the post parameters of a request are encoded or not

My requirement is to know whether the post parameter in a request that is recorded in fiddler is encoded or not so that i can accordingly use it in Jmeter.
I tried recording a scenario in fiddler and i am able to find the post parameters for the requests sent, but I am not able to find whether a post parameter is encoded when request is sent to the server or not.
For example:
Consider the below is my post data of my request captured which has three parameters with respective values(name1,name2,name3 and value1, value2, value3 respectively)
Suppose i capture the same request using Jmeter, we will easily know whether the post parameter is encoded or not as the encode? column will be checked in case of encoding or uncecked if not encoded.
Similarly can we find whether a post parameter is encoded in fiddler, Can anyone help.
You can check the TextView tab in fiddler which will show you if the parameters are encoded or not, and then apply the same thing to your Jmeter script.
If you cant find that in the TextView tab then check the Raw tab which will show the full request you sent and check there if the parameters were encoded or not.

Resources