You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
602 B
25 lines
602 B
|
2 months ago
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestListenRefusesRelativeAndNonSocketPaths(t *testing.T) {
|
||
|
|
if _, err := listen("relative.sock"); err == nil {
|
||
|
|
t.Fatal("listen accepted a relative path")
|
||
|
|
}
|
||
|
|
path := filepath.Join(t.TempDir(), "time.sock")
|
||
|
|
if err := os.WriteFile(path, []byte("preserve"), 0o600); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if _, err := listen(path); err == nil {
|
||
|
|
t.Fatal("listen replaced a non-socket path")
|
||
|
|
}
|
||
|
|
content, err := os.ReadFile(path)
|
||
|
|
if err != nil || string(content) != "preserve" {
|
||
|
|
t.Fatalf("protected path changed: %q, %v", content, err)
|
||
|
|
}
|
||
|
|
}
|