Skip to content

Commit

Permalink
Fix TestEmitAuditEventForLargeEvents (#48227)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rosstimothy authored Oct 31, 2024
1 parent 5bef5fb commit a46342f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/events/dynamoevents/dynamoevents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,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,
Expand Down

0 comments on commit a46342f

Please # to comment.