Skip to content

Commit

Permalink
Merge pull request #5483 from robmry/ip-range-validation
Browse files Browse the repository at this point in the history
Check that --ip-range is a CIDR address
  • Loading branch information
thaJeztah authored Sep 26, 2024
2 parents daabb15 + 8fca0a1 commit c767b9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cli/command/network/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) {
for _, r := range options.ipRanges {
match := false
for _, s := range options.subnets {
if _, _, err := net.ParseCIDR(r); err != nil {
return nil, err
}
ok, err := subnetMatches(s, r)
if err != nil {
return nil, err
Expand Down
9 changes: 9 additions & 0 deletions cli/command/network/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ func TestNetworkCreateErrors(t *testing.T) {
},
expectedError: "no matching subnet for aux-address",
},
{
args: []string{"toto"},
flags: map[string]string{
"ip-range": "192.168.83.1-192.168.83.254",
"gateway": "192.168.80.1",
"subnet": "192.168.80.0/20",
},
expectedError: "invalid CIDR address: 192.168.83.1-192.168.83.254",
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit c767b9b

Please sign in to comment.