Skip to content

Commit

Permalink
Add tests against the tls connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Gilmer authored and Lee Hicks committed Oct 4, 2019
1 parent 8a69866 commit 93f829e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pkg/server/server_test.go
Expand Up @@ -217,29 +217,43 @@ func (suite *serverSuite) TestTLSConfigWithRequest() {
Logger: suite.logger,
Certificates: []tls.Certificate{keyPair},
})
suite.Nil(err)
defer srv.Close()
suite.Nil(err)

// Start the Server
go srv.ListenAndServeTLS()

// Send a request
config := tls.Config{
RootCAs: caCertPool,
Certificates: []tls.Certificate{keyPair},
}
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: caCertPool,
Certificates: []tls.Certificate{keyPair},
},
TLSClientConfig: &config,
},
}
res, err := client.Get(fmt.Sprintf("https://%s:%d", host, port))
suite.Nil(err)

// Read the response
if res != nil {
body, err := ioutil.ReadAll(res.Body)
body, bodyErr := ioutil.ReadAll(res.Body)
res.Body.Close()
suite.Nil(err)
suite.Nil(bodyErr)
suite.Equal(htmlBody+"\n", string(body))
}

// Check the connection
conn, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", host, port), &config)
defer conn.Close()
suite.Nil(err)

connState := conn.ConnectionState()
suite.Equal(tls.VersionTLS12, int(connState.Version))
suite.True(connState.HandshakeComplete)
suite.False(connState.DidResume)
suite.Equal("", connState.NegotiatedProtocol)
suite.True(connState.NegotiatedProtocolIsMutual)
suite.Equal("", connState.ServerName)
}

0 comments on commit 93f829e

Please sign in to comment.