mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-03 13:11:05 +00:00
31 lines
1.2 KiB
Go
31 lines
1.2 KiB
Go
package mcphttp
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// The body of an error response is remote input. The error built from it is
|
|
// logged and stored as the health status, so CR and LF must arrive escaped.
|
|
func TestErrorSnippetEscapesCRLF(t *testing.T) {
|
|
if got := readSnippet(strings.NewReader(" bad\r\n[auth] forged\rline\n ")); strings.ContainsAny(got, "\r\n") || got != `"bad\r\n[auth] forged\rline"` {
|
|
t.Fatalf("readSnippet = %q", got)
|
|
}
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
_, _ = w.Write([]byte("upstream down\r\n2026/11/29 12:00:00 [auth] admin password changed\n"))
|
|
}))
|
|
defer srv.Close()
|
|
ctx := context.Background()
|
|
_, err := New(ctx, "remote", srv.URL, nil, false, 1)
|
|
if err == nil || strings.ContainsAny(err.Error(), "\r\n") || !strings.Contains(err.Error(), `\r\n2026/11/29`) {
|
|
t.Fatalf("streamable HTTP error = %q", err)
|
|
}
|
|
_, err = NewSSE(ctx, "remote", srv.URL+"/sse", nil, false)
|
|
if err == nil || strings.ContainsAny(err.Error(), "\r\n") || !strings.Contains(err.Error(), `\r\n2026/11/29`) {
|
|
t.Fatalf("legacy SSE error = %q", err)
|
|
}
|
|
}
|