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

ocket8888 pushed a commit to branch 5.1.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/5.1.x by this push:
     new bebe020  Fix atscfg Service Category hdr to be internal (#5659) (#5788)
bebe020 is described below

commit bebe0208e3c3f136140afa52f76b17583893da8d
Author: Robert O Butts <[email protected]>
AuthorDate: Tue Apr 27 14:12:47 2021 -0600

    Fix atscfg Service Category hdr to be internal (#5659) (#5788)
    
    (cherry picked from commit 61e38bd21c39aa81e1b627241ef282bc287a60fc)
---
 lib/go-atscfg/remapdotconfig.go      |  10 +-
 lib/go-atscfg/remapdotconfig_test.go | 286 +++++++++++++++++++++++++++++++++++
 2 files changed, 291 insertions(+), 5 deletions(-)

diff --git a/lib/go-atscfg/remapdotconfig.go b/lib/go-atscfg/remapdotconfig.go
index 3ad3af1..333df3e 100644
--- a/lib/go-atscfg/remapdotconfig.go
+++ b/lib/go-atscfg/remapdotconfig.go
@@ -164,7 +164,7 @@ func getServerConfigRemapDotConfigForMid(
                                return "", warnings, err
                        }
                        midRemap += topoTxt
-               } else if (ds.MidHeaderRewrite != nil && *ds.MidHeaderRewrite 
!= "") || ds.MaxOriginConnections != nil || ds.ServiceCategory != nil {
+               } else if (ds.MidHeaderRewrite != nil && *ds.MidHeaderRewrite 
!= "") || (ds.MaxOriginConnections != nil && *ds.MaxOriginConnections > 0) || 
(ds.ServiceCategory != nil && *ds.ServiceCategory != "") {
                        midRemap += ` @plugin=header_rewrite.so @pparam=` + 
midHeaderRewriteConfigFileName(*ds.XMLID)
                }
 
@@ -333,7 +333,7 @@ func buildEdgeRemapLine(
                        return "", warnings, err
                }
                text += topoTxt
-       } else if (ds.EdgeHeaderRewrite != nil && *ds.EdgeHeaderRewrite != "") 
|| ds.ServiceCategory != nil || ds.MaxOriginConnections != nil {
+       } else if (ds.EdgeHeaderRewrite != nil && *ds.EdgeHeaderRewrite != "") 
|| (ds.ServiceCategory != nil && *ds.ServiceCategory != "") || 
(ds.MaxOriginConnections != nil && *ds.MaxOriginConnections != 0) {
                text += ` @plugin=header_rewrite.so @pparam=` + 
edgeHeaderRewriteConfigFileName(*ds.XMLID)
        }
 
@@ -440,13 +440,13 @@ func makeDSTopologyHeaderRewriteTxt(ds DeliveryService, 
cg tc.CacheGroupName, to
        }
        txt := ""
        const pluginTxt = ` @plugin=header_rewrite.so @pparam=`
-       if placement.IsFirstCacheTier && ((ds.FirstHeaderRewrite != nil && 
*ds.FirstHeaderRewrite != "") || ds.ServiceCategory != nil) {
+       if placement.IsFirstCacheTier && ((ds.FirstHeaderRewrite != nil && 
*ds.FirstHeaderRewrite != "") || (ds.ServiceCategory != nil && 
*ds.ServiceCategory != "")) {
                txt += pluginTxt + FirstHeaderRewriteConfigFileName(*ds.XMLID) 
+ ` `
        }
-       if placement.IsInnerCacheTier && ((ds.InnerHeaderRewrite != nil && 
*ds.InnerHeaderRewrite != "") || ds.ServiceCategory != nil) {
+       if placement.IsInnerCacheTier && ((ds.InnerHeaderRewrite != nil && 
*ds.InnerHeaderRewrite != "") || (ds.ServiceCategory != nil && 
*ds.ServiceCategory != "")) {
                txt += pluginTxt + InnerHeaderRewriteConfigFileName(*ds.XMLID) 
+ ` `
        }
-       if placement.IsLastCacheTier && ((ds.LastHeaderRewrite != nil && 
*ds.LastHeaderRewrite != "") || ds.ServiceCategory != nil || 
ds.MaxOriginConnections != nil) {
+       if placement.IsLastCacheTier && ((ds.LastHeaderRewrite != nil && 
*ds.LastHeaderRewrite != "") || (ds.ServiceCategory != nil && 
*ds.ServiceCategory != "") || (ds.MaxOriginConnections != nil && 
*ds.MaxOriginConnections != 0)) {
                txt += pluginTxt + LastHeaderRewriteConfigFileName(*ds.XMLID) + 
` `
        }
        return txt, nil
diff --git a/lib/go-atscfg/remapdotconfig_test.go 
b/lib/go-atscfg/remapdotconfig_test.go
index e054ad5..ede4d8e 100644
--- a/lib/go-atscfg/remapdotconfig_test.go
+++ b/lib/go-atscfg/remapdotconfig_test.go
@@ -8410,3 +8410,289 @@ func TestMakeRemapDotConfigMidNoNoCacheRemapLine(t 
*testing.T) {
                t.Errorf("expected remap line for HTTP_NO_CACHE to not exist on 
Mid server, regardless of Mid Header Rewrite, actual '%v'", txt)
        }
 }
+
+func TestMakeRemapDotConfigNoHeaderRewrite(t *testing.T) {
+       hdr := "myHeaderComment"
+
+       server := makeTestRemapServer()
+       server.Type = "EDGE"
+
+       ds := DeliveryService{}
+       ds.ID = util.IntPtr(48)
+       dsType := tc.DSType("DNS_LIVE")
+       ds.Type = &dsType
+       ds.OrgServerFQDN = util.StrPtr("origin.example.test")
+       ds.RangeRequestHandling = 
util.IntPtr(tc.RangeRequestHandlingCacheRangeRequest)
+       ds.RemapText = util.StrPtr("@plugin=tslua.so 
@pparam=my-range-manipulator.lua")
+       ds.SigningAlgorithm = util.StrPtr("foo")
+       ds.XMLID = util.StrPtr("mydsname")
+       ds.QStringIgnore = 
util.IntPtr(int(tc.QueryStringIgnoreIgnoreInCacheKeyAndPassUp))
+       ds.RegexRemap = util.StrPtr("")
+       ds.FQPacingRate = util.IntPtr(314159)
+       ds.DSCP = util.IntPtr(0)
+       ds.RoutingName = util.StrPtr("myroutingname")
+       ds.MultiSiteOrigin = util.BoolPtr(false)
+       ds.OriginShield = util.StrPtr("myoriginshield")
+       ds.ProfileID = util.IntPtr(49)
+       ds.ProfileName = util.StrPtr("dsprofile")
+       ds.Protocol = util.IntPtr(int(tc.DSProtocolHTTPToHTTPS))
+       ds.AnonymousBlockingEnabled = util.BoolPtr(false)
+       ds.Active = util.BoolPtr(true)
+
+       // non-nil default values should not trigger header rewrite plugin 
directive
+       ds.EdgeHeaderRewrite = util.StrPtr("")
+       ds.MidHeaderRewrite = util.StrPtr("")
+       ds.ServiceCategory = util.StrPtr("")
+       ds.MaxOriginConnections = util.IntPtr(0)
+
+       dses := []DeliveryService{ds}
+
+       dss := []tc.DeliveryServiceServer{
+               tc.DeliveryServiceServer{
+                       Server:          util.IntPtr(*server.ID),
+                       DeliveryService: util.IntPtr(*ds.ID),
+               },
+       }
+
+       dsRegexes := []tc.DeliveryServiceRegexes{
+               tc.DeliveryServiceRegexes{
+                       DSName: *ds.XMLID,
+                       Regexes: []tc.DeliveryServiceRegex{
+                               tc.DeliveryServiceRegex{
+                                       Type:      
string(tc.DSMatchTypeHostRegex),
+                                       SetNumber: 0,
+                                       Pattern:   `.*\.mypattern\..*`,
+                               },
+                       },
+               },
+       }
+
+       serverParams := []tc.Parameter{
+               tc.Parameter{
+                       Name:       "trafficserver",
+                       ConfigFile: "package",
+                       Value:      "7",
+                       Profiles:   []byte(`["global"]`),
+               },
+               tc.Parameter{
+                       Name:       "serverpkgval",
+                       ConfigFile: "package",
+                       Value:      "serverpkgval __HOSTNAME__ foo",
+                       Profiles:   []byte(*server.Profile),
+               },
+               tc.Parameter{
+                       Name:       "dscp_remap_no",
+                       ConfigFile: "package",
+                       Value:      "notused",
+                       Profiles:   []byte(*server.Profile),
+               },
+       }
+
+       cacheKeyParams := []tc.Parameter{
+               tc.Parameter{
+                       Name:       "cachekeykey",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "cachekeyval",
+                       Profiles:   []byte(`["dsprofile"]`),
+               },
+               tc.Parameter{
+                       Name:       "shouldnotexist",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "shouldnotexisteither",
+                       Profiles:   []byte(`["not-dsprofile"]`),
+               },
+               tc.Parameter{
+                       Name:       "cachekeykey",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "cachekeyval",
+                       Profiles:   []byte(`["global"]`),
+               },
+               tc.Parameter{
+                       Name:       "not_location",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "notinconfig",
+                       Profiles:   []byte(`["global"]`),
+               },
+               tc.Parameter{
+                       Name:       "not_location",
+                       ConfigFile: "cachekey.config",
+                       Value:      "notinconfig",
+                       Profiles:   []byte(`["global"]`),
+               },
+       }
+
+       cdn := &tc.CDN{
+               DomainName: "cdndomain.example",
+               Name:       "my-cdn-name",
+       }
+
+       topologies := []tc.Topology{}
+       cgs := []tc.CacheGroupNullable{}
+       serverCapabilities := map[int]map[ServerCapability]struct{}{}
+       dsRequiredCapabilities := map[int]map[ServerCapability]struct{}{}
+
+       cfg, err := MakeRemapDotConfig(server, dses, dss, dsRegexes, 
serverParams, cdn, cacheKeyParams, topologies, cgs, serverCapabilities, 
dsRequiredCapabilities, hdr)
+       if err != nil {
+               t.Fatal(err)
+       }
+       txt := cfg.Text
+
+       txt = strings.TrimSpace(txt)
+
+       testComment(t, txt, hdr)
+
+       txtLines := strings.Split(txt, "\n")
+
+       if len(txtLines) != 2 {
+               t.Fatalf("expected 1 remaps from HTTP_TO_HTTPS DS, actual: '%v' 
count %v", txt, len(txtLines))
+       }
+
+       remapLine := txtLines[1]
+
+       if strings.Contains(remapLine, "hdr_rw") {
+               t.Errorf("expected remap with default header rewrites to not 
have header rewrite directive for a file that won't exist, actual '%v'", txt)
+       }
+}
+
+func TestMakeRemapDotConfigMidNoHeaderRewrite(t *testing.T) {
+       hdr := "myHeaderComment"
+
+       server := makeTestRemapServer()
+       server.Type = "MID"
+
+       ds := DeliveryService{}
+       ds.ID = util.IntPtr(48)
+       dsType := tc.DSType("DNS")
+       ds.Type = &dsType
+       ds.OrgServerFQDN = util.StrPtr("origin.example.test")
+       ds.RangeRequestHandling = 
util.IntPtr(tc.RangeRequestHandlingCacheRangeRequest)
+       ds.RemapText = util.StrPtr("@plugin=tslua.so 
@pparam=my-range-manipulator.lua")
+       ds.SigningAlgorithm = util.StrPtr("foo")
+       ds.XMLID = util.StrPtr("mydsname")
+       ds.QStringIgnore = 
util.IntPtr(int(tc.QueryStringIgnoreIgnoreInCacheKeyAndPassUp))
+       ds.RegexRemap = util.StrPtr("")
+       ds.FQPacingRate = util.IntPtr(314159)
+       ds.DSCP = util.IntPtr(0)
+       ds.RoutingName = util.StrPtr("myroutingname")
+       ds.MultiSiteOrigin = util.BoolPtr(false)
+       ds.OriginShield = util.StrPtr("myoriginshield")
+       ds.ProfileID = util.IntPtr(49)
+       ds.ProfileName = util.StrPtr("dsprofile")
+       ds.Protocol = util.IntPtr(int(tc.DSProtocolHTTPToHTTPS))
+       ds.AnonymousBlockingEnabled = util.BoolPtr(false)
+       ds.Active = util.BoolPtr(true)
+
+       // non-nil default values should not trigger header rewrite plugin 
directive
+       ds.EdgeHeaderRewrite = util.StrPtr("")
+       ds.MidHeaderRewrite = util.StrPtr("")
+       ds.ServiceCategory = util.StrPtr("")
+       ds.MaxOriginConnections = util.IntPtr(0)
+
+       dses := []DeliveryService{ds}
+
+       dss := []tc.DeliveryServiceServer{
+               tc.DeliveryServiceServer{
+                       Server:          util.IntPtr(*server.ID),
+                       DeliveryService: util.IntPtr(*ds.ID),
+               },
+       }
+
+       dsRegexes := []tc.DeliveryServiceRegexes{
+               tc.DeliveryServiceRegexes{
+                       DSName: *ds.XMLID,
+                       Regexes: []tc.DeliveryServiceRegex{
+                               tc.DeliveryServiceRegex{
+                                       Type:      
string(tc.DSMatchTypeHostRegex),
+                                       SetNumber: 0,
+                                       Pattern:   `.*\.mypattern\..*`,
+                               },
+                       },
+               },
+       }
+
+       serverParams := []tc.Parameter{
+               tc.Parameter{
+                       Name:       "trafficserver",
+                       ConfigFile: "package",
+                       Value:      "7",
+                       Profiles:   []byte(`["global"]`),
+               },
+               tc.Parameter{
+                       Name:       "serverpkgval",
+                       ConfigFile: "package",
+                       Value:      "serverpkgval __HOSTNAME__ foo",
+                       Profiles:   []byte(*server.Profile),
+               },
+               tc.Parameter{
+                       Name:       "dscp_remap_no",
+                       ConfigFile: "package",
+                       Value:      "notused",
+                       Profiles:   []byte(*server.Profile),
+               },
+       }
+
+       cacheKeyParams := []tc.Parameter{
+               tc.Parameter{
+                       Name:       "cachekeykey",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "cachekeyval",
+                       Profiles:   []byte(`["dsprofile"]`),
+               },
+               tc.Parameter{
+                       Name:       "shouldnotexist",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "shouldnotexisteither",
+                       Profiles:   []byte(`["not-dsprofile"]`),
+               },
+               tc.Parameter{
+                       Name:       "cachekeykey",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "cachekeyval",
+                       Profiles:   []byte(`["global"]`),
+               },
+               tc.Parameter{
+                       Name:       "not_location",
+                       ConfigFile: "cacheurl.config",
+                       Value:      "notinconfig",
+                       Profiles:   []byte(`["global"]`),
+               },
+               tc.Parameter{
+                       Name:       "not_location",
+                       ConfigFile: "cachekey.config",
+                       Value:      "notinconfig",
+                       Profiles:   []byte(`["global"]`),
+               },
+       }
+
+       cdn := &tc.CDN{
+               DomainName: "cdndomain.example",
+               Name:       "my-cdn-name",
+       }
+
+       topologies := []tc.Topology{}
+       cgs := []tc.CacheGroupNullable{}
+       serverCapabilities := map[int]map[ServerCapability]struct{}{}
+       dsRequiredCapabilities := map[int]map[ServerCapability]struct{}{}
+
+       cfg, err := MakeRemapDotConfig(server, dses, dss, dsRegexes, 
serverParams, cdn, cacheKeyParams, topologies, cgs, serverCapabilities, 
dsRequiredCapabilities, hdr)
+       if err != nil {
+               t.Fatal(err)
+       }
+       txt := cfg.Text
+
+       txt = strings.TrimSpace(txt)
+
+       testComment(t, txt, hdr)
+
+       txtLines := strings.Split(txt, "\n")
+
+       if len(txtLines) != 2 {
+               t.Fatalf("expected 1 remaps from HTTP_TO_HTTPS DS, actual: '%v' 
count %v", txt, len(txtLines))
+       }
+
+       remapLine := txtLines[1]
+
+       if strings.Contains(remapLine, "hdr_rw") {
+               t.Errorf("expected remap with default header rewrites to not 
have header rewrite directive for a file that won't exist, actual '%v'", txt)
+       }
+}

Reply via email to