Skip to content

Commit bc0ab37

Browse files
Andrea Falzettiroboquat
Andrea Falzetti
authored andcommitted
feat: add integration tests for ssh gateway
1 parent b020a46 commit bc0ab37

File tree

8 files changed

+159
-3
lines changed

8 files changed

+159
-3
lines changed

.werft/ide-integration-tests-startup.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pod:
177177
178178
[[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" )
179179
180-
IDE_TEST_LIST=(/workspace/test/tests/ide/vscode /workspace/test/tests/ide/jetbrains)
180+
IDE_TEST_LIST=(/workspace/test/tests/ide/ssh /workspace/test/tests/ide/vscode /workspace/test/tests/ide/jetbrains)
181181
for TEST_PATH in "${IDE_TEST_LIST[@]}"
182182
do
183183
TEST_NAME=$(basename "${TEST_PATH}")

.werft/installer-tests.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ const WORKSPACES_TESTS: { [name: string]: InfraConfig } = {
227227
};
228228

229229
const IDE_TESTS: { [name: string]: InfraConfig } = {
230+
SSH_TEST: {
231+
phase: "run-ssh-tests",
232+
makeTarget: "run-ssh-tests",
233+
description: "SSH Gateway tests",
234+
slackhook: slackHook.get("ide-jobs"),
235+
},
230236
VSCODE_IDE_TEST: {
231237
phase: "run-vscode-ide-tests",
232238
makeTarget: "run-vscode-ide-tests",
@@ -238,7 +244,7 @@ const IDE_TESTS: { [name: string]: InfraConfig } = {
238244
makeTarget: "run-jb-ide-tests",
239245
description: "jetbrains IDE tests",
240246
slackhook: slackHook.get("ide-jobs"),
241-
}
247+
},
242248
}
243249

244250

install/tests/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ run-vscode-ide-tests:
470470
run-jb-ide-tests:
471471
$(call runtests,"test/tests/ide/jetbrains/")
472472

473+
run-ssh-tests:
474+
$(call runtests,"test/tests/ide/ssh/")
475+
473476
run-cs-component-tests:
474477
$(call runtests,"test/tests/components/content-service/")
475478

test/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ require (
7474
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
7575
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
7676
github.com/hashicorp/golang-lru v0.5.4 // indirect
77+
github.com/helloyi/go-sshclient v1.1.1 // indirect
7778
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb // indirect
7879
github.com/imdario/mergo v0.3.12 // indirect
7980
github.com/inconshreveable/mousetrap v1.0.0 // indirect

test/go.sum

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ FAILURE_COUNT=0
2020
LOGS_DIR=$(mktemp -d)
2121

2222
WEBAPP_TEST_LIST="$THIS_DIR/tests/components/database $THIS_DIR/tests/components/server"
23-
IDE_TEST_LIST="$THIS_DIR/tests/ide/vscode $THIS_DIR/tests/ide/jetbrains"
23+
IDE_TEST_LIST="$THIS_DIR/tests/ide/ssh $THIS_DIR/tests/ide/vscode $THIS_DIR/tests/ide/jetbrains"
2424
WORKSPACE_TEST_LIST="$THIS_DIR/tests/components/content-service $THIS_DIR/tests/components/image-builder $THIS_DIR/tests/components/ws-daemon $THIS_DIR/tests/components/ws-manager $THIS_DIR/tests/workspace"
2525

2626
case $TEST_SUITE in

test/tests/ide/ssh/main_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package ide
6+
7+
import (
8+
"context"
9+
"os"
10+
"testing"
11+
12+
"github.com/gitpod-io/gitpod/test/pkg/integration"
13+
"sigs.k8s.io/e2e-framework/pkg/env"
14+
)
15+
16+
var (
17+
testEnv env.Environment
18+
username string
19+
namespace string
20+
kubeconfig string
21+
)
22+
23+
func TestMain(m *testing.M) {
24+
username, namespace, testEnv, _, kubeconfig, _ = integration.Setup(context.Background())
25+
os.Exit(testEnv.Run(m))
26+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package ide
6+
7+
import (
8+
"context"
9+
"io"
10+
"log"
11+
"net/url"
12+
"os"
13+
"strings"
14+
"testing"
15+
"time"
16+
17+
"github.com/helloyi/go-sshclient"
18+
"sigs.k8s.io/e2e-framework/pkg/envconf"
19+
"sigs.k8s.io/e2e-framework/pkg/features"
20+
21+
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
22+
"github.com/gitpod-io/gitpod/test/pkg/integration"
23+
)
24+
25+
func TestSSHGatewayConnection(t *testing.T) {
26+
userToken, _ := os.LookupEnv("USER_TOKEN")
27+
integration.SkipWithoutUsername(t, username)
28+
integration.SkipWithoutUserToken(t, userToken)
29+
30+
f := features.New("TestSSHGatewayConnection").
31+
WithLabel("component", "server").
32+
Assess("it can connect to a workspace via SSH gateway", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context {
33+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
34+
defer cancel()
35+
36+
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
37+
t.Cleanup(func() {
38+
api.Done(t)
39+
})
40+
41+
_, err := api.CreateUser(username, userToken)
42+
if err != nil {
43+
t.Fatal(err)
44+
}
45+
46+
serverOpts := []integration.GitpodServerOpt{integration.WithGitpodUser(username)}
47+
server, err := api.GitpodServer(serverOpts...)
48+
if err != nil {
49+
t.Fatal(err)
50+
}
51+
52+
// This env var caused an incident https://www.gitpodstatus.com/incidents/26gwnhcpvqqx before
53+
// Which was introduced by PR https://github.com/gitpod-io/gitpod/pull/13822
54+
// And fixed by PR https://github.com/gitpod-io/gitpod/pull/13858
55+
_ = server.SetEnvVar(ctx, &gitpod.UserEnvVarValue{
56+
Name: "TEST",
57+
RepositoryPattern: "*/*",
58+
Value: "\\\"test space\\\"",
59+
})
60+
61+
_ = server.SetEnvVar(ctx, &gitpod.UserEnvVarValue{
62+
Name: "TEST_MULTIPLE_LINES",
63+
RepositoryPattern: "*/*",
64+
Value: `Hello
65+
World`,
66+
})
67+
68+
nfo, stopWs, err := integration.LaunchWorkspaceFromContextURL(t, ctx, "github.com/gitpod-io/empty", username, api)
69+
if err != nil {
70+
t.Fatal(err)
71+
}
72+
defer func() {
73+
sctx, scancel := context.WithTimeout(context.Background(), 5*time.Minute)
74+
defer scancel()
75+
76+
sapi := integration.NewComponentAPI(sctx, cfg.Namespace(), kubeconfig, cfg.Client())
77+
defer sapi.Done(t)
78+
79+
stopWs(true, sapi)
80+
}()
81+
82+
wsUrl, err := url.Parse(nfo.LatestInstance.IdeURL)
83+
if err != nil {
84+
t.Fatal(err)
85+
}
86+
87+
wId := nfo.Workspace.ID
88+
ownerToken, err := server.GetOwnerToken(ctx, wId)
89+
if err != nil {
90+
t.Fatal(err)
91+
}
92+
93+
urlComponents := strings.Split(wsUrl.Host, ".")
94+
connUrl := []string{urlComponents[0], "ssh"}
95+
connUrl = append(connUrl, urlComponents[1:]...)
96+
connUrlStr := strings.Join(connUrl, ".")
97+
98+
cli, err := sshclient.DialWithPasswd(connUrlStr+":22", wId, ownerToken)
99+
if err != nil {
100+
t.Fatal(err)
101+
}
102+
103+
output, err := cli.Cmd("gp info").Output()
104+
if err != nil && err != io.EOF {
105+
log.Println("[error]", err)
106+
time.Sleep(1 * time.Second)
107+
}
108+
109+
t.Log(string(output))
110+
111+
return ctx
112+
}).
113+
Feature()
114+
115+
testEnv.Test(t, f)
116+
}

0 commit comments

Comments
 (0)