Skip to content
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

[v17] Fix defunct TestX11Forward #51078

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/client/x11_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package client

import (
"context"
"errors"
"fmt"
"log/slog"
"os"
Expand Down Expand Up @@ -212,7 +213,8 @@ func (ns *NodeSession) serveX11Channels(ctx context.Context, sess *tracessh.Sess
}
}()

if err := utils.ProxyConn(ctx, xconn, xchan); err != nil {
// Proxy the connection until the connection is closed or the request is canceled.
if err := utils.ProxyConn(ctx, xconn, xchan); err != nil && !errors.Is(err, context.Canceled) {
slog.DebugContext(ctx, "Encountered error during X11 forwarding", "err", err)
}
})
Expand Down
13 changes: 8 additions & 5 deletions lib/srv/regular/sshserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"io/fs"
Expand Down Expand Up @@ -1220,6 +1221,7 @@ func TestAgentForward(t *testing.T) {

// TestX11Forward tests x11 forwarding via unix sockets
func TestX11Forward(t *testing.T) {
ctx := context.Background()
if os.Getenv("TELEPORT_XAUTH_TEST") == "" {
t.Skip("Skipping test as xauth is not enabled")
}
Expand All @@ -1232,9 +1234,6 @@ func TestX11Forward(t *testing.T) {
MaxDisplay: x11.DefaultMaxDisplays,
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

roleName := services.RoleNameForUser(f.user)
role, err := f.testSrv.Auth().GetRole(ctx, roleName)
require.NoError(t, err)
Expand Down Expand Up @@ -1268,7 +1267,7 @@ func TestX11Forward(t *testing.T) {
errCh <- x11EchoRequest(serverDisplay2)
}()

for i := 0; i > 4; i++ {
for i := 0; i < 4; i++ {
select {
case err := <-errCh:
assert.NoError(t, err)
Expand Down Expand Up @@ -1324,7 +1323,11 @@ func x11EchoSession(ctx context.Context, t *testing.T, clt *tracessh.Client) x11
}()

err = utils.ProxyConn(ctx, clientXConn, sch)
assert.NoError(t, err)

// Error should be nil if the ssh client is closed first, or canceled if the context is closed first.
if !errors.Is(err, context.Canceled) {
assert.NoError(t, err)
}
})
require.NoError(t, err)

Expand Down
Loading