github.com/openshift/installer@v1.4.17/pkg/asset/imagebased/configimage/cabundle_test.go (about) 1 package configimage 2 3 import ( 4 "bytes" 5 "context" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 10 "github.com/openshift/installer/pkg/asset" 11 "github.com/openshift/installer/pkg/asset/tls" 12 ) 13 14 func TestCaBundle_Generate(t *testing.T) { 15 expectedBundleRaw := bytes.Join([][]byte{ 16 lbCABundle().BundleRaw, 17 localhostCABundle().BundleRaw, 18 serviceNetworkCABundle().BundleRaw, 19 ingressCABundle().BundleRaw, 20 }, []byte{}) 21 22 cases := []struct { 23 name string 24 dependencies []asset.Asset 25 expected *tls.CertBundle 26 }{ 27 { 28 name: "valid dependencies", 29 dependencies: []asset.Asset{ 30 lbCABundle(), 31 localhostCABundle(), 32 serviceNetworkCABundle(), 33 ingressCABundle(), 34 }, 35 expected: &tls.CertBundle{ 36 BundleRaw: expectedBundleRaw, 37 FileList: []*asset.File{ 38 { 39 Filename: "tls/kube-apiserver-complete-server-ca-bundle.crt", 40 Data: expectedBundleRaw, 41 }, 42 }, 43 }, 44 }, 45 } 46 for _, tc := range cases { 47 t.Run(tc.name, func(t *testing.T) { 48 parents := asset.Parents{} 49 parents.Add(tc.dependencies...) 50 51 asset := &ImageBasedKubeAPIServerCompleteCABundle{} 52 err := asset.Generate(context.TODO(), parents) 53 assert.NoError(t, err) 54 assert.Equal(t, string(tc.expected.BundleRaw), string(asset.CertBundle.BundleRaw)) 55 assert.Equal(t, tc.expected.FileList, asset.CertBundle.FileList) 56 }) 57 } 58 } 59 60 func lbCABundle() *tls.KubeAPIServerLBCABundle { 61 return &tls.KubeAPIServerLBCABundle{ 62 CertBundle: tls.CertBundle{ 63 BundleRaw: []byte(testCert), 64 }, 65 } 66 } 67 68 func localhostCABundle() *tls.KubeAPIServerLocalhostCABundle { 69 return &tls.KubeAPIServerLocalhostCABundle{ 70 CertBundle: tls.CertBundle{ 71 BundleRaw: []byte(testCert), 72 }, 73 } 74 } 75 76 func serviceNetworkCABundle() *tls.KubeAPIServerServiceNetworkCABundle { 77 return &tls.KubeAPIServerServiceNetworkCABundle{ 78 CertBundle: tls.CertBundle{ 79 BundleRaw: []byte(testCert), 80 }, 81 } 82 } 83 84 func ingressCABundle() *IngressOperatorCABundle { 85 return &IngressOperatorCABundle{ 86 CertBundle: tls.CertBundle{ 87 BundleRaw: []byte(testCert), 88 }, 89 } 90 }