Spaces:
Running
Running
Upload folder using huggingface_hub (part 2)
Browse files- tests/test_auth.py +0 -29
tests/test_auth.py
CHANGED
|
@@ -23,10 +23,6 @@ def _make_token(sub=SUB, secret=SECRET, expires_delta=3600, headers=None):
|
|
| 23 |
return pyjwt.encode(payload, secret, algorithm="HS256", headers=headers or {})
|
| 24 |
|
| 25 |
|
| 26 |
-
async def _async_identity(value: str, identity: str):
|
| 27 |
-
return identity
|
| 28 |
-
|
| 29 |
-
|
| 30 |
def _creds(token: str) -> HTTPAuthorizationCredentials:
|
| 31 |
return HTTPAuthorizationCredentials(scheme="Bearer", credentials=token)
|
| 32 |
|
|
@@ -88,31 +84,6 @@ class TestGetUserId:
|
|
| 88 |
assert seen["token"] == "aaa.bbb.ccc"
|
| 89 |
|
| 90 |
|
| 91 |
-
def test_falls_back_to_supabase_when_legacy_secret_does_not_match_live_session(self, monkeypatch):
|
| 92 |
-
monkeypatch.setenv("SUPABASE_JWT_SECRET", SECRET)
|
| 93 |
-
token = _make_token(secret="rotated-or-asymmetric-signing-key")
|
| 94 |
-
seen = {}
|
| 95 |
-
|
| 96 |
-
async def fake_verify(value: str):
|
| 97 |
-
seen["token"] = value
|
| 98 |
-
return SUB
|
| 99 |
-
|
| 100 |
-
monkeypatch.setattr(auth, "_verify_via_supabase", fake_verify)
|
| 101 |
-
assert asyncio.run(auth.get_user_id(_creds(token))) == SUB
|
| 102 |
-
assert seen["token"] == token
|
| 103 |
-
|
| 104 |
-
def test_falls_back_to_supabase_for_asymmetric_jwt(self, monkeypatch):
|
| 105 |
-
monkeypatch.setenv("SUPABASE_JWT_SECRET", SECRET)
|
| 106 |
-
# The JWT payload/signature are intentionally not trusted here; the
|
| 107 |
-
# mocked authoritative verifier stands in for Supabase Auth /user.
|
| 108 |
-
import base64, json
|
| 109 |
-
header = base64.urlsafe_b64encode(json.dumps({"alg": "ES256", "typ": "JWT"}).encode()).decode().rstrip("=")
|
| 110 |
-
payload = base64.urlsafe_b64encode(json.dumps({"sub": SUB, "exp": int(time.time()) + 3600}).encode()).decode().rstrip("=")
|
| 111 |
-
token = f"{header}.{payload}.signature"
|
| 112 |
-
monkeypatch.setattr(auth, "_verify_via_supabase", lambda value: _async_identity(value, SUB))
|
| 113 |
-
assert asyncio.run(auth.get_user_id(_creds(token))) == SUB
|
| 114 |
-
|
| 115 |
-
|
| 116 |
class TestRequireUserId:
|
| 117 |
def test_raises_401_on_unverifiable_token(self, monkeypatch):
|
| 118 |
async def fake_verify(token: str):
|
|
|
|
| 23 |
return pyjwt.encode(payload, secret, algorithm="HS256", headers=headers or {})
|
| 24 |
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def _creds(token: str) -> HTTPAuthorizationCredentials:
|
| 27 |
return HTTPAuthorizationCredentials(scheme="Bearer", credentials=token)
|
| 28 |
|
|
|
|
| 84 |
assert seen["token"] == "aaa.bbb.ccc"
|
| 85 |
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
class TestRequireUserId:
|
| 88 |
def test_raises_401_on_unverifiable_token(self, monkeypatch):
|
| 89 |
async def fake_verify(token: str):
|