From 1823162772513b08da8fd69943b76efd643bb2d2 Mon Sep 17 00:00:00 2001 From: rosstimothy <39066650+rosstimothy@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:41:45 -0400 Subject: [PATCH] Fix TestEmitAuditEventForLargeEvents (#48228) The test relied on the fact that AppSessionRequests did not implement TrimToMaxSize. However, now that all events are forced to implemement TrimToMaxSize the test was always failing. To fix a wrapper around the event was added that overrides TrimToMaxSize that does no trimming. --- lib/events/dynamoevents/dynamoevents_test.go | 23 +++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/events/dynamoevents/dynamoevents_test.go b/lib/events/dynamoevents/dynamoevents_test.go index 21a9ed30a6195..656fb52eec4ae 100644 --- a/lib/events/dynamoevents/dynamoevents_test.go +++ b/lib/events/dynamoevents/dynamoevents_test.go @@ -312,17 +312,30 @@ func TestEmitAuditEventForLargeEvents(t *testing.T) { assert.Len(t, result, 1) }, 10*time.Second, 500*time.Millisecond) - appReqEvent := &apievents.AppSessionRequest{ - Metadata: apievents.Metadata{ - Time: tt.suite.Clock.Now().UTC(), - Type: events.AppSessionRequestEvent, + appReqEvent := &testAuditEvent{ + AppSessionRequest: apievents.AppSessionRequest{ + Metadata: apievents.Metadata{ + Time: tt.suite.Clock.Now().UTC(), + Type: events.AppSessionRequestEvent, + }, + Path: strings.Repeat("A", maxItemSize), }, - Path: strings.Repeat("A", maxItemSize), } err = tt.suite.Log.EmitAuditEvent(ctx, appReqEvent) require.ErrorContains(t, err, "ValidationException: Item size has exceeded the maximum allowed size") } +// testAuditEvent wraps an existing AuditEvent, but overrides +// the TrimToMaxSize to be a noop so that functionality can +// be tested if an event exceeds the size limits. +type testAuditEvent struct { + apievents.AppSessionRequest +} + +func (t *testAuditEvent) TrimToMaxSize(maxSizeBytes int) apievents.AuditEvent { + return t +} + func TestConfig_SetFromURL(t *testing.T) { useFipsCfg := Config{ UseFIPSEndpoint: types.ClusterAuditConfigSpecV2_FIPS_ENABLED,