-
Notifications
You must be signed in to change notification settings - Fork 0
/
tls_test.go
54 lines (48 loc) · 2.13 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package hyper
import (
"encoding/base64"
"testing"
)
func TestGetKeyPair(t *testing.T) {
expectedCert := "MIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAwDgYDVQQKEwdBY21lIENvMB4XDTE3MTAyM" +
"DE5NDMwNloXDTE4MTAyMDE5NDMwNlowEjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABD0d7VNhb" +
"WvZLWPuj/RtHFjvtJBEwOkhbN/BnnE8rnZR8+sbwnc/KhCk3FhnpHZnQz7B5aETbbIgmuvewdjvSBSjYzBhMA4GA1UdDwEB/wQEA" +
"wICpDATBgNVHSUEDDAKBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdEQQiMCCCDmxvY2FsaG9zdDo1NDUzgg4xMjcuM" +
"C4wLjE6NTQ1MzAKBggqhkjOPQQDAgNIADBFAiEA2zpJEPQyz6/lWf86aX6PepsntZv2GYlA5UpabfT2EZICICpJ5h/iI+i341gBm" +
"LiAFQOyTDT+/wQc6MF9+Yw1Yy0t"
var certManager = environmentTLS{
EnvironmentTLSOpts{
TLSCert: "t_cert",
TLSCertBlockType: "t_cert_block",
TLSKey: "t_key",
TLSKeyBlockType: "t_key_block",
},
}
getenv = func(key string) string {
switch key {
case certManager.env.TLSCert:
return "MIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAwDgYDVQQKEwdBY21lIENvMB4XDTE3MTAyM" +
"DE5NDMwNloXDTE4MTAyMDE5NDMwNlowEjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABD0d7VNhb" +
"WvZLWPuj/RtHFjvtJBEwOkhbN/BnnE8rnZR8+sbwnc/KhCk3FhnpHZnQz7B5aETbbIgmuvewdjvSBSjYzBhMA4GA1UdDwEB/wQEA" +
"wICpDATBgNVHSUEDDAKBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdEQQiMCCCDmxvY2FsaG9zdDo1NDUzgg4xMjcuM" +
"C4wLjE6NTQ1MzAKBggqhkjOPQQDAgNIADBFAiEA2zpJEPQyz6/lWf86aX6PepsntZv2GYlA5UpabfT2EZICICpJ5h/iI+i341gBm" +
"LiAFQOyTDT+/wQc6MF9+Yw1Yy0t"
case certManager.env.TLSCertBlockType:
return "CERTIFICATE"
case certManager.env.TLSKey:
return "MHcCAQEEIIrYSSNQFaA2Hwf1duRSxKtLYX5CB04fSeQ6tF1aY/PuoAoGCCqGSM49AwEHoUQDQgAEPR3tU2Fta9ktY+6P9G0cW" +
"O+0kETA6SFs38GecTyudlHz6xvCdz8qEKTcWGekdmdDPsHloRNtsiCa697B2O9IFA=="
case certManager.env.TLSKeyBlockType:
return "EC PRIVATE KEY"
default:
return ""
}
}
cfg, err := certManager.from()
if err != nil {
t.Fatal(err)
}
if cert := base64.StdEncoding.EncodeToString(cfg.Certificates[0].Certificate[0]); cert != expectedCert {
t.Errorf("Expected cert should be:\n %s\n instead of:\n%s\n", expectedCert, cert)
}
}