mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
* fix(ota): isolate updates in persistent workspaces Stage online and offline update archives under /root/.kvmcache/nanokvm-update-* and validate storage, manifests, and archive contents before changing the installed application. * fix(ota): harden storage safety and release gates Preserve the last rollback backup when update storage is insufficient, and verify the actual application mount point before installation. Move the shared transfer sentinel from /tmp to /run, enforce device package limits in release verification, and run that verification in package CI.
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package application
|
|
|
|
import (
|
|
"math"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestReserveBytesAndSpaceBoundary(t *testing.T) {
|
|
if got := reserveBytes(1 << 30); got != minFreeReserve {
|
|
t.Fatalf("reserve for 1 GiB = %d, want %d", got, minFreeReserve)
|
|
}
|
|
if got := reserveBytes(4 << 30); got != 214748364 {
|
|
t.Fatalf("reserve for 4 GiB = %d, want 214748364", got)
|
|
}
|
|
space := filesystemSpace{total: 1 << 30, available: (1 << 20) + minFreeReserve}
|
|
ok, required, err := hasFreeSpace(space, 1<<20)
|
|
if err != nil || !ok || required != space.available {
|
|
t.Fatalf("boundary should fit: ok=%v required=%d err=%v", ok, required, err)
|
|
}
|
|
space.available--
|
|
ok, _, err = hasFreeSpace(space, 1<<20)
|
|
if err != nil || ok {
|
|
t.Fatalf("one byte short should fail: ok=%v err=%v", ok, err)
|
|
}
|
|
}
|
|
|
|
func TestStorageOverflowIsRejected(t *testing.T) {
|
|
if _, err := filesystemSpaceFromStats(math.MaxUint64, 1, 2); err == nil {
|
|
t.Fatal("expected filesystem overflow")
|
|
}
|
|
if _, _, err := hasFreeSpace(filesystemSpace{total: 1}, math.MaxUint64); err == nil {
|
|
t.Fatal("expected requirement overflow")
|
|
}
|
|
}
|
|
|
|
func TestInstallFilesystemChecksAppMountPoint(t *testing.T) {
|
|
workspace := t.TempDir()
|
|
backup := filepath.Join(t.TempDir(), "backup")
|
|
|
|
// /proc is a mount point whose parent is /. Checking filepath.Dir(appDir)
|
|
// would therefore miss the cross-filesystem layout on a normal Linux host.
|
|
if err := ensureInstallFilesystem(workspace, "/proc", backup); err == nil {
|
|
t.Fatal("separate application mount point was accepted")
|
|
}
|
|
}
|