You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2018/08/13 17:11:28 UTC

[trafficcontrol] 09/12: added negative test cases for SDE address types

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

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

commit f81811e8e2e5da30ab385ee0607d822eeacc741d
Author: Jesse Rivas <je...@comcast.com>
AuthorDate: Tue Aug 7 11:05:31 2018 -0600

    added negative test cases for SDE address types
---
 traffic_ops/client/v13/staticdnsentry.go           | 20 +++---
 .../testing/api/v13/staticdnsentries_test.go       | 72 +++++++++++++++++++++-
 2 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/traffic_ops/client/v13/staticdnsentry.go b/traffic_ops/client/v13/staticdnsentry.go
index 15e1a42..94e927c 100644
--- a/traffic_ops/client/v13/staticdnsentry.go
+++ b/traffic_ops/client/v13/staticdnsentry.go
@@ -49,23 +49,25 @@ func (to *Session) CreateStaticDNSEntry(cdn v13.StaticDNSEntry) (tc.Alerts, ReqI
 }
 
 // Update a StaticDNSEntry by ID
-func (to *Session) UpdateStaticDNSEntryByID(id int, cdn v13.StaticDNSEntry) (tc.Alerts, ReqInf, error) {
+func (to *Session) UpdateStaticDNSEntryByID(id int, cdn v13.StaticDNSEntry) (tc.Alerts, ReqInf, int, error) {
 
 	var remoteAddr net.Addr
 	reqBody, err := json.Marshal(cdn)
 	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
 	if err != nil {
-		return tc.Alerts{}, reqInf, err
+		return tc.Alerts{}, reqInf, 0, err
 	}
 	route := fmt.Sprintf("%s?id=%d", API_v13_StaticDNSEntries, id)
-	resp, remoteAddr, err := to.request(http.MethodPut, route, reqBody)
-	if err != nil {
-		return tc.Alerts{}, reqInf, err
+	resp, remoteAddr, errClient := to.rawRequest(http.MethodPut, route, reqBody)
+	if resp != nil {
+		defer resp.Body.Close()
+		var alerts tc.Alerts
+		if err = json.NewDecoder(resp.Body).Decode(&alerts); err != nil {
+			return alerts, reqInf, resp.StatusCode, err
+		}
+		return alerts, reqInf, resp.StatusCode, errClient
 	}
-	defer resp.Body.Close()
-	var alerts tc.Alerts
-	err = json.NewDecoder(resp.Body).Decode(&alerts)
-	return alerts, reqInf, nil
+	return tc.Alerts{}, reqInf, 0, errClient
 }
 
 // Returns a list of StaticDNSEntrys
diff --git a/traffic_ops/testing/api/v13/staticdnsentries_test.go b/traffic_ops/testing/api/v13/staticdnsentries_test.go
index 3ca74cb..db8948c 100644
--- a/traffic_ops/testing/api/v13/staticdnsentries_test.go
+++ b/traffic_ops/testing/api/v13/staticdnsentries_test.go
@@ -20,6 +20,7 @@ import (
 
 	"github.com/apache/trafficcontrol/lib/go-log"
 	tc "github.com/apache/trafficcontrol/lib/go-tc"
+	"reflect"
 )
 
 func TestStaticDNSEntries(t *testing.T) {
@@ -37,6 +38,7 @@ func TestStaticDNSEntries(t *testing.T) {
 	CreateTestStaticDNSEntries(t)
 	GetTestStaticDNSEntries(t)
 	UpdateTestStaticDNSEntries(t)
+	UpdateTestStaticDNSEntriesInvalidAddress(t)
 	DeleteTestStaticDNSEntries(t)
 	DeleteTestDeliveryServices(t)
 	DeleteTestServers(t)
@@ -97,10 +99,12 @@ func UpdateTestStaticDNSEntries(t *testing.T) {
 		t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", firstStaticDNSEntry.Host, err)
 	}
 	remoteStaticDNSEntry := resp[0]
-	expectedAddress := "192.168.0.1"
+	expectedAddress := "192.168.0.2"
 	remoteStaticDNSEntry.Address = expectedAddress
 	var alert tc.Alerts
-	alert, _, err = TOSession.UpdateStaticDNSEntryByID(remoteStaticDNSEntry.ID, remoteStaticDNSEntry)
+	var status int
+	alert, _, status, err = TOSession.UpdateStaticDNSEntryByID(remoteStaticDNSEntry.ID, remoteStaticDNSEntry)
+	log.Debugln("Status Code: ", status)
 	if err != nil {
 		t.Errorf("cannot UPDATE StaticDNSEntries using url: %v - %v\n", err, alert)
 	}
@@ -117,6 +121,70 @@ func UpdateTestStaticDNSEntries(t *testing.T) {
 
 }
 
+func UpdateTestStaticDNSEntriesInvalidAddress(t *testing.T) {
+
+	expectedAlerts := []tc.Alerts{tc.Alerts{[]tc.Alert{tc.Alert{"'address' must be a valid IPv4 address","error"}}}, tc.Alerts{[]tc.Alert{tc.Alert{"'address' must be a valid DNS name","error"}}}, tc.Alerts{[]tc.Alert{tc.Alert{"'address' must be a valid IPv6 address","error"}}}}
+
+	// A_RECORD
+	firstStaticDNSEntry := testData.StaticDNSEntries[0]
+	// Retrieve the StaticDNSEntries by name so we can get the id for the Update
+	resp, _, err := TOSession.GetStaticDNSEntriesByHost(firstStaticDNSEntry.Host)
+	if err != nil {
+		t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", firstStaticDNSEntry.Host, err)
+	}
+	remoteStaticDNSEntry := resp[0]
+	expectedAddress := "test.testdomain.net."
+	remoteStaticDNSEntry.Address = expectedAddress
+	var alert tc.Alerts
+	var status int
+	alert, _, status, err = TOSession.UpdateStaticDNSEntryByID(remoteStaticDNSEntry.ID, remoteStaticDNSEntry)
+	log.Debugln("Status Code [expect 400]: ", status)
+	if err != nil {
+		log.Debugf("cannot UPDATE StaticDNSEntries using url: %v - %v\n", err, alert)
+	}
+	if !reflect.DeepEqual(alert, expectedAlerts[0]) {
+		t.Errorf("got alerts: %v but expected alerts: %v", alert, expectedAlerts[0])
+	}
+
+	// CNAME_RECORD
+	secondStaticDNSEntry := testData.StaticDNSEntries[1]
+	// Retrieve the StaticDNSEntries by name so we can get the id for the Update
+	resp, _, err = TOSession.GetStaticDNSEntriesByHost(secondStaticDNSEntry.Host)
+	if err != nil {
+		t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", secondStaticDNSEntry.Host, err)
+	}
+	remoteStaticDNSEntry = resp[0]
+	expectedAddress = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
+	remoteStaticDNSEntry.Address = expectedAddress
+	alert, _, status, err = TOSession.UpdateStaticDNSEntryByID(remoteStaticDNSEntry.ID, remoteStaticDNSEntry)
+	log.Debugln("Status Code [expect 400]: ", status)
+	if err != nil {
+		log.Debugf("cannot UPDATE StaticDNSEntries using url: %v - %v\n", err, alert)
+	}
+	if !reflect.DeepEqual(alert, expectedAlerts[1]) {
+		t.Errorf("got alerts: %v but expected alerts: %v", alert, expectedAlerts[1])
+	}
+
+	// AAAA_RECORD
+	thirdStaticDNSEntry := testData.StaticDNSEntries[2]
+	// Retrieve the StaticDNSEntries by name so we can get the id for the Update
+	resp, _, err = TOSession.GetStaticDNSEntriesByHost(thirdStaticDNSEntry.Host)
+	if err != nil {
+		t.Errorf("cannot GET StaticDNSEntries by name: '%s', %v\n", thirdStaticDNSEntry.Host, err)
+	}
+	remoteStaticDNSEntry = resp[0]
+	expectedAddress = "192.168.0.1"
+	remoteStaticDNSEntry.Address = expectedAddress
+	alert, _, status, err = TOSession.UpdateStaticDNSEntryByID(remoteStaticDNSEntry.ID, remoteStaticDNSEntry)
+	log.Debugln("Status Code [expect 400]: ", status)
+	if err != nil {
+		log.Debugf("cannot UPDATE StaticDNSEntries using url: %v - %v\n", err, alert)
+	}
+	if !reflect.DeepEqual(alert, expectedAlerts[2]) {
+		t.Errorf("got alerts: %v but expected alerts: %v", alert, expectedAlerts[2])
+	}
+}
+
 func GetTestStaticDNSEntries(t *testing.T) {
 
 	for _, staticDNSEntry := range testData.StaticDNSEntries {