-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from pythrick/fix-decode_base64
Fix JSONDecodeError due to Improper Handling of Nested JSON Strings in JWT Payloads
- Loading branch information
Showing
4 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import json | ||
import jwt | ||
|
||
from httpx_auth._oauth2.tokens import decode_base64 | ||
|
||
|
||
def test_decode_base64(): | ||
# Encode a JSON inside the JWT | ||
dummy_token = jwt.encode({"name": "John"}, key="") | ||
header, body, signature = dummy_token.split(".") | ||
|
||
# Decode the body | ||
decoded_bytes = decode_base64(body) | ||
|
||
# Attempt to load JSON | ||
result = json.loads(decoded_bytes) | ||
assert result == {"name": "John"} | ||
|
||
|
||
def test_decode_base64_with_nested_json_string(): | ||
# Encode a JSON inside the JWT | ||
dummy_token = jwt.encode({"data": json.dumps({"something": ["else"]})}, key="") | ||
header, body, signature = dummy_token.split(".") | ||
|
||
# Decode the body | ||
decoded_bytes = decode_base64(body) | ||
|
||
# Attempt to load JSON | ||
result = json.loads(decoded_bytes) | ||
assert result == {"data": '{"something": ["else"]}'} |