Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions litestar/security/jwt/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dataclasses
from dataclasses import asdict, dataclass, field
from datetime import datetime, timezone
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, TypedDict
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, TypedDict, Union

import jwt
import msgspec
Expand Down Expand Up @@ -57,8 +57,8 @@ class Token:
"""Issued at - should always be current now."""
iss: Optional[str] = field(default=None) # noqa: UP007
"""Issuer - optional unique identifier for the issuer."""
aud: Optional[str] = field(default=None) # noqa: UP007
"""Audience - intended audience."""
aud: Union[str, Sequence[str], None] = field(default=None) # noqa: UP007
"""Audience - intended audience(s)."""
jti: Optional[str] = field(default=None) # noqa: UP007
"""JWT ID - a unique identifier of the JWT between different issuers."""
extras: Dict[str, Any] = field(default_factory=dict) # noqa: UP006
Expand Down
40 changes: 34 additions & 6 deletions tests/unit/test_security/test_jwt/test_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,45 @@
from litestar.security.jwt.token import JWTDecodeOptions


@pytest.mark.parametrize("algorithm", ["HS256", "HS384", "HS512"])
@pytest.mark.parametrize("token_issuer", [None, "e3d7d10edbbc28bfebd8861d39ae7587acde1e1fcefe2cbbec686d235d68f475"])
@pytest.mark.parametrize("token_audience", [None, "627224198b4245ed91cf8353e4ccdf1650728c7ee92748f55fe1e9a9c4d961df"])
@pytest.mark.parametrize(
"token_unique_jwt_id", [None, "10f5c6967783ddd6bb0c4e8262d7097caeae64705e45f83275e3c32eee5d30f2"]
"algorithm",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doubles the amount of tests run, due to the multiple parametrize decorators. Could you maybe just add one simple case for the sequence audience?

[pytest.param("HS256", id="HS256"), pytest.param("HS384", id="HS384"), pytest.param("HS512", id="HS512")],
)
@pytest.mark.parametrize(
"token_issuer",
[
pytest.param(None, id="None"),
pytest.param("e3d7d10edbbc28bfebd8861d39ae7587acde1e1fcefe2cbbec686d235d68f475", id="String"),
],
)
@pytest.mark.parametrize(
"token_audience",
[
pytest.param(None, id="None"),
pytest.param("627224198b4245ed91cf8353e4ccdf1650728c7ee92748f55fe1e9a9c4d961df", id="String"),
pytest.param(
[
"627224198b4245ed91cf8353e4ccdf1650728c7ee92748f55fe1e9a9c4d961df",
"887224198b4245ed91cf8353e4ccdf1650728c7ee92748f55fe1e9a9c4d961df",
],
id="List",
),
],
)
@pytest.mark.parametrize(
"token_unique_jwt_id",
[
pytest.param(None, id="None"),
pytest.param("10f5c6967783ddd6bb0c4e8262d7097caeae64705e45f83275e3c32eee5d30f2", id="String"),
],
)
@pytest.mark.parametrize(
"token_extras", [pytest.param(None, id="None"), pytest.param({"email": "[email protected]"}, id="Dict")]
)
@pytest.mark.parametrize("token_extras", [None, {"email": "[email protected]"}])
def test_token(
algorithm: str,
token_issuer: str | None,
token_audience: str | None,
token_audience: str | Sequence[str] | None,
token_unique_jwt_id: str | None,
token_extras: dict[str, Any] | None,
) -> None:
Expand Down