-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅(api) add id token factory to improve testing flow
We are now able to better test tokens validation in our tests.
- Loading branch information
Showing
4 changed files
with
61 additions
and
28 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Authentication model factories.""" | ||
|
||
import uuid | ||
from datetime import datetime | ||
from typing import Any, Dict | ||
|
||
from polyfactory import PostGenerated | ||
from polyfactory.factories.pydantic_factory import ModelFactory | ||
from polyfactory.pytest_plugin import register_fixture | ||
|
||
from qualicharge.conf import settings | ||
|
||
from .models import IDToken | ||
|
||
|
||
def set_token_exp(name: str, values: Dict[str, int], *args: Any, **kwargs: Any) -> int: | ||
"""Set token expiracy field base on the iat.""" | ||
return values["iat"] + 300 | ||
|
||
|
||
@register_fixture(name="id_token_factory") | ||
class IDTokenFactory(ModelFactory[IDToken]): | ||
"""IDToken model factory.""" | ||
|
||
iss = "http://keycloak:8080/realms/qualicharge" | ||
sub = str(uuid.uuid4()) | ||
aud = settings.OIDC_EXPECTED_AUDIENCE | ||
exp = PostGenerated(set_token_exp) | ||
iat = int(datetime.now().timestamp()) | ||
scope = "email profile" | ||
email = "john@doe.com" |
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
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