You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/07/24 16:53:43 UTC

[trafficcontrol] 02/04: added validation rules for the address field

This is an automated email from the ASF dual-hosted git repository.

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

commit b65943460439da16705b53a8f6b5564817630dcb
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Mon Jul 23 14:28:09 2018 -0600

    added validation rules for the address field
---
 traffic_ops/testing/api/v13/staticdnsentries_test.go       |  2 +-
 traffic_ops/testing/api/v13/tc-fixtures.json               | 14 +++++++-------
 .../traffic_ops_golang/staticdnsentry/staticdnsentry.go    |  3 ++-
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/traffic_ops/testing/api/v13/staticdnsentries_test.go b/traffic_ops/testing/api/v13/staticdnsentries_test.go
index ca21937..3ca74cb 100644
--- a/traffic_ops/testing/api/v13/staticdnsentries_test.go
+++ b/traffic_ops/testing/api/v13/staticdnsentries_test.go
@@ -97,7 +97,7 @@ func UpdateTestStaticDNSEntries(t *testing.T) {
 		t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", firstStaticDNSEntry.Host, err)
 	}
 	remoteStaticDNSEntry := resp[0]
-	expectedAddress := "address2"
+	expectedAddress := "192.168.0.1"
 	remoteStaticDNSEntry.Address = expectedAddress
 	var alert tc.Alerts
 	alert, _, err = TOSession.UpdateStaticDNSEntryByID(remoteStaticDNSEntry.ID, remoteStaticDNSEntry)
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json
index e6b7c37..256b9bd 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -1024,7 +1024,7 @@
     ],
     "staticdnsentries": [
         {
-            "address": "address1",
+            "address": "192.168.0.1",
             "cachegroup": "cachegroup1",
             "deliveryservice": "ds1",
             "host": "host1",
@@ -1032,7 +1032,7 @@
             "ttl": 10
         },
         {
-            "address": "address2",
+            "address": "192.168.0.1",
             "cachegroup": "cachegroup2",
             "deliveryservice": "ds1",
             "host": "host2",
@@ -1040,12 +1040,12 @@
             "ttl": 10
         },
         {
-            "host": "host3",
-            "deliveryservice": "ds1",
+            "address": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
             "cachegroup": "cachegroup2",
-            "address": "127.0.0.1",
-            "type": "CNAME_RECORD",
-            "ttl": 10
+            "deliveryservice": "ds1",
+            "host": "host3",
+            "ttl": 10,
+            "type": "CNAME_RECORD"
         }
     ],
     "statuses": [
diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
index 0e162b2..7006b99 100644
--- a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
@@ -32,6 +32,7 @@ import (
 	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
 	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
 	validation "github.com/go-ozzo/ozzo-validation"
+	"github.com/go-ozzo/ozzo-validation/is"
 	"github.com/lib/pq"
 )
 
@@ -82,7 +83,7 @@ func (staticDNSEntry *TOStaticDNSEntry) SetKeys(keys map[string]interface{}) {
 func (staticDNSEntry TOStaticDNSEntry) Validate() error {
 	errs := validation.Errors{
 		"host":    validation.Validate(staticDNSEntry.Host, validation.Required),
-		"address": validation.Validate(staticDNSEntry.Address, validation.Required),
+		"address": validation.Validate(staticDNSEntry.Address, validation.Required, is.IP),
 		"dsname":  validation.Validate(staticDNSEntry.DeliveryService, validation.Required),
 		"ttl":     validation.Validate(staticDNSEntry.TTL, validation.Required),
 		"type":    validation.Validate(staticDNSEntry.Type, validation.Required),