fix: webauthn stub in tests, timezone-aware datetimes, Pydantic v2 ConfigDict, add .gitignore#12
Conversation
…ailures Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/63299979-62f4-489f-a1d2-307336759de9 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com>
…nfig, add .gitignore Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/63299979-62f4-489f-a1d2-307336759de9 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com>
Reviewer's GuideMakes auth tests resilient to missing optional webauthn dependency, standardizes all auth-related datetime handling to timezone-aware usage, updates a Pydantic model to v2-style configuration, and adds a Python-focused .gitignore to stop tracking bytecode artifacts. Sequence diagram for auth router import with webauthn stubs in testssequenceDiagram
actor Pytest
participant TestAuthRouterSecurity
participant SysModules
participant WebauthnStub
participant BackendAuthRouter
Pytest->>TestAuthRouterSecurity: run _load_auth_router
TestAuthRouterSecurity->>WebauthnStub: create _stub_webauthn, _stub_helpers, _stub_structs
TestAuthRouterSecurity->>SysModules: setitem webauthn = _stub_webauthn
TestAuthRouterSecurity->>SysModules: setitem webauthn.helpers = _stub_helpers
TestAuthRouterSecurity->>SysModules: setitem webauthn.helpers.structs = _stub_structs
TestAuthRouterSecurity->>SysModules: setitem backend.database = fake_database
TestAuthRouterSecurity->>SysModules: setitem backend.models = fake_models
TestAuthRouterSecurity->>BackendAuthRouter: import backend.auth_router
BackendAuthRouter->>SysModules: import webauthn and webauthn.helpers.structs
SysModules-->>BackendAuthRouter: return stubbed modules
BackendAuthRouter-->>TestAuthRouterSecurity: loaded auth router without real webauthn
TestAuthRouterSecurity-->>Pytest: continue running auth tests
Updated class diagram for auth models using timezone-aware datetimes and Pydantic v2 ConfigDictclassDiagram
class BaseModel
class UserResponse {
+int id
+str email
+Optional[str] name
+Optional[str] business_registration_number
+Optional[str] representative_name
+ConfigDict model_config
}
class Token {
+str access_token
+str token_type
}
BaseModel <|-- UserResponse
BaseModel <|-- Token
class AuthRouterInternal {
+tuple~str, datetime~ _issue_recovery_token(prefix)
+None _purge_expired_password_recovery_sessions()
+None start_passkey_registration(user, payload, db)
+None finish_passkey_registration(payload, db)
+None start_passkey_login(user)
+None finish_passkey_login(payload, db)
+None verify_password_recovery_identity(payload, db)
+None reset_password_via_recovery(payload, db)
}
class AuthTokenService {
+str create_access_token(data, expires_delta, no_expiry)
}
AuthRouterInternal --> UserResponse
AuthTokenService --> Token
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
정말 편리한 서비스 이런 것이 개발자들에게 꼭 필요한 것입니다. |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In the WebAuthn stubs, consider making the stubbed functions/classes callable objects (e.g., simple no-op functions that raise a clear exception) rather than setting them to None, so that any unexpected use in tests fails with a more explicit and predictable error.
- You repeat
datetime.now(timezone.utc)many times across auth_router and tests; consider introducing a small helper (e.g.,utcnow()ornow_utc()) to centralize this behavior and make future changes to time handling easier.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the WebAuthn stubs, consider making the stubbed functions/classes callable objects (e.g., simple no-op functions that raise a clear exception) rather than setting them to None, so that any unexpected use in tests fails with a more explicit and predictable error.
- You repeat `datetime.now(timezone.utc)` many times across auth_router and tests; consider introducing a small helper (e.g., `utcnow()` or `now_utc()`) to centralize this behavior and make future changes to time handling easier.
## Individual Comments
### Comment 1
<location path="backend/auth_router.py" line_range="432" />
<code_context>
user.passkey_device_label = str(state.get("device_label") or "이 기기 패스키")
user.passkey_sign_count = int(verification.sign_count)
- user.passkey_registered_at = datetime.utcnow()
+ user.passkey_registered_at = datetime.now(timezone.utc)
db.add(user)
db.commit()
</code_context>
<issue_to_address>
**issue (bug_risk):** Check that the ORM column type for `passkey_registered_at` is compatible with timezone-aware datetimes.
This field used to be set with a naive `datetime.utcnow()`, and is now using an aware `datetime.now(timezone.utc)`. If the column is declared as `DateTime(timezone=False)` or otherwise expects naive datetimes, some backends will strip the timezone or error. Please confirm the ORM column uses `timezone=True` (or equivalent) or that this field is consistently treated as timezone-aware across the codebase.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| user.passkey_device_label = str(state.get("device_label") or "이 기기 패스키") | ||
| user.passkey_sign_count = int(verification.sign_count) | ||
| user.passkey_registered_at = datetime.utcnow() | ||
| user.passkey_registered_at = datetime.now(timezone.utc) |
There was a problem hiding this comment.
issue (bug_risk): Check that the ORM column type for passkey_registered_at is compatible with timezone-aware datetimes.
This field used to be set with a naive datetime.utcnow(), and is now using an aware datetime.now(timezone.utc). If the column is declared as DateTime(timezone=False) or otherwise expects naive datetimes, some backends will strip the timezone or error. Please confirm the ORM column uses timezone=True (or equivalent) or that this field is consistently treated as timezone-aware across the codebase.
There was a problem hiding this comment.
Pull request overview
This PR aims to stabilize auth-related tests and runtime behavior by removing an optional webauthn import failure in tests, eliminating datetime.utcnow() deprecation warnings by switching to timezone-aware UTC datetimes, modernizing a Pydantic model config for v2, and adding a Python-focused .gitignore to prevent committing cache artifacts.
Changes:
- Stub
webauthnmodules intests/test_auth_router_security.pysobackend.auth_routercan be imported in test runs without the optional dependency installed. - Replace
datetime.utcnow()usages withdatetime.now(timezone.utc)in auth/token and auth router logic. - Update
UserResponseto use Pydantic v2ConfigDict(from_attributes=True)and add a standard.gitignore.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_auth_router_security.py | Adds webauthn stubbing for import safety and updates fixtures to timezone-aware UTC datetimes. |
| backend/auth.py | Makes JWT expiry generation timezone-aware (timezone.utc). |
| backend/auth_router.py | Makes recovery/passkey expiry logic timezone-aware and updates Pydantic config to ConfigDict. |
| .gitignore | Adds Python/venv/test/IDE/OS ignore rules to prevent cache artifacts from being committed. |
| _stub_helpers = types.ModuleType("webauthn.helpers") | ||
| _stub_helpers.structs = _stub_structs | ||
|
|
||
| monkeypatch.setitem(sys.modules, "webauthn", _stub_webauthn) | ||
| monkeypatch.setitem(sys.modules, "webauthn.helpers", _stub_helpers) | ||
| monkeypatch.setitem(sys.modules, "webauthn.helpers.structs", _stub_structs) |
* Harden Pillow dependency floor to patched range for active image parsing CVEs (#7) * chore: raise Pillow minimum version to 12.2 Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/9ec743ae-a698-4cc0-aa87-8825771cb8d6 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * chore: remove accidental pycache artifacts Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/9ec743ae-a698-4cc0-aa87-8825771cb8d6 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * Harden orchestrator/auth error surfaces and remove CodeQL-flagged unsafe patterns (#8) * chore: start codeql alert remediation plan Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/e096e163-c0eb-430e-95b8-006690b13d72 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * fix: remediate CodeQL security and quality findings Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/e096e163-c0eb-430e-95b8-006690b13d72 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * fix: finalize CodeQL remediation hardening updates Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/e096e163-c0eb-430e-95b8-006690b13d72 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * Sanitize health diagnostic errors to avoid exception detail exposure (#9) * fix: redact health diagnostic exception details Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/5d18c2d0-8dda-4817-837b-37752598afa6 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * test: make health sanitization checks portable Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/5d18c2d0-8dda-4817-837b-37752598afa6 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * chore: remove compiled test artifacts Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/5d18c2d0-8dda-4817-837b-37752598afa6 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * refactor: normalize diagnostic error codes Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/5d18c2d0-8dda-4817-837b-37752598afa6 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * test: share diagnostic error code fixture Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/5d18c2d0-8dda-4817-837b-37752598afa6 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * refactor: simplify safe diagnostic code map Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/5d18c2d0-8dda-4817-837b-37752598afa6 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * Potential fix for code scanning alert no. 4: Information exposure through an exception (#10) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix(ci): set explicit python-version in codeql workflow (#11) Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/4ea2a28e-7f09-4b9d-a3df-785939fa43ac Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * fix: webauthn stub in tests, timezone-aware datetimes, Pydantic v2 ConfigDict, add .gitignore (#12) * fix(tests): stub webauthn in auth_router test fixture to fix import failures Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/63299979-62f4-489f-a1d2-307336759de9 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * fix: stub webauthn in tests, replace datetime.utcnow, fix Pydantic Config, add .gitignore Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/63299979-62f4-489f-a1d2-307336759de9 Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * Add consolidated design-change report and expanded PR body draft (#13) * docs: add overall design change and PR report Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/82b0addf-4e64-42b9-ac75-63d99a14f84d Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * docs: make PR report paths portable Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/82b0addf-4e64-42b9-ac75-63d99a14f84d Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> * docs: clarify bilingual PR report structure Agent-Logs-Url: https://github.com/parkcheolhong/codeAI/sessions/82b0addf-4e64-42b9-ac75-63d99a14f84d Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: parkcheolhong <111139476+parkcheolhong@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Five auth router tests were crashing with
ModuleNotFoundError: No module named 'webauthn', anddatetime.utcnow()deprecation warnings were firing across auth code on Python 3.12+. No.gitignoreexisted, so__pycache__artifacts had been committed.Changes
tests/test_auth_router_security.py–_load_auth_router()now stubswebauthnandwebauthn.helpers.structsintosys.modulesbefore importingbackend.auth_router, matching the existing pattern forbackend.database/backend.modelsbackend/auth_router.py,backend/auth.py– Replace alldatetime.utcnow()withdatetime.now(timezone.utc); addtimezoneto imports. Comparison and creation are now both timezone-aware, eliminating mixed-aware/naiveTypeErrorriskbackend/auth_router.py– Replace deprecated Pydantic v1-styleclass Config: from_attributes = TrueonUserResponsewithmodel_config = ConfigDict(from_attributes=True).gitignore– Add standard Python.gitignore; remove previously tracked__pycache__/*.pycentries from the git indexSummary by Sourcery
Ensure authentication flows and tests use timezone-aware datetimes and work without the optional WebAuthn dependency, while aligning the auth router model with Pydantic v2 configuration and ignoring Python build artifacts in version control.
Bug Fixes:
Enhancements:
Build:
Tests: