package mediamtx import ( "context" "encoding/json" "net/http" "net/http/httptest" "strings" "testing" ) func TestApplyBuildsCredentialSourceOnlyInTransientBody(t *testing.T) { var body map[string]any server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if strings.Contains(r.URL.String(), "password") { t.Fatal("credential leaked in control URL") } if err := json.NewDecoder(r.Body).Decode(&body); err != nil { t.Fatal(err) } w.WriteHeader(http.StatusOK) })) defer server.Close() client := NewHTTPController(server.URL) if err := client.Apply(context.Background(), Source{Path: "sense_test", URI: "rtsp://camera.invalid/main", Username: "fixture-user", Password: "fixture-password"}); err != nil { t.Fatal(err) } if body["source"] != "rtsp://fixture-user:fixture-password@camera.invalid/main" { t.Fatalf("body=%#v", body) } } func TestApplyRejectsCredentialURI(t *testing.T) { client := NewHTTPController("http://127.0.0.1") if err := client.Apply(context.Background(), Source{Path: "x", URI: "rtsp://user:pass@camera.invalid/main"}); err == nil { t.Fatal("credential URI accepted") } }