forked from ortuman/jackal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtls_test.go
35 lines (30 loc) · 905 Bytes
/
tls_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Copyright (c) 2018 Miguel Ángel Ortuño.
* See the LICENSE file for more information.
*/
package util
import (
"crypto/tls"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestLoadCertificate(t *testing.T) {
t.Run("Valid", func(t *testing.T) {
tlsCfg, err := LoadCertificate("../testdata/cert/test.server.key", "../testdata/cert/test.server.crt", "localhost")
require.Nil(t, err)
require.NotNil(t, tlsCfg)
})
t.Run("SelfSigned", func(t *testing.T) {
defer os.RemoveAll(".cert/")
tlsCfg, err := LoadCertificate("", "", "localhost")
require.Nil(t, err)
require.NotNil(t, tlsCfg)
})
t.Run("Failed", func(t *testing.T) {
cer, err := LoadCertificate("", "", "jackal.im")
require.Equal(t, tls.Certificate{}, cer)
require.NotNil(t, err)
require.Equal(t, "must specify a private key and a server certificate for the domain 'jackal.im'", err.Error())
})
}