Not able to read JSON cookie - go

I have a situation where I want to read the contents of a cookie in Go. However the contents of the cookie is in a JSON format. (Changing the format of the cookie is not an option)
For example the contents of the cookie might be:
{"id":"abc","data":"information","on_off":false}
In JavaScript I'm easily able to read the contents of the cookie and parse it.
With Go, on the other hand, when I try to read the cookie with r.Cookie('my_cookie') I get the following error: http: named cookie not present.
If I modify the cookie to a simple string, then it works as expected.
Does anyone know what to do in this case? Is it just not possible to read a such a cookie in Go?
When I use r.Header.Get["Cookie"], the output it returns does contain the cookie and it's JSON value (listed among all the other cookies)

JSON uses many characters not permitted in HTTP cookie values per the RFC - for example, double quotes, commas, and whitespace characters are not permitted. The eastiest way to transfer JSON data via cookie would probably be to Base64 encode it when setting the cookie, and Base64 decode it when reading the cookie, using the encoding/base64 package.

Related

Reading cookie from Wasm

I am attempting to read a cookie from Wasm but have not found any examples so I guessed, but I guessed wrong.
c := js.Global().Get("Cookie").Get("cookiename")
fmt.Println(c)
This gives me an error:
panic: syscall/js: call of Value.Get on undefined
Given that I have not found any documentation regarding reading cookies from Wasm.
Is this even possible?
There are three issues here:
the field is on document, not body
the field name is cookie, not Cookie
the cookie object is a string, you need to parse it to find the cookie by name.
To get the cookie string, use the following:
cookies := js.Global().Get("document").Get("cookie").String()
You will then need to process the string to iterate through the cookies and extract the one with the desired name. See Get cookie by name
As always with wasm, figure out the javascript code first then convert it to wasm.

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.

How to differenciate store token in .csv jmeter

Need help.
Need to log in multiple users, so, I'm using CSV Data Set Config. Received dynamic authCode I'm storing in another .csv file, and as the result finaly I'm receiving token, which I also store in .csv.
While posting HTTP request I'm passing token with user data from .csv, How can I differentiate tokens, to post 1000 of request using 4 users only?
Short Answer: JMeter automatically does it for you. you no need to save authCode & token in the CSV files.
Long Answer:
Save the authCode using Regular Expression Extractor. name the variable as authCode.
Replace with ${authCode} wherever authCode value is sent in subsequent requests.
Capture the token value using Regular Expression Extractor and store the value in a variable token
Replace with ${token} wherever token value is sent in subsequent requests.
you no need to worry about the thread/vuser, to associate authCode, token and the corresponding thread. JMeter handles it for you by storing those authCode, token values for each thread and maintains the state.
For more specific answer, please share your Test Plan and mention what exactly you want to achieve.

setting cookie for use in warden. "invalid cookie value"

I am writing specs for my api and am manually writing a http request.
I am trying to set a cookie by adding the following key-val header
cookies
cookies: {
'warden.user.user.key' => ActiveSupport::JSON.encode(
[[session_data[0]], session_data[1]]
)
}
That's a String-String key-val pair, but the value is invalid. I get ArgumentError: Invalid cookie value for the JSON-serialized value (which ends up as
"\"[[Xy2LppWrQ53yHmpxVOkF7w], $2a$10$a/kS05VaSlNv2wwBXPfGU.]\""
I honestly have no idea how to fix this. I am trying to make a cookie with this format because in my Controller, I figured out that the session cookie is stored in warden.user.user.key and the value is a nested array of [[object_uid], session_token]
Appreciate whatever help! thanks
If it makes any difference, I am using airborne to make the requests (which uses rest-client under the hood, but doesn't throw errors on non-OK status codes.)
In the bigger picture I'm just trying to pass a session token to warden, which is used by devise.

JMeter, authenticity token has been encoded, how to decode

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.

Resources