...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package cert_test
16
17 import (
18 "testing"
19
20 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/webhook/cert/generator"
21 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/webhook/cert/writer"
22
23 "k8s.io/client-go/util/cert"
24 )
25
26 const COMMON_NAME = "foo.example.com"
27
28
29
30
31
32
33
34 func TestDoesCertificateWorkWithKubernetes(t *testing.T) {
35 certConfig := cert.Config{CommonName: COMMON_NAME}
36 privateKey, err := generator.NewPrivateKey()
37 if err != nil {
38 t.Fatalf("error when creating a private key: %s", err)
39 }
40 cert, err := generator.NewSelfSignedCACert(certConfig, privateKey)
41 if err != nil {
42 t.Fatalf("error when creating a new-style certificate: %s", err)
43 }
44 if !writer.DoesCertificateWorkWithK8sAPIClient(cert) {
45 t.Fatalf("writer detected a new-style certificate is invalid. This implies" +
46 "that newly generated certificates may not be compatible with all versions" +
47 "of the Kubernetes HTTP client")
48 }
49 cert.DNSNames = nil
50 if writer.DoesCertificateWorkWithK8sAPIClient(cert) {
51 t.Fatalf("DoesCertificateWorkWithK8sAPIClient recognized an invalid cert as valid.")
52 }
53 }
54
View as plain text