diff --git a/control/controlclient/auto_test.go b/control/controlclient/auto_test.go index e86995e1d..43d5f8180 100644 --- a/control/controlclient/auto_test.go +++ b/control/controlclient/auto_test.go @@ -7,12 +7,14 @@ package controlclient import ( + "bytes" "context" "encoding/json" "fmt" "io/ioutil" "log" "net/http" + "net/http/cookiejar" "net/http/httptest" "net/url" "os" @@ -310,25 +312,7 @@ func TestControl(t *testing.T) { c1.Login(nil, LoginInteractive) status := c1.waitStatus(t, stateURLVisitRequired) - authURL := status.New.URL - - resp, err := c1.httpc.Get(authURL) - if err != nil { - t.Fatal(err) - } - if resp.StatusCode != 200 { - t.Errorf("GET %s failed: %q", authURL, resp.Status) - } - body, err := ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - t.Fatal(err) - } - cookies := resp.Cookies() - if len(cookies) == 0 || cookies[0].Name != "tailcontrol" { - t.Logf("GET %s: %s", authURL, string(body)) - t.Fatalf("GET %s: bad cookie: %v", authURL, cookies) - } + c1.postAuthURL(t, "testuser1@tailscale.com", status.New) c1.waitStatus(t, stateAuthenticated) status = c1.waitStatus(t, stateSynchronized) if status.New.Err != "" { @@ -443,8 +427,8 @@ func TestLoginInterrupt(t *testing.T) { t.Errorf("auth URLs match for subsequent logins: %s", authURL) } - form := url.Values{"user": []string{loginName}} - req, err := http.NewRequest("POST", authURL2, strings.NewReader(form.Encode())) + // Direct auth URL visit is not enough because our cookie is no longer fresh. + req, err := http.NewRequest("GET", authURL2, nil) if err != nil { t.Fatal(err) } @@ -453,10 +437,37 @@ func TestLoginInterrupt(t *testing.T) { if err != nil { t.Fatal(err) } + b, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Fatal(err) + } + resp.Body.Close() + if i := bytes.Index(b, []byte("
header + b = b[i:] + } + if !bytes.Contains(b, []byte("