fix(backup): privately stage restore archive
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/aritmolab/thothii/tools/tht/internal/config"
|
||||
"github.com/aritmolab/thothii/tools/tht/internal/safeio"
|
||||
)
|
||||
|
||||
func TestStageArchiveRejectsSymlinkedInstallationAncestor(t *testing.T) {
|
||||
@@ -46,3 +47,35 @@ func TestStageArchiveRejectsSymlinkedInstallationAncestor(t *testing.T) {
|
||||
t.Fatalf("StageArchive() error = %v, want unsafe symlinked staging-root rejection", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStageArchiveCreatesUnixPrivateRegularFile(t *testing.T) {
|
||||
installation := preflightTestInstallation(t)
|
||||
if err := os.MkdirAll(installation.ControlDirectory(), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
archive := filepath.Join(t.TempDir(), "valid.zip")
|
||||
writePreflightArchive(t, archive, preflightArchiveSpec{
|
||||
entries: []preflightArchiveEntry{{path: "configuration/operator.env", body: []byte("safe")}},
|
||||
})
|
||||
result, err := Preflight(context.Background(), installation, PreflightRequest{Archive: archive, Confirm: true}, permissivePreflightDependencies())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer result.CloseArchive()
|
||||
|
||||
staged, err := result.StageArchive(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer staged.Close()
|
||||
if err := safeio.ValidatePrivateRegular(staged.path); err != nil {
|
||||
t.Fatalf("staged archive privacy = %v, want owner-private regular file", err)
|
||||
}
|
||||
info, err := os.Lstat(staged.path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := info.Mode().Perm(); got != 0o600 {
|
||||
t.Fatalf("staged archive mode = %#o, want 0600", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user