28 lines
656 B
Go
28 lines
656 B
Go
package plugin
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestSafeJoinRelativeRoot(t *testing.T) {
|
|
want, err := filepath.Abs("path_test.go")
|
|
if err != nil {
|
|
t.Fatalf("resolve expected path: %v", err)
|
|
}
|
|
|
|
got, err := safeJoin(".", "path_test.go")
|
|
if err != nil {
|
|
t.Fatalf("safeJoin rejected a path inside a relative root: %v", err)
|
|
}
|
|
if filepath.Clean(got) != filepath.Clean(want) {
|
|
t.Fatalf("safeJoin path = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestSafeJoinRelativeRootRejectsTraversal(t *testing.T) {
|
|
if _, err := safeJoin(".", filepath.Join("..", "go.mod")); err == nil {
|
|
t.Fatal("safeJoin accepted a path outside a relative root")
|
|
}
|
|
}
|