mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-19 06:30:54 +08:00
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.
33 lines
723 B
Go
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")
|
|
}
|
|
}
|