(t *testing.T)
| 2678 | } |
| 2679 | |
| 2680 | func Test_ExportErrSessionMissing(t *testing.T) { |
| 2681 | ctx := context.Background() |
| 2682 | |
| 2683 | // 1. Setup server |
| 2684 | impl := &Implementation{Name: "test", Version: "1.0.0"} |
| 2685 | server := NewServer(impl, nil) |
| 2686 | handler := NewStreamableHTTPHandler(func(r *http.Request) *Server { return server }, nil) |
| 2687 | ts := httptest.NewServer(handler) |
| 2688 | defer ts.Close() |
| 2689 | |
| 2690 | // 2. Setup client |
| 2691 | clientTransport := &StreamableClientTransport{ |
| 2692 | Endpoint: ts.URL, |
| 2693 | } |
| 2694 | client := NewClient(impl, nil) |
| 2695 | session, err := client.Connect(ctx, clientTransport, nil) |
| 2696 | if err != nil { |
| 2697 | t.Fatalf("Connect failed: %v", err) |
| 2698 | } |
| 2699 | defer session.Close() |
| 2700 | |
| 2701 | // 3. Manually invalidate session on server |
| 2702 | handler.mu.Lock() |
| 2703 | if len(handler.sessions) != 1 { |
| 2704 | handler.mu.Unlock() |
| 2705 | t.Fatalf("expected 1 session, got %d", len(handler.sessions)) |
| 2706 | } |
| 2707 | for id := range handler.sessions { |
| 2708 | delete(handler.sessions, id) |
| 2709 | } |
| 2710 | handler.mu.Unlock() |
| 2711 | |
| 2712 | // 4. Try to call a tool (or any request) |
| 2713 | _, err = session.ListTools(ctx, nil) |
| 2714 | if err == nil { |
| 2715 | t.Fatal("expected error, got nil") |
| 2716 | } |
| 2717 | |
| 2718 | // 5. Verify it's ErrSessionMissing |
| 2719 | if !errors.Is(err, ErrSessionMissing) { |
| 2720 | t.Errorf("expected error to wrap ErrSessionMissing, got: %v", err) |
| 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | // TestStreamableLocalhostProtection verifies that DNS rebinding protection |
| 2725 | // is automatically enabled for localhost servers. |
nothing calls this directly
no test coverage detected
searching dependent graphs…