* feat (events): Add new options needed for AuditConfig WithAuditWrapper and WithFilterOperations all for optional paramters when creating AuditConfig types. * refactor (event): Change EventerConfig.Sinks to a ptr We need to modify the SinkConfig.AuditConfig during the NewEventer factory, so we have to use a ptr not a ref. * feat (events): Add audit configuration types * feat (events): add audit config to sink configuration. * feat (events): add redact/encrypt node for audit events to Eventer Integrate the encrypt.Filter node from the eventlogger into the event.Eventer, so audit events can be redacted/encrypted based on data classifications. * test (events) Add test protobufs for events Add test protobufs along with a test service for testing the audit event encrypt node
121 lines
3.6 KiB
Go
121 lines
3.6 KiB
Go
package base
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/internal/observability/event"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// Test_GetOpts provides unit tests for GetOpts and all the options
|
|
func Test_GetOpts(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("nil-options", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(nil, nil)
|
|
testOpts := getDefaultOptions()
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithEventFlags", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
isTrue := true
|
|
f := EventFlags{
|
|
Format: event.JSONSinkFormat,
|
|
AuditEnabled: &isTrue,
|
|
ObservationsEnabled: &isTrue,
|
|
SysEventsEnabled: &isTrue,
|
|
}
|
|
opts := getOpts(WithEventFlags(&f))
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withEventFlags = &f
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithEventerConfig", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
c := event.EventerConfig{
|
|
Sinks: []*event.SinkConfig{
|
|
// not a valid sink, but it doesn't need to be to test the
|
|
// option is properly supported.
|
|
{
|
|
Name: "test-sink",
|
|
Type: "Stderr",
|
|
},
|
|
},
|
|
}
|
|
opts := getOpts(WithEventerConfig(&c))
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withEventerConfig = &c
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithNoTokenScope", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithNoTokenScope())
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withNoTokenScope = true
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithSkipDatabaseDestruction", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithSkipDatabaseDestruction())
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withSkipDatabaseDestruction = true
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithNoTokenValue", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithNoTokenValue())
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withNoTokenValue = true
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithSkipAuthMethodCreation", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithSkipAuthMethodCreation())
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withSkipAuthMethodCreation = true
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithSkipOidcAuthMethodCreation", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithSkipOidcAuthMethodCreation())
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withSkipOidcAuthMethodCreation = true
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithSkipScopesCreation", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithSkipScopesCreation())
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withSkipScopesCreation = true
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithSkipHostResourcesCreation", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithSkipHostResourcesCreation())
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withSkipHostResourcesCreation = true
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithSkipTargetCreation", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithSkipTargetCreation())
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withSkipTargetCreation = true
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("WithContainerImage", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(WithContainerImage("test-container"))
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withContainerImage = "test-container"
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
t.Run("withDialect", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
opts := getOpts(withDialect("test-dialect"))
|
|
testOpts := getDefaultOptions()
|
|
testOpts.withDialect = "test-dialect"
|
|
assert.Equal(opts, testOpts)
|
|
})
|
|
}
|