Skip to content

Commit

Permalink
Merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkov committed Jun 23, 2020
2 parents 8ed2f2e + 5dd65ce commit 576bf02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
24 changes: 12 additions & 12 deletions dns_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,45 +220,45 @@ func TestClientTags(t *testing.T) {

// tags don't match
rules, ok = dnsEngine.MatchRequest(DNSRequest{Hostname: "host2", SortedClientTags: []string{"phone"}})
assert.True(t, !ok)
assert.False(t, ok)

// tags don't match
rules, ok = dnsEngine.MatchRequest(DNSRequest{Hostname: "host2", SortedClientTags: []string{}})
assert.True(t, !ok)
assert.False(t, ok)

// 1 tag matches (exclusion)
rules, ok = dnsEngine.MatchRequest(DNSRequest{Hostname: "host3", SortedClientTags: []string{"phone", "printer"}})
assert.True(t, ok)
assert.True(t, rules.NetworkRule != nil)
assert.True(t, rules.NetworkRule.Text() == "||host3^$ctag=~pc|~router")
assert.NotNil(t, rules.NetworkRule)
assert.Equal(t, "||host3^$ctag=~pc|~router", rules.NetworkRule.Text())

// 1 tag matches (exclusion)
rules, ok = dnsEngine.MatchRequest(DNSRequest{Hostname: "host4", SortedClientTags: []string{"phone", "router"}})
assert.True(t, ok)
assert.True(t, rules.NetworkRule != nil)
assert.True(t, rules.NetworkRule.Text() == "||host4^$ctag=~pc|router")
assert.NotNil(t, rules.NetworkRule)
assert.Equal(t, "||host4^$ctag=~pc|router", rules.NetworkRule.Text())

// tags don't match (exclusion)
rules, ok = dnsEngine.MatchRequest(DNSRequest{Hostname: "host3", SortedClientTags: []string{"pc"}})
assert.True(t, !ok)
assert.False(t, ok)

// tags don't match (exclusion)
rules, ok = dnsEngine.MatchRequest(DNSRequest{Hostname: "host4", SortedClientTags: []string{"pc", "router"}})
assert.True(t, !ok)
assert.False(t, ok)

// tags match but it's a $badfilter
rules, ok = dnsEngine.MatchRequest(DNSRequest{Hostname: "host5", SortedClientTags: []string{"pc"}})
assert.True(t, !ok)
assert.False(t, ok)

// tags match and $badfilter rule disables global rule
rules, ok = dnsEngine.MatchRequest(DNSRequest{Hostname: "host6", SortedClientTags: []string{"pc"}})
assert.True(t, ok)
assert.True(t, rules.NetworkRule != nil)
assert.True(t, rules.NetworkRule.Text() == "||host6^$ctag=pc|printer")
assert.NotNil(t, rules.NetworkRule)
assert.Equal(t, "||host6^$ctag=pc|printer", rules.NetworkRule.Text())

// tags match (exclusion) but it's a $badfilter
rules, ok = dnsEngine.MatchRequest(DNSRequest{Hostname: "host7", SortedClientTags: []string{"phone"}})
assert.True(t, !ok)
assert.False(t, ok)
}

func TestBadfilterRules(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions rules/network_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,6 @@ func (f *NetworkRule) matchClientTags(sortedTags []string) bool {
// the rule doesn't contain $ctag extension
return true
}
if len(sortedTags) == 0 {
// client has no tags
return false
}
if matchClientTagsSpecific(f.restrictedClientTags, sortedTags) {
// matched by restricted client tag
return false
Expand Down

0 comments on commit 576bf02

Please sign in to comment.