package kubesource import ( "path/filepath" "testing" "git.k8s-git-k6n.net/mats/fancy-dns/internal/config" ) // A BlockList cannot name a file, so the runtime keeps each list's copy under // its own data directory. The name comes from the object, so it must never be // able to leave that directory. func TestClusterListsGetAPathUnderTheDataDirectory(t *testing.T) { base := config.Default() base.Cache.Persist.Path = "/var/lib/fancy-dns/cache.db" merged, _ := Merge(base, &Snapshot{Lists: []config.ListSource{ {Name: "haas", URL: "https://a/x", Enabled: true}, {Name: "../escape", URL: "https://a/y", Enabled: true}, }}) got := map[string]string{} for _, l := range merged.Block.Lists { got[l.Name] = l.Path } if want := filepath.Join("/var/lib/fancy-dns", "lists", "haas"); got["haas"] != want { t.Errorf("path = %q, want %q", got["haas"], want) } if got["../escape"] != "" { t.Errorf("a name that is not a plain file name got the path %q", got["../escape"]) } }