Skip to content

Commit

Permalink
Update JWT base model to remove default values causing false positive…
Browse files Browse the repository at this point in the history
… validation results

Update unit tests to account for token changes
  • Loading branch information
NeonDaniel committed Nov 12, 2024
1 parent 39d8d7e commit 278b2eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
16 changes: 7 additions & 9 deletions neon_data_models/models/api/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@


class JWT(BaseModel):
iss: Optional[str] = Field(None, description="Token issuer")
sub: Optional[str] = Field(None,
iss: Optional[str] = Field(None, validate_default=True,
description="Token issuer")
sub: Optional[str] = Field(None, validate_default=True,
description="Unique token subject, ie a user ID")
exp: int = Field(None,
description="Expiration time in epoch seconds")
iat: int = Field(None,
description="Token creation time in epoch seconds")
exp: int = Field(description="Expiration time in epoch seconds")
iat: int = Field(description="Token creation time in epoch seconds")
jti: str = Field(description="Unique token identifier",
default_factory=lambda: str(uuid4()))

client_id: str = Field(None, description="Client identifier")
roles: List[str] = Field(None,
description="List of roles, "
client_id: str = Field(description="Client identifier")
roles: List[str] = Field(description="List of roles, "
"formatted as `<name> <AccessRole>`. "
"See PermissionsConfig for role names")

Expand Down
11 changes: 6 additions & 5 deletions tests/models/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from datetime import date

from neon_data_models.models.api.jwt import HanaToken
from neon_data_models.models.user.database import NeonUserConfig, User
from neon_data_models.models.user.database import NeonUserConfig, User, PermissionsConfig


class TestDatabase(TestCase):
Expand Down Expand Up @@ -88,11 +88,12 @@ def test_user(self):
user_kwargs = dict(username="test",
password_hash="test",
tokens=[{"token_name": "test_token",
"token_id": str(uuid4()),
"user_id": str(uuid4()),
"jti": str(uuid4()),
"sub": str(uuid4()),
"client_id": str(uuid4()),
"permissions": {},
"refresh_expiration_timestamp": round(time()),
"roles": PermissionsConfig().to_roles(),
"iat": round(time()) - 1,
"exp": round(time()) + 1,
"creation_timestamp": round(time()),
"last_refresh_timestamp": round(time())}])
default_user = User(**user_kwargs)
Expand Down

0 comments on commit 278b2eb

Please sign in to comment.