Add install preflight safeguards (T-303)
This commit is contained in:
@@ -42,6 +42,45 @@ func TestExtractorExtractVerifiedFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractorExtractVerifiedFileWithCheckPreflightsBeforeStaging(t *testing.T) {
|
||||
archivePath := writeTestZIP(t, []testZIPEntry{
|
||||
{name: "app.json", body: validAppManifest("1.2.3", "bin/App.exe")},
|
||||
{name: "payload/bin/App.exe", body: []byte("executable"), mode: 0o755},
|
||||
{name: "payload/readme.txt", body: []byte("hello")},
|
||||
})
|
||||
destination := filepath.Join(t.TempDir(), "staging")
|
||||
extractor := mustExtractor(t, testLimits())
|
||||
stop := errors.New("pre-extract check stopped")
|
||||
|
||||
_, err := extractor.ExtractVerifiedFileWithCheck(
|
||||
archivePath,
|
||||
destination,
|
||||
verifiedExpectation(t, archivePath, "1.2.3", "bin/App.exe"),
|
||||
func(verified VerifiedPackage) error {
|
||||
if verified.Entrypoint != "bin/App.exe" {
|
||||
t.Fatalf("entrypoint = %q", verified.Entrypoint)
|
||||
}
|
||||
if verified.PayloadFiles != 2 {
|
||||
t.Fatalf("payload files = %d, want 2", verified.PayloadFiles)
|
||||
}
|
||||
if verified.PayloadBytes != int64(len("executable")+len("hello")) {
|
||||
t.Fatalf("payload bytes = %d", verified.PayloadBytes)
|
||||
}
|
||||
return stop
|
||||
},
|
||||
)
|
||||
if !errors.Is(err, stop) {
|
||||
t.Fatalf("ExtractVerifiedFileWithCheck() error = %v, want %v", err, stop)
|
||||
}
|
||||
var packageErr *PackageError
|
||||
if !errors.As(err, &packageErr) || packageErr.Stage != PackageStagePreflight {
|
||||
t.Fatalf("package error = %#v, want preflight stage", packageErr)
|
||||
}
|
||||
if _, statErr := os.Stat(destination); !os.IsNotExist(statErr) {
|
||||
t.Fatalf("preflight failure left staging, stat error = %v", statErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractorExtractVerifiedFileRejectsBeforeStaging(t *testing.T) {
|
||||
archivePath := writeTestZIP(t, []testZIPEntry{
|
||||
{name: "app.json", body: validAppManifest("1.2.3", "App.exe")},
|
||||
|
||||
Reference in New Issue
Block a user