Skip to content

Commit 6f1f3d0

Browse files
Naveena-058jgwestnas438svghadi
authored
Convert Kuttl test 1-098_validate_dex_clientsecret to Ginkgo test format (#997)
* Update to latest commit of argo-rollouts-manager '4619e3168941619f554e3f987ad440589838c7a3' (#994) * Update to latest commit of argo-rollouts-manager '4619e3168941619f554e3f987ad440589838c7a3' Signed-off-by: Jonathan West <jonwest@redhat.com> * Log additional debug logs on failure of 1-040 Signed-off-by: Jonathan West <jonwest@redhat.com> * chore: Move parallelizable tests to parallel Signed-off-by: Jonathan West <jonwest@redhat.com> * chore: increase Ginkgo sequential timeout slightly: Signed-off-by: Jonathan West <jonwest@redhat.com> --------- Signed-off-by: Jonathan West <jonwest@redhat.com> Signed-off-by: NAVEENA S <nas@redhat.com> * Convert Kuttl test 1-098_validate_dex_clientsecret to Ginkgo test format Signed-off-by: NAVEENA S <nas@redhat.com> --------- Signed-off-by: Jonathan West <jonwest@redhat.com> Signed-off-by: NAVEENA S <nas@redhat.com> Co-authored-by: Jonathan West <jgwest@users.noreply.github.com> Co-authored-by: NAVEENA S <nas@redhat.com> Co-authored-by: Siddhesh Ghadi <61187612+svghadi@users.noreply.github.com>
1 parent ad62d76 commit 6f1f3d0

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package parallel
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"strings"
23+
24+
argov1beta1api "github.com/argoproj-labs/argocd-operator/api/v1beta1"
25+
. "github.com/onsi/ginkgo/v2"
26+
. "github.com/onsi/gomega"
27+
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture"
28+
argocdFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/argocd"
29+
k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s"
30+
fixtureUtils "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
31+
corev1 "k8s.io/api/core/v1"
32+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33+
"sigs.k8s.io/controller-runtime/pkg/client"
34+
)
35+
36+
var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
37+
38+
Context("1-098_validate_dex_clientsecret_deprecated", func() {
39+
40+
var (
41+
k8sClient client.Client
42+
ctx context.Context
43+
)
44+
45+
BeforeEach(func() {
46+
fixture.EnsureParallelCleanSlate()
47+
48+
k8sClient, _ = fixtureUtils.GetE2ETestKubeClient()
49+
ctx = context.Background()
50+
})
51+
52+
It("validates that dex client secret is properly copied from service account token to argocd-secret", func() {
53+
54+
// Create namespace for this test and ensure cleanup
55+
namespace, cleanupFunc := fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
56+
defer cleanupFunc()
57+
58+
By("creating ArgoCD CR with dex SSO enabled using openShiftOAuth")
59+
argoCD := &argov1beta1api.ArgoCD{
60+
ObjectMeta: metav1.ObjectMeta{
61+
Name: "example-argocd",
62+
Namespace: namespace.Name,
63+
},
64+
Spec: argov1beta1api.ArgoCDSpec{
65+
SSO: &argov1beta1api.ArgoCDSSOSpec{
66+
Provider: argov1beta1api.SSOProviderTypeDex,
67+
Dex: &argov1beta1api.ArgoCDDexSpec{
68+
OpenShiftOAuth: true,
69+
},
70+
},
71+
},
72+
}
73+
Expect(k8sClient.Create(ctx, argoCD)).To(Succeed())
74+
75+
By("verifying ArgoCD instance reaches Available phase")
76+
Eventually(argoCD, "3m", "5s").Should(argocdFixture.BeAvailable())
77+
78+
By("verifying dex server service account exists")
79+
dexServiceAccount := &corev1.ServiceAccount{
80+
ObjectMeta: metav1.ObjectMeta{
81+
Name: "example-argocd-argocd-dex-server",
82+
Namespace: namespace.Name,
83+
},
84+
}
85+
Eventually(dexServiceAccount, "2m", "5s").Should(k8sFixture.ExistByName())
86+
87+
By("validating that the Dex Client Secret was copied from dex serviceaccount token secret to argocd-secret, by the operator")
88+
Eventually(func() error {
89+
// Get the service account and find its token secret
90+
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(dexServiceAccount), dexServiceAccount)
91+
if err != nil {
92+
return err
93+
}
94+
95+
// Find the token secret from the service account secrets
96+
var tokenSecretName string
97+
for _, secret := range dexServiceAccount.Secrets {
98+
if secret.Name != "" && strings.Contains(secret.Name, "token") {
99+
tokenSecretName = secret.Name
100+
break
101+
}
102+
}
103+
104+
if tokenSecretName == "" {
105+
return fmt.Errorf("no token secret found for service account %s", dexServiceAccount.Name)
106+
}
107+
108+
// Get the token secret and extract the token
109+
tokenSecret := &corev1.Secret{
110+
ObjectMeta: metav1.ObjectMeta{
111+
Name: tokenSecretName,
112+
Namespace: namespace.Name,
113+
},
114+
}
115+
err = k8sClient.Get(ctx, client.ObjectKeyFromObject(tokenSecret), tokenSecret)
116+
if err != nil {
117+
return err
118+
}
119+
120+
expectedClientSecret, exists := tokenSecret.Data["token"]
121+
if !exists {
122+
return fmt.Errorf("token not found in secret %s", tokenSecretName)
123+
}
124+
125+
// Get the argocd-secret and extract the oidc.dex.clientSecret
126+
argoCDSecret := &corev1.Secret{
127+
ObjectMeta: metav1.ObjectMeta{
128+
Name: "argocd-secret",
129+
Namespace: namespace.Name,
130+
},
131+
}
132+
err = k8sClient.Get(ctx, client.ObjectKeyFromObject(argoCDSecret), argoCDSecret)
133+
if err != nil {
134+
return err
135+
}
136+
137+
actualClientSecret, exists := argoCDSecret.Data["oidc.dex.clientSecret"]
138+
if !exists {
139+
return fmt.Errorf("oidc.dex.clientSecret not found in argocd-secret")
140+
}
141+
142+
// Compare the two secrets
143+
if string(expectedClientSecret) != string(actualClientSecret) {
144+
return fmt.Errorf("dex client secret mismatch: expected length %d, actual length %d",
145+
len(expectedClientSecret), len(actualClientSecret))
146+
}
147+
148+
return nil
149+
}, "3m", "5s").Should(Succeed())
150+
151+
})
152+
153+
})
154+
})

0 commit comments

Comments
 (0)