Fixed filter exclude issue

dev
Ice3man543 2021-07-26 16:57:45 +05:30
parent b9e7772af6
commit ae25d1d108
2 changed files with 13 additions and 16 deletions

View File

@ -29,10 +29,9 @@ func (t *TagFilter) Match(tag, author, severity string) (bool, error) {
matchedAny := false
if len(t.allowedTags) > 0 {
_, ok := t.allowedTags[tag]
if !ok {
return false, nil
if ok {
matchedAny = true
}
matchedAny = true
}
_, ok := t.block[tag]
if ok {
@ -76,10 +75,9 @@ func (t *TagFilter) MatchWithAllowedTags(allowed []string, tag, author, severity
}
if len(allowedMap) > 0 {
_, ok := allowedMap[tag]
if !ok {
return false, nil
if ok {
matchedAny = true
}
matchedAny = true
}
_, ok := t.block[tag]
if ok && !matchedAny {

View File

@ -40,16 +40,6 @@ func TestTagBasedFilter(t *testing.T) {
require.Nil(t, err, "could not get match")
require.True(t, matched, "could not get correct match")
})
t.Run("match-includes", func(t *testing.T) {
config := &Config{
Tags: []string{"fuzz"},
ExcludeTags: []string{"fuzz"},
}
filter := New(config)
matched, err := filter.Match("fuzz", "pdteam", "low")
require.Nil(t, err, "could not get match")
require.True(t, matched, "could not get correct match")
})
t.Run("match-author", func(t *testing.T) {
config := &Config{
Authors: []string{"pdteam"},
@ -66,6 +56,15 @@ func TestTagBasedFilter(t *testing.T) {
matched, _ := filter.Match("fuzz", "pdteam", "high")
require.True(t, matched, "could not get correct match")
})
t.Run("match-exclude-with-tags", func(t *testing.T) {
config := &Config{
Tags: []string{"tag"},
ExcludeTags: []string{"another"},
}
filter := New(config)
matched, _ := filter.Match("another", "pdteam", "high")
require.False(t, matched, "could not get correct match")
})
t.Run("match-conditions", func(t *testing.T) {
config := &Config{
Authors: []string{"pdteam"},