test: ensure ipv6 compatability (#5110)

This commit is contained in:
Damian Debkowski authored and GitHub committed 2024-09-20 11:30:27 -07:00
1 parent eb33649ded
commit 29efd5e6c6
5 files changed
+314 -10

No files matched your search

+12
View File
@@ -14,6 +14,7 @@ import (
"os"
"os/signal"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
@@ -57,6 +58,12 @@ const (
WorkerAuthReqFile = "auth_request_token"
)
var (
// This regular expression is used to find all instances of square brackets within a string.
// This regular expression is used to remove the square brackets from an IPv6 address.
squareBrackets = regexp.MustCompile("\\[|\\]")
)
func init() {
metric.InitializeBuildInfo(prometheus.DefaultRegisterer)
}
@@ -845,7 +852,12 @@ func (b *Server) SetupWorkerPublicAddress(conf *config.Config, flagValue string)
return fmt.Errorf("Error splitting public adddress host/port: %w", err)
}
}
// remove the square brackets from the ipv6 address because the method
// net.JoinHostPort() will add a second pair of square brackets.
host = squareBrackets.ReplaceAllString(host, "")
conf.Worker.PublicAddr = net.JoinHostPort(host, port)
return nil
}