@@ -27,14 +27,17 @@ def _stub_module(name: str) -> MagicMock:
2727 if _name not in sys .modules :
2828 _stub_module (_name )
2929
30- # Stub jose and passlib ONLY when the native cryptography extension is broken.
30+ # Stub passlib ONLY when the native cryptography extension is broken.
3131#
3232# In CI (GitHub Actions) all packages are properly installed and working.
3333# In the dev container the `cryptography` Rust extension (loaded via _cffi_backend)
34- # is broken — importing jose triggers a Rust thread panic (PanicException).
34+ # is broken — importing passlib[bcrypt] triggers a Rust thread panic (PanicException).
35+ #
36+ # PyJWT (our JWT library) uses stdlib hmac for HS256 and does NOT require cffi,
37+ # so it works even in broken-cffi environments — no stub needed for jwt.
3538#
3639# We detect the broken environment by probing _cffi_backend with a plain
37- # ImportError (not a Rust panic) BEFORE touching jose /cryptography.
40+ # ImportError (not a Rust panic) BEFORE touching passlib /cryptography.
3841
3942def _cffi_available () -> bool :
4043 """Return True if the _cffi_backend C extension loads cleanly."""
@@ -46,27 +49,8 @@ def _cffi_available() -> bool:
4649
4750
4851if not _cffi_available ():
49- # Native crypto stack is broken — stub jose and passlib so auth-service
50- # imports work without the cryptography native extension.
51- import json as _json
52- from datetime import datetime as _datetime
53-
54- _jose = _stub_module ("jose" )
55- _jose .JWTError = Exception
56-
57- def _fake_jwt_encode (payload , * args , ** kwargs ):
58- safe = {k : v .isoformat () if isinstance (v , _datetime ) else v for k , v in payload .items ()}
59- return _json .dumps (safe )
60-
61- def _fake_jwt_decode (token , * args , ** kwargs ):
62- return _json .loads (token )
63-
64- _jose .jwt = MagicMock ()
65- _jose .jwt .encode = _fake_jwt_encode
66- _jose .jwt .decode = _fake_jwt_decode
67- _stub_module ("jose.jwt" )
68- _stub_module ("jose.exceptions" )
69-
52+ # Native crypto stack is broken — stub passlib so auth-service imports
53+ # work without the cryptography native extension.
7054 _passlib = _stub_module ("passlib" )
7155 _passlib_ctx = _stub_module ("passlib.context" )
7256 _ctx_cls = MagicMock ()
0 commit comments