parent
74d2751d88
commit
a1f808c86e
12 changed files with 44 additions and 69 deletions
|
|
@ -36,7 +36,7 @@ func TestNewEnterpriseHandler_Validation(t *testing.T) {
|
|||
AccessToken: "mock_access_token",
|
||||
TokenType: "Bearer",
|
||||
}
|
||||
return token.WithExtra(map[string]interface{}{"id_token": "mock_id_token"}), nil
|
||||
return token.WithExtra(map[string]any{"id_token": "mock_id_token"}), nil
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +194,7 @@ func TestNewEnterpriseHandler_Validation(t *testing.T) {
|
|||
AccessToken: "mock_access_token",
|
||||
TokenType: "Bearer",
|
||||
}
|
||||
return token.WithExtra(map[string]interface{}{"id_token": "mock_id_token"}), nil
|
||||
return token.WithExtra(map[string]any{"id_token": "mock_id_token"}), nil
|
||||
},
|
||||
},
|
||||
wantError: "",
|
||||
|
|
@ -254,7 +254,7 @@ func TestEnterpriseHandler_Authorize_E2E(t *testing.T) {
|
|||
AccessToken: "mock_access_token",
|
||||
TokenType: "Bearer",
|
||||
}
|
||||
return token.WithExtra(map[string]interface{}{"id_token": "mock_id_token_from_user_login"}), nil
|
||||
return token.WithExtra(map[string]any{"id_token": "mock_id_token_from_user_login"}), nil
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
|
@ -305,7 +305,7 @@ func setupIdPServer(t *testing.T) *httptest.Server {
|
|||
// OAuth/OIDC metadata endpoint - uses closure to get server URL
|
||||
mux.HandleFunc("/.well-known/oauth-authorization-server", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"issuer": server.URL,
|
||||
"token_endpoint": server.URL + "/token",
|
||||
"authorization_endpoint": server.URL + "/authorize",
|
||||
|
|
@ -350,7 +350,7 @@ func setupIdPServer(t *testing.T) *httptest.Server {
|
|||
|
||||
// Return ID-JAG (Identity Assertion JWT Authorization Grant)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"access_token": "id-jag-token-from-idp",
|
||||
"issued_token_type": oauthex.TokenTypeIDJAG,
|
||||
"token_type": "N_A",
|
||||
|
|
@ -375,7 +375,7 @@ func setupMCPAuthServer(t *testing.T) *httptest.Server {
|
|||
// OAuth metadata endpoint - uses closure to get server URL
|
||||
mux.HandleFunc("/.well-known/oauth-authorization-server", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"issuer": server.URL,
|
||||
"token_endpoint": server.URL + "/token",
|
||||
"code_challenge_methods_supported": []string{"S256"},
|
||||
|
|
@ -412,7 +412,7 @@ func setupMCPAuthServer(t *testing.T) *httptest.Server {
|
|||
|
||||
// Return access token
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"access_token": "mcp_access_token_from_jwt_bearer",
|
||||
"token_type": "Bearer",
|
||||
"expires_in": 3600,
|
||||
|
|
@ -480,7 +480,7 @@ func TestEnterpriseHandler_TokenSource_BeforeAuthorization(t *testing.T) {
|
|||
AccessToken: "mock_access_token",
|
||||
TokenType: "Bearer",
|
||||
}
|
||||
return token.WithExtra(map[string]interface{}{"id_token": "mock_id_token"}), nil
|
||||
return token.WithExtra(map[string]any{"id_token": "mock_id_token"}), nil
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ func createMockOIDCServer(t *testing.T) *httptest.Server {
|
|||
// Handle OIDC discovery
|
||||
if r.URL.Path == "/.well-known/openid-configuration" {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"issuer": serverURL,
|
||||
"authorization_endpoint": serverURL + "/authorize",
|
||||
"token_endpoint": serverURL + "/token",
|
||||
|
|
@ -351,7 +351,7 @@ func createMockOIDCServerWithToken(t *testing.T) *httptest.Server {
|
|||
// Handle OIDC discovery
|
||||
if r.URL.Path == "/.well-known/openid-configuration" {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"issuer": serverURL,
|
||||
"authorization_endpoint": serverURL + "/authorize",
|
||||
"token_endpoint": serverURL + "/token",
|
||||
|
|
@ -376,7 +376,7 @@ func createMockOIDCServerWithToken(t *testing.T) *httptest.Server {
|
|||
// Create mock ID token (JWT)
|
||||
now := time.Now().Unix()
|
||||
idToken := fmt.Sprintf("eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.%s.mock-signature",
|
||||
base64EncodeClaims(map[string]interface{}{
|
||||
base64EncodeClaims(map[string]any{
|
||||
"iss": serverURL,
|
||||
"sub": "test-user",
|
||||
"aud": "test-client",
|
||||
|
|
@ -386,7 +386,7 @@ func createMockOIDCServerWithToken(t *testing.T) *httptest.Server {
|
|||
}))
|
||||
// Return token response
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"access_token": "mock-access-token",
|
||||
"token_type": "Bearer",
|
||||
"expires_in": 3600,
|
||||
|
|
@ -402,7 +402,7 @@ func createMockOIDCServerWithToken(t *testing.T) *httptest.Server {
|
|||
}
|
||||
|
||||
// base64EncodeClaims encodes JWT claims for testing.
|
||||
func base64EncodeClaims(claims map[string]interface{}) string {
|
||||
func base64EncodeClaims(claims map[string]any) string {
|
||||
claimsJSON, _ := json.Marshal(claims)
|
||||
return base64.RawURLEncoding.EncodeToString(claimsJSON)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,9 +69,7 @@ func main() {
|
|||
// Run the test.
|
||||
var wg sync.WaitGroup
|
||||
for range *workers {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
client := mcp.NewClient(&mcp.Implementation{Name: "mcp-client", Version: "v1.0.0"}, nil)
|
||||
cs, err := client.Connect(parentCtx, &mcp.StreamableClientTransport{Endpoint: args[0]}, nil)
|
||||
if err != nil {
|
||||
|
|
@ -108,7 +106,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
stop() // restore the interrupt signal
|
||||
|
|
|
|||
|
|
@ -89,16 +89,14 @@ func parent() {
|
|||
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", childPortVar, port))
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
log.Printf("starting child %d at %s", i, childURL)
|
||||
if err := cmd.Run(); err != nil && ctx.Err() == nil {
|
||||
log.Printf("child %d failed: %v", i, err)
|
||||
} else {
|
||||
log.Printf("child %d exited gracefully", i)
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
// Start a reverse proxy that round-robin's requests to each backend.
|
||||
|
|
@ -116,13 +114,11 @@ func parent() {
|
|||
},
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
if err := server.ListenAndServe(); err != nil && ctx.Err() == nil {
|
||||
log.Printf("Server failed: %v", err)
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
log.Printf("Serving at %s (CTRL-C to cancel)", *httpAddr)
|
||||
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ func (s *FakeAuthorizationServer) handleToken(w http.ResponseWriter, r *http.Req
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"access_token": "test_access_token",
|
||||
"token_type": "Bearer",
|
||||
"expires_in": 3600,
|
||||
|
|
|
|||
|
|
@ -200,8 +200,7 @@ func TestStdioContextCancellation(t *testing.T) {
|
|||
func TestCmdTransport(t *testing.T) {
|
||||
requireExec(t)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
cmd := createServerCommand(t, "default")
|
||||
|
||||
|
|
@ -287,8 +286,7 @@ func TestCommandTransportTerminateDuration(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
// Use a command that won't exit when stdin is closed
|
||||
cmd := exec.Command("sleep", "20")
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ func TestContentUnmarshalNil(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
json string
|
||||
content interface{}
|
||||
want interface{}
|
||||
content any
|
||||
want any
|
||||
}{
|
||||
{
|
||||
name: "CallToolResult nil Content",
|
||||
|
|
@ -83,7 +83,7 @@ func TestContentUnmarshalNilWithDifferentTypes(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
json string
|
||||
content interface{}
|
||||
content any
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
|
|
@ -145,7 +145,7 @@ func TestContentUnmarshalNilWithEmptyContent(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
json string
|
||||
content interface{}
|
||||
content any
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
|
|
@ -186,7 +186,7 @@ func TestContentUnmarshalNilWithInvalidContent(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
json string
|
||||
content interface{}
|
||||
content any
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
|
|
|
|||
|
|
@ -676,13 +676,11 @@ func TestServerClosing(t *testing.T) {
|
|||
|
||||
ctx := context.Background()
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
wg.Go(func() {
|
||||
if err := cs.Wait(); err != nil {
|
||||
t.Errorf("server connection failed: %v", err)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
})
|
||||
if _, err := cs.CallTool(ctx, &CallToolParams{
|
||||
Name: "greet",
|
||||
Arguments: map[string]any{"Name": "user"},
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ func TestAddToolWithSharedCache(t *testing.T) {
|
|||
}
|
||||
|
||||
// Simulate stateless server pattern: new server per request, shared cache.
|
||||
for i := 0; i < 3; i++ {
|
||||
for range 3 {
|
||||
s := NewServer(&Implementation{Name: "test", Version: "1.0"}, &ServerOptions{
|
||||
SchemaCache: cache,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
package mcp_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
|
|
@ -51,8 +50,7 @@ func BenchmarkStreamableServing(b *testing.B) {
|
|||
httpServer := httptest.NewServer(handler)
|
||||
defer httpServer.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := b.Context()
|
||||
session, err := mcp.NewClient(testImpl, nil).Connect(ctx, &mcp.StreamableClientTransport{Endpoint: httpServer.URL}, nil)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
|
|
@ -84,8 +82,7 @@ func BenchmarkStreamableServing_BadSessions(b *testing.B) {
|
|||
httpServer := httptest.NewServer(handler)
|
||||
defer httpServer.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := b.Context()
|
||||
|
||||
if *streamableHeap != "" {
|
||||
writeHeap := func(file string) {
|
||||
|
|
|
|||
|
|
@ -108,9 +108,7 @@ func TestStreamableTransports(t *testing.T) {
|
|||
}
|
||||
// Now, spin off a goroutine that runs after the sampling request, to
|
||||
// check behavior when the client request has completed.
|
||||
sampleWG.Add(1)
|
||||
go func() {
|
||||
defer sampleWG.Done()
|
||||
sampleWG.Go(func() {
|
||||
<-sampleDone
|
||||
// Test that sampling requests in the tool context fail outside of
|
||||
// tool handling, but succeed on the background context.
|
||||
|
|
@ -120,7 +118,7 @@ func TestStreamableTransports(t *testing.T) {
|
|||
} {
|
||||
testSample(test)
|
||||
}
|
||||
}()
|
||||
})
|
||||
return &CallToolResult{}, nil, nil
|
||||
})
|
||||
|
||||
|
|
@ -268,9 +266,7 @@ func TestStreamableConcurrentHandling(t *testing.T) {
|
|||
client := NewClient(testImpl, nil)
|
||||
var wg sync.WaitGroup
|
||||
for range 100 {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
clientSession, err := client.Connect(ctx, &StreamableClientTransport{Endpoint: httpServer.URL}, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Connect failed: %v", err)
|
||||
|
|
@ -287,7 +283,7 @@ func TestStreamableConcurrentHandling(t *testing.T) {
|
|||
t.Errorf("got count %d, want %d", got, i)
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
|
@ -1293,9 +1289,7 @@ func testStreamableHandler(t *testing.T, handler http.Handler, requests []stream
|
|||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
|
||||
for m := range out {
|
||||
if req, ok := m.(*jsonrpc.Request); ok && req.IsCall() {
|
||||
|
|
@ -1315,7 +1309,7 @@ func testStreamableHandler(t *testing.T, handler http.Handler, requests []stream
|
|||
cancel()
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
gotSessionID, gotStatusCode, gotBody, err := request.do(ctx, httpServer.URL, sessionID.Load().(string), out)
|
||||
|
||||
|
|
@ -1353,11 +1347,9 @@ func testStreamableHandler(t *testing.T, handler http.Handler, requests []stream
|
|||
var wg sync.WaitGroup
|
||||
for i, request := range requests {
|
||||
if request.async || request.onRequest > 0 {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
doStep(t, i, request)
|
||||
}()
|
||||
})
|
||||
} else {
|
||||
doStep(t, i, request)
|
||||
}
|
||||
|
|
@ -2071,18 +2063,15 @@ func TestStreamableSessionTimeout(t *testing.T) {
|
|||
// Spin up two goroutines, each making a request every 10ms. These requests
|
||||
// should keep the server from timing out.
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
for range 2 {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
wg.Go(func() {
|
||||
for range 20 {
|
||||
if _, err := session.ListTools(ctx, nil); err != nil {
|
||||
t.Errorf("ListTools failed: %v", err)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
|
@ -2154,8 +2143,7 @@ data: keepalive
|
|||
}
|
||||
|
||||
// Create a minimal streamableClientConn for testing
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
incoming := make(chan jsonrpc.Message, 10)
|
||||
done := make(chan struct{})
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ func TestExchangeToken(t *testing.T) {
|
|||
}
|
||||
|
||||
// Return successful token exchange response per SEP-990 Section 4.2
|
||||
resp := map[string]interface{}{
|
||||
resp := map[string]any{
|
||||
"issued_token_type": TokenTypeIDJAG,
|
||||
"access_token": "fake-id-jag-token",
|
||||
"token_type": "N_A",
|
||||
|
|
|
|||
Loading…
Reference in a new issue