Skip to content

Commit

Permalink
[v10] Deflake TestProxyRoundRobin / TestClientDisconnect (#14188)
Browse files Browse the repository at this point in the history
* Deflake TestProxyRoundRobin / TestClientDisconnect

Configure the test environment in a way that a disk-based session
uploader will not be used. This prevents the tempdir cleanup from
failing while the uploader is still writing to the directory.

Fixes #13938

* Apply fix to TestProxyRoundRobin
  • Loading branch information
zmb3 authored Jul 7, 2022
1 parent f61f6f3 commit a4a5136
Showing 1 changed file with 23 additions and 33 deletions.
56 changes: 23 additions & 33 deletions lib/srv/regular/sshserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ func newFixture(t *testing.T) *sshTestFixture {
return newCustomFixture(t, func(*auth.TestServerConfig) {})
}

func newFixtureWithoutDiskBasedLogging(t *testing.T) *sshTestFixture {
t.Helper()

f := newCustomFixture(t, func(cfg *auth.TestServerConfig) {
cfg.Auth.AuditLog = events.NewDiscardAuditLog()
})

// use a sync recording mode because the disk-based uploader
// that runs in the background introduces races with test cleanup
recConfig := types.DefaultSessionRecordingConfig()
recConfig.SetMode(types.RecordAtNodeSync)
err := f.testSrv.Auth().SetSessionRecordingConfig(context.Background(), recConfig)
require.NoError(t, err)

return f
}

func newCustomFixture(t *testing.T, mutateCfg func(*auth.TestServerConfig), sshOpts ...ServerOption) *sshTestFixture {
ctx := context.Background()

Expand Down Expand Up @@ -493,9 +510,7 @@ func TestAdvertiseAddr(t *testing.T) {
func TestAgentForwardPermission(t *testing.T) {
t.Parallel()

f := newCustomFixture(t, func(cfg *auth.TestServerConfig) {
cfg.Auth.AuditLog = events.NewDiscardAuditLog()
})
f := newFixtureWithoutDiskBasedLogging(t)
ctx := context.Background()

// make sure the role does not allow agent forwarding
Expand All @@ -508,13 +523,6 @@ func TestAgentForwardPermission(t *testing.T) {
role.SetOptions(roleOptions)
require.NoError(t, f.testSrv.Auth().UpsertRole(ctx, role))

// use a sync recording mode because the disk-based uploader
// that runs in the background introduces races with test cleanup
recConfig := types.DefaultSessionRecordingConfig()
recConfig.SetMode(types.RecordAtNodeSync)
err = f.testSrv.Auth().SetSessionRecordingConfig(ctx, recConfig)
require.NoError(t, err)

se, err := f.ssh.clt.NewSession()
require.NoError(t, err)
t.Cleanup(func() { se.Close() })
Expand Down Expand Up @@ -606,9 +614,7 @@ func TestOpenExecSessionSetsSession(t *testing.T) {
// TestAgentForward tests agent forwarding via unix sockets
func TestAgentForward(t *testing.T) {
t.Parallel()
f := newCustomFixture(t, func(cfg *auth.TestServerConfig) {
cfg.Auth.AuditLog = events.NewDiscardAuditLog()
})
f := newFixtureWithoutDiskBasedLogging(t)

ctx := context.Background()
roleName := services.RoleNameForUser(f.user)
Expand All @@ -620,13 +626,6 @@ func TestAgentForward(t *testing.T) {
err = f.testSrv.Auth().UpsertRole(ctx, role)
require.NoError(t, err)

// use a sync recording mode because the disk-based uploader
// that runs in the background introduces races with test cleanup
recConfig := types.DefaultSessionRecordingConfig()
recConfig.SetMode(types.RecordAtNodeSync)
err = f.testSrv.Auth().SetSessionRecordingConfig(ctx, recConfig)
require.NoError(t, err)

se, err := f.ssh.clt.NewSession()
require.NoError(t, err)
t.Cleanup(func() { se.Close() })
Expand Down Expand Up @@ -716,9 +715,7 @@ func TestX11Forward(t *testing.T) {
}

t.Parallel()
f := newCustomFixture(t, func(cfg *auth.TestServerConfig) {
cfg.Auth.AuditLog = events.NewDiscardAuditLog()
})
f := newFixtureWithoutDiskBasedLogging(t)
f.ssh.srv.x11 = &x11.ServerConfig{
Enabled: true,
DisplayOffset: x11.DefaultDisplayOffset,
Expand All @@ -735,13 +732,6 @@ func TestX11Forward(t *testing.T) {
err = f.testSrv.Auth().UpsertRole(ctx, role)
require.NoError(t, err)

// use a sync recording mode because the disk-based uploader
// that runs in the background introduces races with test cleanup
recConfig := types.DefaultSessionRecordingConfig()
recConfig.SetMode(types.RecordAtNodeSync)
err = f.testSrv.Auth().SetSessionRecordingConfig(ctx, recConfig)
require.NoError(t, err)

// Open two x11 sessions, the server should handle multiple
// concurrent X11 sessions.
serverDisplay := x11EchoSession(ctx, t, f.ssh.clt)
Expand Down Expand Up @@ -1145,8 +1135,7 @@ func noCache(clt auth.ClientI, cacheName []string) (auth.RemoteProxyAccessPoint,
func TestProxyRoundRobin(t *testing.T) {
t.Parallel()

log.Infof("[TEST START] TestProxyRoundRobin")
f := newFixture(t)
f := newFixtureWithoutDiskBasedLogging(t)
ctx := context.Background()

proxyClient, _ := newProxyClient(t, f.testSrv)
Expand Down Expand Up @@ -1395,7 +1384,8 @@ func TestPasswordAuth(t *testing.T) {

func TestClientDisconnect(t *testing.T) {
t.Parallel()
f := newFixture(t)
f := newFixtureWithoutDiskBasedLogging(t)

config := &ssh.ClientConfig{
User: f.user,
Auth: []ssh.AuthMethod{ssh.PublicKeys(f.up.certSigner)},
Expand Down

0 comments on commit a4a5136

Please sign in to comment.