Skip to content

Commit

Permalink
Test bearer token flow with nested JSON str
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin-b committed Jan 7, 2025
1 parent 59d97fa commit d23ddca
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Fixed
- Fix `JSONDecodeError` due to Improper Handling of Nested JSON Strings in JWT Payloads
- Bearer tokens with nested JSON string are now properly handled. Thanks to [`Patrick Rodrigues`](https://github.com/pythrick).

### Changed
- Requires [`httpx`](https://www.python-httpx.org)==0.28.\*
Expand Down
10 changes: 9 additions & 1 deletion tests/oauth2/implicit/test_oauth2_implicit_async.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import time
import datetime

import httpx
import jwt
import pytest
from pytest_httpx import HTTPXMock

Expand Down Expand Up @@ -237,7 +239,13 @@ async def test_oauth2_implicit_flow_post_token_is_sent_in_authorization_header_b
expiry_in_1_hour = datetime.datetime.now(
datetime.timezone.utc
) + datetime.timedelta(hours=1)
token = create_token(expiry_in_1_hour)
token = jwt.encode(
{
"exp": expiry_in_1_hour,
"data": json.dumps({"something 漢字": ["漢字 else"]}),
},
"secret",
)
tab = browser_mock.add_response(
opened_url="https://provide_token?response_type=token&state=bee505cb6ceb14b9f6ac3573cd700b3b3e965004078d7bb57c7b92df01e448c992a7a46b4804164fc998ea166ece3f3d5849ca2405c4a548f43b915b0677231c&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F",
reply_url="http://localhost:5000",
Expand Down
10 changes: 9 additions & 1 deletion tests/oauth2/implicit/test_oauth2_implicit_sync.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import time
import datetime

import httpx
import jwt
import pytest
from pytest_httpx import HTTPXMock

Expand Down Expand Up @@ -230,7 +232,13 @@ def test_oauth2_implicit_flow_post_token_is_sent_in_authorization_header_by_defa
expiry_in_1_hour = datetime.datetime.now(
datetime.timezone.utc
) + datetime.timedelta(hours=1)
token = create_token(expiry_in_1_hour)
token = jwt.encode(
{
"exp": expiry_in_1_hour,
"data": json.dumps({"something 漢字": ["漢字 else"]}),
},
"secret",
)
tab = browser_mock.add_response(
opened_url="https://provide_token?response_type=token&state=bee505cb6ceb14b9f6ac3573cd700b3b3e965004078d7bb57c7b92df01e448c992a7a46b4804164fc998ea166ece3f3d5849ca2405c4a548f43b915b0677231c&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F",
reply_url="http://localhost:5000",
Expand Down
Empty file removed tests/oauth2/tokens/__init__.py
Empty file.
30 changes: 0 additions & 30 deletions tests/oauth2/tokens/test_tokens.py

This file was deleted.

0 comments on commit d23ddca

Please sign in to comment.