From 409996695bc633ff06811bba9e2fd8b3477f524e Mon Sep 17 00:00:00 2001 From: ehhuang Date: Thu, 3 Jul 2025 10:26:51 -0700 Subject: [PATCH] Fix auth test assertions to match updated error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update test assertions in test_auth.py and test_auth_github.py to expect "Invalid Authorization header format" instead of "Missing or invalid Authorization header" to align with the error message changes made in the auth implementation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- llama_stack/distribution/server/auth_providers.py | 2 +- tests/unit/server/test_auth.py | 6 +++--- tests/unit/server/test_auth_github.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/llama_stack/distribution/server/auth_providers.py b/llama_stack/distribution/server/auth_providers.py index 1037c4112..e5a4f5068 100644 --- a/llama_stack/distribution/server/auth_providers.py +++ b/llama_stack/distribution/server/auth_providers.py @@ -323,7 +323,7 @@ class GitHubTokenAuthProvider(AuthProvider): async def validate_token(self, token: str, scope: dict | None = None) -> User: """Validate a GitHub token by calling the GitHub API. - + This validates tokens issued by GitHub (personal access tokens or OAuth tokens). """ try: diff --git a/tests/unit/server/test_auth.py b/tests/unit/server/test_auth.py index a8ab83f6d..39d6af1c8 100644 --- a/tests/unit/server/test_auth.py +++ b/tests/unit/server/test_auth.py @@ -149,7 +149,7 @@ def test_missing_auth_header(http_client): def test_invalid_auth_header_format(http_client): response = http_client.get("/test", headers={"Authorization": "InvalidFormat token123"}) assert response.status_code == 401 - assert "Missing or invalid Authorization header" in response.json()["error"]["message"] + assert "Invalid Authorization header format" in response.json()["error"]["message"] @patch("httpx.AsyncClient.post", new=mock_post_success) @@ -277,7 +277,7 @@ def test_missing_auth_header_oauth2(oauth2_client): def test_invalid_auth_header_format_oauth2(oauth2_client): response = oauth2_client.get("/test", headers={"Authorization": "InvalidFormat token123"}) assert response.status_code == 401 - assert "Missing or invalid Authorization header" in response.json()["error"]["message"] + assert "Invalid Authorization header format" in response.json()["error"]["message"] async def mock_jwks_response(*args, **kwargs): @@ -502,7 +502,7 @@ def test_missing_auth_header_introspection(introspection_client): def test_invalid_auth_header_format_introspection(introspection_client): response = introspection_client.get("/test", headers={"Authorization": "InvalidFormat token123"}) assert response.status_code == 401 - assert "Missing or invalid Authorization header" in response.json()["error"]["message"] + assert "Invalid Authorization header format" in response.json()["error"]["message"] async def mock_introspection_active(*args, **kwargs): diff --git a/tests/unit/server/test_auth_github.py b/tests/unit/server/test_auth_github.py index 462e90126..9fbaba760 100644 --- a/tests/unit/server/test_auth_github.py +++ b/tests/unit/server/test_auth_github.py @@ -72,7 +72,7 @@ def test_authenticated_endpoint_with_invalid_bearer_format(github_token_client): """Test accessing protected endpoint with invalid bearer format""" response = github_token_client.get("/test", headers={"Authorization": "InvalidFormat token123"}) assert response.status_code == 401 - assert "Missing or invalid Authorization header" in response.json()["error"]["message"] + assert "Invalid Authorization header format" in response.json()["error"]["message"] @patch("llama_stack.distribution.server.auth_providers.httpx.AsyncClient")