trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dewr...@apache.org
Subject [trafficcontrol] branch master updated: validate that a servers ip6address field is an IPv6 address or CIDR
Date Fri, 07 Sep 2018 15:49:22 GMT
This is an automated email from the ASF dual-hosted git repository.

dewrich pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 60bb970  validate that a servers ip6address field is an IPv6 address or CIDR
60bb970 is described below

commit 60bb97076d6de6a3a58d304c96489fa187e00e14
Author: Dylan Volz <Dylan_Volz@comcast.com>
AuthorDate: Fri Sep 7 09:25:18 2018 -0600

    validate that a servers ip6address field is an IPv6 address or CIDR
---
 lib/go-tc/tovalidate/rules.go                    | 31 ++++++++++++++++++++++++
 traffic_ops/testing/api/v13/tc-fixtures.json     | 22 ++++++++---------
 traffic_ops/traffic_ops_golang/server/servers.go |  2 +-
 3 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/lib/go-tc/tovalidate/rules.go b/lib/go-tc/tovalidate/rules.go
index f7ba82e..3ea3ae1 100644
--- a/lib/go-tc/tovalidate/rules.go
+++ b/lib/go-tc/tovalidate/rules.go
@@ -15,6 +15,7 @@ package tovalidate
 import (
 	"errors"
 	"fmt"
+	"net"
 	"reflect"
 	"strings"
 )
@@ -129,3 +130,33 @@ func IsValidPortNumber(value interface{}) error {
 	}
 	return errors.New("must be a valid port number")
 }
+
+func IsValidIPv6CIDROrAddress(value interface{}) error {
+	switch v := value.(type) {
+	case *string:
+		if v == nil {
+			return nil
+		}
+		ip, _, err := net.ParseCIDR(*v)
+		if err == nil {
+			if ip.To4() == nil {
+				return nil
+			} else {
+				return fmt.Errorf("got IPv4 CIDR, IPv6 expected")
+			}
+		} else {
+			ip := net.ParseIP(*v)
+			if ip != nil {
+				if ip.To4() == nil {
+					return nil
+				} else {
+					return fmt.Errorf("got IPv4 address, IPv6 expected")
+				}
+			}
+		}
+		return fmt.Errorf("unable to parse an IPv6 address or CIDR from: %s", v)
+	default:
+		return fmt.Errorf("IsValidIPv6CIDROrAddress validation failure: unknown type %T", value)
+	}
+	return errors.New("must be a valid IPv6 address or CIDR")
+}
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json
index 870021a..20c38dc 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -660,7 +660,7 @@
             "domainName": "ga.atlanta.kabletown.net",
             "guid": null,
             "hostName": "atlanta-edge-01",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
@@ -692,7 +692,7 @@
             "domainName": "kabletown.net",
             "guid": null,
             "hostName": "influxdb02",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
@@ -724,7 +724,7 @@
             "domainName": "ga.atlanta.kabletown.net",
             "guid": null,
             "hostName": "atlanta-router-01",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
@@ -756,7 +756,7 @@
             "domainName": "ga.atlanta.kabletown.net",
             "guid": null,
             "hostName": "atlanta-edge-03",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
@@ -788,7 +788,7 @@
             "domainName": "ga.atlanta.kabletown.net",
             "guid": null,
             "hostName": "atlanta-edge-14",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
@@ -820,7 +820,7 @@
             "domainName": "ga.atlanta.kabletown.net",
             "guid": null,
             "hostName": "atlanta-edge-15",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
@@ -852,7 +852,7 @@
             "domainName": "ga.atlanta.kabletown.net",
             "guid": null,
             "hostName": "atlanta-mid-16",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
@@ -884,7 +884,7 @@
             "domainName": "ga.atlanta.kabletown.net",
             "guid": null,
             "hostName": "atlanta-org-1",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
@@ -916,7 +916,7 @@
             "domainName": "ga.atlanta.kabletown.net",
             "guid": null,
             "hostName": "atlanta-org-2",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
@@ -948,7 +948,7 @@
             "domainName": "ga.atlanta.kabletown.net",
             "guid": null,
             "hostName": "atlanta-mid-01",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
@@ -980,7 +980,7 @@
             "domainName": "kabletown.net",
             "guid": null,
             "hostName": "rascal01",
-            "httpsPort": null,
+            "httpsPort": 443,
             "iloIpAddress": "",
             "iloIpGateway": "",
             "iloIpNetmask": "",
diff --git a/traffic_ops/traffic_ops_golang/server/servers.go b/traffic_ops/traffic_ops_golang/server/servers.go
index 34361c5..89577f1 100644
--- a/traffic_ops/traffic_ops_golang/server/servers.go
+++ b/traffic_ops/traffic_ops_golang/server/servers.go
@@ -100,7 +100,7 @@ func (server *TOServer) Validate() error {
 		"ipAddress":      validation.Validate(server.IPAddress, validation.NotNil, is.IPv4),
 		"ipNetmask":      validation.Validate(server.IPNetmask, validation.NotNil),
 		"ipGateway":      validation.Validate(server.IPGateway, validation.NotNil),
-		"ip6Address":     validation.Validate(server.IP6Address, is.IPv6),
+		"ip6Address":     validation.Validate(server.IP6Address, validation.By(tovalidate.IsValidIPv6CIDROrAddress)),
 		"physLocationId": validation.Validate(server.PhysLocationID, validation.NotNil),
 		"profileId":      validation.Validate(server.ProfileID, validation.NotNil),
 		"statusId":       validation.Validate(server.StatusID, validation.NotNil),


Mime
View raw message