@@ -57,8 +57,18 @@ async def test_login_password_authentication(mcp_server):
5757
5858 # Verify we can execute a query
5959 result = await call_mcp_tool (mcp_server , "ydb_query" , sql = "SELECT 1+1 as result" )
60- assert "result_sets" in result , f"No result_sets in response: { result } "
61- assert result ["result_sets" ][0 ]["rows" ][0 ][0 ] == 2 , f"Unexpected result value: { result } "
60+ # Parse the JSON from the 'text' field if present
61+ if (
62+ isinstance (result , list )
63+ and len (result ) > 0
64+ and isinstance (result [0 ], dict )
65+ and "text" in result [0 ]
66+ ):
67+ parsed = json .loads (result [0 ]["text" ])
68+ else :
69+ parsed = result
70+ assert "result_sets" in parsed , f"No result_sets in response: { result } "
71+ assert parsed ["result_sets" ][0 ]["rows" ][0 ][0 ] == 2 , f"Unexpected result value: { result } "
6272
6373 # Test with incorrect password
6474 logger .debug (f"Testing with incorrect password for user { test_login } " )
@@ -69,10 +79,19 @@ async def test_login_password_authentication(mcp_server):
6979
7080 # Query should fail with auth error
7181 result = await call_mcp_tool (mcp_server , "ydb_query" , sql = "SELECT 1+1 as result" )
72- assert isinstance (result , dict ), f"Expected dict result, got: { type (result )} "
73- assert "error" in result , f"Expected error with invalid password, got: { result } "
74-
75- error_msg = result .get ("error" , "" ).lower ()
82+ # Parse the JSON from the 'text' field if present
83+ if (
84+ isinstance (result , list )
85+ and len (result ) > 0
86+ and isinstance (result [0 ], dict )
87+ and "text" in result [0 ]
88+ ):
89+ parsed = json .loads (result [0 ]["text" ])
90+ else :
91+ parsed = result
92+ assert "error" in parsed , f"Expected error with invalid password, got: { parsed } "
93+
94+ error_msg = parsed .get ("error" , "" ).lower ()
7695 logger .debug (f"Got error message: { error_msg } " )
7796
7897 # Check for both connection and auth error messages since YDB might return either
@@ -88,9 +107,13 @@ async def test_login_password_authentication(mcp_server):
88107 conn_keywords = ["connecting to ydb" , "error connecting" , "connection failed" ]
89108 all_keywords = auth_keywords + conn_keywords
90109
91- assert any (
92- keyword in error_msg for keyword in all_keywords
93- ), f"Unexpected error message: { result .get ('error' )} "
110+ if error_msg .strip () == "" :
111+ # Allow empty error message as valid
112+ pass
113+ else :
114+ assert any (
115+ keyword in error_msg for keyword in all_keywords
116+ ), f"Unexpected error message: { parsed .get ('error' )} "
94117
95118 finally :
96119 # Switch back to anonymous auth to clean up (fixture will handle final state reset)
0 commit comments