package sanitize import ( "strings" "testing" "time" ) func TestNeutralZonesAreValidAndSameLength(t *testing.T) { // If the runtime has no zoneinfo at all, skip the loadability half. _, tzErr := time.LoadLocation("Europe/Moscow") haveTZDB := tzErr == nil for n, zone := range neutralZoneByLen { if len(zone) != n { t.Errorf("neutralZoneByLen[%d] = %q has length %d", n, zone, len(zone)) } if haveTZDB { if _, err := time.LoadLocation(zone); err != nil { t.Errorf("neutral zone %q does not load: %v", zone, err) } } } } func TestTZFiller(t *testing.T) { cases := map[string]string{ "Europe/Moscow": "Etc/Universal", "Asia/Yekaterinburg": "Antarctica/McMurdo", "180": "000", "-300": "-000", "MSK": "UTC", } for in, want := range cases { if got := tzFiller(in); got != want { t.Errorf("tzFiller(%q) = %q, want %q", in, got, want) } if got := tzFiller(in); len(got) != len(in) { t.Errorf("tzFiller(%q) length %d != %d", in, len(got), len(in)) } } } func TestRedact_SkipsAllowlistedTemplateFile(t *testing.T) { // _tianyiyun is a vendor factory template - must not be scanned/redacted. nb, ch, _, err := rewriteBytes("onekeylog/configuration/conf/syslog_tianyiyun.conf_bak", []byte("server ntp.acme.ru\n")) if err != nil { t.Fatal(err) } if len(ch) != 0 || string(nb) != "server ntp.acme.ru\n" { t.Fatalf("template file was modified: %q %+v", nb, ch) } } func TestXFill(t *testing.T) { if got := xFill("a1-b2.c3_d4@e5:f6"); got != "xx-xx.xx_xx@xx:xx" { t.Fatalf("xFill = %q", got) } if !strings.HasPrefix(xFill("corp.acme.ru"), "xxxx.") { t.Fatalf("xFill domain: %q", xFill("corp.acme.ru")) } }