| index 78ee520..b8b0b12 100644 |
| --- a/transport_test.go |
| +++ b/transport_test.go |
| @@ -2,6 +2,8 @@ package suite |
| |
| import ( |
| "context" |
| + "crypto/tls" |
| + "crypto/x509" |
| "net" |
| "net/http" |
| "net/http/httptest" |
| @@ -123,11 +125,11 @@ func TestSiblingClientRefusesAFixtureRedirect(t *testing.T) { |
| f := loadHostileHosts(t) |
| |
| // A server that answers every request with a redirect to another team. |
| - srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| http.Redirect(w, r, "http://"+f.Redirect.To+"/suite/s3/doc-1", http.StatusFound) |
| })) |
| defer srv.Close() |
| - srvAddr := strings.TrimPrefix(srv.URL, "http://") |
| + srvAddr := strings.TrimPrefix(srv.URL, "https://") |
| |
| // Every name resolves to the test server, so the only thing stopping a |
| // second hop is the client's own refusal — not the absence of a host. |
| @@ -138,13 +140,20 @@ func TestSiblingClientRefusesAFixtureRedirect(t *testing.T) { |
| } |
| |
| c := NewSiblingClient(f.Team, dial) |
| - resp, err := c.Get("http://" + f.Redirect.From + "/suite/s3/doc-1") |
| + roots := x509.NewCertPool() |
| + roots.AddCert(srv.Certificate()) |
| + c.Transport.(*teamBoundTransport).next.(*http.Transport).TLSClientConfig = &tls.Config{ |
| + RootCAs: roots, ServerName: srv.Certificate().DNSNames[0], |
| + } |
| + resp, err := c.Get("https://" + f.Redirect.From + "/suite/s3/doc-1") |
| if resp != nil { |
| resp.Body.Close() |
| } |
| |
| if err == nil { |
| t.Error("got nil error following a redirect to another team, want a refusal") |
| + } else if !strings.Contains(err.Error(), "refusing to follow a redirect") { |
| + t.Errorf("request failed before reaching the redirect: %v", err) |
| } |
| if len(dialed) != 1 { |
| t.Fatalf("dialled %v, want exactly one hop — the allowed host, and no follow-up", dialed) |