feat(scum): add bounded UE4SS notification adapter
This commit is contained in:
@@ -3,6 +3,7 @@ package companion
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type configPortFixture struct {
|
||||
@@ -18,6 +19,16 @@ func (fixture *configPortFixture) ApplyConfigPatch(_ context.Context, _ string,
|
||||
return map[string]string{"ServerName": "Moon", "hostPath": "C:/secret"}, nil
|
||||
}
|
||||
|
||||
type notificationPortFixture struct {
|
||||
deliveries []ue4SSPlayerNotification
|
||||
accepted bool
|
||||
}
|
||||
|
||||
func (fixture *notificationPortFixture) SendPlayerNotification(_ context.Context, notification ue4SSPlayerNotification) (UE4SSNotificationReceipt, error) {
|
||||
fixture.deliveries = append(fixture.deliveries, notification)
|
||||
return UE4SSNotificationReceipt{Accepted: fixture.accepted}, nil
|
||||
}
|
||||
|
||||
func TestVersionedAdapterUsesOnlyLogicalConfigValuesAndRedactsDiagnostics(t *testing.T) {
|
||||
port := &configPortFixture{fields: map[string]string{"ServerName": "Moon", "hostPath": "C:/secret", "Password": "nope"}}
|
||||
adapter := VersionedAdapter{ServerVersion: "0.9.700.90357", Config: port, DiagnosticsState: map[string]string{"status": "healthy", "hostPath": "C:/secret"}}
|
||||
@@ -41,3 +52,48 @@ func TestVersionedAdapterUsesOnlyLogicalConfigValuesAndRedactsDiagnostics(t *tes
|
||||
t.Fatalf("diagnostics leaked unsafe details: %+v", diagnostics)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersionedUE4SSNotificationIsFixedTypedAndRedacted(t *testing.T) {
|
||||
port := ¬ificationPortFixture{accepted: true}
|
||||
adapter := VersionedAdapter{BoundServerID: "server-1", ServerVersion: "0.9.700.90357", UE4SSBuild: UE4SSReferenceBuild, UE4SSReferenceRevision: UE4SSReferenceRevision, Notification: port}
|
||||
result, err := adapter.NotifyPlayer(context.Background(), map[string]any{"playerId": "76561198000000001", "message": "Moon \"gift\""})
|
||||
if err != nil || !result["accepted"].(bool) || len(port.deliveries) != 1 {
|
||||
t.Fatalf("typed notification was not delivered: result=%+v err=%v deliveries=%+v", result, err, port.deliveries)
|
||||
}
|
||||
delivery := port.deliveries[0]
|
||||
if delivery.ServerID != "server-1" || delivery.chatType != fixedNotificationType || delivery.protectedAuditCommand != "SendChat 4 \"Moon \\\"gift\\\"\" 76561198000000001" {
|
||||
t.Fatalf("notification did not use the fixed UE4SS contract: %+v", delivery)
|
||||
}
|
||||
if result["message"] == delivery.protectedAuditCommand || result["command"] != nil || result["rcon"] != nil {
|
||||
t.Fatalf("notification leaked protected transport details: %+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersionedUE4SSNotificationFailsClosedForUnpinnedBuildOrInvalidRecipient(t *testing.T) {
|
||||
port := ¬ificationPortFixture{accepted: true}
|
||||
adapter := VersionedAdapter{BoundServerID: "server-1", ServerVersion: "0.9.700.90357", UE4SSBuild: "3.0.2", UE4SSReferenceRevision: UE4SSReferenceRevision, Notification: port}
|
||||
if _, err := adapter.NotifyPlayer(context.Background(), map[string]any{"playerId": "76561198000000001", "message": "Moonlight"}); err == nil {
|
||||
t.Fatal("unpinned UE4SS build must be unavailable")
|
||||
}
|
||||
adapter.UE4SSBuild = UE4SSReferenceBuild
|
||||
if _, err := adapter.NotifyPlayer(context.Background(), map[string]any{"playerId": "not-a-steam-id", "message": "Moonlight"}); err == nil {
|
||||
t.Fatal("unverified recipient identity must be rejected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotificationFailureIsCachedWithoutInvokingRewardDelivery(t *testing.T) {
|
||||
stamp := time.Now().UTC()
|
||||
port := ¬ificationPortFixture{accepted: false}
|
||||
adapter := VersionedAdapter{BoundServerID: "server-1", ServerVersion: "0.9.700.90357", UE4SSBuild: UE4SSReferenceBuild, UE4SSReferenceRevision: UE4SSReferenceRevision, Notification: port}
|
||||
registry := NewHandlerRegistry(HandlerAvailability{BoundServerID: "server-1", ServerVersion: "0.9.700.90357", Approved: true, Capabilities: map[string]bool{"player.notify": true}}, adapter)
|
||||
command := ClaimedCommand{ID: "notification-1", ProfileKey: ProfileKey, CommandType: "player.notify", Payload: map[string]any{"playerId": "76561198000000001", "message": "Moonlight"}, FencingToken: 1, LeaseExpiresAt: stamp.Add(time.Minute), ExpiresAt: stamp.Add(time.Minute)}
|
||||
for range 2 {
|
||||
result, err := registry.Execute(context.Background(), command)
|
||||
if err != nil || result.Payload["accepted"] != false {
|
||||
t.Fatalf("notification failure was not typed: result=%+v err=%v", result, err)
|
||||
}
|
||||
}
|
||||
if len(port.deliveries) != 1 {
|
||||
t.Fatalf("duplicate notification attempted transport %d times", len(port.deliveries))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user