Skip to content

Commit

Permalink
Disable xauth tests in CI.
Browse files Browse the repository at this point in the history
Add xauth tests.
  • Loading branch information
Joerger committed Feb 4, 2022
1 parent 11102a9 commit 52c3d3c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .cloudbuild/scripts/cmd/unit-tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func runUnitTests(workspace string) error {
cmd := exec.Command("make", "test")
cmd.Dir = workspace
cmd.Env = append(os.Environ(), "TELEPORT_ETCD_TEST=yes")
cmd.Env = append(os.Environ(), "TELEPORT_XAUTH_TEST=yes")
// TODO(Joerger): enabled xauth tests once the updated buildbox is in GCB
// cmd.Env = append(os.Environ(), "TELEPORT_XAUTH_TEST=yes")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

Expand Down
6 changes: 5 additions & 1 deletion lib/sshutils/x11/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ func (x *XAuthCommand) AddEntry(entry XAuthEntry) error {
func (x *XAuthCommand) GenerateUntrustedCookie(display Display, timeout time.Duration) error {
x.Cmd.Args = append(x.Cmd.Args, "generate", display.String(), mitMagicCookieProto, "untrusted")
x.Cmd.Args = append(x.Cmd.Args, "timeout", fmt.Sprint(timeout/time.Second))
return trace.Wrap(x.run())
out, err := x.output()
if err != nil {
return trace.Wrap(err, out)
}
return nil
}

// run Run and wrap error with stderr.
Expand Down
66 changes: 66 additions & 0 deletions lib/sshutils/x11/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,80 @@ package x11

import (
"bytes"
"context"
"encoding/binary"
"encoding/hex"
"os"
"path/filepath"
"testing"

"github.com/gravitational/trace"
"github.com/stretchr/testify/require"
)

func TestXAuthCommands(t *testing.T) {
if os.Getenv("TELEPORT_XAUTH_TEST") == "" {
t.Skip("Skipping test as xauth is not enabled")
}

ctx := context.Background()

tmpDir := t.TempDir()
xauthFile := filepath.Join(tmpDir, ".Xauthority")

l, display, err := OpenNewXServerListener(DefaultDisplayOffset, DefaultMaxDisplay, 0)
require.NoError(t, err)
t.Cleanup(func() { l.Close() })

// Wait for connection from generate request
go func() {
conn, err := l.Accept()
require.NoError(t, err)
defer conn.Close()
}()

// New xauth file should have no entries
xauth := NewXAuthCommand(ctx, xauthFile)
xauthEntry, err := xauth.ReadEntry(display)
require.Error(t, err)
require.True(t, trace.IsNotFound(err))
require.Nil(t, xauthEntry)

// Add trusted xauth entry
trustedXauthEntry, err := NewFakeXAuthEntry(display)
require.NoError(t, err)
xauth = NewXAuthCommand(ctx, xauthFile)
err = xauth.AddEntry(*trustedXauthEntry)
require.NoError(t, err)

// Read back the xauth entry
xauth = NewXAuthCommand(ctx, xauthFile)
xauthEntry, err = xauth.ReadEntry(display)
require.NoError(t, err)
require.Equal(t, trustedXauthEntry, xauthEntry)

// Remove xauth entries
xauth = NewXAuthCommand(ctx, xauthFile)
err = xauth.RemoveEntries(xauthEntry.Display)
require.NoError(t, err)

xauth = NewXAuthCommand(ctx, xauthFile)
xauthEntry, err = xauth.ReadEntry(display)
require.Error(t, err)
require.True(t, trace.IsNotFound(err))
require.Nil(t, xauthEntry)

// Generate untrusted xauth entry
xauth = NewXAuthCommand(ctx, xauthFile)
err = xauth.GenerateUntrustedCookie(display, 0)
require.Error(t, err)
// TODO(Joerger): xauth generate requires an actual XServer listener
// to be opened, but above we only open a proxy XServer listener.
// This leads to an error, but ideally we'd give the proper response
// to the generate request and this would succeed in creating the entry.
require.Contains(t, err.Error(), "unable to open display")
}

func TestReadAndRewriteXAuthPacket(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 52c3d3c

Please sign in to comment.