-
Notifications
You must be signed in to change notification settings - Fork 26
feat: allow remote hostnames in ssh forward ports #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
e110964
293955a
7897d98
6b88d4a
392a962
62d12e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| "context" | ||
| "fmt" | ||
| "io" | ||
| "net" | ||
| "net/http" | ||
| "os" | ||
| "os/exec" | ||
|
|
@@ -161,6 +162,77 @@ var _ = ginkgo.Describe( | |
| )) | ||
| }, ginkgo.SpecTimeout(framework.GetTimeout())) | ||
|
|
||
| ginkgo.It("ssh forward ports support remote service names", func(ctx context.Context) { | ||
| _, workspace, err := tc.setupAndStartWorkspace( | ||
| ctx, | ||
| "tests/up-docker-compose/testdata/docker-compose-forward-ports", | ||
| "--debug", | ||
| ) | ||
| framework.ExpectNoError(err) | ||
|
|
||
| ids, err := findComposeContainer( | ||
| ctx, | ||
| tc.dockerHelper, | ||
| tc.composeHelper, | ||
| workspace.UID, | ||
| "app", | ||
| ) | ||
| framework.ExpectNoError(err) | ||
| gomega.Expect(ids).To(gomega.HaveLen(1), "1 compose container to be created") | ||
|
|
||
| listener, err := net.Listen("tcp", "127.0.0.1:0") | ||
| framework.ExpectNoError(err) | ||
| localPort := listener.Addr().(*net.TCPAddr).Port | ||
| framework.ExpectNoError(listener.Close()) | ||
|
Comment on lines
+183
to
+186
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dynamic port allocation has a minor TOCTOU window, but acceptable for e2e. Closing the listener and reusing the port has a brief race where another process could grab it before 🤖 Prompt for AI Agents |
||
|
|
||
| done := make(chan error) | ||
| sshContext, sshCancel := context.WithCancel(context.Background()) | ||
| go func() { | ||
| // #nosec G204 -- test command with controlled arguments | ||
| cmd := exec.CommandContext( | ||
| sshContext, | ||
| filepath.Join(tc.f.DevpodBinDir, tc.f.DevpodBinName), | ||
| "ssh", | ||
| "--forward-ports", | ||
| fmt.Sprintf("%d:nginx:8080", localPort), | ||
| workspace.ID, | ||
| ) | ||
|
|
||
| if err := cmd.Start(); err != nil { | ||
| done <- err | ||
| return | ||
| } | ||
|
|
||
| if err := cmd.Wait(); err != nil { | ||
| done <- err | ||
| return | ||
| } | ||
|
|
||
| done <- nil | ||
| }() | ||
|
|
||
| gomega.Eventually(func(g gomega.Gomega) { | ||
| response, err := http.Get(fmt.Sprintf("http://127.0.0.1:%d", localPort)) | ||
| g.Expect(err).NotTo(gomega.HaveOccurred()) | ||
| defer func() { _ = response.Body.Close() }() | ||
|
|
||
| body, err := io.ReadAll(response.Body) | ||
| g.Expect(err).NotTo(gomega.HaveOccurred()) | ||
| g.Expect(body).To(gomega.ContainSubstring("Thank you for using nginx.")) | ||
| }). | ||
| WithPolling(1 * time.Second). | ||
| WithTimeout(20 * time.Second). | ||
| Should(gomega.Succeed()) | ||
|
|
||
| sshCancel() | ||
| err = <-done | ||
|
|
||
| gomega.Expect(err).To(gomega.Or( | ||
| gomega.MatchError("signal: killed"), | ||
| gomega.MatchError(context.Canceled), | ||
| )) | ||
| }, ginkgo.SpecTimeout(framework.GetTimeout())) | ||
|
|
||
| ginkgo.It("features", func(ctx context.Context) { | ||
| tempDir, workspace, err := tc.setupAndStartWorkspace( | ||
| ctx, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.