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


The following commit(s) were added to refs/heads/master by this push:
     new a91f7b2  Add t3c dns_local not inserting if it exists (#6047)
a91f7b2 is described below

commit a91f7b2bcfc3fbd5c4c40bdb3df426d3096c85e2
Author: Robert O Butts <[email protected]>
AuthorDate: Wed Aug 4 16:55:10 2021 -0600

    Add t3c dns_local not inserting if it exists (#6047)
---
 lib/go-atscfg/recordsdotconfig.go      |   5 ++
 lib/go-atscfg/recordsdotconfig_test.go | 131 +++++++++++++++++++++++++++++++++
 2 files changed, 136 insertions(+)

diff --git a/lib/go-atscfg/recordsdotconfig.go 
b/lib/go-atscfg/recordsdotconfig.go
index 6b75d43..6b336a9 100644
--- a/lib/go-atscfg/recordsdotconfig.go
+++ b/lib/go-atscfg/recordsdotconfig.go
@@ -179,14 +179,19 @@ func addRecordsDotConfigDNSLocal(txt string, server 
*Server) (string, []string)
        const dnsLocalV6 = `proxy.config.dns.local_ipv6`
 
        v4, v6 := getServiceAddresses(server)
+
        if v4 == nil {
                warnings = append(warnings, "server had no IPv4 Service 
Address, not setting records.config dns v4 local bind addr!")
+       } else if strings.Contains(txt, dnsLocalV4) {
+               warnings = append(warnings, "dns local option was set, but 
proxy.config.dns.local_ipv4 was already in records.config, not overriding! 
Check the server's Parameters.")
        } else {
                txt += `CONFIG ` + dnsLocalV4 + ` STRING ` + v4.String() + "\n"
        }
 
        if v6 == nil {
                warnings = append(warnings, "server had no IPv6 Service 
Address, not setting records.config dns v6 local bind addr!")
+       } else if strings.Contains(txt, dnsLocalV6) {
+               warnings = append(warnings, "dns local option was set, but 
proxy.config.dns.local_ipv6 was already in records.config, not overriding! 
Check the server's Parameters!")
        } else {
                txt += `CONFIG ` + dnsLocalV6 + ` STRING [` + v6.String() + `]` 
+ "\n"
        }
diff --git a/lib/go-atscfg/recordsdotconfig_test.go 
b/lib/go-atscfg/recordsdotconfig_test.go
index 95f5106..aaad2ab 100644
--- a/lib/go-atscfg/recordsdotconfig_test.go
+++ b/lib/go-atscfg/recordsdotconfig_test.go
@@ -164,3 +164,134 @@ STRING __FULL_HOSTNAME__
                }
        }
 }
+
+func TestMakeRecordsDotConfigDNSLocalBindNoOverrideV4(t *testing.T) {
+       profileName := "myProfile"
+       hdr := "myHeaderComment"
+
+       paramData := makeParamsFromMap("serverProfile", RecordsFileName, 
map[string]string{
+               "CONFIG proxy.config.dns.local_ipv4": "STRING 1.2.3.4",
+               "param1":                             "val1",
+               "param2":                             "val2",
+               "test-hostname-replacement":          "fooSTRING __HOSTNAME__",
+       })
+
+       server := makeTestRemapServer()
+       server.Interfaces = nil
+       ipStr := "192.163.2.99"
+       ipCIDR := ipStr + "/30" // set the ip to a cidr, to make sure addr 
logic removes it
+       setIP(server, ipCIDR)
+       ip6Str := "2001:db8::9"
+       ip6CIDR := ip6Str + "/48" // set the ip to a cidr, to make sure addr 
logic removes it
+       setIP6(server, ip6CIDR)
+       server.Profile = util.StrPtr(profileName)
+       opt := RecordsConfigOpts{}
+       opt.DNSLocalBindServiceAddr = true
+       cfg, err := MakeRecordsDotConfig(server, paramData, hdr, opt)
+       if err != nil {
+               t.Fatal(err)
+       }
+       txt := cfg.Text
+
+       testComment(t, txt, hdr)
+
+       if strings.Contains(txt, "CONFIG proxy.config.dns.local_ipv4 STRING 
"+ipStr) {
+               t.Errorf("expected config to not contain dns.local_ipv4 from 
server when Parameter exists, actual: '%v'", txt)
+       }
+       if !strings.Contains(txt, "CONFIG proxy.config.dns.local_ipv4 STRING 
"+"1.2.3.4") {
+               t.Errorf("expected config to contain dns.local_ipv4 Parameter 
when it exists, actual: '%v'", txt)
+       }
+
+       if !strings.Contains(txt, "CONFIG proxy.config.dns.local_ipv6 STRING 
["+ip6Str+"]") {
+               t.Errorf("expected config to contain dns.local_ipv6 from 
server, actual: '%v'", txt)
+       }
+}
+
+func TestMakeRecordsDotConfigDNSLocalBindNoOverrideV6(t *testing.T) {
+       profileName := "myProfile"
+       hdr := "myHeaderComment"
+
+       paramData := makeParamsFromMap("serverProfile", RecordsFileName, 
map[string]string{
+               "CONFIG proxy.config.dns.local_ipv6": "STRING 2001:db8::11",
+               "param1":                             "val1",
+               "param2":                             "val2",
+               "test-hostname-replacement":          "fooSTRING __HOSTNAME__",
+       })
+
+       server := makeTestRemapServer()
+       server.Interfaces = nil
+       ipStr := "192.163.2.99"
+       ipCIDR := ipStr + "/30" // set the ip to a cidr, to make sure addr 
logic removes it
+       setIP(server, ipCIDR)
+       ip6Str := "2001:db8::9"
+       ip6CIDR := ip6Str + "/48" // set the ip to a cidr, to make sure addr 
logic removes it
+       setIP6(server, ip6CIDR)
+       server.Profile = util.StrPtr(profileName)
+       opt := RecordsConfigOpts{}
+       opt.DNSLocalBindServiceAddr = true
+       cfg, err := MakeRecordsDotConfig(server, paramData, hdr, opt)
+       if err != nil {
+               t.Fatal(err)
+       }
+       txt := cfg.Text
+
+       testComment(t, txt, hdr)
+
+       if strings.Contains(txt, "CONFIG proxy.config.dns.local_ipv6 STRING 
"+ip6Str) {
+               t.Errorf("expected config to not contain dns.local_ipv6 from 
server when Parameter exists, actual: '%v'", txt)
+       }
+       if !strings.Contains(txt, "CONFIG proxy.config.dns.local_ipv6 STRING 
"+"2001:db8::11") {
+               t.Errorf("expected config to contain dns.local_ipv4 Parameter 
when it exists, actual: '%v'", txt)
+       }
+
+       if !strings.Contains(txt, "CONFIG proxy.config.dns.local_ipv4 STRING 
"+ipStr) {
+               t.Errorf("expected config to contain dns.local_ipv4 from 
server, actual: '%v'", txt)
+       }
+}
+
+func TestMakeRecordsDotConfigDNSLocalBindNoOverrideBoth(t *testing.T) {
+       profileName := "myProfile"
+       hdr := "myHeaderComment"
+
+       paramData := makeParamsFromMap("serverProfile", RecordsFileName, 
map[string]string{
+               "CONFIG proxy.config.dns.local_ipv4": "STRING 9.10.11.12",
+               "CONFIG proxy.config.dns.local_ipv6": "STRING 2001:db8::11",
+               "param1":                             "val1",
+               "param2":                             "val2",
+               "test-hostname-replacement":          "fooSTRING __HOSTNAME__",
+       })
+
+       server := makeTestRemapServer()
+       server.Interfaces = nil
+       ipStr := "192.163.2.99"
+       ipCIDR := ipStr + "/30" // set the ip to a cidr, to make sure addr 
logic removes it
+       setIP(server, ipCIDR)
+       ip6Str := "2001:db8::9"
+       ip6CIDR := ip6Str + "/48" // set the ip to a cidr, to make sure addr 
logic removes it
+       setIP6(server, ip6CIDR)
+       server.Profile = util.StrPtr(profileName)
+       opt := RecordsConfigOpts{}
+       opt.DNSLocalBindServiceAddr = true
+       cfg, err := MakeRecordsDotConfig(server, paramData, hdr, opt)
+       if err != nil {
+               t.Fatal(err)
+       }
+       txt := cfg.Text
+
+       testComment(t, txt, hdr)
+
+       if strings.Contains(txt, "CONFIG proxy.config.dns.local_ipv4 STRING 
"+ipStr) {
+               t.Errorf("expected config to not contain dns.local_ipv4 from 
server when Parameter exists, actual: '%v'", txt)
+       }
+       if !strings.Contains(txt, "CONFIG proxy.config.dns.local_ipv4 STRING 
"+"9.10.11.12") {
+               t.Errorf("expected config to contain dns.local_ipv4 Parameter 
when it exists, actual: '%v'", txt)
+       }
+
+       if strings.Contains(txt, "CONFIG proxy.config.dns.local_ipv6 STRING 
"+ip6Str) {
+               t.Errorf("expected config to not contain dns.local_ipv6 from 
server when Parameter exists, actual: '%v'", txt)
+       }
+       if !strings.Contains(txt, "CONFIG proxy.config.dns.local_ipv6 STRING 
"+"2001:db8::11") {
+               t.Errorf("expected config to contain dns.local_ipv4 Parameter 
when it exists, actual: '%v'", txt)
+       }
+
+}

Reply via email to