Skip to content

Commit

Permalink
Add event listerner to NoopAudit for audited request assertions. (#25507
Browse files Browse the repository at this point in the history
)
  • Loading branch information
victorr authored Feb 19, 2024
1 parent b33e37d commit 633dae1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions helper/testhelpers/corehelpers/corehelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ type noopWrapper struct {
backend *NoopAudit
}

// NoopAuditEventListener is a callback used by noopWrapper.Process() to notify
// of each received audit event.
type NoopAuditEventListener func(*audit.AuditEvent)

type NoopAudit struct {
Config *audit.BackendConfig

Expand All @@ -339,6 +343,8 @@ type NoopAudit struct {

nodeIDList []eventlogger.NodeID
nodeMap map[eventlogger.NodeID]eventlogger.Node

listener NoopAuditEventListener
}

// Process handles the contortions required by older test code to ensure behavior.
Expand All @@ -358,6 +364,10 @@ func (n *noopWrapper) Process(ctx context.Context, e *eventlogger.Event) (*event
return nil, errors.New("cannot parse payload as an audit event")
}

if n.backend.listener != nil {
n.backend.listener(a)
}

in := a.Data

// Depending on the type of the audit event (request or response) we need to
Expand Down Expand Up @@ -495,6 +505,10 @@ func (n *NoopAudit) RegisterNodesAndPipeline(broker *eventlogger.Broker, name st
return broker.RegisterPipeline(pipeline)
}

func (n *NoopAudit) SetListener(listener NoopAuditEventListener) {
n.listener = listener
}

type TestLogger struct {
hclog.InterceptLogger
Path string
Expand Down

0 comments on commit 633dae1

Please sign in to comment.