Skip to content

Commit

Permalink
Minor test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmcconnell committed Oct 2, 2024
1 parent 3660f64 commit f62b983
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions internal/server/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -35,23 +36,9 @@ func TestCertificateLoading(t *testing.T) {

cert, err := manager.GetCertificate(&tls.ClientHelloInfo{})
require.NoError(t, err)
require.NotNil(t, cert)
}

func TestCertificateLoadingRaceCondition(t *testing.T) {
certPath, keyPath := prepareTestCertificateFiles(t)

manager, err := NewStaticCertManager(certPath, keyPath)
require.NoError(t, err)

go func() {
_, err2 := manager.GetCertificate(&tls.ClientHelloInfo{})
require.NoError(t, err2)
}()

cert, err := manager.GetCertificate(&tls.ClientHelloInfo{})
require.NoError(t, err)
require.NotNil(t, cert)
assert.Equal(t, cert.Leaf.Issuer.Organization, []string{"Acme Co"})
assert.Nil(t, cert.Leaf.VerifyHostname("localhost:5453"))
}

func TestErrorWhenFileDoesNotExist(t *testing.T) {
Expand All @@ -62,10 +49,12 @@ func TestErrorWhenFileDoesNotExist(t *testing.T) {
func TestErrorWhenKeyFormatIsInvalid(t *testing.T) {
certPath, keyPath := prepareTestCertificateFiles(t)

_, err := NewStaticCertManager(keyPath, certPath)
_, err := NewStaticCertManager(keyPath, certPath) // swapped paths
require.ErrorContains(t, err, "unable to load certificate")
}

// Helpers

func prepareTestCertificateFiles(t *testing.T) (string, string) {
t.Helper()

Expand Down

0 comments on commit f62b983

Please sign in to comment.