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
@@ -15,6 +15,7 @@ import (
"net"
"os"
"reflect"
"regexp"
"strconv"
"strings"
"time"
@@ -132,6 +133,12 @@ kms "aead" {
defaultCsp = "default-src 'none'; script-src 'self' 'wasm-unsafe-eval'; frame-src 'self'; font-src 'self'; connect-src 'self'; img-src 'self' data:; style-src 'self'; media-src 'self'; manifest-src 'self'; style-src-attr 'self'; frame-ancestors 'self'"
)
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("\\[|\\]")
)
// Config is the configuration for the boundary controller
type Config struct {
*configutil.SharedConfig `hcl:"-"`
@@ -1278,7 +1285,12 @@ func (c *Config) SetupControllerPublicClusterAddress(flagValue string) error {
return fmt.Errorf("Error splitting public cluster 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, "")
c.Controller.PublicClusterAddr = net.JoinHostPort(host, port)
return nil
}
+211 -7
View File
@@ -1495,7 +1495,7 @@ func TestWorkerUpstreams(t *testing.T) {
expErr: false,
},
{
name: "One Upstream",
name: "ipv4 Upstream",
in: `
worker {
name = "test"
@@ -1505,6 +1505,28 @@ func TestWorkerUpstreams(t *testing.T) {
expWorkerUpstreams: []string{"127.0.0.1"},
expErr: false,
},
{
name: "ipv6 Upstream",
in: `
worker {
name = "test"
initial_upstreams = ["[2001:4860:4860:0:0:0:0:8888]"]
}
`,
expWorkerUpstreams: []string{"[2001:4860:4860:0:0:0:0:8888]"},
expErr: false,
},
{
name: "abbreviated ipv6 Upstream",
in: `
worker {
name = "test"
initial_upstreams = ["[2001:4860:4860::8888]"]
}
`,
expWorkerUpstreams: []string{"[2001:4860:4860::8888]"},
expErr: false,
},
{
name: "Multiple Upstreams",
in: `
@@ -2346,7 +2368,7 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
expPublicClusterAddress: ":9201",
},
{
name: "setting public cluster address directly with ip",
name: "setting public cluster address directly with ipv4",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{},
@@ -2361,7 +2383,7 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
expPublicClusterAddress: "127.0.0.1:9201",
},
{
name: "setting public cluster address directly with ip:port",
name: "setting public cluster address directly with ipv4:port",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{},
@@ -2375,6 +2397,66 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
expErrStr: "",
expPublicClusterAddress: "127.0.0.1:8080",
},
{
name: "setting public cluster address directly with ipv6",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{},
},
Controller: &Controller{
PublicClusterAddr: "[2001:4860:4860:0:0:0:0:8888]",
},
},
inputFlagValue: "",
expErr: false,
expErrStr: "",
expPublicClusterAddress: "[2001:4860:4860:0:0:0:0:8888]:9201",
},
{
name: "setting public cluster address directly with ipv6:port",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{},
},
Controller: &Controller{
PublicClusterAddr: "[2001:4860:4860:0:0:0:0:8888]:8080",
},
},
inputFlagValue: "",
expErr: false,
expErrStr: "",
expPublicClusterAddress: "[2001:4860:4860:0:0:0:0:8888]:8080",
},
{
name: "setting public cluster address directly with abbreviated ipv6",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{},
},
Controller: &Controller{
PublicClusterAddr: "[2001:4860:4860::8888]",
},
},
inputFlagValue: "",
expErr: false,
expErrStr: "",
expPublicClusterAddress: "[2001:4860:4860::8888]:9201",
},
{
name: "setting public cluster address directly with abbreviated ipv6:port",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{},
},
Controller: &Controller{
PublicClusterAddr: "[2001:4860:4860::8888]:8080",
},
},
inputFlagValue: "",
expErr: false,
expErrStr: "",
expPublicClusterAddress: "[2001:4860:4860::8888]:8080",
},
{
name: "setting public cluster address to env var",
inputConfig: &Config{
@@ -2530,7 +2612,7 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
expPublicClusterAddress: "127.0.0.1:8080",
},
{
name: "read address from listeners ip only",
name: "read address from listeners ipv4 only",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{
@@ -2544,7 +2626,7 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
expPublicClusterAddress: "127.0.0.1:9201",
},
{
name: "read address from listeners ip:port",
name: "read address from listeners ipv4:port",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{
@@ -2557,6 +2639,62 @@ func TestSetupControllerPublicClusterAddress(t *testing.T) {
expErrStr: "",
expPublicClusterAddress: "127.0.0.1:8080",
},
{
name: "read address from listeners ipv6 only",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{
{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",
},
{
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"},
},
},
Controller: &Controller{},
},
expErr: false,
expErrStr: "",
expPublicClusterAddress: "[2001:4860:4860:0:0:0:0: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]"},
},
},
Controller: &Controller{},
},
expErr: false,
expErrStr: "",
expPublicClusterAddress: "[2001:4860:4860::8888]:9201",
},
{
name: "read address from listeners abbreviated ipv6:port",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{
{Purpose: []string{"cluster"}, Address: "[2001:4860:4860::8888]:8080"},
},
},
Controller: &Controller{},
},
expErr: false,
expErrStr: "",
expPublicClusterAddress: "[2001:4860:4860::8888]:8080",
},
{
name: "read address from listeners is ignored on different purpose",
inputConfig: &Config{
@@ -2671,7 +2809,7 @@ func TestSetupWorkerInitialUpstreams(t *testing.T) {
expInitialUpstreams: nil,
},
{
name: "PublicClusterAddr",
name: "ipv4 PublicClusterAddr",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{},
@@ -2685,6 +2823,36 @@ func TestSetupWorkerInitialUpstreams(t *testing.T) {
expErrStr: "",
expInitialUpstreams: []string{"192.168.0.4:9201"},
},
{
name: "ipv6 PublicClusterAddr",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{},
},
Controller: &Controller{
PublicClusterAddr: "[2001:4860:4860:0:0:0:0:8888]:9201",
},
Worker: &Worker{},
},
expErr: false,
expErrStr: "",
expInitialUpstreams: []string{"[2001:4860:4860:0:0:0:0:8888]:9201"},
},
{
name: "abbreviated ipv6 PublicClusterAddr",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{},
},
Controller: &Controller{
PublicClusterAddr: "[2001:4860:4860::8888]:9201",
},
Worker: &Worker{},
},
expErr: false,
expErrStr: "",
expInitialUpstreams: []string{"[2001:4860:4860::8888]:9201"},
},
{
name: "ListenerNoAddr",
inputConfig: &Config{
@@ -2703,7 +2871,7 @@ func TestSetupWorkerInitialUpstreams(t *testing.T) {
expInitialUpstreams: []string{"127.0.0.1:9201"},
},
{
name: "ListenerAddr",
name: "ipv4 ListenerAddr",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{
@@ -2720,6 +2888,42 @@ func TestSetupWorkerInitialUpstreams(t *testing.T) {
expErrStr: "",
expInitialUpstreams: []string{"192.168.0.5:9201"},
},
{
name: "ipv6 ListenerAddr",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{
{
Purpose: []string{"cluster"},
Address: "[2001:4860:4860:0:0:0:0:8888]:9201",
},
},
},
Controller: &Controller{},
Worker: &Worker{},
},
expErr: false,
expErrStr: "",
expInitialUpstreams: []string{"[2001:4860:4860:0:0:0:0:8888]:9201"},
},
{
name: "abbreviated ipv6 ListenerAddr",
inputConfig: &Config{
SharedConfig: &configutil.SharedConfig{
Listeners: []*listenerutil.ListenerConfig{
{
Purpose: []string{"cluster"},
Address: "[2001:4860:4860::8888]:9201",
},
},
},
Controller: &Controller{},
Worker: &Worker{},
},
expErr: false,
expErrStr: "",
expInitialUpstreams: []string{"[2001:4860:4860::8888]:9201"},
},
{
name: "ListenerAddrDomain",
inputConfig: &Config{