You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/09/07 15:49:21 UTC

[GitHub] dewrich closed pull request #2792: validate that a servers ip6address field is an IPv6 address or CIDR

dewrich closed pull request #2792: validate that a servers ip6address field is an IPv6 address or CIDR
URL: https://github.com/apache/trafficcontrol/pull/2792
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lib/go-tc/tovalidate/rules.go b/lib/go-tc/tovalidate/rules.go
index f7ba82e8c..3ea3ae17d 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 870021a08..20c38dcf9 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 34361c5c9..89577f1b4 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),


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services