def test_pypale_token_issue_expiry(_example_dot_com_1s_token: Pypale) -> None: email = test_email() token = _example_dot_com_1s_token.generate_token(email=email) time.sleep(2) assert not _example_dot_com_1s_token.valid_token( return_token=token, return_email=email )
def test_pypale_invalid_token_binascii( _example_dot_com_1s_token: Pypale, ) -> None: email = test_email(name="user") assert not _example_dot_com_1s_token.valid_token( return_token="notvalidmultipleof4", return_email=email )
def test_pypale_invalid_token_no_return_token( _example_dot_com_1s_token: Pypale, ) -> None: email = test_email(name="user") assert not _example_dot_com_1s_token.valid_token( return_token=None, return_email=email )
def _example_dot_com_1s_token() -> Pypale: return Pypale( token_ttl_minutes=1, token_issue_ttl_seconds=1, base_url=test_base_url(), secret_key="itsasecret", )
def test_pypale_valid_token(_example_dot_com_1s_token: Pypale) -> None: email = test_email() token = _example_dot_com_1s_token.generate_token(email=email) assert _example_dot_com_1s_token.valid_token(return_token=token, return_email=email)
def test_pypale_invalid_token_no_user(_example_dot_com_1s_token: Pypale) -> None: email = test_email(name="user") token = _example_dot_com_1s_token.generate_token(email=email) assert not _example_dot_com_1s_token.valid_token( return_token=token, return_email=None )
from . import crud, models, schemas from .database import SessionLocal, engine from config import get_settings models.Base.metadata.create_all(bind=engine) app = FastAPI() token_ttl_minutes = 14 * 24 * 60 # 2 weeks token_issue_ttl_seconds = 2 * 60 * 60 # 2 hours pypale = Pypale( base_url="localhost:8023", secret_key=get_settings().secret_key, token_ttl_minutes=token_ttl_minutes, token_issue_ttl_seconds=token_issue_ttl_seconds ) # Dependency def get_db(): db = SessionLocal() try: yield db finally: db.close() async def authenticate(token: str): valid = pypale.valid_token(token) print(valid)