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

rawlin 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 c9ea091  Dont allow blank hostName/domainName on servers (#5114)
c9ea091 is described below

commit c9ea0910ec7739965aeeb3cd246d18d8098930ec
Author: Steve Hamrick <[email protected]>
AuthorDate: Wed Oct 7 09:22:59 2020 -0600

    Dont allow blank hostName/domainName on servers (#5114)
    
    * Dont allow blank host/domain
    
    * Better error message
---
 traffic_ops/testing/api/v3/servers_test.go       | 25 ++++++++++++++++++++++++
 traffic_ops/traffic_ops_golang/server/servers.go |  4 ++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/traffic_ops/testing/api/v3/servers_test.go 
b/traffic_ops/testing/api/v3/servers_test.go
index 9d68c6e..09e6774 100644
--- a/traffic_ops/testing/api/v3/servers_test.go
+++ b/traffic_ops/testing/api/v3/servers_test.go
@@ -41,6 +41,7 @@ func TestServers(t *testing.T) {
                GetTestServers(t)
                GetTestServersIMSAfterChange(t, header)
                GetTestServersQueryParameters(t)
+               CreateTestBlankFields(t)
                CreateTestServerWithoutProfileId(t)
                UniqueIPProfileTestServers(t)
                UpdateTestServerStatus(t)
@@ -249,6 +250,30 @@ func CreateTestServers(t *testing.T) {
        }
 }
 
+func CreateTestBlankFields(t *testing.T) {
+       serverResp, _, err := TOSession.GetServersWithHdr(nil, nil)
+       if err != nil {
+               t.Fatalf("couldnt get servers: %v", err)
+       }
+       if len(serverResp.Response) < 1 {
+               t.Fatal("expected at least one server")
+       }
+       server := serverResp.Response[0]
+       originalHost := server.HostName
+
+       server.HostName = util.StrPtr("")
+       _, _, err = TOSession.UpdateServerByID(*server.ID, server)
+       if err == nil {
+               t.Fatal("should not be able to update server with blank 
HostName")
+       }
+
+       server.HostName = originalHost
+       server.DomainName = util.StrPtr("")
+       _, _, err = TOSession.UpdateServerByID(*server.ID, server)
+       if err == nil {
+               t.Fatal("should not be able to update server with blank 
DomainName")
+       }
+}
 func CreateTestServerWithoutProfileId(t *testing.T) {
        params := url.Values{}
        servers := testData.Servers[19]
diff --git a/traffic_ops/traffic_ops_golang/server/servers.go 
b/traffic_ops/traffic_ops_golang/server/servers.go
index fa239ab..86aab8d 100644
--- a/traffic_ops/traffic_ops_golang/server/servers.go
+++ b/traffic_ops/traffic_ops_golang/server/servers.go
@@ -403,8 +403,8 @@ func validateCommon(s *tc.CommonServerProperties, tx 
*sql.Tx) []error {
        errs := tovalidate.ToErrors(validation.Errors{
                "cachegroupId":   validation.Validate(s.CachegroupID, 
validation.NotNil),
                "cdnId":          validation.Validate(s.CDNID, 
validation.NotNil),
-               "domainName":     validation.Validate(s.DomainName, 
validation.NotNil, noSpaces),
-               "hostName":       validation.Validate(s.HostName, 
validation.NotNil, noSpaces),
+               "domainName":     validation.Validate(s.DomainName, 
validation.Required, noSpaces),
+               "hostName":       validation.Validate(s.HostName, 
validation.Required, noSpaces),
                "physLocationId": validation.Validate(s.PhysLocationID, 
validation.NotNil),
                "profileId":      validation.Validate(s.ProfileID, 
validation.NotNil),
                "statusId":       validation.Validate(s.StatusID, 
validation.NotNil),

Reply via email to