You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gentoo-overlay/www-apps/roundup/files/roundup-2.0.0-test-pyjwt.patch

92 lines
4.6 KiB

# HG changeset patch
# User John Rouillard <rouilj@ieee.org>
# Date 1609557405 18000
# Fri Jan 01 22:16:45 2021 -0500
# Node ID a2fbd3592322379f0c54a75446d2a282c6f40075
# Parent e3edb0b44d94df71f46094cdda9ed4e51e6c1de4
pyjwt 2.00 changed return type of jwt.encode from byte to str
Need to change tests to only do b2s conversion if using version before
2.0.0. Note 2.0.0 drops support for python 2. Also it is not
installed for the python 3.4 ci test by pip install.
diff --git a/test/rest_common.py b/test/rest_common.py
--- a/test/rest_common.py
+++ b/test/rest_common.py
@@ -68,6 +68,8 @@ class TestCase():
url_pfx = 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/'
def setUp(self):
+ from packaging import version
+
self.dirname = '_test_rest'
# set up and open a tracker
# Set optimize=True as code under test (Client.main()::determine_user)
@@ -162,50 +164,58 @@ class TestCase():
'iat': now_ts,
'exp': plus1min_ts,
}
+
+ # in version 2.0.0 and newer jwt.encode returns string
+ # not bytestring. So we have to skip b2s conversion
+ if version.parse(jwt.__version__) >= version.parse('2.0.0'):
+ tostr = lambda x: x
+ else:
+ tostr = b2s
+
self.jwt = {}
self.claim = {}
# generate invalid claim with expired timestamp
self.claim['expired'] = copy(claim)
self.claim['expired']['exp'] = expired_ts
- self.jwt['expired'] = b2s(jwt.encode(self.claim['expired'], secret,
+ self.jwt['expired'] = tostr(jwt.encode(self.claim['expired'], secret,
algorithm='HS256'))
# generate valid claim with user role
self.claim['user'] = copy(claim)
self.claim['user']['exp'] = plus1min_ts
- self.jwt['user'] = b2s(jwt.encode(self.claim['user'], secret,
+ self.jwt['user'] = tostr(jwt.encode(self.claim['user'], secret,
algorithm='HS256'))
# generate invalid claim bad issuer
self.claim['badiss'] = copy(claim)
self.claim['badiss']['iss'] = "http://someissuer/bugs"
- self.jwt['badiss'] = b2s(jwt.encode(self.claim['badiss'], secret,
+ self.jwt['badiss'] = tostr(jwt.encode(self.claim['badiss'], secret,
algorithm='HS256'))
# generate invalid claim bad aud(ience)
self.claim['badaud'] = copy(claim)
self.claim['badaud']['aud'] = "http://someaudience/bugs"
- self.jwt['badaud'] = b2s(jwt.encode(self.claim['badaud'], secret,
+ self.jwt['badaud'] = tostr(jwt.encode(self.claim['badaud'], secret,
algorithm='HS256'))
# generate invalid claim bad sub(ject)
self.claim['badsub'] = copy(claim)
self.claim['badsub']['sub'] = str("99")
- self.jwt['badsub'] = b2s(jwt.encode(self.claim['badsub'], secret,
+ self.jwt['badsub'] = tostr(jwt.encode(self.claim['badsub'], secret,
algorithm='HS256'))
# generate invalid claim bad roles
self.claim['badroles'] = copy(claim)
self.claim['badroles']['roles'] = [ "badrole1", "badrole2" ]
- self.jwt['badroles'] = b2s(jwt.encode(self.claim['badroles'], secret,
+ self.jwt['badroles'] = tostr(jwt.encode(self.claim['badroles'], secret,
algorithm='HS256'))
# generate valid claim with limited user:email role
self.claim['user:email'] = copy(claim)
self.claim['user:email']['roles'] = [ "user:email" ]
- self.jwt['user:email'] = b2s(jwt.encode(self.claim['user:email'], secret,
+ self.jwt['user:email'] = tostr(jwt.encode(self.claim['user:email'], secret,
algorithm='HS256'))
# generate valid claim with limited user:emailnorest role
self.claim['user:emailnorest'] = copy(claim)
self.claim['user:emailnorest']['roles'] = [ "user:emailnorest" ]
- self.jwt['user:emailnorest'] = b2s(jwt.encode(self.claim['user:emailnorest'], secret,
+ self.jwt['user:emailnorest'] = tostr(jwt.encode(self.claim['user:emailnorest'], secret,
algorithm='HS256'))
self.db.tx_Source = 'web'