mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-09 23:27:43 +02:00
config: generate derived certificates instead of self-signed certificates (#3860)
This commit is contained in:
parent
488bcd6f72
commit
3f1a87727f
5 changed files with 151 additions and 84 deletions
|
@ -1,69 +1,12 @@
|
|||
package cryptutil
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetCertificateForServerName(t *testing.T) {
|
||||
gen := func(t *testing.T, serverName string) *tls.Certificate {
|
||||
cert, err := GenerateSelfSignedCertificate(serverName)
|
||||
if !assert.NoError(t, err, "error generating certificate for: %s", serverName) {
|
||||
t.FailNow()
|
||||
}
|
||||
return cert
|
||||
}
|
||||
|
||||
t.Run("exact match", func(t *testing.T) {
|
||||
certs := []tls.Certificate{
|
||||
*gen(t, "a.example.com"),
|
||||
*gen(t, "b.example.com"),
|
||||
}
|
||||
|
||||
found, err := GetCertificateForServerName(certs, "b.example.com")
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, &certs[1], found)
|
||||
})
|
||||
t.Run("wildcard match", func(t *testing.T) {
|
||||
certs := []tls.Certificate{
|
||||
*gen(t, "a.example.com"),
|
||||
*gen(t, "*.example.com"),
|
||||
}
|
||||
|
||||
found, err := GetCertificateForServerName(certs, "b.example.com")
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, &certs[1], found)
|
||||
})
|
||||
t.Run("no name match", func(t *testing.T) {
|
||||
certs := []tls.Certificate{
|
||||
*gen(t, "a.example.com"),
|
||||
}
|
||||
|
||||
found, err := GetCertificateForServerName(certs, "b.example.com")
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.NotNil(t, found)
|
||||
assert.NotEqual(t, &certs[0], found)
|
||||
})
|
||||
t.Run("generate", func(t *testing.T) {
|
||||
certs := []tls.Certificate{}
|
||||
|
||||
found, err := GetCertificateForServerName(certs, "b.example.com")
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.NotNil(t, found)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetCertificateServerNames(t *testing.T) {
|
||||
cert, err := GenerateSelfSignedCertificate("www.example.com")
|
||||
require.NoError(t, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue