Skip to content

Commit 8eb3537

Browse files
committed
Added a deprecation warning for using verify= instead of options= on decode()
1 parent 29f1ef9 commit 8eb3537

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
88
-------------------------------------------------------------------------
99
### Changed
1010
- Added flexible and complete verification options during decode #131
11+
- Deprecated usage of the .decode(..., verify=False) parameter
1112
- Added support for PS256, PS384, and PS512 algorithms. #132
1213
- Added this CHANGELOG.md file
1314

jwt/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import binascii
22
import json
3+
import warnings
34

45
from calendar import timegm
56
from collections import Mapping
@@ -133,6 +134,8 @@ def decode(self, jwt, key='', verify=True, algorithms=None, options=None, **kwar
133134
key, algorithms)
134135

135136
self._validate_claims(payload, options=merged_options, **kwargs)
137+
else:
138+
warnings.warn("The verify parameter is deprecated. Please use options instead.", DeprecationWarning)
136139

137140
return payload
138141

tests/test_api.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import json
33
import time
4+
import warnings
45

56
from calendar import timegm
67
from datetime import datetime, timedelta
@@ -35,10 +36,18 @@ def utc_timestamp():
3536
class TestAPI(unittest.TestCase):
3637

3738
def setUp(self): # noqa
39+
self.warnings_context = warnings.catch_warnings(record=True)
40+
self.warnings = self.warnings_context.__enter__()
41+
42+
warnings.simplefilter('always', DeprecationWarning)
43+
3844
self.payload = {'iss': 'jeff', 'exp': utc_timestamp() + 15,
3945
'claim': 'insanity'}
4046
self.jwt = PyJWT()
4147

48+
def tearDown(self): # noqa
49+
self.warnings_context.__exit__()
50+
4251
def test_register_algorithm_does_not_allow_duplicate_registration(self):
4352
self.jwt.register_algorithm('AAA', Algorithm())
4453

@@ -356,6 +365,18 @@ def test_allow_skip_verification(self):
356365

357366
self.assertEqual(decoded_payload, self.payload)
358367

368+
def test_verify_false_deprecated(self):
369+
example_jwt = (
370+
b'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9'
371+
b'.eyJoZWxsbyI6ICJ3b3JsZCJ9'
372+
b'.tvagLDLoaiJKxOKqpBXSEGy7SYSifZhjntgm9ctpyj8')
373+
374+
self.assertEqual(len(self.warnings), 0)
375+
self.jwt.decode(example_jwt, verify=False)
376+
377+
self.assertEqual(len(self.warnings), 1)
378+
self.assertEqual(self.warnings[-1].category, DeprecationWarning)
379+
359380
def test_load_no_verification(self):
360381
right_secret = 'foo'
361382
jwt_message = self.jwt.encode(self.payload, right_secret)

0 commit comments

Comments
 (0)