MCPcopy
hub / github.com/tailscale/tailscale / TestDebuggerHandle

Function TestDebuggerHandle

tsweb/debug_test.go:132–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

130}
131
132func TestDebuggerHandle(t *testing.T) {
133 mux := http.NewServeMux()
134 dbg := Debugger(mux)
135 dbg.Handle("check", "Consistency check", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
136 fmt.Fprintf(w, "Test output %v", r.RemoteAddr)
137 }))
138
139 code, body := get(mux, "/debug/", tsIP)
140 if code != 200 {
141 t.Fatalf("debug access failed, got %v", code)
142 }
143 for _, want := range []string{"/debug/check", "Consistency check"} {
144 if !strings.Contains(body, want) {
145 t.Errorf("want %q in output, not found", want)
146 }
147 }
148
149 code, _ = get(mux, "/debug/check", pubIP)
150 if code != 403 {
151 t.Fatal("/debug/check should be protected, but isn't")
152 }
153
154 code, body = get(mux, "/debug/check", tsIP)
155 if code != 200 {
156 t.Fatal("/debug/check denied debug access")
157 }
158 want := "Test output " + tsIP
159 if !strings.Contains(body, want) {
160 t.Errorf("want %q in output, not found", want)
161 }
162}
163
164func ExampleDebugHandler_Handle() {
165 mux := http.NewServeMux()

Callers

nothing calls this directly

Calls 7

DebuggerFunction · 0.70
getFunction · 0.70
HandleMethod · 0.65
FatalfMethod · 0.65
ErrorfMethod · 0.65
FatalMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…