Skip to content

Commit df44942

Browse files
committed
test: update e2e implementation
Signed-off-by: Jayendra Parsai <jparsai@redhat.com>
1 parent a7e622a commit df44942

4 files changed

Lines changed: 14 additions & 106 deletions

File tree

test/openshift/e2e/ginkgo/fixture/agent/fixture.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,3 @@ func buildDefaultSANs(serviceName, namespace string) []string {
568568
fmt.Sprintf("%s.%s.svc.cluster.local", serviceName, namespace),
569569
}
570570
}
571-
572-
// GetInitialAdminSecretPassword reads the admin password from the ArgoCD instance's cluster secret
573-
func GetInitialAdminSecretPassword(argocdCRName, secretNS string, k8sClient client.Client) string {
574-
secret := &corev1.Secret{}
575-
Expect(k8sClient.Get(context.Background(), types.NamespacedName{
576-
Name: fmt.Sprintf("%s-cluster", argocdCRName),
577-
Namespace: secretNS,
578-
}, secret)).To(Succeed())
579-
return string(secret.Data["admin.password"])
580-
}

test/openshift/e2e/ginkgo/fixture/argocdclient/fixture.go

Lines changed: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package argocdclient
1818

1919
import (
20-
"bytes"
2120
"crypto/tls"
2221
"encoding/json"
2322
"errors"
@@ -33,72 +32,6 @@ import (
3332
"github.com/gorilla/websocket"
3433
)
3534

36-
type ArgoRestClient struct {
37-
endpoint string
38-
username string
39-
password string
40-
token string
41-
client *http.Client
42-
}
43-
44-
// NewArgoClient returns a new client for Argo CD's REST API
45-
func NewArgoClient(endpoint, username, password string) *ArgoRestClient {
46-
ac := &ArgoRestClient{
47-
endpoint: endpoint,
48-
username: username,
49-
password: password,
50-
client: &http.Client{
51-
Transport: &http.Transport{
52-
TLSClientConfig: &tls.Config{
53-
InsecureSkipVerify: true, // #nosec G402
54-
},
55-
},
56-
},
57-
}
58-
return ac
59-
}
60-
61-
// Login creates a new Argo CD session
62-
func (c *ArgoRestClient) Login() error {
63-
// Get session token from API
64-
authStr := fmt.Sprintf(`{"username": "%s", "password": "%s"}`, c.username, c.password)
65-
payload := io.NopCloser(bytes.NewReader([]byte(authStr)))
66-
res, err := c.client.Do(&http.Request{
67-
Method: http.MethodPost,
68-
URL: &url.URL{Scheme: "https", Host: c.endpoint, Path: "/api/v1/session"},
69-
Body: payload,
70-
Header: http.Header{"Content-Type": []string{"application/json"}},
71-
ContentLength: int64(len(authStr)),
72-
})
73-
if err != nil {
74-
return err
75-
}
76-
defer func() {
77-
_ = res.Body.Close()
78-
}()
79-
if res.StatusCode != 200 {
80-
return fmt.Errorf("expected HTTP 200, got %d", res.StatusCode)
81-
}
82-
body, err := io.ReadAll(res.Body)
83-
if err != nil {
84-
return err
85-
}
86-
87-
type tokenResponse struct {
88-
Token string `json:"token"`
89-
}
90-
token := &tokenResponse{}
91-
err = json.Unmarshal(body, token)
92-
if err != nil {
93-
return err
94-
}
95-
if token.Token == "" {
96-
return errors.New("empty token received")
97-
}
98-
c.token = token.Token
99-
return nil
100-
}
101-
10235
// TerminalClient represents a test client for terminal WebSocket connections.
10336
type TerminalClient struct {
10437
wsConn *websocket.Conn
@@ -111,15 +44,10 @@ type TerminalClient struct {
11144
// ExecTerminal opens a terminal session to a pod via WebSocket.
11245
// This replicates the behavior of the ArgoCD UI when a user opens a terminal session to an application.
11346
// ArgoCD decides which shell to use based on the configured allowed shells.
114-
func (c *ArgoRestClient) ExecTerminal(app *v1alpha1.Application, namespace, podName, container string) (*TerminalClient, error) {
115-
if err := c.ensureToken(); err != nil {
116-
return nil, err
117-
}
118-
119-
// Build the exec URL
47+
func ExecTerminal(endpoint, token string, app *v1alpha1.Application, namespace, podName, container string) (*TerminalClient, error) {
12048
u := &url.URL{
12149
Scheme: "wss",
122-
Host: c.endpoint,
50+
Host: endpoint,
12351
Path: "/terminal",
12452
}
12553

@@ -132,18 +60,15 @@ func (c *ArgoRestClient) ExecTerminal(app *v1alpha1.Application, namespace, podN
13260
q.Set("namespace", namespace)
13361
u.RawQuery = q.Encode()
13462

135-
// Create WebSocket dialer with TLS config
13663
dialer := websocket.Dialer{
13764
TLSClientConfig: &tls.Config{
13865
InsecureSkipVerify: true, // #nosec G402
13966
},
14067
}
14168

142-
// Set token as cookie - ArgoCD expects auth token in argocd.token cookie
14369
headers := http.Header{}
144-
headers.Set("Cookie", fmt.Sprintf("argocd.token=%s", c.token))
70+
headers.Set("Cookie", fmt.Sprintf("argocd.token=%s", token))
14571

146-
// Connect to WebSocket
14772
wsConn, resp, err := dialer.Dial(u.String(), headers)
14873
if err != nil {
14974
if resp != nil {
@@ -158,20 +83,11 @@ func (c *ArgoRestClient) ExecTerminal(app *v1alpha1.Application, namespace, podN
15883
wsConn: wsConn,
15984
}
16085

161-
// Start reading output in background
16286
go session.readOutput()
16387

16488
return session, nil
16589
}
16690

167-
// ensureToken makes sure we have a valid authentication token
168-
func (c *ArgoRestClient) ensureToken() error {
169-
if c.token == "" {
170-
return c.Login()
171-
}
172-
return nil
173-
}
174-
17591
// terminalMessage is the JSON message format used by ArgoCD terminal WebSocket
17692
type terminalMessage struct {
17793
Operation string `json:"operation"`

test/openshift/e2e/ginkgo/sequential/1-053_validate_argocd_agent_principal_connected_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
516516
It("Should deploy ArgoCD principal and agent instances in both modes and verify they are working as expected", func() {
517517

518518
By("Deploy principal and verify it starts successfully")
519-
deployPrincipal(ctx, k8sClient, registerCleanup)
519+
deployPrincipal(ctx, k8sClient, registerCleanup, false)
520520

521521
By("Deploy managed agent and verify it starts successfully")
522522
deployAgent(ctx, k8sClient, registerCleanup, argov1beta1api.AgentModeManaged)
@@ -609,7 +609,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
609609
// This function deploys the principal ArgoCD instance and waits for it to be ready.
610610
// It creates the required secrets for the principal and verifies that the principal deployment is in Ready state.
611611
// It also verifies that the principal logs contain the expected messages.
612-
func deployPrincipal(ctx context.Context, k8sClient client.Client, registerCleanup func(func()), enableServerRoute ...bool) {
612+
func deployPrincipal(ctx context.Context, k8sClient client.Client, registerCleanup func(func()), enableServerRoute bool) {
613613
GinkgoHelper()
614614

615615
nsPrincipal, cleanup := fixture.CreateNamespaceWithCleanupFunc(namespaceAgentPrincipal)
@@ -624,7 +624,7 @@ func deployPrincipal(ctx context.Context, k8sClient client.Client, registerClean
624624
waitForLoadBalancer = false
625625
}
626626

627-
if len(enableServerRoute) > 0 && enableServerRoute[0] {
627+
if enableServerRoute {
628628
argoCDInstance.Spec.Server.Route = argov1beta1api.ArgoCDRouteSpec{
629629
Enabled: true,
630630
}

test/openshift/e2e/ginkgo/sequential/1-054_validate_argocd_agent_terminal_streaming_test.go renamed to test/openshift/e2e/ginkgo/sequential/1-059_validate_argocd_agent_terminal_streaming_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/argoproj/gitops-engine/pkg/health"
3838

3939
argov1beta1api "github.com/argoproj-labs/argocd-operator/api/v1beta1"
40+
argocdFixture "github.com/argoproj-labs/argocd-operator/tests/ginkgo/fixture/argocd"
4041

4142
routev1 "github.com/openshift/api/route/v1"
4243

@@ -51,7 +52,7 @@ import (
5152
// This test validates that terminal streaming works through the ArgoCD agent architecture
5253
// on OpenShift. It exercises the full terminal flow:
5354
var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
54-
Context("1-054_validate_argocd_agent_terminal_streaming", func() {
55+
Context("1-059_validate_argocd_agent_terminal_streaming", func() {
5556
var (
5657
k8sClient client.Client
5758
ctx context.Context
@@ -218,9 +219,10 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
218219
argoEndpoint := serverRoute.Spec.Host
219220
GinkgoWriter.Printf("ArgoCD server Route host: %s\n", argoEndpoint)
220221

221-
password := agentFixture.GetInitialAdminSecretPassword(argoCDAgentInstanceNamePrincipal, namespaceAgentPrincipal, k8sClient)
222-
argoClient := argocdClient.NewArgoClient(argoEndpoint, "admin", password)
223-
Expect(argoClient.Login()).To(Succeed())
222+
password := argocdFixture.GetInitialAdminSecretPassword(argoCDAgentInstanceNamePrincipal, namespaceAgentPrincipal, k8sClient)
223+
_, sessionToken, closer, err := argocdFixture.CreateArgoCDAPIClient(ctx, argoEndpoint, password)
224+
Expect(err).ToNot(HaveOccurred())
225+
defer closer.Close()
224226

225227
// Find the application pod which we want to open a terminal session for.
226228
By("Find a running pod in the application namespace")
@@ -257,14 +259,14 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
257259
var session *argocdClient.TerminalClient
258260
Eventually(func() error {
259261
var err error
260-
session, err = argoClient.ExecTerminal(application, managedAgentApplicationNamespace, podName, containerName)
262+
session, err = argocdClient.ExecTerminal(argoEndpoint, sessionToken, application, managedAgentApplicationNamespace, podName, containerName)
261263
return err
262264
}, "30s", "5s").Should(Succeed(), "failed to open terminal session")
263265
defer session.Close()
264266

265267
// Send a resize message first, this is required by the shell to render the
266268
// output content accordingly.
267-
err := session.SendResize(80, 24)
269+
err = session.SendResize(80, 24)
268270
Expect(err).ToNot(HaveOccurred(), "failed to send resize")
269271

270272
// Wait for shell to initialize by checking for any output

0 commit comments

Comments
 (0)