Add secure automatic agent updates

This commit is contained in:
Maxim
2026-08-06 21:01:54 +03:00
parent c618eb018c
commit 12aba383f1
6 changed files with 255 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"os"
"testing"
"time"
)
@@ -27,6 +28,31 @@ func TestAgentEnrollmentTokenIsSingleUse(t *testing.T) {
}
}
func TestCurrentAgentUpdateManifestMatchesExecutable(t *testing.T) {
manifest, path, err := currentAgentUpdate()
if err != nil {
t.Fatal(err)
}
if manifest.URL != "/api/agent/binary" || len(manifest.SHA256) != 64 {
t.Fatalf("unexpected manifest: %#v", manifest)
}
if _, err = os.Stat(path); err != nil {
t.Fatal(err)
}
}
func TestAgentOnlyInstallsNewerVersion(t *testing.T) {
if !newerAgentVersion("v0.14.0", "v0.13.0") {
t.Fatal("new version was not detected")
}
if newerAgentVersion("v0.12.0", "v0.13.0") {
t.Fatal("downgrade was allowed")
}
if newerAgentVersion("v0.13.0", "v0.13.0") {
t.Fatal("same version was offered")
}
}
func TestAgentReportAuthenticationAndOfflineState(t *testing.T) {
store, err := openStore(":memory:")
if err != nil {