Skip to content

Commit af8de6e

Browse files
committed
add option merging to init() - add test for full coverage
1 parent 4a29443 commit af8de6e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

jwt/api_jwt.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@
4242
class PyJWT:
4343
def __init__(self, options: Options | None = None) -> None:
4444
self.options: FullOptions
45-
if options is None:
46-
self.options = self._get_default_options()
47-
else:
48-
self.options = {**self._get_default_options(), **options}
45+
self.options = self._get_default_options()
46+
if options is not None:
47+
self.options = self._merge_options(options)
4948

5049
@staticmethod
5150
def _get_default_options() -> FullOptions:

tests/test_api_jwt.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ def payload():
3636

3737

3838
class TestJWT:
39+
def test_jwt_with_options(self):
40+
jwt = PyJWT(options={"verify_signature": False})
41+
assert jwt.options["verify_signature"] is False
42+
# assert that unrelated option is unchanged from default
43+
assert jwt.options["strict_aud"] is False
44+
# assert that verify_signature is respected unless verify_exp is overridden
45+
assert jwt.options["verify_exp"] is False
46+
3947
def test_decodes_valid_jwt(self, jwt):
4048
example_payload = {"hello": "world"}
4149
example_secret = "secret"

0 commit comments

Comments
 (0)