Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/cli/logs_extract_zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,21 @@ func TestExtractZipFileErrorHandling(t *testing.T) {
zipReader, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
require.NoError(t, err)

// Extract to a read-only destination (will fail on create)
// Extract to a read-only destination (will fail on create in most environments).
//
// Note: When running as root (or with elevated permissions), creating files inside a
// 0555 directory may still succeed depending on the platform and filesystem.
// In that case, we skip this assertion rather than make the suite flaky.
readOnlyDir := filepath.Join(tempDir, "readonly")
err = os.MkdirAll(readOnlyDir, 0555) // Read-only directory
require.NoError(t, err)

// Try to extract - should fail and return error
err = extractZipFile(zipReader.File[0], readOnlyDir, false)
require.Error(t, err, "extractZipFile should return error when destination is read-only")
if err == nil {
// Likely running with elevated privileges.
t.Skip("expected extraction to fail in read-only directory, but it succeeded (likely elevated privileges)")
}
assert.Contains(t, err.Error(), "failed to create", "Error should mention creation failure")
})

Expand Down