- Add shared resumable + SHA256SUMS-verified downloader (internal/fetch) and Windows executable swap/relaunch flow (internal/selfupdate, internal/app/appupdate_flow.go, --wait-pid in main.go/cli). - Add dedicated About page and sidebar update capsule with background release checks, download progress, and restart confirmation when VMs are running. - Implement plugin-contributed UI and backend/CLI locale packs (contributes.locales, LocalizedText extra tags, validation, runtime overlay, and PopupSelect language picker). - Move kernel-irqchip and Windows processor scheduling controls into VM Compute > Performance settings, hide Plugins settings gear for VM-only schemas, and align locked system plugin switches.
88 lines
2.6 KiB
Go
88 lines
2.6 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/config"
|
|
"github.com/Nwflower/reims-go/internal/i18n"
|
|
"github.com/Nwflower/reims-go/internal/version"
|
|
)
|
|
|
|
func TestDownloadAppUpdateVerifiesAgainstSums(t *testing.T) {
|
|
body := []byte("reims-go v9.9.9 build")
|
|
h := sha256.Sum256(body)
|
|
good := hex.EncodeToString(h[:])
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.URL.Path {
|
|
case "/SHA256SUMS.txt":
|
|
fmt.Fprintf(w, "%s reims-go-v9.9.9-windows-amd64.exe\n", good)
|
|
case "/bad/SHA256SUMS.txt":
|
|
fmt.Fprintf(w, "%s reims-go-v9.9.9-windows-amd64.exe\n", strings.Repeat("0", 64))
|
|
case "/app.exe":
|
|
_, _ = w.Write(body)
|
|
default:
|
|
http.NotFound(w, r)
|
|
}
|
|
}))
|
|
defer srv.Close()
|
|
info := version.UpdateInfo{
|
|
Latest: "v9.9.9", HasUpdate: true,
|
|
AssetName: "reims-go-v9.9.9-windows-amd64.exe", AssetSize: int64(len(body)),
|
|
DownloadURL: srv.URL + "/app.exe", SumsURL: srv.URL + "/SHA256SUMS.txt",
|
|
}
|
|
|
|
dir := t.TempDir()
|
|
path, sum, err := downloadAppUpdate(context.Background(), info, dir, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if sum != good || filepath.Dir(path) != dir {
|
|
t.Fatalf("path %s sum %s", path, sum)
|
|
}
|
|
|
|
info.SumsURL = srv.URL + "/bad/SHA256SUMS.txt"
|
|
if _, _, err := downloadAppUpdate(context.Background(), info, t.TempDir(), nil); err == nil || !strings.Contains(err.Error(), "SHA256 mismatch") {
|
|
t.Fatalf("a hash mismatch must fail, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestInstallAppUpdateGuards(t *testing.T) {
|
|
cfg := config.Default()
|
|
cfg.Locale = i18n.EnUS
|
|
a := &App{cfg: cfg}
|
|
|
|
appUpdateReady.Lock()
|
|
appUpdateReady.version, appUpdateReady.path, appUpdateReady.sha256 = "", "", ""
|
|
appUpdateReady.Unlock()
|
|
if err := a.InstallAppUpdate(); err == nil || !strings.Contains(err.Error(), "Download the update first") {
|
|
t.Fatalf("nothing downloaded: got %v", err)
|
|
}
|
|
|
|
// A file that no longer matches its verified hash is refused before any swap.
|
|
f := filepath.Join(t.TempDir(), "reims-go-v9.9.9-windows-amd64.exe")
|
|
if err := os.WriteFile(f, []byte("swapped after download"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
appUpdateReady.Lock()
|
|
appUpdateReady.version, appUpdateReady.path, appUpdateReady.sha256 = "v9.9.9", f, strings.Repeat("a", 64)
|
|
appUpdateReady.Unlock()
|
|
if err := a.InstallAppUpdate(); err == nil || !strings.Contains(err.Error(), "changed on disk") {
|
|
t.Fatalf("changed file: got %v", err)
|
|
}
|
|
appUpdateReady.Lock()
|
|
cleared := appUpdateReady.path == ""
|
|
appUpdateReady.Unlock()
|
|
if !cleared {
|
|
t.Fatal("a changed download must be forgotten")
|
|
}
|
|
}
|