Skip to content

Commit

Permalink
Merge pull request #20 from softonic/bugfix/filter-adaptive-rules
Browse files Browse the repository at this point in the history
Bugfix/filter adaptive rules
  • Loading branch information
santinoncs authored Feb 2, 2022
2 parents 106e8c8 + a7685b8 commit 89565d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/actor/armor_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func getIPsAlreadyBlockedFromRules(g *GCPArmorActor, securityPolicy string) ([]s

for _, singleRule := range resp.Rules {

if *singleRule.Action != "allow" {
if *singleRule.Action != "allow" && singleRule.Match.Config.SrcIpRanges != nil {

sourceIps = computepb.SecurityPolicyRuleMatcherConfig{
SrcIpRanges: singleRule.Match.Config.SrcIpRanges,
Expand Down Expand Up @@ -280,7 +280,7 @@ func uniqueItems(sourceIPs []string, exceptionsIPs []string) []string {
count := 0
for _, armorIps := range exceptionsIPs {
ipWithMaskES = elasticIps
if ipWithMaskES == armorIps {
if ipWithMaskES == armorIps || ipWithMaskES == armorIps+"/32" || ipWithMaskES+"/32" == armorIps {
count++
}
}
Expand Down
6 changes: 6 additions & 0 deletions app/actor/armor_actor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestDetectWhichOfTheseIPsAreNotBlocked(t *testing.T) {
elasticIPs := []string{
"1.1.1.1",
"2.2.2.2",
"2.2.2.2",
}

armorIPs := []string{
Expand All @@ -34,6 +35,8 @@ func TestDetectWhichOfTheseIPsAreNotBlocked(t *testing.T) {

result := uniqueItems(elasticIPs, armorIPs)

result = removeDuplicateStr(result)

if !reflect.DeepEqual(expected, result) {
t.Errorf("Error actual = %v, and Expected = %v.", result, expected)
}
Expand All @@ -55,6 +58,7 @@ func TestDetectWhichOfTheseIPsAreNotExcluded(t *testing.T) {
elasticIPs := []string{
"1.1.1.1",
"2.2.2.2",
"2.2.2.2",
}

exceptionsIPs := []string{
Expand All @@ -69,6 +73,8 @@ func TestDetectWhichOfTheseIPsAreNotExcluded(t *testing.T) {

result := uniqueItems(elasticIPs, exceptionsIPs)

result = removeDuplicateStr(result)

if !reflect.DeepEqual(expected, result) {
t.Errorf("Error actual = %v, and Expected = %v.", result, expected)
}
Expand Down

0 comments on commit 89565d6

Please sign in to comment.