yuqi1129 commented on code in PR #12439:
URL: https://github.com/apache/gravitino/pull/12439#discussion_r3766570464


##########
mcp-server/mcp_server/core/context.py:
##########
@@ -31,6 +31,10 @@
 # (e.g. rotating tokens) come and go.
 _MAX_CACHED_CLIENTS = 128
 
+# Authorization schemes recognised on a static --token. A token that starts 
with
+# one of these is passed through unchanged rather than being wrapped in Bearer.
+_AUTH_SCHEMES = frozenset({"basic", "bearer", "negotiate", "digest"})

Review Comment:
   If Auth types `negotiate` and `digest` haven't been supported,  is it more 
proper to remove it?



##########
mcp-server/tests/unit/test_auth_flow.py:
##########
@@ -157,6 +157,45 @@ def test_no_token_anywhere_defaults_to_empty(self):
         self.assertEqual(args.token, "")
 
 
+class TestStartupAuthorization(unittest.TestCase):
+    """Verify startup_authorization renders the static --token correctly."""
+
+    def test_bare_token_is_prefixed_with_bearer(self):
+        """A bare token is treated as OAuth2 and prefixed with Bearer."""
+        setting = Setting(metalake="ml", token="abc")
+        self.assertEqual(startup_authorization(setting), "Bearer abc")
+
+    def test_bearer_token_is_not_double_wrapped(self):
+        """A value already carrying the Bearer scheme is used verbatim."""
+        setting = Setting(metalake="ml", token="Bearer abc")
+        self.assertEqual(startup_authorization(setting), "Bearer abc")
+
+    def test_basic_token_passes_through(self):
+        """A value carrying the Basic scheme is used verbatim."""
+        setting = Setting(metalake="ml", token="Basic dXNlcjpwYXNz")
+        self.assertEqual(startup_authorization(setting), "Basic dXNlcjpwYXNz")
+
+    def test_scheme_match_is_case_insensitive(self):
+        """The scheme is matched case-insensitively and passed through."""
+        setting = Setting(metalake="ml", token="basic dXNlcjpwYXNz")
+        self.assertEqual(startup_authorization(setting), "basic dXNlcjpwYXNz")
+
+    def test_empty_token_stays_empty(self):
+        """No token configured yields an empty Authorization value."""
+        setting = Setting(metalake="ml", token="")
+        self.assertEqual(startup_authorization(setting), "")
+
+    def test_bare_token_is_stripped_then_prefixed(self):
+        """Surrounding whitespace is stripped before prefixing a bare token."""
+        setting = Setting(metalake="ml", token="  abc  ")
+        self.assertEqual(startup_authorization(setting), "Bearer abc")
+
+    def test_scheme_word_with_no_credential_is_bare_token(self):
+        """A scheme-like word with nothing after it is treated as a bare 
token."""
+        setting = Setting(metalake="ml", token="Bearer")
+        self.assertEqual(startup_authorization(setting), "Bearer Bearer")

Review Comment:
   Add tests for invalid uath type



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to