package validator import ( "strings" "testing" "browser.local/platform/domain" ) func TestValidateGamePluginRuntimeProfilesAllowsSafeCasePreservingDataTargetPath(t *testing.T) { profiles := validRuntimeDataTargetProfiles("Game/Saved/SaveFiles/state.db") if err := ValidateGamePluginRuntimeProfiles(profiles); err != nil { t.Fatalf("expected safe cross-platform data target path to validate: %v", err) } } func TestValidateGamePluginRuntimeProfilesRejectsUnsafeDataTargetPath(t *testing.T) { for _, sourcePath := range []string{"../state.db", "/state.db", `Game\\Saved\\state.db`, "C:/state.db", "https://example.test/state.db"} { t.Run(sourcePath, func(t *testing.T) { err := ValidateGamePluginRuntimeProfiles(validRuntimeDataTargetProfiles(sourcePath)) if err == nil || !strings.Contains(err.Error(), "sourcePath must be a safe relative path") { t.Fatalf("expected unsafe source path rejection, got %v", err) } }) } } func validRuntimeDataTargetProfiles(sourcePath string) domain.GamePluginRuntimeProfiles { return domain.GamePluginRuntimeProfiles{ TransportProfiles: []domain.RuntimeTransportProfile{{ Key: "game-database", Kind: "sqlite", TargetKey: "game-database", Capabilities: []string{domain.JobCapabilityRemoteRunDBSQLiteQuery}, }}, DataTargets: []domain.RuntimeDataTarget{{ Key: "game-database", Kind: "sqlite.snapshot", TransportKey: "game-database", SourceRootKey: "server-root", SourcePath: sourcePath, WorkspaceKey: "databases/game-database", RefreshPolicy: "on-demand-snapshot", MaxBytes: 1024 * 1024, Platforms: []string{"windows"}, }}, } }