mirror of
https://github.com/tailscale/tailscale.git
synced 2025-06-08 08:48:35 +00:00

In 1.84 we made 'tailscale set'/'tailscale up' error out if duplicate command line flags are passed. This broke some container configurations as we have two env vars that can be used to set --accept-dns flag: - TS_ACCEPT_DNS- specifically for --accept-dns - TS_EXTRA_ARGS- accepts any arbitrary 'tailscale up'/'tailscale set' flag. We default TS_ACCEPT_DNS to false (to make the container behaviour more declarative), which with the new restrictive CLI behaviour resulted in failure for users who had set --accept-dns via TS_EXTRA_ARGS as the flag would be provided twice. This PR re-instates the previous behaviour by checking if TS_EXTRA_ARGS contains --accept-dns flag and if so using its value to override TS_ACCEPT_DNS. Updates tailscale/tailscale#16108 Signed-off-by: Irbe Krumina <irbe@tailscale.com>
109 lines
2.9 KiB
Go
109 lines
2.9 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build linux
|
|
|
|
package main
|
|
|
|
import "testing"
|
|
|
|
func Test_parseAcceptDNS(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
extraArgs string
|
|
acceptDNS bool
|
|
wantExtraArgs string
|
|
wantAcceptDNS bool
|
|
}{
|
|
{
|
|
name: "false_extra_args_unset",
|
|
extraArgs: "",
|
|
wantExtraArgs: "",
|
|
wantAcceptDNS: false,
|
|
},
|
|
{
|
|
name: "false_unrelated_args_set",
|
|
extraArgs: "--accept-routes=true --advertise-routes=10.0.0.1/32",
|
|
wantExtraArgs: "--accept-routes=true --advertise-routes=10.0.0.1/32",
|
|
wantAcceptDNS: false,
|
|
},
|
|
{
|
|
name: "true_extra_args_unset",
|
|
extraArgs: "",
|
|
acceptDNS: true,
|
|
wantExtraArgs: "",
|
|
wantAcceptDNS: true,
|
|
},
|
|
{
|
|
name: "true_unrelated_args_set",
|
|
acceptDNS: true,
|
|
extraArgs: "--accept-routes=true --advertise-routes=10.0.0.1/32",
|
|
wantExtraArgs: "--accept-routes=true --advertise-routes=10.0.0.1/32",
|
|
wantAcceptDNS: true,
|
|
},
|
|
{
|
|
name: "false_extra_args_set_to_false",
|
|
extraArgs: "--accept-dns=false",
|
|
wantExtraArgs: "",
|
|
wantAcceptDNS: false,
|
|
},
|
|
{
|
|
name: "false_extra_args_set_to_true",
|
|
extraArgs: "--accept-dns=true",
|
|
wantExtraArgs: "",
|
|
wantAcceptDNS: true,
|
|
},
|
|
{
|
|
name: "true_extra_args_set_to_false",
|
|
extraArgs: "--accept-dns=false",
|
|
acceptDNS: true,
|
|
wantExtraArgs: "",
|
|
wantAcceptDNS: false,
|
|
},
|
|
{
|
|
name: "true_extra_args_set_to_true",
|
|
extraArgs: "--accept-dns=true",
|
|
acceptDNS: true,
|
|
wantExtraArgs: "",
|
|
wantAcceptDNS: true,
|
|
},
|
|
{
|
|
name: "false_extra_args_set_to_true_implicitly",
|
|
extraArgs: "--accept-dns",
|
|
wantExtraArgs: "",
|
|
wantAcceptDNS: true,
|
|
},
|
|
{
|
|
name: "false_extra_args_set_to_true_implicitly_with_unrelated_args",
|
|
extraArgs: "--accept-dns --accept-routes --advertise-routes=10.0.0.1/32",
|
|
wantExtraArgs: "--accept-routes --advertise-routes=10.0.0.1/32",
|
|
wantAcceptDNS: true,
|
|
},
|
|
{
|
|
name: "false_extra_args_set_to_true_implicitly_surrounded_with_unrelated_args",
|
|
extraArgs: "--accept-routes --accept-dns --advertise-routes=10.0.0.1/32",
|
|
wantExtraArgs: "--accept-routes --advertise-routes=10.0.0.1/32",
|
|
wantAcceptDNS: true,
|
|
},
|
|
{
|
|
name: "true_extra_args_set_to_false_with_unrelated_args",
|
|
extraArgs: "--accept-routes --accept-dns=false",
|
|
acceptDNS: true,
|
|
wantExtraArgs: "--accept-routes",
|
|
wantAcceptDNS: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
gotExtraArgs, gotAcceptDNS := parseAcceptDNS(tt.extraArgs, tt.acceptDNS)
|
|
if gotExtraArgs != tt.wantExtraArgs {
|
|
t.Errorf("parseAcceptDNS() gotExtraArgs = %v, want %v", gotExtraArgs, tt.wantExtraArgs)
|
|
}
|
|
if gotAcceptDNS != tt.wantAcceptDNS {
|
|
t.Errorf("parseAcceptDNS() gotAcceptDNS = %v, want %v", gotAcceptDNS, tt.wantAcceptDNS)
|
|
}
|
|
})
|
|
}
|
|
}
|