37 lines
2.4 KiB
Go
37 lines
2.4 KiB
Go
package validator
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"browser.local/platform/domain"
|
|
)
|
|
|
|
func TestValidateRuntimeProfilesRejectsLegacyClientManagers(t *testing.T) {
|
|
profile := domain.RuntimeClientManagerProfile{Key: "scum-client-manager", DisplayName: "SCUM Client Manager"}
|
|
err := ValidateGamePluginRuntimeProfiles(domain.GamePluginRuntimeProfiles{ClientManagers: []domain.RuntimeClientManagerProfile{profile}})
|
|
if err == nil || !strings.Contains(err.Error(), "runtimeProfiles.clientManagers is no longer supported") {
|
|
t.Fatalf("expected legacy client-manager profile rejection, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidateClientManagerPersistenceContractsFailClosed(t *testing.T) {
|
|
stamp := time.Date(2026, 7, 18, 4, 0, 0, 0, time.UTC)
|
|
installation := domain.ClientManagerInstallation{ID: "cm-install-1", ServerInstanceID: "server-1", PluginID: "game.scum", ProfileKey: "scum-client-manager", RunEndpointID: "run-1", TargetOS: "linux", TargetArch: "amd64", Status: domain.ClientManagerLifecycleOnline, Phase: "healthy", KeyGeneration: 1, DeploymentGeneration: 1, Health: domain.ClientManagerHealthHealthy, HealthReason: "ready", CreatedAt: stamp, UpdatedAt: stamp}
|
|
if err := ValidateClientManagerInstallation(installation); err != nil {
|
|
t.Fatalf("validate historical installation projection: %v", err)
|
|
}
|
|
installation.HealthReason = "Bearer stolen-session"
|
|
if err := ValidateClientManagerInstallation(installation); err == nil {
|
|
t.Fatal("expected session-bearing health reason rejection")
|
|
}
|
|
session := domain.ClientManagerSession{ID: "cm-session-1", InstallationID: "cm-install-1", ServerInstanceID: "server-1", ProfileKey: "scum-client-manager", RunEndpointID: "run-1", ArtifactID: "artifact-1", KeyGeneration: 1, DeploymentGeneration: 1, TokenHash: strings.Repeat("a", 64), Capabilities: []string{"component.heartbeat"}, Status: domain.ClientManagerSessionActive, ExpiresAt: stamp.Add(time.Minute), CreatedAt: stamp, UpdatedAt: stamp}
|
|
if err := ValidateClientManagerSession(session); err != nil {
|
|
t.Fatalf("validate historical hashed session: %v", err)
|
|
}
|
|
if err := ValidateClientManagerHeartbeat(domain.ClientManagerHeartbeat{InstallationID: "cm-install-1", SessionToken: "component-session", Sequence: 1, Health: domain.ClientManagerHealthHealthy, HealthReason: "password=leak", Capabilities: []string{"component.heartbeat"}, SentAt: stamp}); err == nil {
|
|
t.Fatal("expected unsafe heartbeat reason rejection")
|
|
}
|
|
}
|