Skip to content

Commit

Permalink
Set up TLS for TestDefaultClientRejectSelfSigned
Browse files Browse the repository at this point in the history
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 5642c3e
  • Loading branch information
tgross committed Nov 14, 2016
1 parent b96ab9f commit c7917be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 10 additions & 3 deletions http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

httpsuite "github.com/joyent/gocommon/testing"
"github.com/joyent/gosign/auth"
"github.com/julienschmidt/httprouter"
)

const (
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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{}
Expand Down
9 changes: 4 additions & 5 deletions testing/httpsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

jt "github.com/joyent/gocommon/testing"
"github.com/julienschmidt/httprouter"
)

type HTTPTestSuite struct {
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit c7917be

Please sign in to comment.