Skip to content

Commit

Permalink
Merge pull request #10 from ReproNim/enh-tests
Browse files Browse the repository at this point in the history
Make warnings into errors during tests. Ignore two warnings (see comments)
  • Loading branch information
vmdocua authored Oct 18, 2023
2 parents e04b0ac + 0914c3f commit 95ac5f9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
git config --global user.name "repromon-test"
git config --global user.email "[email protected]"
uname -a
date -Is
date -u
- name: Checkout source code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ or via poetry:

./venv/bin/poetry run pytest

./venv/bin/poetry run pytest --cov=. --cov-report=xml -s

<!--
## Web Application UI
Expand Down
14 changes: 12 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@ httpx = "^0.25.0"
[tool.pytest.ini_options]
log_cli = true
log_cli_level = "DEBUG"
# log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
# log_cli_date_format = "%Y-%m-%d %H:%M:%S"
addopts = "--tb=short"
filterwarnings = [
"error",
# filed an issue: https://foss.heptapod.net/python-libs/passlib/-/issues/188
"ignore:'crypt' is deprecated and slated for removal.*:DeprecationWarning:passlib",
# https://github.com/ReproNim/repromon/issues/9
"ignore: passing settings to sha256_crypt.hash\\(\\) is deprecated, .*:DeprecationWarning:passlib",
# jose/jwt.py", line 311, in _validate_exp has deprecated code
# now = timegm(datetime.utcnow().utctimetuple())
"ignore: datetime.datetime.utcnow\\(\\) is deprecated .*:DeprecationWarning:jose",
]


[build-system]
requires = ["poetry>=1.0"]
Expand Down
9 changes: 5 additions & 4 deletions repromon_app/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import hashlib
import logging
import uuid
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Annotated

from fastapi import Depends, HTTPException, Request, status
Expand Down Expand Up @@ -166,10 +166,10 @@ def create_access_token(self, username: str, expire_sec: int = -1) -> str:
expire_sec = app_settings().TOKEN_EXPIRE_SEC
if username and len(username) > 0:
expire: datetime.datetime = \
datetime.utcnow() + timedelta(seconds=expire_sec)
datetime.now(timezone.utc) + timedelta(seconds=expire_sec)
data = {
"sub": username,
"exp": expire
"exp": expire.timestamp()
}
logger.debug(f"data={str(data)}")
token: str = jwt.encode(data,
Expand Down Expand Up @@ -498,7 +498,7 @@ async def _web_oauth2_context(
detail="Unauthorized: Could not validate credentials",
headers={"WWW-Authenticate": "Bearer"},
)
logger.debug(f"_web_oauth2_context, token: {token}, strict={strict}")
logger.debug(f"_web_oauth2_context, token: ***, strict={strict}")
try:
mgr: SecurityManager = SecurityManager.instance()
username: str = mgr.get_username_by_token(token)
Expand All @@ -515,6 +515,7 @@ async def _web_oauth2_context(
return SecurityManager.instance().create_empty_context()
except BaseException as be:
if strict:
logging.error(f"Unauthorized exception occurred: {str(be)}", exc_info=True)
credentials_exception.detail = f"Unauthorized: {str(be)}"
raise credentials_exception
return SecurityManager.instance().create_empty_context()
Expand Down

0 comments on commit 95ac5f9

Please sign in to comment.