From 8e86b1df54ed3c77b2eccd8e8740c0d670843243 Mon Sep 17 00:00:00 2001 From: Tim Ross Date: Thu, 31 Oct 2024 09:49:24 -0400 Subject: [PATCH] Fix TestEmitAuditEventForLargeEvents 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 8a4080c7e44c3..27804a14143a8 100644 --- a/lib/events/dynamoevents/dynamoevents_test.go +++ b/lib/events/dynamoevents/dynamoevents_test.go @@ -315,17 +315,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,