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

srijeet0406 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 86a24aeb08 [RFC3339] Using the correct function to check if existing 
asn was modified. (#7616)
86a24aeb08 is described below

commit 86a24aeb0833a5ea308b0372438ca469e95db7b7
Author: Rima Shah <[email protected]>
AuthorDate: Wed Jul 5 14:37:41 2023 -0600

    [RFC3339] Using the correct function to check if existing asn was modified. 
(#7616)
    
    * using the correct function to check if existing asn was modified.
    
    * Added IfUnmodifiedSince test case
---
 traffic_ops/testing/api/v5/asns_test.go    | 29 ++++++++++++++++++++++-------
 traffic_ops/traffic_ops_golang/asn/asns.go |  6 +++---
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/traffic_ops/testing/api/v5/asns_test.go 
b/traffic_ops/testing/api/v5/asns_test.go
index 0a531a0c54..91e88598ca 100644
--- a/traffic_ops/testing/api/v5/asns_test.go
+++ b/traffic_ops/testing/api/v5/asns_test.go
@@ -35,26 +35,30 @@ import (
 func TestASN(t *testing.T) {
        WithObjs(t, []TCObj{Types, CacheGroups, ASN}, func() {
                tomorrow := time.Now().AddDate(0, 0, 1).Format(time.RFC1123)
-               currentTime := time.Now().UTC().Add(-5 * time.Second)
+               currentTime := time.Now().UTC().Add(-15 * time.Second)
                currentTimeRFC := currentTime.Format(time.RFC1123)
 
                methodTests := utils.V5TestCase{
                        "GET": {
                                "NOT MODIFIED when NO CHANGES made": {
-                                       ClientSession: TOSession, RequestOpts: 
client.RequestOptions{Header: http.Header{rfc.IfModifiedSince: {tomorrow}}},
-                                       Expectations: 
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
+                                       ClientSession: TOSession,
+                                       RequestOpts:   
client.RequestOptions{Header: http.Header{rfc.IfModifiedSince: {tomorrow}}},
+                                       Expectations:  
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
                                },
                                "OK when VALID request": {
-                                       ClientSession: TOSession, Expectations: 
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), 
validateSorted()),
+                                       ClientSession: TOSession,
+                                       Expectations:  
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), 
validateSorted()),
                                },
                                "OK when VALID ASN PARAMETER": {
-                                       ClientSession: TOSession, RequestOpts: 
client.RequestOptions{QueryParameters: url.Values{"asn": {"9999"}}},
-                                       Expectations: 
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), 
utils.ResponseHasLength(1)),
+                                       ClientSession: TOSession,
+                                       RequestOpts:   
client.RequestOptions{QueryParameters: url.Values{"asn": {"9999"}}},
+                                       Expectations:  
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), 
utils.ResponseHasLength(1)),
                                },
                        },
                        "PUT": {
                                "OK when VALID request": {
-                                       ClientSession: TOSession, EndpointID: 
GetASNId(t, "8888"),
+                                       ClientSession: TOSession,
+                                       EndpointID:    GetASNId(t, "8888"),
                                        RequestBody: map[string]interface{}{
                                                "asn":            7777,
                                                "cachegroupName": 
"originCachegroup",
@@ -62,6 +66,17 @@ func TestASN(t *testing.T) {
                                        },
                                        Expectations: 
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
                                },
+                               "PRECONDITION FAILED when updating with IMS & 
IUS Headers": {
+                                       ClientSession: TOSession,
+                                       EndpointID:    GetASNId(t, "7777"),
+                                       RequestOpts:   
client.RequestOptions{Header: http.Header{rfc.IfUnmodifiedSince: 
{currentTimeRFC}}},
+                                       RequestBody: map[string]interface{}{
+                                               "asn":            8888,
+                                               "cachegroupName": 
"originCachegroup",
+                                               "cachegroupId":   -1,
+                                       },
+                                       Expectations: 
utils.CkRequest(utils.HasError(), 
utils.HasStatus(http.StatusPreconditionFailed)),
+                               },
                        },
                        "GET AFTER CHANGES": {
                                "OK when CHANGES made": {
diff --git a/traffic_ops/traffic_ops_golang/asn/asns.go 
b/traffic_ops/traffic_ops_golang/asn/asns.go
index bd0ec3bf62..b313d1295b 100644
--- a/traffic_ops/traffic_ops_golang/asn/asns.go
+++ b/traffic_ops/traffic_ops_golang/asn/asns.go
@@ -317,7 +317,7 @@ func Create(w http.ResponseWriter, r *http.Request) {
 
 // Update an ASN for APIv5
 func Update(w http.ResponseWriter, r *http.Request) {
-       inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+       inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"id"}, 
[]string{"id"})
        if userErr != nil || sysErr != nil {
                api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
                return
@@ -331,9 +331,9 @@ func Update(w http.ResponseWriter, r *http.Request) {
                return
        }
 
-       requestedAsnId := inf.Params["id"]
+       requestedAsnId := inf.IntParams["id"]
        // check if the entity was already updated
-       userErr, sysErr, errCode = api.CheckIfUnModifiedByName(r.Header, 
inf.Tx, requestedAsnId, "asn")
+       userErr, sysErr, errCode = api.CheckIfUnModified(r.Header, inf.Tx, 
requestedAsnId, "asn")
        if userErr != nil || sysErr != nil {
                api.HandleErr(w, r, tx, errCode, userErr, sysErr)
                return

Reply via email to