From c7917be01e258eb5a57795cff50ff807f1056312 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Mon, 14 Nov 2016 16:23:11 -0500 Subject: [PATCH] Set up TLS for TestDefaultClientRejectSelfSigned In a previous commit we accidentally removed the setup of the TLS test suite which is used to verify the client behavior on self-signed TLS cert. This restores the correct behavior by splitting out a second test suite. previous ref 5642c3e463b246197f7019a0eaae2441b36843ef --- http/client_test.go | 13 ++++++++++--- testing/httpsuite_test.go | 9 ++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/http/client_test.go b/http/client_test.go index 55d2f7e..53c8d02 100644 --- a/http/client_test.go +++ b/http/client_test.go @@ -10,6 +10,7 @@ import ( httpsuite "github.com/joyent/gocommon/testing" "github.com/joyent/gosign/auth" + "github.com/julienschmidt/httprouter" ) const ( @@ -66,7 +67,7 @@ func (s *LoopingHTTPSuite) SetUpSuite(c *gc.C) { func (s *LoopingHTTPSuite) setupLoopbackRequest() (*http.Header, chan string, *Client) { var headers http.Header bodyChan := make(chan string, 1) - handler := func(resp http.ResponseWriter, req *http.Request) { + handler := func(resp http.ResponseWriter, req *http.Request, _ httprouter.Params) { headers = req.Header bodyBytes, _ := ioutil.ReadAll(req.Body) req.Body.Close() @@ -75,7 +76,7 @@ func (s *LoopingHTTPSuite) setupLoopbackRequest() (*http.Header, chan string, *C resp.WriteHeader(http.StatusNoContent) resp.Write([]byte{}) } - s.Mux.HandleFunc("/", handler) + s.Mux.POST("/", handler) client := New(s.creds, "", nil) return &headers, bodyChan, client @@ -89,8 +90,14 @@ type HTTPSClientTestSuite struct { LoopingHTTPSuite } +func newTLSsuite() *HTTPSClientTestSuite { + suite := &HTTPSClientTestSuite{} + suite.UseTLS = true + return suite +} + var _ = gc.Suite(&HTTPClientTestSuite{}) -var _ = gc.Suite(&HTTPSClientTestSuite{}) +var _ = gc.Suite(newTLSsuite()) func (s *HTTPClientTestSuite) assertHeaderValues(c *gc.C, apiVersion string) { emptyHeaders := http.Header{} diff --git a/testing/httpsuite_test.go b/testing/httpsuite_test.go index 60e31e1..c93e723 100644 --- a/testing/httpsuite_test.go +++ b/testing/httpsuite_test.go @@ -11,6 +11,7 @@ import ( "testing" jt "github.com/joyent/gocommon/testing" + "github.com/julienschmidt/httprouter" ) type HTTPTestSuite struct { @@ -28,16 +29,14 @@ func Test(t *testing.T) { var _ = gc.Suite(&HTTPTestSuite{}) var _ = gc.Suite(&HTTPSTestSuite{jt.HTTPSuite{UseTLS: true}}) -type HelloHandler struct{} - -func (h *HelloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { +func HelloHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(200) w.Write([]byte("Hello World\n")) } func (s *HTTPTestSuite) TestHelloWorld(c *gc.C) { - s.Mux.Handle("/", &HelloHandler{}) + s.Mux.GET("/", HelloHandler) response, err := http.Get(s.Server.URL) c.Check(err, gc.IsNil) content, err := ioutil.ReadAll(response.Body) @@ -49,7 +48,7 @@ func (s *HTTPTestSuite) TestHelloWorld(c *gc.C) { } func (s *HTTPSTestSuite) TestHelloWorldWithTLS(c *gc.C) { - s.Mux.Handle("/", &HelloHandler{}) + s.Mux.GET("/", HelloHandler) c.Check(s.Server.URL[:8], gc.Equals, "https://") response, err := http.Get(s.Server.URL) // Default http.Get fails because the cert is self-signed