-
Notifications
You must be signed in to change notification settings - Fork 1
/
cert_test.go
30 lines (27 loc) · 897 Bytes
/
cert_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
package godot_web
import (
"crypto/x509"
"testing"
)
func TestGenerateSelfSignedCertificate(t *testing.T) {
cert, err := generateSelfSignedCertificate("192.168.0.100")
if err != nil {
t.Errorf("generateSelfSignedCertificate() returned unwanted error: %v", err)
}
if len(cert.Certificate) != 1 {
t.Errorf("generateSelfSignedCertificate() wanted Certificate length 1, got %v",
len(cert.Certificate))
}
parsed, err := x509.ParseCertificate(cert.Certificate[0])
if err != nil {
t.Errorf("generateSelfSignedCertificate() returned unparseable certificate: %v", err)
}
expectedCommon := "192.168.0.100"
if parsed.Subject.CommonName != expectedCommon {
t.Errorf("generateSelfSignedCertificate() wanted CommonName %q, got %q",
expectedCommon, parsed.Subject.CommonName)
}
if !parsed.IsCA {
t.Errorf("generateSelfSignedCertificate() wanted IsCA = true, but was false")
}
}