@@ -30,18 +30,14 @@ import (
3030 "strings"
3131 "time"
3232
33- b64 "encoding/base64"
3433 "encoding/json"
3534
3635 argoapp "github.com/argoproj-labs/argocd-operator/api/v1beta1"
3736 "github.com/argoproj-labs/argocd-operator/common"
3837 "github.com/argoproj-labs/argocd-operator/controllers/argoutil"
3938 . "github.com/onsi/ginkgo/v2"
4039 . "github.com/onsi/gomega"
41- osappsv1 "github.com/openshift/api/apps/v1"
4240 configv1 "github.com/openshift/api/config/v1"
43- routev1 "github.com/openshift/api/route/v1"
44- templatev1 "github.com/openshift/api/template/v1"
4541 monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
4642 pipelinesv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1"
4743 gitopscommon "github.com/redhat-developer/gitops-operator/common"
@@ -79,14 +75,6 @@ var _ = Describe("GitOpsServiceController", func() {
7975 // update .sso.provider = keycloak to enable RHSSO for default Argo CD instance.
8076 // update verifyTLS = false to ensure operator(when run locally) can create RHSSO resources.
8177 argoCDInstance .Spec .DisableAdmin = true
82- insecure := false
83- // remove dex configuration, only one SSO is supported.
84- argoCDInstance .Spec .SSO = & argoapp.ArgoCDSSOSpec {
85- Provider : "keycloak" ,
86- Keycloak : & argoapp.ArgoCDKeycloakSpec {
87- VerifyTLS : & insecure ,
88- },
89- }
9078
9179 err := retry .RetryOnConflict (retry .DefaultBackoff , func () error {
9280 updatedInstance := & argoapp.ArgoCD {}
@@ -95,7 +83,6 @@ var _ = Describe("GitOpsServiceController", func() {
9583 return err
9684 }
9785 updatedInstance .Spec .DisableAdmin = argoCDInstance .Spec .DisableAdmin
98- updatedInstance .Spec .SSO = argoCDInstance .Spec .SSO
9986 return k8sClient .Update (context .TODO (), updatedInstance )
10087 })
10188 Expect (err ).NotTo (HaveOccurred ())
@@ -633,176 +620,6 @@ var _ = Describe("GitOpsServiceController", func() {
633620 })
634621 })
635622
636- Context ("Verify RHSSO installation" , func () {
637- namespace := argoCDNamespace
638- It ("Template instance is created" , func () {
639- tInstance := & templatev1.TemplateInstance {}
640- checkIfPresent (types.NamespacedName {Name : defaultTemplateIdentifier , Namespace : namespace }, tInstance )
641- })
642-
643- It ("Keycloak deployment is created" , func () {
644- Eventually (func () error {
645- dc := osappsv1.DeploymentConfig {}
646- err := k8sClient .Get (context .TODO (), types.NamespacedName {Name : defaultKeycloakIdentifier , Namespace : namespace }, & dc )
647- if err != nil {
648- return err
649- }
650- got := dc .Status .AvailableReplicas
651- want := int32 (1 )
652- if got != want {
653- return fmt .Errorf ("expected %d, got %d" , want , got )
654- }
655- return nil
656- }, timeout , interval ).ShouldNot (HaveOccurred ())
657- })
658-
659- It ("Keycloak service is created" , func () {
660- svc := & corev1.Service {}
661- checkIfPresent (types.NamespacedName {Name : defaultKeycloakIdentifier , Namespace : namespace }, svc )
662- })
663-
664- It ("Keycloak service route is created" , func () {
665- route := & routev1.Route {}
666- checkIfPresent (types.NamespacedName {Name : defaultKeycloakIdentifier , Namespace : namespace }, route )
667- })
668- })
669-
670- Context ("Verify RHSSO configuration" , func () {
671- namespace := argoCDNamespace
672-
673- It ("Verify RHSSO Realm creation" , func () {
674- By ("get keycloak URL and credentials" )
675- route := & routev1.Route {}
676- checkIfPresent (types.NamespacedName {Name : defaultKeycloakIdentifier , Namespace : namespace }, route )
677-
678- secret := & corev1.Secret {}
679- checkIfPresent (types.NamespacedName {Name : rhssosecret , Namespace : namespace }, secret )
680-
681- userEnc := b64 .URLEncoding .EncodeToString (secret .Data ["SSO_USERNAME" ])
682- user , _ := b64 .URLEncoding .DecodeString (userEnc )
683-
684- passEnc := b64 .URLEncoding .EncodeToString (secret .Data ["SSO_PASSWORD" ])
685- pass , _ := b64 .URLEncoding .DecodeString (passEnc )
686-
687- By ("get auth token from kaycloak" )
688- accessURL := fmt .Sprintf ("https://%s%s" , route .Spec .Host , authURL )
689- argoRealmURL := fmt .Sprintf ("https://%s%s" , route .Spec .Host , realmURL )
690-
691- accessToken , err := getAccessToken (string (user ), string (pass ), accessURL )
692- Expect (err ).NotTo (HaveOccurred ())
693-
694- By ("create a new https request to verify Realm creation" )
695- client := http.Client {}
696- http .DefaultTransport .(* http.Transport ).TLSClientConfig = & tls.Config {InsecureSkipVerify : true }
697- request , err := http .NewRequest ("GET" , argoRealmURL , nil )
698- Expect (err ).NotTo (HaveOccurred ())
699- request .Header .Set ("Content-Type" , "application/json" )
700- request .Header .Add ("Authorization" , fmt .Sprintf ("Bearer %s" , accessToken ))
701-
702- By ("verify RHSSO realm creation and check if HTTP GET returns 200 " )
703- response , err := client .Do (request )
704- Expect (err ).NotTo (HaveOccurred ())
705- defer response .Body .Close ()
706-
707- By ("verify reponse" )
708- b , err := io .ReadAll (response .Body )
709- Expect (err ).NotTo (HaveOccurred ())
710-
711- m := make (map [string ]interface {})
712- err = json .Unmarshal (b , & m )
713- Expect (err ).NotTo (HaveOccurred ())
714-
715- Expect (m ["realm" ]).To (Equal ("argocd" ))
716- Expect (m ["registrationFlow" ]).To (Equal ("registration" ))
717- Expect (m ["browserFlow" ]).To (Equal ("browser" ))
718- Expect (m ["clientAuthenticationFlow" ]).To (Equal ("clients" ))
719- Expect (m ["directGrantFlow" ]).To (Equal ("direct grant" ))
720- Expect (m ["loginWithEmailAllowed" ]).To (BeTrue ())
721-
722- idps := m ["identityProviders" ].([]interface {})
723- idp := idps [0 ].(map [string ]interface {})
724-
725- Expect (idp ["alias" ]).To (Equal ("openshift-v4" ))
726- Expect (idp ["displayName" ]).To (Equal ("Login with OpenShift" ))
727- Expect (idp ["providerId" ]).To (Equal ("openshift-v4" ))
728- Expect (idp ["firstBrokerLoginFlowAlias" ]).To (Equal ("first broker login" ))
729- })
730-
731- It ("Verify OIDC Configuration is created" , func () {
732- Eventually (func () error {
733- cm := & corev1.ConfigMap {}
734- err := k8sClient .Get (context .TODO (), types.NamespacedName {Name : argoCDConfigMapName , Namespace : namespace }, cm )
735- if err != nil {
736- return err
737- }
738- if cm .Data [common .ArgoCDKeyOIDCConfig ] == "" {
739- return fmt .Errorf ("expected OIDC configuration to be created" )
740- }
741- return nil
742- }, timeout , interval ).ShouldNot (HaveOccurred ())
743- })
744-
745- })
746-
747- Context ("Verify RHSSO uninstallation" , func () {
748- namespace := argoCDNamespace
749- argocd := & argoapp.ArgoCD {}
750- It ("Remove SSO field from Argo CD CR" , func () {
751-
752- err := retry .RetryOnConflict (retry .DefaultBackoff , func () error {
753- err := k8sClient .Get (context .TODO (), types.NamespacedName {Name : argoCDInstanceName , Namespace : namespace }, argocd )
754- Expect (err ).ToNot (HaveOccurred ())
755-
756- argocd .Spec .SSO = nil
757- return k8sClient .Update (context .TODO (), argocd )
758- })
759- Expect (err ).NotTo (HaveOccurred ())
760- })
761-
762- It ("OIDC configuration is removed" , func () {
763- Eventually (func () bool {
764- cm := & corev1.ConfigMap {}
765- err := k8sClient .Get (context .TODO (), types.NamespacedName {Name : argoCDConfigMapName , Namespace : namespace }, cm )
766- Expect (err ).NotTo (HaveOccurred ())
767- return cm .Data [common .ArgoCDKeyOIDCConfig ] == ""
768- }, timeout , interval ).Should (BeTrue ())
769- })
770-
771- It ("Template instance is deleted" , func () {
772- Eventually (func () error {
773- templateInstance := & templatev1.TemplateInstance {}
774- err := k8sClient .Get (context .TODO (), types.NamespacedName {Name : defaultTemplateIdentifier , Namespace : namespace }, templateInstance )
775- if kubeerrors .IsNotFound (err ) {
776- return nil
777- }
778- return err
779- }, timeout , interval ).ShouldNot (HaveOccurred ())
780- })
781-
782- It ("Add SSO field back and verify reconcilation" , func () {
783- insecure := false
784- argocd .Spec .SSO = & argoapp.ArgoCDSSOSpec {
785- Provider : defaultKeycloakIdentifier ,
786- Keycloak : & argoapp.ArgoCDKeycloakSpec {
787- VerifyTLS : & insecure ,
788- },
789- }
790- err := retry .RetryOnConflict (retry .DefaultBackoff , func () error {
791- updatedInstance := & argoapp.ArgoCD {}
792- err := k8sClient .Get (context .TODO (), types.NamespacedName {Name : argoCDInstanceName , Namespace : argoCDNamespace }, updatedInstance )
793- if err != nil {
794- return err
795- }
796- updatedInstance .Spec .SSO = argocd .Spec .SSO
797- return k8sClient .Update (context .TODO (), updatedInstance )
798- })
799- Expect (err ).NotTo (HaveOccurred ())
800-
801- templateInstance := & templatev1.TemplateInstance {}
802- checkIfPresent (types.NamespacedName {Name : defaultTemplateIdentifier , Namespace : namespace }, templateInstance )
803- })
804- })
805-
806623 Context ("Verify Configuring Infrastructure NodeSelector " , func () {
807624 name := "cluster"
808625 gitopsService := & pipelinesv1alpha1.GitopsService {}
0 commit comments