You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2018/06/25 18:19:54 UTC

[trafficcontrol] branch master updated (860e9a9 -> e8463e8)

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

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


    from 860e9a9  Fix TM to warn not err on matchset without regex
     new 1ad2f16  Fix delivery service validation
     new e8463e8  Fix DSR API tests that are requesting an invalid DS type

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 lib/go-tc/deliveryservices.go                      | 34 ++++++++++++++++------
 lib/go-tc/tovalidate/rules.go                      | 18 ++++++++++++
 .../api/v13/deliveryservice_requests_test.go       |  6 ++--
 traffic_ops/testing/api/v13/tc-fixtures.json       |  4 +++
 4 files changed, 50 insertions(+), 12 deletions(-)


[trafficcontrol] 02/02: Fix DSR API tests that are requesting an invalid DS type

Posted by de...@apache.org.
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

commit e8463e8d695265041b163f461e75c27f9ecf5e22
Author: Rawlin Peters <ra...@comcast.com>
AuthorDate: Mon Jun 25 11:56:29 2018 -0600

    Fix DSR API tests that are requesting an invalid DS type
---
 traffic_ops/testing/api/v13/deliveryservice_requests_test.go | 6 +++---
 traffic_ops/testing/api/v13/tc-fixtures.json                 | 4 ++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/traffic_ops/testing/api/v13/deliveryservice_requests_test.go b/traffic_ops/testing/api/v13/deliveryservice_requests_test.go
index 6f83fb1..6d974ae 100644
--- a/traffic_ops/testing/api/v13/deliveryservice_requests_test.go
+++ b/traffic_ops/testing/api/v13/deliveryservice_requests_test.go
@@ -56,10 +56,10 @@ func CreateTestDeliveryServiceRequests(t *testing.T) {
 	respCDN := resp[0]
 
 	// Attach Type
-	typ := testData.Types[19]
-	respTypes, _, err := TOSession.GetTypeByName(typ.Name)
+	typ := testData.DeliveryServiceRequests[dsrGood].DeliveryService.Type.String()
+	respTypes, _, err := TOSession.GetTypeByName(typ)
 	if err != nil {
-		t.Errorf("cannot GET Type by name: %v - %v\n", typ.Name, err)
+		t.Errorf("cannot GET Type by name: %v - %v\n", typ, err)
 	}
 	respTyp := respTypes[0]
 
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json
index 6ce32b1..c41eb8b 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -103,6 +103,7 @@
                 "regionalGeoBlocking": true,
                 "routingName": "goodroute",
                 "tenantId": 2,
+                "type": "HTTP",
                 "xmlId": "test-ds1"
             },
             "status": "draft"
@@ -122,6 +123,7 @@
                 "longDesc": "long desc",
                 "regionalGeoBlocking": false,
                 "tenantId": 1,
+                "type": "HTTP",
                 "xmlId": "test-ds1"
             },
             "status": "draft"
@@ -143,6 +145,7 @@
                 "regionalGeoBlocking": true,
                 "routingName": "x routing",
                 "tenantId": 2,
+                "type": "HTTP",
                 "xmlId": "test ds1"
             },
             "status": "draft"
@@ -163,6 +166,7 @@
                 "regionalGeoBlocking": true,
                 "routingName": "goodroute",
                 "tenantId": 2,
+                "type": "HTTP",
                 "xmlId": "test-transitions"
             },
             "status": "draft"


[trafficcontrol] 01/02: Fix delivery service validation

Posted by de...@apache.org.
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

commit 1ad2f1627aaa50a1fdeffecece96de9e9b0d33f3
Author: Rawlin Peters <ra...@comcast.com>
AuthorDate: Thu Jun 21 15:37:16 2018 -0600

    Fix delivery service validation
    
    Add the rest of the validation done by the Perl API that the Go API is
    missing.
    
    Fixes #2373
---
 lib/go-tc/deliveryservices.go | 34 +++++++++++++++++++++++++---------
 lib/go-tc/tovalidate/rules.go | 18 ++++++++++++++++++
 2 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/lib/go-tc/deliveryservices.go b/lib/go-tc/deliveryservices.go
index 354b76d..9f8f56e 100644
--- a/lib/go-tc/deliveryservices.go
+++ b/lib/go-tc/deliveryservices.go
@@ -241,15 +241,21 @@ func (ds *DeliveryServiceNullableV12) Sanitize() {
 	}
 }
 
-func getTypeName(tx *sql.Tx, id int) (string, bool, error) {
+// getTypeData returns the type's name and use_in_table, true/false if the query returned data, and any error
+func getTypeData(tx *sql.Tx, id int) (string, string, bool, error) {
 	name := ""
-	if err := tx.QueryRow(`SELECT name from type where id=$1`, id).Scan(&name); err != nil {
+	var useInTablePtr *string
+	if err := tx.QueryRow(`SELECT name, use_in_table from type where id=$1`, id).Scan(&name, &useInTablePtr); err != nil {
 		if err == sql.ErrNoRows {
-			return "", false, nil
+			return "", "", false, nil
 		}
-		return "", false, errors.New("querying type name: " + err.Error())
+		return "", "", false, errors.New("querying type data: " + err.Error())
 	}
-	return name, true, nil
+	useInTable := ""
+	if useInTablePtr != nil {
+		useInTable = *useInTablePtr
+	}
+	return name, useInTable, true, nil
 }
 
 func requiredIfMatchesTypeName(patterns []string, typeName string) func(interface{}) error {
@@ -296,25 +302,35 @@ func (ds *DeliveryServiceNullableV12) validateTypeFields(tx *sql.Tx) error {
 	DNSRegexType := "^DNS.*$"
 	HTTPRegexType := "^HTTP.*$"
 	SteeringRegexType := "^STEERING.*$"
+	latitudeErr := "Must be a floating point number within the range +-90"
+	longitudeErr := "Must be a floating point number within the range +-180"
 	if ds.TypeID == nil {
 		return errors.New("missing type")
 	}
-	typeName, ok, err := getTypeName(tx, *ds.TypeID)
+	typeName, useInTable, ok, err := getTypeData(tx, *ds.TypeID)
 	if err != nil {
 		return errors.New("getting type name: " + err.Error())
 	}
 	if !ok {
 		return errors.New("type not found")
 	}
+	if useInTable != "deliveryservice" {
+		return errors.New("type is not a valid deliveryservice type")
+	}
 	errs := validation.Errors{
 		"initialDispersion": validation.Validate(ds.InitialDispersion,
-			validation.By(requiredIfMatchesTypeName([]string{HTTPRegexType}, typeName))),
+			validation.By(requiredIfMatchesTypeName([]string{HTTPRegexType}, typeName)),
+			validation.By(tovalidate.IsGreaterThanZero)),
 		"ipv6RoutingEnabled": validation.Validate(ds.IPV6RoutingEnabled,
 			validation.By(requiredIfMatchesTypeName([]string{SteeringRegexType, DNSRegexType, HTTPRegexType}, typeName))),
 		"missLat": validation.Validate(ds.MissLat,
-			validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName))),
+			validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName)),
+			validation.Min(-90.0).Error(latitudeErr),
+			validation.Max(90.0).Error(latitudeErr)),
 		"missLong": validation.Validate(ds.MissLong,
-			validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName))),
+			validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName)),
+			validation.Min(-180.0).Error(longitudeErr),
+			validation.Max(180.0).Error(longitudeErr)),
 		"multiSiteOrigin": validation.Validate(ds.MultiSiteOrigin,
 			validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, typeName))),
 		"orgServerFqdn": validation.Validate(ds.OrgServerFQDN,
diff --git a/lib/go-tc/tovalidate/rules.go b/lib/go-tc/tovalidate/rules.go
index aeb1b9b..1e86407 100644
--- a/lib/go-tc/tovalidate/rules.go
+++ b/lib/go-tc/tovalidate/rules.go
@@ -13,6 +13,8 @@
 package tovalidate
 
 import (
+	"errors"
+	"fmt"
 	"strings"
 )
 
@@ -46,3 +48,19 @@ func IsOneOfStringICase(set ...string) func(string) bool {
 	}
 	return IsOneOfString(lowcased...)
 }
+
+func IsGreaterThanZero(value interface{}) error {
+	switch v := value.(type) {
+	case *int:
+		if v == nil || *v > 0 {
+			return nil
+		}
+	case *float64:
+		if v == nil || *v > 0 {
+			return nil
+		}
+	default:
+		return fmt.Errorf("IsGreaterThanZero validation failure: unknown type %T", value)
+	}
+	return errors.New("must be greater than zero")
+}