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

Fix flaky test TestTSHConfigConnectWithOpenSSHClient #35861

Merged
Merged
Changes from 2 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
36 changes: 16 additions & 20 deletions tool/tsh/common/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,28 +1086,24 @@ func mustFailToRunOpenSSHCommand(t *testing.T, configFile string, sshConnString
require.Error(t, err)
}

func mustSearchEvents(t *testing.T, auth *auth.Server) []apievents.AuditEvent {
now := time.Now()
ctx := context.Background()
events, _, err := auth.SearchEvents(ctx, events.SearchEventsRequest{
From: now.Add(-time.Hour),
To: now.Add(time.Hour),
Order: types.EventOrderDescending,
})

require.NoError(t, err)
return events
}

func mustFindFailedNodeLoginAttempt(t *testing.T, s *suite, nodeLogin string) {
av := mustSearchEvents(t, s.root.GetAuthServer())
for _, e := range av {
if e.GetCode() == events.AuthAttemptFailureCode {
require.Equal(t, e.(*apievents.AuthAttempt).Login, nodeLogin)
return
require.EventuallyWithT(t, func(t *assert.CollectT) {
Joerger marked this conversation as resolved.
Show resolved Hide resolved
now := time.Now()
ctx := context.Background()
es, _, err := s.root.GetAuthServer().SearchEvents(ctx, events.SearchEventsRequest{
From: now.Add(-time.Hour),
To: now.Add(time.Hour),
Order: types.EventOrderDescending,
})
assert.NoError(t, err)

for _, e := range es {
if e.GetCode() == events.AuthAttemptFailureCode && e.(*apievents.AuthAttempt).Login == nodeLogin {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics here are slightly different than what we had before - is this intentional?

Before, if there was an AuthAttempt failure, the test would fail if the login was incorrect.

After, we just ignore these events if the login is incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed

return
}
}
}
t.Errorf("failed to find AuthAttemptFailureCode event (0/%d events matched)", len(av))
t.Errorf("Failed to find an AuthAttemptFailureCode event")
}, 5*time.Second, 500*time.Millisecond)
}

func TestFormatCommand(t *testing.T) {
Expand Down
Loading