Files
ARTEX/server/decode_json_test.go
T
Coff0xc 230a99c2b9 fix(mcp): keep MCP env a writable map when JSON is null
json.Unmarshal of JSON null into a map yields nil. syncBrowserMCPProxy
then assigned NODE_EXTRA_CA_CERTS under traffic capture and panicked,
including during NewManager on every restart once that row was stored.
2026-11-18 11:43:40 +00:00

33 lines
723 B
Go

package server
import (
"encoding/json"
"testing"
)
func TestDecodeStrMapJSONNull(t *testing.T) {
m := decodeStrMap(json.RawMessage("null"))
if m == nil {
t.Fatal("JSON null must decode to an empty map, not nil")
}
m["NODE_EXTRA_CA_CERTS"] = "/tmp/ca.pem"
if m["NODE_EXTRA_CA_CERTS"] != "/tmp/ca.pem" {
t.Fatal("decoded map must be writable")
}
empty := decodeStrMap(nil)
if empty == nil {
t.Fatal("empty input must decode to an empty map")
}
got := decodeStrMap(json.RawMessage(`{"FOO":"bar"}`))
if got["FOO"] != "bar" {
t.Fatalf("got %#v", got)
}
invalid := decodeStrMap(json.RawMessage(`["not","an","object"]`))
if invalid == nil {
t.Fatal("invalid JSON must decode to an empty map")
}
}