Skip to content

Commit 380fc34

Browse files
committed
Remove cookie auth support
Bugzilla dropped cookie auth support in 4.4 version, released in 1. I think that's long enough to drop support here. If anyone still needs this feature, they can continue to use old python-bugzilla versions Signed-off-by: Cole Robinson <[email protected]>
1 parent 017a931 commit 380fc34

12 files changed

Lines changed: 30 additions & 183 deletions

File tree

bugzilla/_authfiles.py

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
# See the COPYING file in the top-level directory.
33

44
import configparser
5-
import http.cookiejar
65
import os
76
from logging import getLogger
87
import urllib.parse
98

10-
from .exceptions import BugzillaError
119
from ._util import listify
1210

1311
log = getLogger(__name__)
@@ -26,17 +24,12 @@ def _makedirs(path):
2624
os.makedirs(os.path.dirname(path), 0o700)
2725

2826

29-
def _default_location(filename, kind):
27+
def _default_cache_location(filename):
3028
"""
31-
Determine default location for passed filename and xdg kind,
32-
example: ~/.cache/python-bugzilla/bugzillacookies
29+
Determine default location for passed xdg filename.
30+
example: ~/.cache/python-bugzilla/bugzillarc
3331
"""
34-
xdgpath = os.path.expanduser("~/.%s/python-bugzilla/%s" % (kind, filename))
35-
return xdgpath
36-
37-
38-
def _default_cache_location(filename):
39-
return _default_location(filename, 'cache')
32+
return os.path.expanduser("~/.cache/python-bugzilla/%s" % filename)
4033

4134

4235
class _BugzillaRCFile(object):
@@ -184,51 +177,3 @@ def set_filename(self, filename):
184177
cfg.read(filename)
185178
self._filename = filename
186179
self._cfg = cfg
187-
188-
189-
class _BugzillaCookieCache(object):
190-
@staticmethod
191-
def get_default_path():
192-
return _default_cache_location("bugzillacookies")
193-
194-
def __init__(self):
195-
self._cookiejar = None
196-
197-
def _build_cookiejar(self, cookiefile):
198-
cj = http.cookiejar.MozillaCookieJar(cookiefile)
199-
if (cookiefile is None or
200-
not os.path.exists(cookiefile)):
201-
return cj
202-
203-
try:
204-
cj.load()
205-
return cj
206-
except http.cookiejar.LoadError:
207-
msg = "cookiefile=%s not in Mozilla format" % cookiefile
208-
raise BugzillaError(msg) from None
209-
210-
def set_filename(self, cookiefile):
211-
log.debug("Using cookiefile=%s", cookiefile)
212-
self._cookiejar = self._build_cookiejar(cookiefile)
213-
214-
def get_filename(self):
215-
return self._cookiejar.filename
216-
217-
def get_cookiejar(self):
218-
return self._cookiejar
219-
220-
def set_cookies(self, cookies):
221-
for cookie in cookies:
222-
self._cookiejar.set_cookie(cookie)
223-
224-
cookiefile = self._cookiejar.filename
225-
if not cookiefile:
226-
return
227-
228-
if not os.path.exists(cookiefile):
229-
_makedirs(cookiefile)
230-
# Make sure a new file has correct permissions
231-
open(cookiefile, 'a').close()
232-
os.chmod(cookiefile, 0o600)
233-
234-
self._cookiejar.save()

bugzilla/_cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ def _setup_root_parser():
125125
help="Don't save any bugzilla cookies or tokens to disk, and "
126126
"don't use any pre-existing credentials.")
127127

128-
p.add_argument('--cookiefile', default=None,
129-
help="cookie file to use for bugzilla authentication")
128+
p.add_argument('--cookiefile', default=None, help=argparse.SUPPRESS)
130129
p.add_argument('--tokenfile', default=None,
131130
help="token file to use for bugzilla authentication")
132131

bugzilla/_session.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ class _BugzillaSession(object):
1818
Class to handle the backend agnostic 'requests' setup
1919
"""
2020
def __init__(self, url, user_agent,
21-
cookiecache, sslverify, cert,
21+
sslverify, cert,
2222
tokencache, api_key, requests_session=None):
2323
self._url = url
2424
self._user_agent = user_agent
2525
self._scheme = urllib.parse.urlparse(url)[0]
26-
self._cookiecache = cookiecache
2726
self._tokencache = tokencache
2827
self._api_key = api_key
2928
self._is_xmlrpc = False
@@ -38,8 +37,6 @@ def __init__(self, url, user_agent,
3837

3938
if cert:
4039
self._session.cert = cert
41-
if self._cookiecache:
42-
self._session.cookies = self._cookiecache.get_cookiejar()
4340
if sslverify is False:
4441
self._session.verify = False
4542
self._session.headers["User-Agent"] = self._user_agent
@@ -85,12 +82,6 @@ def _set_tokencache_param(self):
8582
token = self.get_token_value()
8683
self._session.params["Bugzilla_token"] = token
8784

88-
def set_response_cookies(self, response):
89-
"""
90-
Save any cookies received from the passed requests response
91-
"""
92-
self._cookiecache.set_cookies(response.cookies)
93-
9485
def get_requests_session(self):
9586
return self._session
9687

@@ -105,8 +96,6 @@ def request(self, *args, **kwargs):
10596
# Yes this still appears to matter for properly decoding unicode
10697
# code points in bugzilla.redhat.com content
10798
response.encoding = "UTF-8"
108-
# Set response cookies
109-
self.set_response_cookies(response)
11099

111100
try:
112101
response.raise_for_status()

bugzilla/base.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
from io import BytesIO
1919

20-
from ._authfiles import (_BugzillaRCFile,
21-
_BugzillaCookieCache, _BugzillaTokenCache)
20+
from ._authfiles import _BugzillaRCFile, _BugzillaTokenCache
2221
from .apiversion import __version__
2322
from ._backendrest import _BackendREST
2423
from ._backendxmlrpc import _BackendXMLRPC
@@ -87,7 +86,7 @@ class Bugzilla(object):
8786
bzapi = Bugzilla("http://bugzilla.example.com")
8887
8988
If you have previously logged into that URL, and have cached login
90-
cookies/tokens, you will automatically be logged in. Otherwise to
89+
tokens, you will automatically be logged in. Otherwise to
9190
log in, you can either pass auth options to __init__, or call a login
9291
helper like interactive_login().
9392
@@ -185,18 +184,14 @@ def __init__(self, url=-1, user=None, password=None, cookiefile=-1,
185184
:param password: optional password for the connecting user
186185
:param cert: optional certificate file for client side certificate
187186
authentication
188-
:param cookiefile: Location to cache the login session cookies so you
189-
don't have to keep specifying username/password. Bugzilla 5+ will
190-
use tokens instead of cookies.
191-
If -1, use the default path. If None, don't use or save
192-
any cookiefile.
187+
:param cookiefile: Deprecated, raises an error if not -1 or None
193188
:param sslverify: Set this to False to skip SSL hostname and CA
194189
validation checks, like out of date certificate
195190
:param tokenfile: Location to cache the API login token so youi
196191
don't have to keep specifying username/password.
197192
If -1, use the default path. If None, don't use
198193
or save any tokenfile.
199-
:param use_creds: If False, this disables cookiefile, tokenfile,
194+
:param use_creds: If False, this disables tokenfile
200195
and configpaths by default. This is a convenience option to
201196
unset those values at init time. If those values are later
202197
changed, they may be used for future operations.
@@ -232,25 +227,23 @@ def __init__(self, url=-1, user=None, password=None, cookiefile=-1,
232227
self._is_redhat_bugzilla = False
233228

234229
self._rcfile = _BugzillaRCFile()
235-
self._cookiecache = _BugzillaCookieCache()
236230
self._tokencache = _BugzillaTokenCache()
237231

238232
self._force_rest = force_rest
239233
self._force_xmlrpc = force_xmlrpc
240234

235+
if cookiefile not in [None, -1]:
236+
raise TypeError("cookiefile is deprecated, don't pass any value.")
237+
241238
if not use_creds:
242-
cookiefile = None
243239
tokenfile = None
244240
configpaths = []
245241

246-
if cookiefile == -1:
247-
cookiefile = self._cookiecache.get_default_path()
248242
if tokenfile == -1:
249243
tokenfile = self._tokencache.get_default_path()
250244
if configpaths == -1:
251245
configpaths = _BugzillaRCFile.get_default_configpaths()
252246

253-
self._setcookiefile(cookiefile)
254247
self._settokenfile(tokenfile)
255248
self._setconfigpath(configpaths)
256249

@@ -368,12 +361,8 @@ def _get_api_aliases(self):
368361
#################
369362

370363
def _getcookiefile(self):
371-
return self._cookiecache.get_filename()
372-
def _delcookiefile(self):
373-
self._setcookiefile(None)
374-
def _setcookiefile(self, cookiefile):
375-
self._cookiecache.set_filename(cookiefile)
376-
cookiefile = property(_getcookiefile, _setcookiefile, _delcookiefile)
364+
return None
365+
cookiefile = property(_getcookiefile)
377366

378367
def _gettokenfile(self):
379368
return self._tokencache.get_filename()
@@ -516,7 +505,6 @@ def connect(self, url=None):
516505
self.readconfig(overwrite=False)
517506

518507
self._session = _BugzillaSession(self.url, self.user_agent,
519-
cookiecache=self._cookiecache,
520508
sslverify=self._sslverify,
521509
cert=self.cert,
522510
tokencache=self._tokencache,
@@ -686,7 +674,7 @@ def interactive_login(self, user=None, password=None, force=False,
686674
def logout(self):
687675
"""
688676
Log out of bugzilla. Drops server connection and user info, and
689-
destroys authentication cookies.
677+
destroys authentication cache
690678
"""
691679
self._backend.user_logout()
692680
self.disconnect()

examples/apikey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020

2121
# API key usage assumes the API caller is storing the API key; if you would
2222
# like to use one of the login options that stores credentials on-disk for
23-
# command-line usage, use tokens or cookies.
23+
# command-line usage, use login tokens.
2424
bzapi = bugzilla.Bugzilla(URL, api_key=api_key)
2525
assert bzapi.logged_in

man/bugzilla.rst

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,10 @@ they expire the tool errors, rather than subtly change output.
127127

128128
**Syntax:** ``--no-cache-credentials``
129129

130-
Don't save any bugzilla cookies or tokens to disk, and don't use any
130+
Don't save any bugzilla tokens to disk, and don't use any
131131
pre-existing credentials.
132132

133133

134-
``--cookiefile``
135-
^^^^^^^^^^^^^^^^
136-
137-
**Syntax:** ``--cookiefile`` COOKIEFILE
138-
139-
cookie file to use for bugzilla authentication
140-
141-
142134
``--tokenfile``
143135
^^^^^^^^^^^^^^^
144136

@@ -817,8 +809,8 @@ YOUR_API_KEY with the generated API Key from the Web UI.
817809
Alternatively, you can use 'bugzilla login --api-key', which will ask
818810
for the API key, and save it to bugzillarc for you.
819811

820-
For older bugzilla instances, you will need to cache a login cookie or
821-
token with the "login" subcommand or the "--login" argument.
812+
For older bugzilla instances, you will need to cache a login token
813+
with the "login" subcommand or the "--login" argument.
822814

823815
Additionally, the --no-cache-credentials option will tell the bugzilla
824816
tool to *not* save or use any authentication cache, including the

tests/data/authfiles/output-cookies.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/data/cookies-bad.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/data/cookies-lwp.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/data/cookies-moz.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)