mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-18 04:39:06 +02:00
[management,signal,proxy,relay,misc] Remove obsolete config tests
This commit is contained in:
@@ -791,162 +791,6 @@ func TestRunServerPreservesLegacyTokenRequirement(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// proxy-12: with a valid token, legacy initialised the logger before parsing
|
||||
// the performance variables, so the log-level line preceded the parse error.
|
||||
func TestRunServerPreservesLegacyPerformanceErrorOrdering(t *testing.T) {
|
||||
clearProxyConfigEnvironment(t)
|
||||
t.Setenv("NB_PROXY_TOKEN", "test-token")
|
||||
t.Setenv("NB_PROXY_PREALLOCATED_BUFFERS", "invalid")
|
||||
cmd := newLegacyProxyCommand(t)
|
||||
|
||||
oldDebugLogs := debugLogs
|
||||
oldConfigPath := configPath
|
||||
t.Cleanup(func() {
|
||||
debugLogs = oldDebugLogs
|
||||
configPath = oldConfigPath
|
||||
})
|
||||
debugLogs = false
|
||||
configPath = ""
|
||||
|
||||
var runErr error
|
||||
output := captureStderr(t, func() {
|
||||
runErr = runServer(cmd, nil)
|
||||
})
|
||||
require.Error(t, runErr)
|
||||
assert.Contains(t, output, "configured log level: info",
|
||||
"Legacy initialised the logger before parsing the performance environment variables")
|
||||
assert.EqualError(t, runErr, `invalid NB_PROXY_PREALLOCATED_BUFFERS "invalid": strconv.ParseUint: parsing "invalid": invalid syntax`,
|
||||
"Legacy reported the performance parse error with the variable name after logger initialisation")
|
||||
}
|
||||
|
||||
// proxy-13: legacy had no --config flag; cobra rejected it as unknown.
|
||||
func TestLegacyProxyRejectsConfigFlag(t *testing.T) {
|
||||
oldConfigPath := configPath
|
||||
t.Cleanup(func() {
|
||||
configPath = oldConfigPath
|
||||
if flag := rootCmd.Flags().Lookup("config"); flag != nil {
|
||||
require.NoError(t, flag.Value.Set(oldConfigPath))
|
||||
flag.Changed = false
|
||||
}
|
||||
})
|
||||
|
||||
err := rootCmd.ParseFlags([]string{"--config", filepath.Join(t.TempDir(), "proxy.yaml")})
|
||||
require.Error(t, err, "Legacy proxy command did not register a --config flag")
|
||||
assert.EqualError(t, err, "unknown flag: --config",
|
||||
"Legacy cobra rejected --config as an unknown flag")
|
||||
}
|
||||
|
||||
// proxy-critic-1: legacy parsed --trusted-proxies / NB_PROXY_TRUSTED_PROXIES
|
||||
// last in runServer, after the token check, logger initialisation and the
|
||||
// forwarded-proto and domain validation, and reported it as
|
||||
// `invalid --trusted-proxies: ...`.
|
||||
func TestRunServerPreservesLegacyTrustedProxiesValidationOrdering(t *testing.T) {
|
||||
const legacyTokenError = "proxy token is required: set NB_PROXY_TOKEN environment variable"
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
env map[string]string
|
||||
flagValue string
|
||||
wantErr string
|
||||
wantErrPart string
|
||||
wantLogLine bool
|
||||
}{
|
||||
{
|
||||
name: "missing token is reported before trusted proxy parsing",
|
||||
env: map[string]string{"NB_PROXY_TRUSTED_PROXIES": "not-an-ip"},
|
||||
wantErr: legacyTokenError,
|
||||
},
|
||||
{
|
||||
name: "invalid forwarded-proto is reported before trusted proxy parsing",
|
||||
env: map[string]string{
|
||||
"NB_PROXY_TOKEN": "test-token",
|
||||
"NB_PROXY_FORWARDED_PROTO": "bogus",
|
||||
"NB_PROXY_TRUSTED_PROXIES": "not-an-ip",
|
||||
},
|
||||
wantErr: `invalid --forwarded-proto value "bogus": must be auto, http, or https`,
|
||||
wantLogLine: true,
|
||||
},
|
||||
{
|
||||
name: "invalid domain is reported before trusted proxy parsing",
|
||||
env: map[string]string{
|
||||
"NB_PROXY_TOKEN": "test-token",
|
||||
"NB_PROXY_DOMAIN": "invalid domain",
|
||||
"NB_PROXY_TRUSTED_PROXIES": "not-an-ip",
|
||||
},
|
||||
wantErrPart: `invalid domain value "invalid domain"`,
|
||||
wantLogLine: true,
|
||||
},
|
||||
{
|
||||
name: "invalid trusted proxy environment is reported after logger initialisation",
|
||||
env: map[string]string{
|
||||
"NB_PROXY_TOKEN": "test-token",
|
||||
"NB_PROXY_DOMAIN": "proxy.example.com",
|
||||
"NB_PROXY_TRUSTED_PROXIES": "not-an-ip",
|
||||
},
|
||||
wantErr: `invalid --trusted-proxies: parse trusted proxy "not-an-ip": not a valid CIDR or IP: ParseAddr("not-an-ip"): unable to parse IP`,
|
||||
wantLogLine: true,
|
||||
},
|
||||
{
|
||||
name: "invalid trusted proxy flag is reported after logger initialisation",
|
||||
env: map[string]string{
|
||||
"NB_PROXY_TOKEN": "test-token",
|
||||
"NB_PROXY_DOMAIN": "proxy.example.com",
|
||||
},
|
||||
flagValue: "10.0.0.0/8,garbage",
|
||||
wantErr: `invalid --trusted-proxies: parse trusted proxy "garbage": not a valid CIDR or IP: ParseAddr("garbage"): unable to parse IP`,
|
||||
wantLogLine: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
clearProxyConfigEnvironment(t)
|
||||
for name, value := range test.env {
|
||||
t.Setenv(name, value)
|
||||
}
|
||||
cmd := newLegacyProxyCommand(t)
|
||||
if test.flagValue != "" {
|
||||
trustedProxiesFlag := cmd.Flags().Lookup("trusted-proxies")
|
||||
require.NotNil(t, trustedProxiesFlag, "Trusted proxies flag should be registered")
|
||||
require.NoError(t, trustedProxiesFlag.Value.Set(test.flagValue))
|
||||
trustedProxiesFlag.Changed = true
|
||||
}
|
||||
|
||||
oldDebugLogs := debugLogs
|
||||
oldConfigPath := configPath
|
||||
t.Cleanup(func() {
|
||||
debugLogs = oldDebugLogs
|
||||
configPath = oldConfigPath
|
||||
})
|
||||
debugLogs = false
|
||||
configPath = ""
|
||||
|
||||
var runErr error
|
||||
output := captureStderr(t, func() {
|
||||
runErr = runServer(cmd, nil)
|
||||
})
|
||||
require.Error(t, runErr)
|
||||
if test.wantLogLine {
|
||||
assert.Contains(t, output, "configured log level: info",
|
||||
"Legacy initialised the logger before validating the trusted proxy list")
|
||||
} else {
|
||||
assert.NotContains(t, output, "configured log level",
|
||||
"Legacy checked the token before initialising the logger")
|
||||
}
|
||||
if test.wantErr != "" {
|
||||
assert.EqualError(t, runErr, test.wantErr,
|
||||
"Legacy parsed the trusted proxy list last in runServer and reported it as invalid --trusted-proxies")
|
||||
}
|
||||
if test.wantErrPart != "" {
|
||||
assert.ErrorContains(t, runErr, test.wantErrPart,
|
||||
"Legacy validated the domain before parsing the trusted proxy list")
|
||||
assert.NotContains(t, runErr.Error(), "trusted prox",
|
||||
"Legacy never mentioned trusted proxies when an earlier validation step failed")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func newLegacyProxyCommand(t *testing.T) *cobra.Command {
|
||||
t.Helper()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user