summaryrefslogtreecommitdiff
path: root/www-apps/roundup/files/roundup-2.0.0-test-pyjwt.patch
blob: 74f71dab57ff9aa0b9cf27ac3300972d45d2e671 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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'