saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.19k stars 5.48k forks source link

Can't save cookies with salt.utils.http.query and parse_cookies not working correctly #54873

Open jtraub91 opened 5 years ago

jtraub91 commented 5 years ago

Description of Issue

Cannot save cookies to file when using salt.utils.http.query Ex:

ret = salt.utils.http.query(URL, username=user, password=passwd, verify_ssl=False, cookies='/cookies.txt')

When specifying a cookie_jar the file will be opened but with no cookies inserted.

I believe the problem is stemming from a poor implementation of save() in future.backports.http.cookiejar library being used

waynew commented 5 years ago

Hey @jtraub91, thanks for the report!

Could you put together a MCVE? I'm seeing some weird behavior, but your example doesn't look like the documentation - that should be cookies=True, cookie_jar='/cookies.txt'), perhaps?

I'm actually seeing an error message, not just a simple failure - looks like the issue that I'm seeing though is that something is parsing the cookie value into a Python value (in this particular case, 'True' ->True`).

Definitely some unexpected behavior, in either case.

jtraub91 commented 5 years ago

@waynew Sure. Here it is (sensitive data hidden):

Via curl

$ curl -k -c ~/cookies.txt https://localhost -u username:password
...
$ cat ~/cookies.txt
# Netscape HTTP Cookie File
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

localhost       FALSE   /       FALSE   0       _xsrf   x|xxxxxxx|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|xxxxxxxxxxx

Via salt.utils.http.query:

>>> from salt.utils.http import query
>>> q = query('https://localhost', username=username, password=password, verify_ssl=False, cookies=True, cookie_jar='{}/cookies_salt.txt'.format(HOME_DIR))
>>> q
...
$ cat ~/cookies_salt.txt
#LWP-Cookies-2.0