-
Notifications
You must be signed in to change notification settings - Fork 8
fix(ts2021): document and verify control-protocol upgrade handling #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,13 +268,20 @@ func TestBuildMainHandlerRewritesResponses(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestTS2021HandlerUsesInjectedDialer(t *testing.T) { | ||
| func TestTS2021HandlerPreservesMethodAndUpgradeHeaders(t *testing.T) { | ||
| withProxyTestGlobals(t) | ||
|
|
||
| var receivedMethod string | ||
| var receivedConnection string | ||
| var receivedUpgrade string | ||
|
|
||
| backend := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if r.URL.Path != "/ts2021" { | ||
| t.Fatalf("backend path = %q, want /ts2021", r.URL.Path) | ||
| } | ||
| receivedMethod = r.Method | ||
| receivedConnection = r.Header.Get("Connection") | ||
| receivedUpgrade = r.Header.Get("Upgrade") | ||
|
Comment on lines
+282
to
+284
|
||
| w.Header().Set("X-Upstream", "local-fake") | ||
| _, _ = w.Write([]byte("controlplane ok")) | ||
| })) | ||
|
Comment on lines
285
to
287
|
||
|
|
@@ -289,7 +296,14 @@ func TestTS2021HandlerUsesInjectedDialer(t *testing.T) { | |
| proxy := httptest.NewServer(buildMainHandler(nil)) | ||
| t.Cleanup(proxy.Close) | ||
|
|
||
| resp, err := proxy.Client().Get(proxy.URL + "/ts2021") | ||
| req, err := http.NewRequest(http.MethodPost, proxy.URL+"/ts2021", nil) | ||
| if err != nil { | ||
| t.Fatalf("new request: %v", err) | ||
| } | ||
| req.Header.Set("Connection", "upgrade") | ||
| req.Header.Set("Upgrade", "tailscale-control-protocol") | ||
|
|
||
| resp, err := proxy.Client().Do(req) | ||
| if err != nil { | ||
| t.Fatalf("ts2021 request: %v", err) | ||
| } | ||
|
|
@@ -304,6 +318,15 @@ func TestTS2021HandlerUsesInjectedDialer(t *testing.T) { | |
| if body := readBody(t, resp.Body); body != "controlplane ok" { | ||
| t.Fatalf("body = %q, want controlplane ok", body) | ||
| } | ||
| if receivedMethod != http.MethodPost { | ||
| t.Fatalf("backend method = %q, want POST", receivedMethod) | ||
| } | ||
| if receivedConnection != "upgrade" { | ||
| t.Fatalf("backend Connection = %q, want upgrade", receivedConnection) | ||
| } | ||
| if receivedUpgrade != "tailscale-control-protocol" { | ||
| t.Fatalf("backend Upgrade = %q, want tailscale-control-protocol", receivedUpgrade) | ||
| } | ||
| } | ||
|
|
||
| func TestTS2021HandlerReturnsBadGatewayOnDialFailure(t *testing.T) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README now refers to the project as "ProxyT" here, but nearby text still uses "Proxyt" to refer to the same thing. Please standardize the product name throughout this document (and reserve
proxytfor the CLI command) to avoid confusing readers.