mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-13 11:31:29 -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.2 KiB
Go
47 lines
1.2 KiB
Go
package application
|
|
|
|
import (
|
|
"crypto/sha512"
|
|
"encoding/base64"
|
|
"testing"
|
|
)
|
|
|
|
func validLatest() Latest {
|
|
digest := sha512.Sum512([]byte("package"))
|
|
return Latest{
|
|
Version: "1.2.3", Name: "nanokvm_1.2.3.tar.gz",
|
|
Sha512: base64.StdEncoding.EncodeToString(digest[:]), LegacySize: 1,
|
|
}
|
|
}
|
|
|
|
func TestValidateLatestV1DoesNotInterpretLegacySizeAsBytes(t *testing.T) {
|
|
latest := validLatest()
|
|
latest.LegacySize = 15048 // historic stable manifests used a non-byte value
|
|
if err := validateLatest(&latest); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := validateDownloadedSize(&latest, 15406125); err != nil {
|
|
t.Fatalf("v1 must not require equality with legacy size: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidateLatestV2RequiresExactByteFields(t *testing.T) {
|
|
latest := validLatest()
|
|
latest.ManifestVersion = 2
|
|
latest.SizeBytes = 100
|
|
latest.UnpackedSizeBytes = 200
|
|
if err := validateLatest(&latest); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := validateDownloadedSize(&latest, 99); err == nil {
|
|
t.Fatal("v2 size mismatch was accepted")
|
|
}
|
|
if err := validateExpandedSize(&latest, 199); err == nil {
|
|
t.Fatal("v2 expanded size mismatch was accepted")
|
|
}
|
|
latest.ManifestVersion = 3
|
|
if err := validateLatest(&latest); err == nil {
|
|
t.Fatal("unknown manifest version was accepted")
|
|
}
|
|
}
|