From 5a65e7b4642911b85cc1579c98b45ad2c2fdcd83 Mon Sep 17 00:00:00 2001 From: Joe Burianek Date: Wed, 8 Jun 2022 11:21:55 -0500 Subject: [PATCH] Fix type on filter object --- audit.go | 2 +- audit_test.go | 26 +++++++++++++------------- pkg/marshaller/audit_filter.go | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/audit.go b/audit.go index 44229cc..e16acf2 100644 --- a/audit.go +++ b/audit.go @@ -123,7 +123,7 @@ func createFilters(config *viper.Viper) ([]marshaller.AuditFilter, error) { } for i, f := range ft { - f2, ok := f.(map[interface{}]interface{}) + f2, ok := f.(map[string]interface{}) if !ok { return filters, fmt.Errorf("Could not parse filter %d; '%+v'", i+1, f) } diff --git a/audit_test.go b/audit_test.go index 525afd9..7dcd9e1 100644 --- a/audit_test.go +++ b/audit_test.go @@ -174,7 +174,7 @@ func Test_createFilters(t *testing.T) { // Bad message type - string c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"message_type": "bad message type"}) + rf = append(rf, map[string]interface{}{"message_type": "bad message type"}) c.Set("filters", rf) f, err = createFilters(c) assert.EqualError(t, err, "`message_type` in filter 1 could not be parsed; Value: `bad message type`; Error: strconv.ParseUint: parsing \"bad message type\": invalid syntax") @@ -183,7 +183,7 @@ func Test_createFilters(t *testing.T) { // Bad message type - unknown c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"message_type": false}) + rf = append(rf, map[string]interface{}{"message_type": false}) c.Set("filters", rf) f, err = createFilters(c) assert.EqualError(t, err, "`message_type` in filter 1 could not be parsed; Value: `false`") @@ -192,7 +192,7 @@ func Test_createFilters(t *testing.T) { // Bad regex - not string c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"regex": false}) + rf = append(rf, map[string]interface{}{"regex": false}) c.Set("filters", rf) f, err = createFilters(c) assert.EqualError(t, err, "`regex` in filter 1 could not be parsed; Value: `false`") @@ -201,7 +201,7 @@ func Test_createFilters(t *testing.T) { // Bad regex - un-parse-able c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"regex": "["}) + rf = append(rf, map[string]interface{}{"regex": "["}) c.Set("filters", rf) f, err = createFilters(c) assert.EqualError(t, err, "`regex` in filter 1 could not be parsed; Value: `[`; Error: error parsing regexp: missing closing ]: `[`") @@ -210,7 +210,7 @@ func Test_createFilters(t *testing.T) { // Bad syscall - not string or int c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"syscall": []string{}}) + rf = append(rf, map[string]interface{}{"syscall": []string{}}) c.Set("filters", rf) f, err = createFilters(c) assert.EqualError(t, err, "`syscall` in filter 1 could not be parsed; Value: `[]`") @@ -219,7 +219,7 @@ func Test_createFilters(t *testing.T) { // Bad key - not string c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"key": []string{}}) + rf = append(rf, map[string]interface{}{"key": []string{}}) c.Set("filters", rf) f, err = createFilters(c) assert.EqualError(t, err, "`key` in filter 1 could not be parsed; Value: `[]`") @@ -228,7 +228,7 @@ func Test_createFilters(t *testing.T) { // Missing regex c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"syscall": "1", "message_type": "1"}) + rf = append(rf, map[string]interface{}{"syscall": "1", "message_type": "1"}) c.Set("filters", rf) f, err = createFilters(c) assert.EqualError(t, err, "Filter 1 is missing the `regex` entry") @@ -237,7 +237,7 @@ func Test_createFilters(t *testing.T) { // Missing message_type c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"syscall": "1", "regex": "1"}) + rf = append(rf, map[string]interface{}{"syscall": "1", "regex": "1"}) c.Set("filters", rf) f, err = createFilters(c) assert.EqualError(t, err, "Filter 1 is missing either the `key` entry or `syscall` and `message_type` entry") @@ -248,7 +248,7 @@ func Test_createFilters(t *testing.T) { elb.Reset() c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"message_type": "1", "regex": "1"}) + rf = append(rf, map[string]interface{}{"message_type": "1", "regex": "1"}) c.Set("filters", rf) f, err = createFilters(c) assert.Nil(t, err) @@ -262,7 +262,7 @@ func Test_createFilters(t *testing.T) { // Missing syscall and missing key and missing message type c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"regex": "1"}) + rf = append(rf, map[string]interface{}{"regex": "1"}) c.Set("filters", rf) f, err = createFilters(c) assert.EqualError(t, err, "Filter 1 is missing either the `key` entry or `syscall` and `message_type` entry") @@ -273,7 +273,7 @@ func Test_createFilters(t *testing.T) { elb.Reset() c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"message_type": "1", "regex": "1", "syscall": "1"}) + rf = append(rf, map[string]interface{}{"message_type": "1", "regex": "1", "syscall": "1"}) c.Set("filters", rf) f, err = createFilters(c) assert.Nil(t, err) @@ -289,7 +289,7 @@ func Test_createFilters(t *testing.T) { elb.Reset() c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"message_type": 1, "regex": "1", "syscall": 1}) + rf = append(rf, map[string]interface{}{"message_type": 1, "regex": "1", "syscall": 1}) c.Set("filters", rf) f, err = createFilters(c) assert.Nil(t, err) @@ -305,7 +305,7 @@ func Test_createFilters(t *testing.T) { elb.Reset() c = viper.New() rf = make([]interface{}, 0) - rf = append(rf, map[interface{}]interface{}{"key": "testkey", "regex": "1"}) + rf = append(rf, map[string]interface{}{"key": "testkey", "regex": "1"}) c.Set("filters", rf) f, err = createFilters(c) assert.Nil(t, err) diff --git a/pkg/marshaller/audit_filter.go b/pkg/marshaller/audit_filter.go index 413323e..6999727 100644 --- a/pkg/marshaller/audit_filter.go +++ b/pkg/marshaller/audit_filter.go @@ -31,7 +31,7 @@ type AuditFilter struct { Action FilterAction } -func NewAuditFilter(ruleNumber int, obj map[interface{}]interface{}) (*AuditFilter, error) { +func NewAuditFilter(ruleNumber int, obj map[string]interface{}) (*AuditFilter, error) { var err error af, err := parse(ruleNumber, obj) @@ -55,7 +55,7 @@ func NewAuditFilter(ruleNumber int, obj map[interface{}]interface{}) (*AuditFilt return af, nil } -func parse(ruleNumber int, obj map[interface{}]interface{}) (*AuditFilter, error) { +func parse(ruleNumber int, obj map[string]interface{}) (*AuditFilter, error) { var err error var ok bool