Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bug on Events Configuration Equal function #1429

Merged
merged 1 commit into from
Dec 16, 2020

Conversation

cesnietor
Copy link
Contributor

If Config.Events was nil, it would cause an null pointer exception

  • Tests included

Copy link
Member

@harshavardhana harshavardhana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the simplified diff

diff --git a/pkg/notification/notification.go b/pkg/notification/notification.go
index d150636..b17e6c5 100644
--- a/pkg/notification/notification.go
+++ b/pkg/notification/notification.go
@@ -180,30 +180,29 @@ func EqualFilterRuleList(a, b []FilterRule) bool {
 
 // Equal returns whether this `Config` is equal to another defined by the passed parameters
 func (t *Config) Equal(events []EventType, prefix, suffix string) bool {
-       //Compare events
+       if t == nil {
+               return false
+       }
+
+       // Compare events
        passEvents := EqualEventTypeList(t.Events, events)
 
-       //Compare filters
-       var newFilter []FilterRule
+       // Compare filters
+       var newFilterRules []FilterRule
        if prefix != "" {
-               newFilter = append(newFilter, FilterRule{Name: "prefix", Value: prefix})
+               newFilterRules = append(newFilterRules, FilterRule{Name: "prefix", Value: prefix})
        }
        if suffix != "" {
-               newFilter = append(newFilter, FilterRule{Name: "suffix", Value: suffix})
+               newFilterRules = append(newFilterRules, FilterRule{Name: "suffix", Value: suffix})
        }
 
-       if len(newFilter) > 0 {
-               // compare newFilter with Config.Filter
-               if t.Filter != nil {
-                       passFilters := EqualFilterRuleList(t.Filter.S3Key.FilterRules, newFilter)
-                       return passEvents && passFilters
-               }
-               // if Config is nil, they are not equal
-               return false
+       var currentFilterRules []FilterRule
+       if t.Filter != nil {
+               currentFilterRules = t.Filter.S3Key.FilterRules
        }
 
-       // if matches events and t.filter == nil
-       return (t.Filter == nil) && passEvents
+       passFilters := EqualFilterRuleList(currentFilterRules, newFilterRules)
+       return passEvents && passFilters
 }

If Config.Events was nil, it would cause an null pointer exception
@cesnietor
Copy link
Contributor Author

@harshavardhana I've addressed it and added more tests for the function itself.

Copy link
Contributor

@Alevsk Alevsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants