-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise limit of destination_ports of network_rule_collection for azure…
…rm_firewall_policy_rule_collection_group (#9490) fixes #9304 --- PASS: TestAccAzureRMFirewallPolicyRuleCollectionGroup_requiresImport (153.90s) --- PASS: TestAccAzureRMFirewallPolicyRuleCollectionGroup_basic (194.10s) --- PASS: TestAccAzureRMFirewallPolicyRuleCollectionGroup_complete (202.27s) --- PASS: TestAccAzureRMFirewallPolicyRuleCollectionGroup_update (269.51s)
- Loading branch information
Neil Ye
authored
Jan 4, 2021
1 parent
7c2d726
commit d2482ec
Showing
5 changed files
with
126 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strconv" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func PortOrPortRangeWithin(min int, max int) schema.SchemaValidateFunc { | ||
return func(i interface{}, k string) (warnings []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) | ||
return | ||
} | ||
|
||
assertWithinRange := func(n int) error { | ||
if n < min || n > max { | ||
return fmt.Errorf("port %d is out of range (%d-%d)", n, min, max) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Allowed format including: `num` or `num1-num2` (num1 < num2). | ||
groups := regexp.MustCompile(`^(\d+)((-)(\d+))?$`).FindStringSubmatch(v) | ||
if len(groups) != 5 { | ||
errors = append(errors, fmt.Errorf("invalid format of %q", k)) | ||
return | ||
} | ||
|
||
if groups[2] == "" { | ||
p1, _ := strconv.Atoi(groups[1]) | ||
|
||
if err := assertWithinRange(p1); err != nil { | ||
errors = append(errors, err) | ||
return | ||
} | ||
} else { | ||
p1, _ := strconv.Atoi(groups[1]) | ||
p2, _ := strconv.Atoi(groups[4]) | ||
|
||
if p1 >= p2 { | ||
errors = append(errors, fmt.Errorf("beginning port (%d) should be less than ending port (%d)", p1, p2)) | ||
return | ||
} | ||
|
||
if err := assertWithinRange(p1); err != nil { | ||
errors = append(errors, err) | ||
return | ||
} | ||
|
||
if err := assertWithinRange(p2); err != nil { | ||
errors = append(errors, err) | ||
return | ||
} | ||
} | ||
|
||
return nil, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package validate | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestPortOrPortRangeWithin(t *testing.T) { | ||
testData := []struct { | ||
input string | ||
expected bool | ||
}{ | ||
{ | ||
input: "0", | ||
expected: false, | ||
}, | ||
{ | ||
input: "65536", | ||
expected: false, | ||
}, | ||
{ | ||
input: "1", | ||
expected: true, | ||
}, | ||
{ | ||
input: "65535", | ||
expected: true, | ||
}, | ||
{ | ||
input: "634", | ||
expected: true, | ||
}, | ||
{ | ||
input: "1000-50000", | ||
expected: true, | ||
}, | ||
{ | ||
input: "1-65535", | ||
expected: true, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q..", v.input) | ||
|
||
_, errors := PortOrPortRangeWithin(1, 65535)(v.input, "port_or_port_range") | ||
actual := len(errors) == 0 | ||
if v.expected != actual { | ||
t.Fatalf("Expected %t but got %t", v.expected, actual) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
azurerm/internal/services/firewall/validate/firewall_policy_rule_port.go
This file was deleted.
Oops, something went wrong.