diff --git a/internal/controller/operator/eventing/integrationtests/controller/integration_test.go b/internal/controller/operator/eventing/integrationtests/controller/integration_test.go index 9c1239e95..971d5c4a6 100644 --- a/internal/controller/operator/eventing/integrationtests/controller/integration_test.go +++ b/internal/controller/operator/eventing/integrationtests/controller/integration_test.go @@ -577,6 +577,123 @@ func Test_WatcherEventingCRK8sObjects(t *testing.T) { } } +func Test_EventMesh_MalformattedSecret(t *testing.T) { + testCases := []struct { + name string + givenSecretData map[string][]byte + wantMatcher gomegatypes.GomegaMatcher + }{ + { + name: "should have ready state when EventMesh secret is malformatted", + givenSecretData: map[string][]byte{ + "management": []byte("foo"), + "messaging": []byte(`[ + { + "broker": { + "type": "bar" + }, + "oa2": { + "clientid": "foo", + "clientsecret": "foo", + "granttype": "client_credentials", + "tokenendpoint": "bar" + }, + "protocol": [ + "amqp10ws" + ], + "uri": "foo" + }, + { + "broker": { + "type": "foo" + }, + "oa2": { + "clientid": "bar", + "clientsecret": "bar", + "granttype": "client_credentials", + "tokenendpoint": "foo" + }, + "protocol": [ + "bar" + ], + "uri": "bar" + }, + { + "broker": { + "type": "foo" + }, + "oa2": { + "clientid": "foo", + "clientsecret": "bar", + "granttype": "client_credentials", + "tokenendpoint": "foo" + }, + "protocol": [ + "httprest" + ], + "uri": "bar" + } + ]`), + "namespace": []byte("bar"), + "serviceinstanceid": []byte("foo"), + "xsappname": []byte("bar"), + }, + wantMatcher: gomega.And( + matchers.HaveStatusReady(), + ), + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + g := gomega.NewWithT(t) + + // Given: + // Make the Deployment always beeing ready. + eventingcontroller.IsDeploymentReady = func(deployment *kappsv1.Deployment) bool { + return true + } + + // Create an Eventing CR. We do not care about the details in this test. + givenEventingCR := utils.NewEventingCR( + utils.WithEventMeshBackend("test-secret-name"), + utils.WithEventingPublisherData(1, 1, "199m", "99Mi", "399m", "199Mi"), + utils.WithEventingEventTypePrefix("test-prefix"), + ) + + // Create an unique Namespace for this test run. + givenNamespace := givenEventingCR.Namespace + testEnvironment.EnsureNamespaceCreation(t, givenNamespace) + + // // Create an EventMesh Secret. This is the crucial part of the test; + // // if the Secret is malformatted, Eventing should have the warning status. + // // Frist we need to extract the Secret name and namespace from the given Eventing CR. + // subArray := strings.Split(givenEventingCR.Spec.Backend.Config.EventMeshSecret, "/") + // secretName, secretNameSpace := subArray[1], subArray[0] + // // Now we can assemble the Secret. + // secret := kcorev1.Secret{ + // ObjectMeta: kmetav1.ObjectMeta{ + // Name: secretName, + // Namespace: secretNameSpace, + // }, + // Data: tc.givenSecretData, + // Type: "Opaque", + // } + // // Finally, we create the Secret in the K8s cluster. + // testEnvironment.EnsureEventMeshSecretCreated(t, &secret) + testEnvironment.EnsureDefaultEventMeshSecretCreated(t, givenEventingCR) + + // When: + // Create the Eventing CR with the given EventMesh Secret. + testEnvironment.EnsureK8sResourceCreated(t, givenEventingCR) + + // Then: + // Check the Eventing CR status against the expected status. + testEnvironment.GetEventingAssert(g, givenEventingCR).Should(tc.wantMatcher) + }) + } +} + func Test_CreateEventingCR_EventMesh(t *testing.T) { testCases := []struct { name string @@ -662,8 +779,7 @@ func Test_CreateEventingCR_EventMesh(t *testing.T) { } // create unique namespace for this test run. - givenNamespace := testcase.givenEventing.Namespace - + givenNamespace := tc.givenEventing.Namespace testEnvironment.EnsureNamespaceCreation(t, givenNamespace) // create eventing-webhook-auth secret. @@ -671,7 +787,7 @@ func Test_CreateEventingCR_EventMesh(t *testing.T) { if !testcase.shouldEventMeshSecretNotFound { // create EventMesh secret. - testEnvironment.EnsureEventMeshSecretCreated(t, testcase.givenEventing) + testEnvironment.EnsureDefaultEventMeshSecretCreated(t, tc.givenEventing) } originalKubeClient := testEnvironment.KubeClient @@ -804,8 +920,8 @@ func Test_DeleteEventingCR(t *testing.T) { testEnvironment.EnsureNATSResourceStateReady(t, nats) } else { // create eventing-webhook-auth secret. - testEnvironment.EnsureOAuthSecretCreated(t, testcase.givenEventing) - testEnvironment.EnsureEventMeshSecretCreated(t, testcase.givenEventing) + testEnvironment.EnsureOAuthSecretCreated(t, tc.givenEventing) + testEnvironment.EnsureDefaultEventMeshSecretCreated(t, tc.givenEventing) } testEnvironment.EnsureK8sResourceCreated(t, testcase.givenEventing) @@ -936,7 +1052,7 @@ func Test_WatcherNATSResource(t *testing.T) { ) // create necessary EventMesh secrets testEnvironment.EnsureOAuthSecretCreated(t, eventingResource) - testEnvironment.EnsureEventMeshSecretCreated(t, eventingResource) + testEnvironment.EnsureDefaultEventMeshSecretCreated(t, eventingResource) } else { eventingResource = utils.NewEventingCR( utils.WithEventingCRNamespace(givenNamespace), diff --git a/internal/controller/operator/eventing/integrationtests/controllerswitching/integration_test.go b/internal/controller/operator/eventing/integrationtests/controllerswitching/integration_test.go index fbe2c4141..2b320036f 100644 --- a/internal/controller/operator/eventing/integrationtests/controllerswitching/integration_test.go +++ b/internal/controller/operator/eventing/integrationtests/controllerswitching/integration_test.go @@ -166,10 +166,10 @@ func Test_Switching(t *testing.T) { // create eventing-webhook-auth secret. testEnvironment.EnsureOAuthSecretCreated(t, testcase.givenEventing) // create EventMesh secret. - if testcase.givenEventing.Spec.Backend.Type == operatorv1alpha1.EventMeshBackendType { - testEnvironment.EnsureEventMeshSecretCreated(t, testcase.givenEventing) - } else if testcase.givenSwitchedEventing.Spec.Backend.Type == operatorv1alpha1.EventMeshBackendType { - testEnvironment.EnsureEventMeshSecretCreated(t, testcase.givenSwitchedEventing) + if tc.givenEventing.Spec.Backend.Type == operatorv1alpha1.EventMeshBackendType { + testEnvironment.EnsureDefaultEventMeshSecretCreated(t, tc.givenEventing) + } else if tc.givenSwitchedEventing.Spec.Backend.Type == operatorv1alpha1.EventMeshBackendType { + testEnvironment.EnsureDefaultEventMeshSecretCreated(t, tc.givenSwitchedEventing) } // create Eventing CR. diff --git a/internal/controller/operator/eventing/integrationtests/without_apirule_crd/integration_test.go b/internal/controller/operator/eventing/integrationtests/without_apirule_crd/integration_test.go index 0d144f636..a7e072a29 100644 --- a/internal/controller/operator/eventing/integrationtests/without_apirule_crd/integration_test.go +++ b/internal/controller/operator/eventing/integrationtests/without_apirule_crd/integration_test.go @@ -91,7 +91,7 @@ func Test_EventMesh_APIRule_Dependency_Check(t *testing.T) { testEnvironment.EnsureOAuthSecretCreated(t, testcase.givenEventing) // create EventMesh secret. - testEnvironment.EnsureEventMeshSecretCreated(t, testcase.givenEventing) + testEnvironment.EnsureDefaultEventMeshSecretCreated(t, tc.givenEventing) // when // create Eventing CR.