tests: fixups

This commit is contained in:
mudler 2023-05-19 01:06:36 +02:00
parent a90b324fb8
commit 9b6c8ce411
2 changed files with 26 additions and 12 deletions

View file

@ -89,18 +89,7 @@ func inTrustedRoot(path string, trustedRoot string) error {
func verifyPath(path, basePath string) error {
c := filepath.Clean(filepath.Join(basePath, path))
r, err := filepath.EvalSymlinks(c)
if err != nil {
return fmt.Errorf("unsafe or invalid path specified")
}
err = inTrustedRoot(r, basePath)
if err != nil {
return fmt.Errorf("unsafe or invalid path specified")
}
return nil
return inTrustedRoot(c, basePath)
}
func Apply(basePath, nameOverride string, config *Config) error {

View file

@ -26,5 +26,30 @@ var _ = Describe("Model test", func() {
Expect(err).ToNot(HaveOccurred())
}
})
It("renames model correctly", func() {
tempdir, err := os.MkdirTemp("", "test")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tempdir)
c, err := ReadConfigFile(filepath.Join(os.Getenv("FIXTURES"), "gallery_simple.yaml"))
Expect(err).ToNot(HaveOccurred())
err = Apply(tempdir, "foo", c)
Expect(err).ToNot(HaveOccurred())
for _, f := range []string{"cerebras", "cerebras-completion.tmpl", "cerebras-chat.tmpl", "foo.yaml"} {
_, err = os.Stat(filepath.Join(tempdir, f))
Expect(err).ToNot(HaveOccurred())
}
})
It("catches path traversals", func() {
tempdir, err := os.MkdirTemp("", "test")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tempdir)
c, err := ReadConfigFile(filepath.Join(os.Getenv("FIXTURES"), "gallery_simple.yaml"))
Expect(err).ToNot(HaveOccurred())
err = Apply(tempdir, "../../../foo", c)
Expect(err).To(HaveOccurred())
})
})
})