Skip to content

Commit

Permalink
Merge pull request #75 from kaleido-io/fix_intermitten_test
Browse files Browse the repository at this point in the history
fix: intermittent tls server test
  • Loading branch information
peterbroadhurst authored Jun 26, 2023
2 parents 6815651 + 2fa0534 commit 17b0710
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/ffresty/ffresty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ func TestMTLSClientWithServer(t *testing.T) {

// Create a Server instance to listen on port 8443 with the TLS config
server := &http.Server{
Addr: "127.0.0.1:8443",
TLSConfig: tlsConfig,
}

Expand All @@ -321,13 +320,20 @@ func TestMTLSClientWithServer(t *testing.T) {
}
}()

go server.ListenAndServeTLS(publicKeyFile.Name(), privateKeyFile.Name())
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Fatal(err)
}

defer ln.Close()

go server.ServeTLS(ln, publicKeyFile.Name(), privateKeyFile.Name())

// Use ffresty to test the mTLS client as well
var restyConfig = config.RootSection("resty")
InitConfig(restyConfig)
clientTLSSection := restyConfig.SubSection("tls")
restyConfig.Set(HTTPConfigURL, "https://127.0.0.1")
restyConfig.Set(HTTPConfigURL, ln.Addr())
clientTLSSection.Set(fftls.HTTPConfTLSEnabled, true)
clientTLSSection.Set(fftls.HTTPConfTLSKeyFile, privateKeyFile.Name())
clientTLSSection.Set(fftls.HTTPConfTLSCertFile, publicKeyFile.Name())
Expand All @@ -336,8 +342,9 @@ func TestMTLSClientWithServer(t *testing.T) {
c, err := New(context.Background(), restyConfig)
assert.Nil(t, err)

//httpsAddr := fmt.Sprintf("https://localhost:8443/hello", server.Addr)
res, err := c.R().Get("https://127.0.0.1:8443/hello")
httpsAddr := fmt.Sprintf("https://%s/hello", ln.Addr())
fmt.Println(httpsAddr)
res, err := c.R().Get(httpsAddr)
assert.NoError(t, err)

assert.NoError(t, err)
Expand Down

0 comments on commit 17b0710

Please sign in to comment.