@@ -685,6 +685,20 @@ async def test_refresh_token_invalid(test_client, auth_httpx_mock: HTTPXMock):
685685 assert data ["detail" ] == "Invalid JWT: bad_signature: "
686686
687687
688+ async def test_bad_access_token (test_client ):
689+ """Test accessing a resource with a bad token."""
690+ # From https://github.com/DIRACGrid/diracx/pull/496
691+ r = test_client .get (
692+ "/api/auth/userinfo" , headers = {"Authorization" : "Bearer thisisabadbearer" }
693+ )
694+ data = r .json ()
695+
696+ # Should raise a 401, with "Invalid JWT"
697+ # Not Invalid Authorization Header because raised when decoding the token
698+ assert r .status_code == 401 , data
699+ assert data ["detail" ] == "Invalid JWT"
700+
701+
688702async def test_list_refresh_tokens (test_client , auth_httpx_mock : HTTPXMock ):
689703 """Test the refresh token listing with 2 users, a normal one and token manager:
690704 - normal user gets a refresh token and lists it
@@ -875,7 +889,6 @@ async def test_revoke_refresh_token_classic(test_client, auth_httpx_mock: HTTPXM
875889 "refresh_token" : "does-not-exist" ,
876890 "client_id" : DIRAC_CLIENT_ID ,
877891 },
878- headers = {"Authorization" : f"Bearer { normal_user_access_token } " },
879892 )
880893 assert r .status_code == 200
881894
@@ -886,7 +899,6 @@ async def test_revoke_refresh_token_classic(test_client, auth_httpx_mock: HTTPXM
886899 "refresh_token" : normal_user_refresh_token ,
887900 "client_id" : DIRAC_CLIENT_ID ,
888901 },
889- headers = {"Authorization" : f"Bearer { normal_user_access_token } " },
890902 )
891903 assert r .status_code == 200
892904
@@ -905,7 +917,6 @@ async def test_revoke_refresh_token_classic(test_client, auth_httpx_mock: HTTPXM
905917 "refresh_token" : normal_user_refresh_token ,
906918 "client_id" : "a_wrong_dirac_client_id" ,
907919 },
908- headers = {"Authorization" : f"Bearer { normal_user_access_token } " },
909920 )
910921 assert r .status_code == 403
911922 assert r .json ()["detail" ] == "Unrecognised client_id"
0 commit comments