feat: Normalize fields across various Boundary components (#5599)
Normalizes various IP/Address/Host fields across Boundary resources/components to comply with IPv6 specifications.
This commit is contained in:
37 files changed
+1028
-348
No files matched your search
@@ -244,7 +244,7 @@ func (b *Server) CreateDevLdapAuthMethod(ctx context.Context) error {
|
||||
continue
|
||||
}
|
||||
host, _, err = util.SplitHostPort(ln.Config.Address)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrMissingPort) {
|
||||
return fmt.Errorf("error splitting host/port: %w", err)
|
||||
}
|
||||
}
|
||||
@@ -262,7 +262,7 @@ func (b *Server) CreateDevLdapAuthMethod(ctx context.Context) error {
|
||||
// added back, otherwise the gldap server will fail to start due to a parsing
|
||||
// error.
|
||||
if ip := net.ParseIP(host); ip != nil {
|
||||
if ip.To16() != nil {
|
||||
if ip.To4() == nil && ip.To16() != nil {
|
||||
host = fmt.Sprintf("[%s]", host)
|
||||
}
|
||||
}
|
||||
@@ -463,7 +463,7 @@ func (b *Server) CreateDevOidcAuthMethod(ctx context.Context) error {
|
||||
continue
|
||||
}
|
||||
b.DevOidcSetup.hostAddr, b.DevOidcSetup.callbackPort, err = util.SplitHostPort(ln.Config.Address)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrMissingPort) {
|
||||
return fmt.Errorf("error splitting host/port: %w", err)
|
||||
}
|
||||
if b.DevOidcSetup.callbackPort == "" {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/boundary/internal/util"
|
||||
"github.com/hashicorp/go-secure-stdlib/listenerutil"
|
||||
"github.com/hashicorp/go-secure-stdlib/parseutil"
|
||||
"github.com/hashicorp/go-secure-stdlib/reloadutil"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/pires/go-proxyproto"
|
||||
@@ -139,7 +140,7 @@ func tcpListenerFactory(purpose string, l *listenerutil.ListenerConfig, ui cli.U
|
||||
}
|
||||
|
||||
host, port, err := util.SplitHostPort(l.Address)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrMissingPort) {
|
||||
return "", nil, fmt.Errorf("error splitting host/port: %w", err)
|
||||
}
|
||||
if port == "" {
|
||||
@@ -173,10 +174,15 @@ func tcpListenerFactory(purpose string, l *listenerutil.ListenerConfig, ui cli.U
|
||||
}
|
||||
|
||||
if l.RandomPort {
|
||||
port = ""
|
||||
port = "0" // net.Listen will choose an available port automatically. Used for tests.
|
||||
}
|
||||
|
||||
finalListenAddr := net.JoinHostPort(host, port)
|
||||
normalizedListenAddr, err := parseutil.NormalizeAddr(finalListenAddr)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("failed to normalize final listen addr %q: %w", finalListenAddr, err)
|
||||
}
|
||||
finalListenAddr = normalizedListenAddr
|
||||
|
||||
ln, err := net.Listen(bindProto, finalListenAddr)
|
||||
if err != nil {
|
||||
|
||||
@@ -525,6 +525,35 @@ func TestSetupWorkerPublicAddress(t *testing.T) {
|
||||
expErrStr: "",
|
||||
expPublicAddress: "127.0.0.1:8080",
|
||||
},
|
||||
{
|
||||
name: "setting public address directly with invalid ipv6",
|
||||
inputConfig: &config.Config{
|
||||
SharedConfig: &configutil.SharedConfig{
|
||||
Listeners: []*listenerutil.ListenerConfig{},
|
||||
},
|
||||
Worker: &config.Worker{
|
||||
PublicAddr: "[2001:4860:4860:0:0:0:8888]",
|
||||
},
|
||||
},
|
||||
inputFlagValue: "",
|
||||
expErr: true,
|
||||
expErrStr: "Error normalizing worker address",
|
||||
},
|
||||
{
|
||||
name: "setting public address directly with ipv6 but no brackets",
|
||||
inputConfig: &config.Config{
|
||||
SharedConfig: &configutil.SharedConfig{
|
||||
Listeners: []*listenerutil.ListenerConfig{},
|
||||
},
|
||||
Worker: &config.Worker{
|
||||
PublicAddr: "2001:4860:4860:0:0:0:0:8888",
|
||||
},
|
||||
},
|
||||
inputFlagValue: "",
|
||||
expErr: false,
|
||||
expErrStr: "",
|
||||
expPublicAddress: "[2001:4860:4860::8888]:9202",
|
||||
},
|
||||
{
|
||||
name: "setting public address directly with ipv6",
|
||||
inputConfig: &config.Config{
|
||||
@@ -532,13 +561,13 @@ func TestSetupWorkerPublicAddress(t *testing.T) {
|
||||
Listeners: []*listenerutil.ListenerConfig{},
|
||||
},
|
||||
Worker: &config.Worker{
|
||||
PublicAddr: "[2001:4860:4860:0:0:0:0:8888]",
|
||||
PublicAddr: "2001:4860:4860:0:0:0:0:8888",
|
||||
},
|
||||
},
|
||||
inputFlagValue: "",
|
||||
expErr: false,
|
||||
expErrStr: "",
|
||||
expPublicAddress: "[2001:4860:4860:0:0:0:0:8888]:9202",
|
||||
expPublicAddress: "[2001:4860:4860::8888]:9202",
|
||||
},
|
||||
{
|
||||
name: "setting public address directly with ipv6:port",
|
||||
@@ -553,7 +582,7 @@ func TestSetupWorkerPublicAddress(t *testing.T) {
|
||||
inputFlagValue: "",
|
||||
expErr: false,
|
||||
expErrStr: "",
|
||||
expPublicAddress: "[2001:4860:4860:0:0:0:0:8888]:8080",
|
||||
expPublicAddress: "[2001:4860:4860::8888]:8080",
|
||||
},
|
||||
{
|
||||
name: "setting public address directly with abbreviated ipv6",
|
||||
@@ -562,7 +591,7 @@ func TestSetupWorkerPublicAddress(t *testing.T) {
|
||||
Listeners: []*listenerutil.ListenerConfig{},
|
||||
},
|
||||
Worker: &config.Worker{
|
||||
PublicAddr: "[2001:4860:4860::8888]",
|
||||
PublicAddr: "2001:4860:4860::8888",
|
||||
},
|
||||
},
|
||||
inputFlagValue: "",
|
||||
@@ -781,6 +810,20 @@ func TestSetupWorkerPublicAddress(t *testing.T) {
|
||||
expErrStr: "",
|
||||
expPublicAddress: ":9202",
|
||||
},
|
||||
{
|
||||
name: "read unix address from listeners ip only",
|
||||
inputConfig: &config.Config{
|
||||
SharedConfig: &configutil.SharedConfig{
|
||||
Listeners: []*listenerutil.ListenerConfig{
|
||||
{Purpose: []string{"proxy"}, Address: "someaddr", Type: "unix"},
|
||||
},
|
||||
},
|
||||
Worker: &config.Worker{},
|
||||
},
|
||||
expErr: false,
|
||||
expErrStr: "",
|
||||
expPublicAddress: "someaddr:9202",
|
||||
},
|
||||
{
|
||||
name: "using flag value to point to nonexistent file",
|
||||
inputConfig: &config.Config{
|
||||
@@ -802,9 +845,9 @@ func TestSetupWorkerPublicAddress(t *testing.T) {
|
||||
},
|
||||
Worker: &config.Worker{},
|
||||
},
|
||||
inputFlagValue: "abc::123",
|
||||
inputFlagValue: "abc::123:::",
|
||||
expErr: true,
|
||||
expErrStr: "Error splitting public adddress host/port: address abc::123: too many colons in address",
|
||||
expErrStr: "Error splitting public adddress host/port: too many colons in address",
|
||||
expPublicAddress: "",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -812,12 +812,16 @@ func (b *Server) SetupWorkerPublicAddress(conf *config.Config, flagValue string)
|
||||
if flagValue != "" {
|
||||
conf.Worker.PublicAddr = flagValue
|
||||
}
|
||||
isUnixListener := false
|
||||
if conf.Worker.PublicAddr == "" {
|
||||
FindAddr:
|
||||
for _, listener := range conf.Listeners {
|
||||
for _, purpose := range listener.Purpose {
|
||||
if purpose == "proxy" {
|
||||
conf.Worker.PublicAddr = listener.Address
|
||||
if strings.EqualFold(listener.Type, "unix") {
|
||||
isUnixListener = true
|
||||
}
|
||||
break FindAddr
|
||||
}
|
||||
}
|
||||
@@ -836,14 +840,29 @@ func (b *Server) SetupWorkerPublicAddress(conf *config.Config, flagValue string)
|
||||
}
|
||||
|
||||
host, port, err := util.SplitHostPort(conf.Worker.PublicAddr)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrMissingPort) {
|
||||
return fmt.Errorf("Error splitting public adddress host/port: %w", err)
|
||||
}
|
||||
if host != "" {
|
||||
if host, err = parseutil.NormalizeAddr(host); err != nil {
|
||||
return fmt.Errorf("Error normalizing worker address")
|
||||
}
|
||||
}
|
||||
if port == "" {
|
||||
port = "9202"
|
||||
}
|
||||
conf.Worker.PublicAddr = util.JoinHostPort(host, port)
|
||||
|
||||
if host != "" && !isUnixListener {
|
||||
// NormalizeAddr requires that a host be present, but that is not
|
||||
// guaranteed in this code path. Additionally, if no host is present,
|
||||
// there's no need to normalize.
|
||||
conf.Worker.PublicAddr, err = parseutil.NormalizeAddr(conf.Worker.PublicAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to normalize worker public adddress: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -475,7 +475,7 @@ func (c *Command) Run(args []string) (retCode int) {
|
||||
proxyAddr := clientProxy.ListenerAddress(context.Background())
|
||||
var clientProxyHost, clientProxyPort string
|
||||
clientProxyHost, clientProxyPort, err = util.SplitHostPort(proxyAddr)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrMissingPort) {
|
||||
c.PrintCliError(fmt.Errorf("error splitting listener addr: %w", err))
|
||||
return base.CommandCliError
|
||||
}
|
||||
@@ -600,7 +600,7 @@ func (c *Command) handleExec(clientProxy *apiproxy.ClientProxy, passthroughArgs
|
||||
var host, port string
|
||||
var err error
|
||||
host, port, err = util.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrMissingPort) {
|
||||
c.PrintCliError(fmt.Errorf("Error splitting listener addr: %w", err))
|
||||
c.execCmdReturnValue.Store(int32(3))
|
||||
return
|
||||
|
||||
@@ -593,7 +593,7 @@ func (c *Command) Run(args []string) int {
|
||||
}
|
||||
|
||||
host, port, err := util.SplitHostPort(c.flagHostAddress)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrMissingPort) {
|
||||
c.UI.Error(fmt.Errorf("Invalid host address specified: %w", err).Error())
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ func (c *Command) Run(args []string) int {
|
||||
}
|
||||
for _, upstream := range c.Config.Worker.InitialUpstreams {
|
||||
host, _, err := util.SplitHostPort(upstream)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrMissingPort) {
|
||||
c.UI.Error(fmt.Errorf("Invalid worker upstream address %q: %w", upstream, err).Error())
|
||||
return base.CommandUserError
|
||||
}
|
||||
@@ -412,7 +412,7 @@ func (c *Command) Run(args []string) int {
|
||||
continue
|
||||
}
|
||||
host, _, err := util.SplitHostPort(ln.Address)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrMissingPort) {
|
||||
c.UI.Error(fmt.Errorf("Invalid cluster listener address %q: %w", ln.Address, err).Error())
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ kms "aead" {
|
||||
}
|
||||
|
||||
listener "tcp" {
|
||||
address = "[::1]"
|
||||
address = "::1"
|
||||
purpose = "api"
|
||||
tls_disable = true
|
||||
cors_enabled = true
|
||||
@@ -147,12 +147,12 @@ listener "tcp" {
|
||||
}
|
||||
|
||||
listener "tcp" {
|
||||
address = "[::1]"
|
||||
address = "::1"
|
||||
purpose = "cluster"
|
||||
}
|
||||
|
||||
listener "tcp" {
|
||||
address = "[::1]"
|
||||
address = "::1"
|
||||
purpose = "ops"
|
||||
tls_disable = true
|
||||
}
|
||||
@@ -160,15 +160,15 @@ listener "tcp" {
|
||||
|
||||
devIpv6WorkerExtraConfig = `
|
||||
listener "tcp" {
|
||||
address = "[::1]"
|
||||
address = "::1"
|
||||
purpose = "proxy"
|
||||
}
|
||||
|
||||
worker {
|
||||
name = "w_1234567890"
|
||||
description = "A default worker created in dev mode"
|
||||
public_addr = "[::1]"
|
||||
initial_upstreams = ["[::1]"]
|
||||
public_addr = "::1"
|
||||
initial_upstreams = ["::1"]
|
||||
tags {
|
||||
type = ["dev", "local"]
|
||||
}
|
||||
@@ -1240,14 +1240,13 @@ func parseWorkerUpstreams(c *Config) ([]string, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
upstreams := make([]string, 0)
|
||||
switch t := c.Worker.InitialUpstreamsRaw.(type) {
|
||||
case []any:
|
||||
var upstreams []string
|
||||
err := mapstructure.WeakDecode(c.Worker.InitialUpstreamsRaw, &upstreams)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode worker initial_upstreams block into config field: %w", err)
|
||||
}
|
||||
return upstreams, nil
|
||||
|
||||
case string:
|
||||
upstreamsStr, err := parseutil.ParsePath(t)
|
||||
@@ -1255,17 +1254,25 @@ func parseWorkerUpstreams(c *Config) ([]string, error) {
|
||||
return nil, fmt.Errorf("bad env var or file pointer: %w", err)
|
||||
}
|
||||
|
||||
var upstreams []string
|
||||
err = json.Unmarshal([]byte(upstreamsStr), &upstreams)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal env/file contents: %w", err)
|
||||
}
|
||||
return upstreams, nil
|
||||
|
||||
default:
|
||||
typ := reflect.TypeOf(t)
|
||||
return nil, fmt.Errorf("unexpected type %q", typ.String())
|
||||
}
|
||||
|
||||
for i := range upstreams {
|
||||
normalized, err := parseutil.NormalizeAddr(upstreams[i])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to normalize worker upstream %q: %w", upstreams[i], err)
|
||||
}
|
||||
upstreams[i] = normalized
|
||||
}
|
||||
|
||||
return upstreams, nil
|
||||
}
|
||||
|
||||
func parseEventing(eventObj *ast.ObjectItem) (*event.EventerConfig, error) {
|
||||
@@ -1379,12 +1386,16 @@ func (c *Config) SetupControllerPublicClusterAddress(flagValue string) error {
|
||||
if flagValue != "" {
|
||||
c.Controller.PublicClusterAddr = flagValue
|
||||
}
|
||||
isUnixListener := false
|
||||
if c.Controller.PublicClusterAddr == "" {
|
||||
FindAddr:
|
||||
for _, listener := range c.Listeners {
|
||||
for _, purpose := range listener.Purpose {
|
||||
if purpose == "cluster" {
|
||||
c.Controller.PublicClusterAddr = listener.Address
|
||||
if strings.EqualFold(listener.Type, "unix") {
|
||||
isUnixListener = true
|
||||
}
|
||||
break FindAddr
|
||||
}
|
||||
}
|
||||
@@ -1403,7 +1414,7 @@ func (c *Config) SetupControllerPublicClusterAddress(flagValue string) error {
|
||||
}
|
||||
|
||||
host, port, err := util.SplitHostPort(c.Controller.PublicClusterAddr)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrMissingPort) {
|
||||
return fmt.Errorf("Error splitting public cluster adddress host/port: %w", err)
|
||||
}
|
||||
if port == "" {
|
||||
@@ -1411,6 +1422,16 @@ func (c *Config) SetupControllerPublicClusterAddress(flagValue string) error {
|
||||
}
|
||||
c.Controller.PublicClusterAddr = util.JoinHostPort(host, port)
|
||||
|
||||
if host != "" && !isUnixListener {
|
||||
// NormalizeAddr requires that a host be present, but that is not
|
||||
// guaranteed in this code path. Additionally, if no host is present,
|
||||
// there's no need to normalize.
|
||||
c.Controller.PublicClusterAddr, err = parseutil.NormalizeAddr(c.Controller.PublicClusterAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to normalize controller public cluster adddress: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1464,7 +1485,7 @@ func (c *Config) SetupWorkerInitialUpstreams() error {
|
||||
}
|
||||
// Best effort see if it's a domain name and if not assume it must match
|
||||
host, _, err := util.SplitHostPort(c.Worker.InitialUpstreams[0])
|
||||
if err == nil {
|
||||
if err == nil || errors.Is(err, util.ErrMissingPort) {
|
||||
ip := net.ParseIP(host)
|
||||
if ip == nil {
|
||||
// Assume it's a domain name
|
||||
|
||||
@@ -781,98 +781,112 @@ func TestDevWorkerRecordingStoragePath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestDevControllerIpv6 validates that all listeners use an IPv6 address when
|
||||
// the WithIPv6Enabled(true) option is passed into DevController. Other dev
|
||||
// controller configurations are validated in TestDevController.
|
||||
func TestDevControllerIpv6(t *testing.T) {
|
||||
require, assert := require.New(t), assert.New(t)
|
||||
// This test only validates that all listeners are utilizing an IPv6 address.
|
||||
// Other dev controller configurations are validates in TestDevController.
|
||||
require := require.New(t)
|
||||
|
||||
actual, err := DevController(WithIPv6Enabled(true))
|
||||
require.NoError(err)
|
||||
|
||||
// expected an error here because we purposely did not provide a port number
|
||||
// to allow randomly assigned port values
|
||||
// Expected an error here because PublicClusterAddr is not set.
|
||||
_, _, err = net.SplitHostPort(actual.Controller.PublicClusterAddr)
|
||||
require.Error(err)
|
||||
|
||||
// assert the square brackets are removed from the host ipv6 address and that the port value is empty
|
||||
// Same here.
|
||||
publicAddr, port, err := util.SplitHostPort(actual.Controller.PublicClusterAddr)
|
||||
require.NoError(err)
|
||||
assert.Empty(port)
|
||||
assert.Empty(publicAddr)
|
||||
require.ErrorIs(err, util.ErrMissingPort)
|
||||
require.Empty(port)
|
||||
require.Empty(publicAddr)
|
||||
|
||||
require.NotEmpty(actual.Listeners)
|
||||
for _, l := range actual.Listeners {
|
||||
addr, _, err := util.SplitHostPort(l.Address)
|
||||
require.NoError(err)
|
||||
require.ErrorIs(err, util.ErrMissingPort)
|
||||
require.NotEmpty(t, addr)
|
||||
|
||||
ip := net.ParseIP(addr)
|
||||
assert.NotNil(ip, "failed to parse listener address for %v", l.Purpose)
|
||||
assert.NotNil(ip.To16(), "failed to convert address to IPv6 for %v, found %v", l.Purpose, addr)
|
||||
require.NotNil(ip, "failed to parse listener address for %v", l.Purpose)
|
||||
require.NotNil(ip.To16(), "failed to convert address to IPv6 for %v, found %v", l.Purpose, addr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDevWorkerIpv6 validates that all listeners use an IPv6 address when the
|
||||
// WithIPv6Enabled(true) option is passed into DevWorker. Other dev worker
|
||||
// configurations are validated in TestDevWorker.
|
||||
func TestDevWorkerIpv6(t *testing.T) {
|
||||
require, assert := require.New(t), assert.New(t)
|
||||
// This test only validates that all listeners are utilizing an IPv6 address.
|
||||
// Other dev worker configurations are validates in TestDevWorker.
|
||||
require := require.New(t)
|
||||
|
||||
actual, err := DevWorker(WithIPv6Enabled(true))
|
||||
require.NoError(err)
|
||||
|
||||
// expected an error here because we purposely did not provide a port number
|
||||
// to allow randomly assigned port values
|
||||
// Expected an error here because PublicAddr does not have a port.
|
||||
_, _, err = net.SplitHostPort(actual.Worker.PublicAddr)
|
||||
require.Error(err)
|
||||
|
||||
// assert the square brackets are removed from the worker ipv6 address and that the port value is empty
|
||||
// util.SplitHostPort, however, can handle it when ports are missing.
|
||||
publicAddr, port, err := util.SplitHostPort(actual.Worker.PublicAddr)
|
||||
require.NoError(err)
|
||||
assert.Empty(port)
|
||||
require.ErrorIs(err, util.ErrMissingPort)
|
||||
require.Empty(port)
|
||||
require.NotEmpty(t, publicAddr)
|
||||
|
||||
ip := net.ParseIP(publicAddr)
|
||||
assert.NotNil(ip, "failed to parse worker public address")
|
||||
assert.NotNil(ip.To16(), "worker public address is not IPv6 %s", actual.Worker.PublicAddr)
|
||||
require.NotNil(ip, "failed to parse worker public address")
|
||||
require.NotNil(ip.To16(), "worker public address is not IPv6 %s", actual.Worker.PublicAddr)
|
||||
|
||||
require.NotEmpty(actual.Listeners)
|
||||
for _, l := range actual.Listeners {
|
||||
addr, _, err := util.SplitHostPort(l.Address)
|
||||
require.NoError(err)
|
||||
require.ErrorIs(err, util.ErrMissingPort)
|
||||
require.NotEmpty(addr)
|
||||
|
||||
ip := net.ParseIP(addr)
|
||||
assert.NotNil(ip, "failed to parse listener address for %v", l.Purpose)
|
||||
assert.NotNil(ip.To16(), "failed to convert address to IPv6 for %v, found %v", l.Purpose, addr)
|
||||
require.NotNil(ip, "failed to parse listener address for %v", l.Purpose)
|
||||
require.NotNil(ip.To16(), "failed to convert address to IPv6 for %v, found %v", l.Purpose, addr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDevCombinedIpv6 validates that all listeners use an IPv6 address when the
|
||||
// WithIPv6Enabled(true) option is passed into DevCombined.
|
||||
func TestDevCombinedIpv6(t *testing.T) {
|
||||
require, assert := require.New(t), assert.New(t)
|
||||
// This test only validates that all listeners are utilizing an IPv6 address.
|
||||
require := require.New(t)
|
||||
|
||||
actual, err := DevCombined(WithIPv6Enabled(true))
|
||||
require.NoError(err)
|
||||
|
||||
// expected an error here because we purposely did not provide a port number
|
||||
// to allow randomly assigned port values for the worker and controller
|
||||
// Expected to fail because PublicAddr does not have a port.
|
||||
_, _, err = net.SplitHostPort(actual.Worker.PublicAddr)
|
||||
require.Error(err)
|
||||
// Expected to fail because PublicClusterAddr is not set.
|
||||
_, _, err = net.SplitHostPort(actual.Controller.PublicClusterAddr)
|
||||
require.Error(err)
|
||||
|
||||
// assert the square brackets are removed from the host ipv6 address and that the port value is empty
|
||||
// util.SplitHostPort, however, can handle it when ports are missing.
|
||||
publicAddr, port, err := util.SplitHostPort(actual.Worker.PublicAddr)
|
||||
require.NoError(err)
|
||||
assert.Empty(port)
|
||||
ip := net.ParseIP(publicAddr)
|
||||
assert.NotNil(ip, "failed to parse worker public address")
|
||||
assert.NotNil(ip.To16(), "worker public address is not IPv6 %s", actual.Worker.PublicAddr)
|
||||
require.ErrorIs(err, util.ErrMissingPort)
|
||||
require.Empty(port)
|
||||
require.NotEmpty(publicAddr)
|
||||
|
||||
// assert the square brackets are removed from the controller ipv6 address and that the port value is empty
|
||||
ip := net.ParseIP(publicAddr)
|
||||
require.NotNil(ip, "failed to parse worker public address")
|
||||
require.NotNil(ip.To16(), "worker public address is not IPv6 %s", actual.Worker.PublicAddr)
|
||||
|
||||
// Expected to fail because PublicClusterAddr is not set.
|
||||
publicAddr, port, err = util.SplitHostPort(actual.Controller.PublicClusterAddr)
|
||||
require.NoError(err)
|
||||
assert.Empty(port)
|
||||
assert.Empty(publicAddr)
|
||||
require.ErrorIs(err, util.ErrMissingPort)
|
||||
require.Empty(port)
|
||||
require.Empty(publicAddr)
|
||||
|
||||
require.NotEmpty(actual.Listeners)
|
||||
for _, l := range actual.Listeners {
|
||||
addr, _, err := util.SplitHostPort(l.Address)
|
||||
require.NoError(err)
|
||||
require.ErrorIs(err, util.ErrMissingPort)
|
||||
require.NotEmpty(addr)
|
||||
|
||||
ip := net.ParseIP(addr)
|
||||
assert.NotNil(ip, "failed to parse listener address for %v", l.Purpose)
|
||||
assert.NotNil(ip.To16(), "failed to convert address to IPv6 for %v, found %v", l.Purpose, addr)
|
||||
require.NotNil(ip, "failed to parse listener address for %v", l.Purpose)
|
||||
require.NotNil(ip.To16(), "failed to convert address to IPv6 for %v, found %v", l.Purpose, addr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1607,10 +1621,10 @@ func TestWorkerUpstreams(t *testing.T) {
|
||||
in: `
|
||||
worker {
|
||||
name = "test"
|
||||
initial_upstreams = ["[2001:4860:4860:0:0:0:0:8888]"]
|
||||
initial_upstreams = ["2001:4860:4860:0:0:0:0:8888"]
|
||||
}
|
||||
`,
|
||||
expWorkerUpstreams: []string{"[2001:4860:4860:0:0:0:0:8888]"},
|
||||
expWorkerUpstreams: []string{"2001:4860:4860::8888"},
|
||||
expErr: false,
|
||||
},
|
||||
{
|
||||
@@ -1618,10 +1632,10 @@ func TestWorkerUpstreams(t *testing.T) {
|
||||
in: `
|
||||
worker {
|
||||
name = "test"
|
||||
initial_upstreams = ["[2001:4860:4860::8888]"]
|
||||
initial_upstreams = ["2001:4860:4860::8888"]
|
||||
}
|
||||
`,
|
||||
expWorkerUpstreams: []string{"[2001:4860:4860::8888]"},
|
||||
expWorkerUpstreams: []string{"2001:4860:4860::8888"},
|
||||
expErr: false,
|
||||
},
|
||||
{
|
||||
@@ -2467,13 +2481,13 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
|
||||
Listeners: []*listenerutil.ListenerConfig{},
|
||||
},
|
||||
Controller: &Controller{
|
||||
PublicClusterAddr: "[2001:4860:4860:0:0:0:0:8888]",
|
||||
PublicClusterAddr: "2001:4860:4860:0:0:0:0:8888",
|
||||
},
|
||||
},
|
||||
inputFlagValue: "",
|
||||
expErr: false,
|
||||
expErrStr: "",
|
||||
expPublicClusterAddress: "[2001:4860:4860:0:0:0:0:8888]:9201",
|
||||
expPublicClusterAddress: "[2001:4860:4860::8888]:9201",
|
||||
},
|
||||
{
|
||||
name: "setting public cluster address directly with ipv6:port",
|
||||
@@ -2488,7 +2502,7 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
|
||||
inputFlagValue: "",
|
||||
expErr: false,
|
||||
expErrStr: "",
|
||||
expPublicClusterAddress: "[2001:4860:4860:0:0:0:0:8888]:8080",
|
||||
expPublicClusterAddress: "[2001:4860:4860::8888]:8080",
|
||||
},
|
||||
{
|
||||
name: "setting public cluster address directly with abbreviated ipv6",
|
||||
@@ -2497,7 +2511,7 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
|
||||
Listeners: []*listenerutil.ListenerConfig{},
|
||||
},
|
||||
Controller: &Controller{
|
||||
PublicClusterAddr: "[2001:4860:4860::8888]",
|
||||
PublicClusterAddr: "2001:4860:4860::8888",
|
||||
},
|
||||
},
|
||||
inputFlagValue: "",
|
||||
@@ -2707,35 +2721,35 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
|
||||
inputConfig: &Config{
|
||||
SharedConfig: &configutil.SharedConfig{
|
||||
Listeners: []*listenerutil.ListenerConfig{
|
||||
{Purpose: []string{"cluster"}, Address: "[2001:4860:4860:0:0:0:0:8888]"},
|
||||
{Purpose: []string{"cluster"}, Address: "2001:4860:4860:0:0:0:0:8888"},
|
||||
},
|
||||
},
|
||||
Controller: &Controller{},
|
||||
},
|
||||
expErr: false,
|
||||
expErrStr: "",
|
||||
expPublicClusterAddress: "[2001:4860:4860:0:0:0:0:8888]:9201",
|
||||
expPublicClusterAddress: "[2001:4860:4860::8888]:9201",
|
||||
},
|
||||
{
|
||||
name: "read address from listeners ipv6:port",
|
||||
inputConfig: &Config{
|
||||
SharedConfig: &configutil.SharedConfig{
|
||||
Listeners: []*listenerutil.ListenerConfig{
|
||||
{Purpose: []string{"cluster"}, Address: "[2001:4860:4860:0:0:0:0:8888]:8080"},
|
||||
{Purpose: []string{"cluster"}, Address: "[2001:4860:4860::8888]:8080"},
|
||||
},
|
||||
},
|
||||
Controller: &Controller{},
|
||||
},
|
||||
expErr: false,
|
||||
expErrStr: "",
|
||||
expPublicClusterAddress: "[2001:4860:4860:0:0:0:0:8888]:8080",
|
||||
expPublicClusterAddress: "[2001:4860:4860::8888]:8080",
|
||||
},
|
||||
{
|
||||
name: "read address from listeners abbreviated ipv6 only",
|
||||
inputConfig: &Config{
|
||||
SharedConfig: &configutil.SharedConfig{
|
||||
Listeners: []*listenerutil.ListenerConfig{
|
||||
{Purpose: []string{"cluster"}, Address: "[2001:4860:4860::8888]"},
|
||||
{Purpose: []string{"cluster"}, Address: "2001:4860:4860::8888"},
|
||||
},
|
||||
},
|
||||
Controller: &Controller{},
|
||||
@@ -2793,9 +2807,9 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
|
||||
},
|
||||
Controller: &Controller{},
|
||||
},
|
||||
inputFlagValue: "abc::123",
|
||||
inputFlagValue: "abc::123:::",
|
||||
expErr: true,
|
||||
expErrStr: "Error splitting public cluster adddress host/port: address abc::123: too many colons in address",
|
||||
expErrStr: "Error splitting public cluster adddress host/port: too many colons in address",
|
||||
expPublicClusterAddress: "",
|
||||
},
|
||||
{
|
||||
@@ -2811,6 +2825,18 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
|
||||
expErrStr: "Error parsing IP template on controller public cluster addr: unable to parse address template \"{{ somethingthatdoesntexist }}\": unable to parse template \"{{ somethingthatdoesntexist }}\": template: sockaddr.Parse:1: function \"somethingthatdoesntexist\" not defined",
|
||||
expPublicClusterAddress: "",
|
||||
},
|
||||
{
|
||||
name: "unix listener",
|
||||
inputConfig: &Config{
|
||||
SharedConfig: &configutil.SharedConfig{
|
||||
Listeners: []*listenerutil.ListenerConfig{
|
||||
{Address: "someaddr", Type: "unix", Purpose: []string{"cluster"}},
|
||||
},
|
||||
},
|
||||
Controller: &Controller{},
|
||||
},
|
||||
expPublicClusterAddress: "someaddr:9201",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in new issue
Block a user