Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
1.2 KiB

package connect
import (
"crypto/tls"
"testing"
"github.com/stretchr/testify/require"
)
func TestReloadableTLSConfig(t *testing.T) {
base := TestTLSConfig(t, "ca1", "web")
c := NewReloadableTLSConfig(base)
a := &TestAuther{
Return: nil,
}
// The dynamic config should be the one we loaded, but with the passed auther
expect := base
expect.VerifyPeerCertificate = a.Auth
require.Equal(t, base, c.TLSConfig(a))
// The server config should return same too for new connections
serverCfg := c.ServerTLSConfig()
require.NotNil(t, serverCfg.GetConfigForClient)
got, err := serverCfg.GetConfigForClient(&tls.ClientHelloInfo{})
require.Nil(t, err)
require.Equal(t, base, got)
// Now change the config as if we just rotated to a new CA
new := TestTLSConfig(t, "ca2", "web")
err = c.SetTLSConfig(new)
require.Nil(t, err)
// The dynamic config should be the one we loaded (with same auther due to nil)
require.Equal(t, new, c.TLSConfig(nil))
// The server config should return same too for new connections
serverCfg = c.ServerTLSConfig()
require.NotNil(t, serverCfg.GetConfigForClient)
got, err = serverCfg.GetConfigForClient(&tls.ClientHelloInfo{})
require.Nil(t, err)
require.Equal(t, new, got)
}