feat: apply sealed installation plans without interactive setup
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
//go:build linux || darwin
|
||||
|
||||
package safeio
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func TestPublicationWriteFailureLeavesNoTarget(t *testing.T) {
|
||||
if path := os.Getenv("THT_SAFEIO_WRITE_FAILURE_PATH"); path != "" {
|
||||
signal.Ignore(syscall.SIGXFSZ)
|
||||
if err := unix.Setrlimit(unix.RLIMIT_FSIZE, &unix.Rlimit{Cur: 1, Max: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if PublishCanonicalNewFile(path, bytes.Repeat([]byte("x"), 4096), 0o600) == nil {
|
||||
t.Fatal("short write published")
|
||||
}
|
||||
if _, err := os.Lstat(path); !os.IsNotExist(err) {
|
||||
t.Fatal("failed write exposed target")
|
||||
}
|
||||
return
|
||||
}
|
||||
root, _ := filepath.EvalSymlinks(t.TempDir())
|
||||
if err := os.Chmod(root, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := exec.Command(os.Args[0], "-test.run=^TestPublicationWriteFailureLeavesNoTarget$")
|
||||
cmd.Env = append(os.Environ(), "THT_SAFEIO_WRITE_FAILURE_PATH="+filepath.Join(root, "asset"))
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("write fault proof: %v %s", err, output)
|
||||
}
|
||||
entries, _ := os.ReadDir(root)
|
||||
if len(entries) != 0 {
|
||||
t.Fatal("failed write leaked temporary file")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user