Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie check issue (jar & non-jar cookie, potential encoding issue) #772

Closed
san-slysz opened this issue Sep 20, 2018 · 10 comments
Closed

Cookie check issue (jar & non-jar cookie, potential encoding issue) #772

san-slysz opened this issue Sep 20, 2018 · 10 comments

Comments

@san-slysz
Copy link

san-slysz commented Sep 20, 2018

Here,'s the issue

Code

import { group, check, sleep } from 'k6';
import http from 'k6/http';

export default function() {

	//Cookie Jar (per-VU)
    let jar = http.cookieJar();
    jar.set("plop.my_url.com", "mycookie", "hello world");

	group("SSO call", function() {
		let res;
		res = http.get("https://sso.ourdomain.com/stuff",
			{
				"cookies": {
				"cookieilike": "q1epul507"

			},
			"headers": {
					"Host": "https://plop.my_url.com",
					"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0",
					"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
					//Bunch of headers
				}
			}
		);
		check(res, {
			"status is 200": (r) => r.status === 200,
			//"cookie has jar value": (r) => r.json().cookies.mycookie === "hello world"
                        //"cookie": (r) => r.json().cookies.PHPSESSID === "plop"
		});
	});
}

Status check alone is ok (fails if not 200, pass if 200). However:
1 - if I uncomment any of the 2 cookie checks, I get an error (see below)
2 - the cookie checks always pass, whatever value they check
3 - if I activate the debug (k6 run --http-debug="full" myscript.js) I got my cookie value :
Cookie: cookieilike=q1epul507; mycookie="hello world" ; does
4 - if I activate the debug mode, the end of my stack seems to go wrong, and it basically mess with my IDE (see screens below).

Error (1)
The value it complains about may vary depending on calls modifications I make. Lines number match the cookie check line.

ERRO[0001] GoError: invalid character '\x05' looking for beginning of value
        at native
        at cookieHasJarValue (/home/plop/WebstormProjects/mypath/myscript.js:29:66(5))
        at native
        at /home/plop/WebstormProjects/mypath/myscript.js:27:22(33)
        at native
        at /home/plop/WebstormProjects/mypath/myscript.js:10:16(21)
done [==========================================================] 1 / 1

█ page_2 - Inscription

  ✗ status is 301
   ↳  0% — ✓ 0 / ✗ 1
  ✓ cookie has jar value

Issue (4)
image
image

PS: I tired reach through slack, but this page link is "not active anymore" slack says. If you need more info, feel free to ask. I obviously can join a slack chat if this help :).

@na-- na-- added the bug label Sep 20, 2018
@robingustafsson
Copy link
Member

@san-ouadghiri Thanks for the report. The slack link has been updated, it expired earlier today.

@na--
Copy link
Member

na-- commented Sep 20, 2018

Regarding the issues you encountered - the GoError: invalid character '\x05' looking for beginning of value error seems like it could be a bug, I'll check later.

The issue with the broken text in the terminal probably is due to the fact that you want k6 to output binary HTTP response bodies, and the terminal may be affected by special characters in that response. Running reset in the console usually fixes those those things, I think, but I'm not sure if there's anything we can do in k6 to avoid that. Maybe print response bodies as hex in the debug output, when the expected responseType is binary?

@san-slysz
Copy link
Author

@robingustafsson > Wo, so I got very unlucky on my slack-access timing :D ! Thanks for that quick link update.

@na-- > Thanks for the quick analysis. For the terminal, hopefully k6 can evolve to accompany this kind of situations. In the meanwhile I'll use the reset, that way more useful than rebooting my IDE, so thanks! For the GoError if I narrow the issue I'll let you know as I really need to make that work somehow. Hopefully someone will find the bug root cause soon (>__<).

Ping me if you need me to do some test on my code :).

@na--
Copy link
Member

na-- commented Sep 20, 2018

@san-ouadghiri, I think the problem happens because you try to parse the response as a JSON, i.e. r.json().cookies.something should just be r.cookies.something. Take a look at the http.Response object and its properties and methods in the docs: https://docs.k6.io/docs/response-k6http

That said, the error message should be much better, but I've created a separate issue for it: #773

@san-slysz
Copy link
Author

I'll try that tomorrow morning and let u know.

I actually got the .json part from some of the code samples given here*. I now see that some examples have it and some haven't. Not sure if I miss-understand when it should be used, or if the samples are not up to date. Anyway I'll definitively try without and use the doc page you gave me. And thanks for creating 774 :).

*https://docs.k6.io/docs/cookies

@na--
Copy link
Member

na-- commented Sep 21, 2018

Ah, those docs examples that use response.json().cookies do so because the requested page, https://httpbin.org/cookies, is used for debugging HTTP requests - it simply returns a JSON document containing any cookies that we've passed to it as HTTP headers. So in a sense, we're using it in the examples and parsing the response JSON to demonstrate that the cookies we've set in the cookie jar are actually used in the subsequent requests to httpbin.org

@san-slysz
Copy link
Author

@na-- , anyone that will one day have this issue > The binary topic
One of my header was "Accept-Encoding": "gzip, deflate, br". It came from the .har recording my .js is based on. Bad idea to keep it -> commenting it allow me to receive a readable output (both for my and k6 debug mode).

@na--
Copy link
Member

na-- commented Sep 21, 2018

Thanks @san-ouadghiri, this issue is great, it generates a bunch of things we can improve or fix! 😃

Regarding the Accept-Encoding header, the problem comes from the fact that k6 doesn't support the br (i.e. Brotli) encoding. But if we send the header the way it was sent by the browser, the remote server is more than happy to send is a brotli-encoded response.

We already plan to stop adding the Accept-Encoding header in scripts generated from HAR files by default, as part of this rewrite/refactoring of the HAR converter, just because, as you demonstrated, browsers can support different encodings that k6 doesn't understand.

But still, supporting brotli seems a good idea and should be relatively easy, so I've added an issue about it as well: #776

And about the original cookie check issue, the script works when you remove the .json() call, right? No further issues there?

@san-slysz
Copy link
Author

I focused today on a simpler usecase. It allowed me to understand that the accept-encoding header was involved in my binary-drama. But it did not imply cookies. So about that I didn't check yet sorry :(.

I'm actually a really basic doc-user I realize XD. I read samples, copy-paste them, play and get how it work on that base. I totally missed that https://httpbin.org/cookies cool page impact and supposed it was generic code for any valid url. Now I got it. But who doesn't cargo-cult this days :D ?

I'm happy if this feedback is useful in any way. I'm a QA so I'm always happy to spread the (QA-)love. I'll probably raise more questions (or feature suggestions) in the future as i'd like to use k6 for some projects i look after. So thanks for your work and be prepared for more me hehe :) !

So yep, you can close this ticket.

@na--
Copy link
Member

na-- commented Sep 21, 2018

Yeah, I know the feeling, I regularly try stuff out and only much later read the docs... Closing this for now, feel free to open new issues if you find anything else. Any feedback is much appreciated!

@na-- na-- closed this as completed Sep 21, 2018
@na-- na-- removed the bug label Sep 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants