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

ocket8888 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 7517836  Allow '0' as a valid value for TTL field in DNS static entry 
(#4955)
7517836 is described below

commit 75178363edf8762a2a73a9ea8adfe72a3ff4101f
Author: rimashah25 <[email protected]>
AuthorDate: Mon Aug 17 13:52:24 2020 -0600

    Allow '0' as a valid value for TTL field in DNS static entry (#4955)
    
    * Fixed github issue: 3400
    
    * Fixed github issue: 3400 on TP
    
    * Removed min and step condition for TTL
    
    * Fixed null-pointer error
    
    * Revert "Removed min and step condition for TTL"
    
    This reverts commit 91c430ca10d0c8438796f3c69e789fd4515c481f.
    
    * Updated TP's TTL field pattern match
---
 CHANGELOG.md                                                 |  1 +
 traffic_ops/testing/api/v2/tc-fixtures.json                  |  2 +-
 traffic_ops/testing/api/v3/tc-fixtures.json                  |  2 +-
 .../traffic_ops_golang/staticdnsentry/staticdnsentry.go      | 12 ++++++++++--
 .../form.deliveryServiceStaticDnsEntry.tpl.html              |  4 ++--
 .../end_to_end/deliveryServices/delivery-services-spec.js    |  2 +-
 6 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 78d6d1b..078a95c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - Added debugging functionality to CDN-in-a-Box for Traffic Stats.
 
 ### Fixed
+- Fixed #3400 - Allow "0" as a TTL value for Static DNS entries
 - Fixed #4743 - Validate absolute DNS name requirement on Static DNS entry for 
CNAME type [Related github 
issue](https://github.com/apache/trafficcontrol/issues/4743)
 - Fixed #4848 - `GET /api/x/cdns/capacity` gives back 500, with the message 
`capacity was zero`
 - Fixed #2156 - Renaming a host in TC, does not impact xmpp_id and thereby 
hashid [Related github 
issue](https://github.com/apache/trafficcontrol/issues/2156)
diff --git a/traffic_ops/testing/api/v2/tc-fixtures.json 
b/traffic_ops/testing/api/v2/tc-fixtures.json
index 3ed7661..a30a338 100644
--- a/traffic_ops/testing/api/v2/tc-fixtures.json
+++ b/traffic_ops/testing/api/v2/tc-fixtures.json
@@ -2160,7 +2160,7 @@
             "deliveryservice": "ds1",
             "host": "host1",
             "type": "CNAME_RECORD",
-            "ttl": 10
+            "ttl": 0
         },
         {
             "address": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
diff --git a/traffic_ops/testing/api/v3/tc-fixtures.json 
b/traffic_ops/testing/api/v3/tc-fixtures.json
index 83b7e0d..7aad2ad 100644
--- a/traffic_ops/testing/api/v3/tc-fixtures.json
+++ b/traffic_ops/testing/api/v3/tc-fixtures.json
@@ -2687,7 +2687,7 @@
             "deliveryservice": "ds1",
             "host": "host1",
             "type": "CNAME_RECORD",
-            "ttl": 10
+            "ttl": 0
         },
         {
             "address": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
diff --git a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go 
b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
index a0e0e04..643f874 100644
--- a/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
+++ b/traffic_ops/traffic_ops_golang/staticdnsentry/staticdnsentry.go
@@ -96,7 +96,7 @@ func (staticDNSEntry TOStaticDNSEntry) Validate() error {
                return err
        }
 
-       var addressErr error
+       var addressErr, ttlErr error
        switch typeStr {
        case "A_RECORD":
                addressErr = validation.Validate(staticDNSEntry.Address, 
validation.Required, is.IPv4)
@@ -115,11 +115,19 @@ func (staticDNSEntry TOStaticDNSEntry) Validate() error {
                addressErr = validation.Validate(staticDNSEntry.Address, 
validation.Required)
        }
 
+       if staticDNSEntry.TTL != nil {
+               if *staticDNSEntry.TTL == 0 {
+                       ttlErr = validation.Validate(staticDNSEntry.TTL, 
is.Digit)
+               }
+       } else {
+               ttlErr = validation.Validate(staticDNSEntry.TTL, 
validation.Required)
+       }
+
        errs := validation.Errors{
                "host":              validation.Validate(staticDNSEntry.Host, 
validation.Required, is.DNSName),
                "address":           addressErr,
                "deliveryserviceId": 
validation.Validate(staticDNSEntry.DeliveryServiceID, validation.Required),
-               "ttl":               validation.Validate(staticDNSEntry.TTL, 
validation.Required),
+               "ttl":               ttlErr,
                "typeId":            validation.Validate(staticDNSEntry.TypeID, 
validation.Required),
        }
        return util.JoinErrs(tovalidate.ToErrors(errs))
diff --git 
a/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/form.deliveryServiceStaticDnsEntry.tpl.html
 
b/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/form.deliveryServiceStaticDnsEntry.tpl.html
index aac08b2..19c4025 100644
--- 
a/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/form.deliveryServiceStaticDnsEntry.tpl.html
+++ 
b/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/form.deliveryServiceStaticDnsEntry.tpl.html
@@ -50,9 +50,9 @@ under the License.
             <div class="form-group" ng-class="{'has-error': 
hasError(dsStaticDnsEntryForm.ttl), 'has-feedback': 
hasError(dsStaticDnsEntryForm.ttl)}">
                 <label for="ttl" class="control-label col-md-2 col-sm-2 
col-xs-12">TTL *</label>
                 <div class="col-md-10 col-sm-10 col-xs-12">
-                    <input id="ttl" name="ttl" type="number" 
class="form-control" ng-model="staticDnsEntry.ttl" min="0" step="1" required>
+                    <input id="ttl" name="ttl" type="number" 
class="form-control" ng-model="staticDnsEntry.ttl" min="0" step="1" 
pattern="\d+" required>
                     <small class="input-error" 
ng-show="hasPropertyError(dsStaticDnsEntryForm.ttl, 
'required')">Required</small>
-                    <small class="input-error" 
ng-show="hasPropertyError(dsStaticDnsEntryForm.ttl, 'step') || 
hasPropertyError(dsStaticDnsEntryForm.ttl, 'min')">Whole Number</small>
+                    <small class="input-error" 
ng-show="hasPropertyError(dsStaticDnsEntryForm.ttl, 'step') || 
hasPropertyError(dsStaticDnsEntryForm.ttl, 'min') || 
hasPropertyError(dsStaticDnsEntryForm.ttl, 'pattern')">Whole Number</small>
                     <span ng-show="hasError(dsStaticDnsEntryForm.ttl)" 
class="form-control-feedback"><i class="fa fa-times"></i></span>
                 </div>
             </div>
diff --git 
a/traffic_portal/test/end_to_end/deliveryServices/delivery-services-spec.js 
b/traffic_portal/test/end_to_end/deliveryServices/delivery-services-spec.js
index 90ffb25..54d0f5d 100644
--- a/traffic_portal/test/end_to_end/deliveryServices/delivery-services-spec.js
+++ b/traffic_portal/test/end_to_end/deliveryServices/delivery-services-spec.js
@@ -52,7 +52,7 @@ describe('Traffic Portal Delivery Services Suite', function() 
{
                steeringXmlId: "http-xml-id-" + 
commonFunctions.shuffle('abcdefghijklmonpqrstuvwxyz'),
                longDesc: "This is only a test delivery service that should be 
disposed of by Automated UI Testing.",
                staticDNShostName: "static-dns-xml-id-" + 
commonFunctions.shuffle('abcdefghijklmonpqrstuvwxyz'),
-               staticDNSTTL: 50,
+               staticDNSTTL: 0,
                staticDNSAddress: "cdn.test.com."
 
        };

Reply via email to