|
3 | 3 |
|
4 | 4 | try: |
5 | 5 | from datetime import UTC, datetime, timedelta |
| 6 | + |
6 | 7 | utc_now = datetime.now(UTC) # Preferred in Python 3.13+ |
7 | 8 | except ImportError: |
8 | 9 | from datetime import datetime, timedelta, timezone |
| 10 | + |
9 | 11 | utc_now = datetime.now(timezone.utc) # Preferred in Python 3.12 and below |
10 | 12 | UTC = timezone.utc |
11 | 13 |
|
@@ -92,9 +94,7 @@ def return_encoded_array(token, key, algorithms, verify=True): |
92 | 94 |
|
93 | 95 | jws.verify = return_encoded_array |
94 | 96 |
|
95 | | - with pytest.raises( |
96 | | - JWTError, match="Invalid payload string: must be a json object" |
97 | | - ): |
| 97 | + with pytest.raises(JWTError, match="Invalid payload string: must be a json object"): |
98 | 98 | jwt.decode(token, "secret", ["HS256"]) |
99 | 99 | finally: |
100 | 100 | jws.verify = old_jws_verify |
@@ -154,35 +154,20 @@ def test_deterministic_headers(self): |
154 | 154 |
|
155 | 155 | # manually decode header to compare it to known good |
156 | 156 | decoded_headers1 = base64url_decode(encoded_headers1.encode("utf-8")) |
157 | | - assert ( |
158 | | - decoded_headers1 |
159 | | - == b"""{"alg":"HS256","another_key":"another_value","kid":"my-key-id","typ":"JWT"}""" |
160 | | - ) |
| 157 | + assert decoded_headers1 == b"""{"alg":"HS256","another_key":"another_value","kid":"my-key-id","typ":"JWT"}""" |
161 | 158 |
|
162 | 159 | def test_encode(self, claims, key): |
163 | 160 | expected = ( |
164 | | - ( |
165 | | - "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9" |
166 | | - ".eyJhIjoiYiJ9" |
167 | | - ".xNtk2S0CNbCBZX_f67pFgGRugaP1xi2ICfet3nwOSxw" |
168 | | - ), |
169 | | - ( |
170 | | - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" |
171 | | - ".eyJhIjoiYiJ9" |
172 | | - ".jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8" |
173 | | - ), |
| 161 | + ("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9" ".eyJhIjoiYiJ9" ".xNtk2S0CNbCBZX_f67pFgGRugaP1xi2ICfet3nwOSxw"), |
| 162 | + ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" ".eyJhIjoiYiJ9" ".jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8"), |
174 | 163 | ) |
175 | 164 |
|
176 | 165 | encoded = jwt.encode(claims, key) |
177 | 166 |
|
178 | 167 | assert encoded in expected |
179 | 168 |
|
180 | 169 | def test_decode(self, claims, key): |
181 | | - token = ( |
182 | | - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" |
183 | | - ".eyJhIjoiYiJ9" |
184 | | - ".jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8" |
185 | | - ) |
| 170 | + token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" ".eyJhIjoiYiJ9" ".jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8" |
186 | 171 |
|
187 | 172 | decoded = jwt.decode(token, key) |
188 | 173 |
|
|
0 commit comments