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.
Related
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.
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$
On Xamarin iOS. I'm using HttpClient to get a JSON string. The problem is that it ignores updates and gives me the same JSON response if I query the same URL. I want it to not cache anything and always actually query the URL and give me the new response.
This sounds trivial, there must be a simple way for this. I'm using a Forms shared project.
I assume you are setting the cache-control header to no-cache?
client.DefaultRequestHeaders.CacheControl.NoCache = true;
If so but it still doesn't work - maybe the server is caching the response? If it comes down to it, you can usually defeat something like that by adding a cachebuster to the querystring though. Just append a bogus param and pass it a unique value each time. For example, if your URL is http://my.url.com/resource/someid then you can defeat the caching by using http://my.url.com/resource/someid?b=1 and then increment that "b" param with each call.
I'm trying to set a persistent cookie for several consecutive requests. The idea is that if a request does not contain the cookie in the first place, a uuid4 identifier is set in a cookie under 'mykey' and the response is sent. This all happens via requests made to a REST api from a javascript client.
I can see the cookie when inspecting the response on my browser, but if I issue a second request—which should not set a new cookie, as 'mykey' is already populated—the cookie is reset with a new uuid4 identifier.
This is the code:
def some_view(request):
cookie = request.get_signed_cookie('mykey', salt='foobar', default=False)
# do stuff
response = HttpResponse(content='foo')
if not cookie:
value = str(uuid.uuid4())
response.set_signed_cookie('mykey', value, salt='foobar')
return response
Any ideas? Thnx!
A.
With the signed cookies, you are probably running into problems with HTTPOnly. You could try this:
set_signed_cookie(key, value, salt='', httponly=False)
HTTParty's parsed_response method returns a Hash if you get a response code 200 but otherwise it will return a String regardless if the webserver returns a XML response.
HTTParty.get(post_url).parsed_response.class # Depends on response code
Amazon will provide XML (explaining what went wrong) even on a 403.
Am I missing something?
HTTParty parses its #parsed_response based on what the HTTP response's Content-Type header is. Verify what the value is for that HTTP header. In your case, you'd want it to be application/xml.
In case anyone is still encountering this issue today, get can take a format parameter, which can help you ensure your HTTParty::Response object is a Hash:
url = HTTParty.get('http://domain.com', format: :json) # class is a Hash