99 "testing"
1010 "time"
1111
12+ "github.com/google/uuid"
1213 "github.com/kong/go-kong/kong"
1314 "github.com/kong/kubernetes-testing-framework/pkg/clusters"
1415 "github.com/kong/kubernetes-testing-framework/pkg/utils/kubernetes/generators"
@@ -27,6 +28,7 @@ import (
2728 "github.com/kong/kong-operator/ingress-controller/internal/util"
2829 "github.com/kong/kong-operator/ingress-controller/test"
2930 "github.com/kong/kong-operator/ingress-controller/test/consts"
31+ "github.com/kong/kong-operator/ingress-controller/test/helpers/certificate"
3032 "github.com/kong/kong-operator/ingress-controller/test/internal/helpers"
3133 testutils "github.com/kong/kong-operator/ingress-controller/test/util"
3234 "github.com/kong/kong-operator/pkg/clientset"
@@ -50,6 +52,38 @@ func TestTranslationFailures(t *testing.T) {
5052 // that we expect translation failure warning events to be created for.
5153 translationFailureTrigger func (t * testing.T , cleaner * clusters.Cleaner , ns string ) expectedTranslationFailure
5254 }{
55+ {
56+ name : "CA secret with multiple PEMs" ,
57+ translationFailureTrigger : func (t * testing.T , cleaner * clusters.Cleaner , ns string ) expectedTranslationFailure {
58+ createdSecret , err := env .Cluster ().Client ().CoreV1 ().Secrets (ns ).Create (ctx , multiPEMCASecret (ns , uuid .NewString ()), metav1.CreateOptions {})
59+ require .NoError (t , err )
60+ cleaner .Add (createdSecret )
61+
62+ return expectedTranslationFailure {
63+ causingObjects : []client.Object {createdSecret },
64+ reasonContains : "multiple PEM certificates found" ,
65+ }
66+ },
67+ },
68+ {
69+ name : "CA secret with multiple PEMs referred by a plugin" ,
70+ translationFailureTrigger : func (t * testing.T , cleaner * clusters.Cleaner , ns string ) expectedTranslationFailure {
71+ createdSecret , err := env .Cluster ().Client ().CoreV1 ().Secrets (ns ).Create (ctx , multiPEMCASecret (ns , invalidCASecretID ), metav1.CreateOptions {})
72+ require .NoError (t , err )
73+ cleaner .Add (createdSecret )
74+
75+ c , err := clientset .NewForConfig (env .Cluster ().Config ())
76+ require .NoError (t , err )
77+ createdPlugin , err := c .ConfigurationV1 ().KongPlugins (ns ).Create (ctx , pluginUsingInvalidCACert (ns ), metav1.CreateOptions {})
78+ require .NoError (t , err )
79+ cleaner .Add (createdPlugin )
80+
81+ return expectedTranslationFailure {
82+ causingObjects : []client.Object {createdSecret , createdPlugin },
83+ reasonContains : "multiple PEM certificates found" ,
84+ }
85+ },
86+ },
5387 {
5488 name : "invalid CA secret" ,
5589 translationFailureTrigger : func (t * testing.T , cleaner * clusters.Cleaner , ns string ) expectedTranslationFailure {
@@ -362,6 +396,34 @@ func invalidCASecret(ns string) *corev1.Secret {
362396 }
363397}
364398
399+ func multiPEMCASecret (ns , id string ) * corev1.Secret {
400+ ca1 , _ := certificate .MustGenerateCertPEMFormat (
401+ certificate .WithCommonName ("test-ca-1" ),
402+ certificate .WithCATrue (),
403+ )
404+ ca2 , _ := certificate .MustGenerateCertPEMFormat (
405+ certificate .WithCommonName ("test-ca-2" ),
406+ certificate .WithCATrue (),
407+ )
408+
409+ return & corev1.Secret {
410+ ObjectMeta : metav1.ObjectMeta {
411+ Name : testutils .RandomName (testTranslationFailuresObjectsPrefix ),
412+ Namespace : ns ,
413+ Labels : map [string ]string {
414+ "konghq.com/ca-cert" : "true" ,
415+ },
416+ Annotations : map [string ]string {
417+ annotations .IngressClassKey : consts .IngressClass ,
418+ },
419+ },
420+ StringData : map [string ]string {
421+ "id" : id ,
422+ "cert" : string (ca1 ) + string (ca2 ),
423+ },
424+ }
425+ }
426+
365427func pluginUsingInvalidCACert (ns string ) * configurationv1.KongPlugin {
366428 return & configurationv1.KongPlugin {
367429 ObjectMeta : metav1.ObjectMeta {
0 commit comments