Skip to content

Commit

Permalink
test trustedCABundle ManagementState conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sara4994 committed Nov 13, 2024
1 parent d765e48 commit 96ec2c2
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions tests/e2e/creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,43 +452,49 @@ func (tc *testContext) testDefaultCertsAvailable() error {
}

func (tc *testContext) testTrustedCABundle() error {
managementStateChangeTrustedCA := false
CAConfigMapName := "odh-trusted-ca-bundle"
CADataFieldName := "odh-ca-bundle.crt"

err := trustedcabundle.ConfigureTrustedCABundle(tc.ctx, tc.customClient, logr.Logger{}, tc.testDSCI, managementStateChangeTrustedCA)
if tc.testDSCI.Spec.TrustedCABundle.ManagementState == "Managed" {
istrustedCABundleUpdated, err := trustedcabundle.IsTrustedCABundleUpdated(tc.ctx, tc.customClient, tc.testDSCI)

if err != nil {
return fmt.Errorf("Error while configuring trusted-ca-bundle: %w", err)
}
istrustedCABundleUpdated, err := trustedcabundle.IsTrustedCABundleUpdated(tc.ctx, tc.customClient, tc.testDSCI)
if istrustedCABundleUpdated == true {
return fmt.Errorf("odh-trusted-ca-bundle in config map does not match with DSCI's TrustedCABundle.CustomCABundle, needs update: %w", err)
}

if istrustedCABundleUpdated == true {
return fmt.Errorf("odh-trusted-ca-bundle in config map does not match with DSCI's TrustedCABundle.CustomCABundle, needs update: %w", err)
}
err = trustedcabundle.AddCABundleCMInAllNamespaces(tc.ctx, tc.customClient, logr.Logger{}, tc.testDSCI)

err = trustedcabundle.AddCABundleCMInAllNamespaces(tc.ctx, tc.customClient, logr.Logger{}, tc.testDSCI)
if err != nil {
return fmt.Errorf("failed adding configmap %s to all namespaces: %w", CAConfigMapName, err)
}

if err != nil {
return fmt.Errorf("failed adding configmap %s to all namespaces: %w", CAConfigMapName, err)
}
if err := trustedcabundle.RemoveCABundleCMInAllNamespaces(tc.ctx, tc.customClient); err != nil {
return fmt.Errorf("error deleting configmap %s from all namespaces %w", CAConfigMapName, err)
}

if err := trustedcabundle.RemoveCABundleCMInAllNamespaces(tc.ctx, tc.customClient); err != nil {
return fmt.Errorf("error deleting configmap %s from all namespaces %w", CAConfigMapName, err)
}
foundConfigMap := &corev1.ConfigMap{}
err = tc.customClient.Get(tc.ctx, client.ObjectKey{
Name: CAConfigMapName,
Namespace: tc.testDSCI.Spec.ApplicationsNamespace,
}, foundConfigMap)

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)
}

if err != nil {
return errors.New("Config map not found")
}
if 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 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)
if err != nil {
return fmt.Errorf("Config map not found, %w", err)
}
}
return nil
}
Expand Down

0 comments on commit 96ec2c2

Please sign in to comment.