@@ -19,29 +19,19 @@ package e2e
1919import (
2020 "bytes"
2121 "context"
22- "crypto/tls"
2322 "fmt"
24- "io"
25- "net/http"
26- "net/url"
2723 "os/exec"
2824 "path/filepath"
2925 "reflect"
3026 "strings"
3127 "time"
3228
33- b64 "encoding/base64"
34- "encoding/json"
35-
3629 argoapp "github.com/argoproj-labs/argocd-operator/api/v1beta1"
3730 "github.com/argoproj-labs/argocd-operator/common"
3831 "github.com/argoproj-labs/argocd-operator/controllers/argoutil"
3932 . "github.com/onsi/ginkgo/v2"
4033 . "github.com/onsi/gomega"
41- osappsv1 "github.com/openshift/api/apps/v1"
4234 configv1 "github.com/openshift/api/config/v1"
43- routev1 "github.com/openshift/api/route/v1"
44- templatev1 "github.com/openshift/api/template/v1"
4535 monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
4636 pipelinesv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1"
4737 gitopscommon "github.com/redhat-developer/gitops-operator/common"
@@ -79,14 +69,6 @@ var _ = Describe("GitOpsServiceController", func() {
7969 // update .sso.provider = keycloak to enable RHSSO for default Argo CD instance.
8070 // update verifyTLS = false to ensure operator(when run locally) can create RHSSO resources.
8171 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- }
9072
9173 err := retry .RetryOnConflict (retry .DefaultBackoff , func () error {
9274 updatedInstance := & argoapp.ArgoCD {}
@@ -95,7 +77,6 @@ var _ = Describe("GitOpsServiceController", func() {
9577 return err
9678 }
9779 updatedInstance .Spec .DisableAdmin = argoCDInstance .Spec .DisableAdmin
98- updatedInstance .Spec .SSO = argoCDInstance .Spec .SSO
9980 return k8sClient .Update (context .TODO (), updatedInstance )
10081 })
10182 Expect (err ).NotTo (HaveOccurred ())
@@ -633,176 +614,6 @@ var _ = Describe("GitOpsServiceController", func() {
633614 })
634615 })
635616
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-
806617 Context ("Verify Configuring Infrastructure NodeSelector " , func () {
807618 name := "cluster"
808619 gitopsService := & pipelinesv1alpha1.GitopsService {}
@@ -889,61 +700,6 @@ var _ = Describe("GitOpsServiceController", func() {
889700
890701})
891702
892- type tokenResponse struct {
893- AccessToken string `json:"access_token"`
894- ExpiresIn int `json:"expires_in"`
895- RefreshExpiresIn int `json:"refresh_expires_in"`
896- RefreshToken string `json:"refresh_token"`
897- TokenType string `json:"token_type"`
898- NotBeforePolicy int `json:"not-before-policy"`
899- SessionState string `json:"session_state"`
900- Error string `json:"error"`
901- ErrorDescription string `json:"error_description"`
902- }
903-
904- func getAccessToken (user , pass , accessURL string ) (string , error ) {
905- form := url.Values {}
906- form .Add ("username" , user )
907- form .Add ("password" , pass )
908- form .Add ("client_id" , "admin-cli" )
909- form .Add ("grant_type" , "password" )
910-
911- client := http.Client {}
912- http .DefaultTransport .(* http.Transport ).TLSClientConfig = & tls.Config {InsecureSkipVerify : true }
913- req , err := http .NewRequest (
914- "POST" ,
915- accessURL ,
916- strings .NewReader (form .Encode ()),
917- )
918- if err != nil {
919- return "" , err
920- }
921-
922- req .Header .Add ("Content-Type" , "application/x-www-form-urlencoded" )
923- res , err := client .Do (req )
924- if err != nil {
925- return "" , err
926- }
927-
928- defer res .Body .Close ()
929- body , err := io .ReadAll (res .Body )
930- if err != nil {
931- return "" , err
932- }
933-
934- tokenRes := & tokenResponse {}
935- err = json .Unmarshal (body , tokenRes )
936- if err != nil {
937- return "" , err
938- }
939-
940- if tokenRes .Error != "" {
941- return "" , err
942- }
943-
944- return tokenRes .AccessToken , nil
945- }
946-
947703func runCommandWithOutput (cmdList ... string ) (string , string , error ) {
948704
949705 // Output the commands to be run, so that if the test fails we can determine why
0 commit comments