mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-03 10:33:40 +01:00
31 lines
628 B
Go
31 lines
628 B
Go
package securityutil
|
|
|
|
import "testing"
|
|
|
|
func TestJoinStorageLeaf(t *testing.T) {
|
|
path, err := JoinStorageLeaf("/tmp/pulse", "session.json")
|
|
if err != nil {
|
|
t.Fatalf("JoinStorageLeaf() error = %v", err)
|
|
}
|
|
if path != "/tmp/pulse/session.json" {
|
|
t.Fatalf("JoinStorageLeaf() = %q", path)
|
|
}
|
|
}
|
|
|
|
func TestJoinStorageLeafRejectsPathSeparators(t *testing.T) {
|
|
tests := []string{
|
|
"../session.json",
|
|
"nested/session.json",
|
|
`nested\session.json`,
|
|
".",
|
|
"..",
|
|
"",
|
|
}
|
|
|
|
for _, leaf := range tests {
|
|
if _, err := JoinStorageLeaf("/tmp/pulse", leaf); err == nil {
|
|
t.Fatalf("expected %q to be rejected", leaf)
|
|
}
|
|
}
|
|
}
|