Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: e2e test for trusted-ca-bundle #1346

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions tests/e2e/creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"fmt"
"log"
"reflect"
"strings"
"testing"
"time"

operatorv1 "github.com/openshift/api/operator/v1"
"github.com/stretchr/testify/require"
autoscalingv1 "k8s.io/api/autoscaling/v1"
corev1 "k8s.io/api/core/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -99,6 +101,10 @@ func creationTestSuite(t *testing.T) {
err = testCtx.testDefaultModelRegistryCertAvailable()
require.NoError(t, err, "error getting default cert secret for ModelRegistry")
})
t.Run("Validate trusted CA bundle", func(t *testing.T) {
err = testCtx.testTrustedCABundle()
require.NoError(t, err, "error validating trusted CA bundle")
})
t.Run("Validate model registry servicemeshmember available", func(t *testing.T) {
err = testCtx.testMRServiceMeshMember()
require.NoError(t, err, "error getting servicemeshmember for Model Registry")
Expand Down Expand Up @@ -444,6 +450,46 @@ func (tc *testContext) testDefaultCertsAvailable() error {
return nil
}

func (tc *testContext) testTrustedCABundle() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i understand the logic here:
if we are making e2e test (not unit-test) , what we should test is:

  1. set managementStateChangeTrustedCA := true
  • check if Configmap is created in tc.testDSCI.Spec.ApplicationsNamespace
  • check content of CADataFieldName == tc.testDSCI.Spec.TrustedCABundle.CustomCABundle
  • check content of CADataFieldName has newline as ending (this is new from current code base)
  1. set managementStateChangeTrustedCA := false
  • check no Configmap in tc.testDSCI.Spec.ApplicationsNamespace

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, seems confusion for the above comments:
set managementStateChangeTrustedCA := true
is not meant to be set in the testcase, this is only to illustrate the case when set to Managed VS Removed
what need to be done is tc.testDSCI.Spec.TrustedCABundle.ManagementState: Managed

CAConfigMapName := "odh-trusted-ca-bundle"
CADataFieldName := "odh-ca-bundle.crt"

if tc.testDSCI.Spec.TrustedCABundle.ManagementState == operatorv1.Managed {
foundConfigMap := &corev1.ConfigMap{}
err := tc.customClient.Get(tc.ctx, client.ObjectKey{
Name: CAConfigMapName,
Namespace: tc.testDSCI.Spec.ApplicationsNamespace,
}, foundConfigMap)

if err != nil {
return fmt.Errorf("Config map not found, %w", err)
}

checkNewline := strings.HasSuffix(foundConfigMap.Data[CADataFieldName], "\n")

if checkNewline == false {
fmt.Print("Newline not found at the end of configmap")
}
Comment on lines +470 to +472
Copy link
Member

@grdryn grdryn Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are both cases acceptable here (newline or not), or should this assert one of the cases?

Also, the check looks like it will pass if a newline character is found anywhere in the string, not just at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grdryn yea true, i have modified the check here


if strings.TrimSpace(foundConfigMap.Data[CADataFieldName]) != tc.testDSCI.Spec.TrustedCABundle.CustomCABundle {
return fmt.Errorf("odh-trusted-ca-bundle in config map does not match with DSCI's TrustedCABundle.CustomCABundle, needs update: %w", err)
}
} else {
foundConfigMap := &corev1.ConfigMap{}
err := tc.customClient.Get(tc.ctx, client.ObjectKey{
Name: CAConfigMapName,
Namespace: tc.testDSCI.Spec.ApplicationsNamespace,
}, foundConfigMap)

if k8serr.IsNotFound(err) {
fmt.Printf("Config map not found in the namespace")
} else {
return fmt.Errorf("failed to validate trusted CA bundle %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should return other errors here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VaishnaviHire this is done

}
return nil
}

func (tc *testContext) testDefaultModelRegistryCertAvailable() error {
// return if MR is not set to Managed
if tc.testDsc.Spec.Components.ModelRegistry.ManagementState != operatorv1.Managed {
Expand Down
6 changes: 5 additions & 1 deletion tests/e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ func setupDSCICR(name string) *dsciv1.DSCInitialization {
},
TrustedCABundle: &dsciv1.TrustedCABundleSpec{
ManagementState: "Managed",
CustomCABundle: "",
CustomCABundle: `-----BEGIN CERTIFICATE-----
MIIFVjCCAz6gAwIBAgIUQ+NxE9izWRRdt86M/TX9b7wFjUUwDQYJKoZIhvcNAQEL
...
IrrVQJLuM7IjWcmOvFjai57QGfIvWcaMY1q6n6MLsLOaXLoRuBLpDLvPbmyAhykU
------END ------`,
},
ServiceMesh: &infrav1.ServiceMeshSpec{
ControlPlane: infrav1.ControlPlaneSpec{
Expand Down
Loading