Skip to content

Commit

Permalink
Merge pull request #62 from pantheon-systems/fix-filters
Browse files Browse the repository at this point in the history
Fix type on filter object
  • Loading branch information
Joe Burianek authored Jun 8, 2022
2 parents 8745a0e + 5a65e7b commit c56bd82
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
26 changes: 13 additions & 13 deletions audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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`")
Expand All @@ -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`")
Expand All @@ -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 ]: `[`")
Expand All @@ -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: `[]`")
Expand All @@ -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: `[]`")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/marshaller/audit_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit c56bd82

Please sign in to comment.