summaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authorShayne Sweeney <shayne@tailscale.com>2022-11-20 12:02:47 -0500
committerShayne Sweeney <shayne@tailscale.com>2022-11-20 12:56:12 -0500
commit1ceaabbc7b5ded52d02ae01f9c89a47c8a4db922 (patch)
tree7ff484fedcf191e4fa3be292ac201c504db406fc /cmd
parent538f431d5d9eda4d40d07f346eca7f9eaf3d9869 (diff)
downloadtailscale-shayne/serve_empty_text_handler.tar.xz
tailscale-shayne/serve_empty_text_handler.zip
cmd/tailscale/cli: allow empty text ("") serveshayne/serve_empty_text_handler
Current behavior is broken. `tailscale serve text / ""` returns no error and shows up in `tailscale serve status` but requests return a 500 "empty handler". The commit changes the handler field `Text` to type of `*string`. Closes #6405 Signed-off-by: Shayne Sweeney <shayne@tailscale.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/tailscale/cli/cli.go6
-rw-r--r--cmd/tailscale/cli/serve.go6
-rw-r--r--cmd/tailscale/cli/serve_test.go6
-rw-r--r--cmd/tailscale/cli/set_test.go2
4 files changed, 12 insertions, 8 deletions
diff --git a/cmd/tailscale/cli/cli.go b/cmd/tailscale/cli/cli.go
index 6845cbd93..cbe937588 100644
--- a/cmd/tailscale/cli/cli.go
+++ b/cmd/tailscale/cli/cli.go
@@ -53,6 +53,12 @@ func outln(a ...any) {
fmt.Fprintln(Stdout, a...)
}
+// ptrTo returns a pointer to the provided value.
+// It's a convenience function to avoid having to write &value,
+// or where the language doesn't allow it.
+// Used primarily in tests.
+func ptrTo[T any](v T) *T { return &v }
+
// ActLikeCLI reports whether a GUI application should act like the
// CLI based on os.Args, GOOS, the context the process is running in
// (pty, parent PID), etc.
diff --git a/cmd/tailscale/cli/serve.go b/cmd/tailscale/cli/serve.go
index 402b64da5..cc455c90c 100644
--- a/cmd/tailscale/cli/serve.go
+++ b/cmd/tailscale/cli/serve.go
@@ -285,7 +285,7 @@ func (e *serveEnv) runServe(ctx context.Context, args []string) error {
}
h.Proxy = t
case "text":
- h.Text = args[2]
+ h.Text = ptrTo(args[2])
default:
fmt.Fprintf(os.Stderr, "error: unknown serve type %q\n\n", args[1])
return flag.ErrHelp
@@ -547,8 +547,8 @@ func printWebStatusTree(sc *ipn.ServeConfig, hp ipn.HostPort) {
return "path", h.Path
case h.Proxy != "":
return "proxy", h.Proxy
- case h.Text != "":
- return "text", "\"" + elipticallyTruncate(h.Text, 20) + "\""
+ case h.Text != nil:
+ return "text", "\"" + elipticallyTruncate(*h.Text, 20) + "\""
}
return "", ""
}
diff --git a/cmd/tailscale/cli/serve_test.go b/cmd/tailscale/cli/serve_test.go
index e3269b674..e526a54e8 100644
--- a/cmd/tailscale/cli/serve_test.go
+++ b/cmd/tailscale/cli/serve_test.go
@@ -151,7 +151,7 @@ func TestServeConfigMutations(t *testing.T) {
"/abc": {Proxy: "http://127.0.0.1:3001"},
}},
"foo.test.ts.net:10000": {Handlers: map[string]*ipn.HTTPHandler{
- "/": {Text: "hi"},
+ "/": {Text: ptrTo("hi")},
}},
},
},
@@ -314,7 +314,7 @@ func TestServeConfigMutations(t *testing.T) {
TCP: map[uint16]*ipn.TCPPortHandler{443: {HTTPS: true}},
Web: map[ipn.HostPort]*ipn.WebServerConfig{
"foo.test.ts.net:443": {Handlers: map[string]*ipn.HTTPHandler{
- "/": {Text: "hello"},
+ "/": {Text: ptrTo("hello")},
}},
},
},
@@ -547,7 +547,7 @@ func TestServeConfigMutations(t *testing.T) {
TCP: map[uint16]*ipn.TCPPortHandler{443: {HTTPS: true}},
Web: map[ipn.HostPort]*ipn.WebServerConfig{
"foo.test.ts.net:443": {Handlers: map[string]*ipn.HTTPHandler{
- "/tcp": {Text: "foo"},
+ "/tcp": {Text: ptrTo("foo")},
}},
},
},
diff --git a/cmd/tailscale/cli/set_test.go b/cmd/tailscale/cli/set_test.go
index 013896a4a..e7a7c45f1 100644
--- a/cmd/tailscale/cli/set_test.go
+++ b/cmd/tailscale/cli/set_test.go
@@ -13,8 +13,6 @@ import (
"tailscale.com/net/tsaddr"
)
-func ptrTo[T any](v T) *T { return &v }
-
func TestCalcAdvertiseRoutesForSet(t *testing.T) {
pfx := netip.MustParsePrefix
tests := []struct {