MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / TestRobustSSHConnectCtxAuthErrorRetries

Function TestRobustSSHConnectCtxAuthErrorRetries

utils/ssh_test.go:486–515  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

484}
485
486func TestRobustSSHConnectCtxAuthErrorRetries(t *testing.T) {
487 // Auth errors are now retried (key may still be propagating to instance)
488 // so this test verifies the retry behavior with a wrong key eventually times out
489 tmpDir, cleanup := setupTestEnvironment(t)
490 defer cleanup()
491
492 acceptedKey, acceptedSigner, acceptedPublic := generateRSAKeyPair(t)
493 _ = acceptedSigner // keep for clarity
494 rejectedKey, _, _ := generateRSAKeyPair(t)
495
496 acceptedKeyPath := filepath.Join(tmpDir, "accepted")
497 savePrivateKeyToFile(t, acceptedKey, acceptedKeyPath)
498
499 rejectedKeyPath := filepath.Join(tmpDir, "rejected")
500 savePrivateKeyToFile(t, rejectedKey, rejectedKeyPath)
501
502 server, serverCleanup := setupSSHTestServer(t, acceptedPublic)
503 defer serverCleanup()
504
505 // Use a short timeout since auth errors are now retried
506 ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
507 defer cancel()
508
509 _, err := RobustSSHConnectCtx(ctx, "127.0.0.1", rejectedKeyPath, server.port, 3)
510 require.Error(t, err)
511 // Should either timeout or be cancelled (auth errors are retried until timeout)
512 assert.True(t, strings.Contains(err.Error(), "timeout") ||
513 strings.Contains(err.Error(), "cancelled"),
514 "unexpected error: %s", err.Error())
515}
516
517// customNetError implements net.Error with configurable behavior
518type customNetError struct {

Callers

nothing calls this directly

Calls 6

generateRSAKeyPairFunction · 0.85
savePrivateKeyToFileFunction · 0.85
setupSSHTestServerFunction · 0.85
RobustSSHConnectCtxFunction · 0.85
setupTestEnvironmentFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected