-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathtest_token_refresh.py
More file actions
47 lines (37 loc) · 1.69 KB
/
Copy pathtest_token_refresh.py
File metadata and controls
47 lines (37 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Regression test for #2110: background token refresh thread must survive
authlib OAuthError (e.g. invalid_grant), not just httpx.HTTPError."""
import pytest
from authlib.common.errors import AuthlibBaseError
from httpx import HTTPError
def test_authlib_base_error_is_not_http_error():
"""AuthlibBaseError does NOT inherit from httpx.HTTPError, confirming
the bug: the old `except HTTPError` clause could never catch it."""
assert not issubclass(AuthlibBaseError, HTTPError)
def test_authlib_base_error_caught_by_fixed_except_clause():
"""The fixed except clause `(HTTPError, AuthlibBaseError)` must catch
authlib protocol-level errors like invalid_grant."""
try:
raise AuthlibBaseError("invalid_grant")
except (HTTPError, AuthlibBaseError):
pass # This is what the fixed code does
else:
pytest.fail("AuthlibBaseError was not caught by (HTTPError, AuthlibBaseError)")
def test_http_error_still_caught_by_fixed_except_clause():
"""The fix must not break the existing HTTPError handling."""
try:
raise HTTPError("connection reset")
except (HTTPError, AuthlibBaseError):
pass
else:
pytest.fail("HTTPError was not caught by (HTTPError, AuthlibBaseError)")
def test_oauth_error_subclass_caught():
"""Concrete authlib errors (e.g. OAuthError) inherit from AuthlibBaseError
and must also be caught."""
from authlib.integrations.base_client.errors import OAuthError
assert issubclass(OAuthError, AuthlibBaseError)
try:
raise OAuthError("invalid_grant")
except (HTTPError, AuthlibBaseError):
pass
else:
pytest.fail("OAuthError was not caught by (HTTPError, AuthlibBaseError)")