(t *testing.T)
| 484 | } |
| 485 | |
| 486 | func 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 |
| 518 | type customNetError struct { |
nothing calls this directly
no test coverage detected