package runtime import ( "net" "testing" "github.com/owen/vibeproxy/internal/models" ) func TestSnapshotLookupHost(t *testing.T) { snap := &Snapshot{ HostsByDomain: map[string]*ProxyHostRuntime{ "example.com": {Model: models.ProxyHost{Name: "example"}}, }, } if rt := snap.LookupHost("Example.com:8443"); rt == nil || rt.Model.Name != "example" { t.Fatalf("expected case-insensitive, port-stripped lookup to match, got %+v", rt) } if rt := snap.LookupHost("other.com"); rt != nil { t.Fatalf("expected no match for unknown host, got %+v", rt) } } func TestSnapshotTrustedProxy(t *testing.T) { _, cidr, err := net.ParseCIDR("10.0.0.0/8") if err != nil { t.Fatal(err) } snap := &Snapshot{TrustedProxies: []*net.IPNet{cidr}} if !snap.IsTrustedProxy(net.ParseIP("10.1.2.3")) { t.Fatal("expected 10.1.2.3 to be trusted") } if snap.IsTrustedProxy(net.ParseIP("8.8.8.8")) { t.Fatal("expected 8.8.8.8 not to be trusted") } } func TestSettingsFromMapDefaults(t *testing.T) { s := settingsFromMap(map[string]string{}) if s.LogRetentionDays != 30 { t.Fatalf("expected default retention 30, got %d", s.LogRetentionDays) } if s.AdminUsername != "admin" { t.Fatalf("expected default admin username, got %q", s.AdminUsername) } }