(t *testing.T)
| 324 | } |
| 325 | |
| 326 | func TestKeepAlive(t *testing.T) { |
| 327 | //t.Parallel()() |
| 328 | |
| 329 | logger := log.NewTestLogger(t) |
| 330 | |
| 331 | user := sshserver.NewTestUser("test") |
| 332 | user.RandomPassword() |
| 333 | |
| 334 | config := config.SSHConfig{} |
| 335 | structutils.Defaults(&config) |
| 336 | config.ClientAliveInterval = 1 * time.Second |
| 337 | srv := sshserver.NewTestServer( |
| 338 | t, |
| 339 | sshserver.NewTestAuthenticationHandler( |
| 340 | sshserver.NewTestHandler(), |
| 341 | user, |
| 342 | ), |
| 343 | logger, |
| 344 | &config, |
| 345 | ) |
| 346 | srv.Start() |
| 347 | defer srv.Stop(1 * time.Minute) |
| 348 | |
| 349 | hostkey, err := ssh.ParsePrivateKey([]byte(srv.GetHostKey())) |
| 350 | if err != nil { |
| 351 | t.Fatal("Failed to parse private key") |
| 352 | } |
| 353 | sshConfig := &ssh.ClientConfig{ |
| 354 | User: user.Username(), |
| 355 | Auth: user.GetAuthMethods(), |
| 356 | } |
| 357 | sshConfig.HostKeyCallback = func(hostname string, remote net.Addr, key ssh.PublicKey) error { |
| 358 | if bytes.Equal(key.Marshal(), hostkey.PublicKey().Marshal()) { |
| 359 | return nil |
| 360 | } |
| 361 | return fmt.Errorf("invalid host") |
| 362 | } |
| 363 | tcpConnection, err := net.Dial("tcp", srv.GetListen()) |
| 364 | if err != nil { |
| 365 | t.Fatal("tcp handshake failed (%w)", err) |
| 366 | } |
| 367 | connection, _, globalReq, err := ssh.NewClientConn(tcpConnection, srv.GetListen(), sshConfig) |
| 368 | if err != nil { |
| 369 | t.Fatal("ssh handshake failed (%w)", err) |
| 370 | } |
| 371 | defer func() { |
| 372 | _ = connection.Close() |
| 373 | }() |
| 374 | |
| 375 | req := <-globalReq |
| 376 | err = req.Reply(false, nil) |
| 377 | if err != nil { |
| 378 | t.Fatal("Failed to respond to first request") |
| 379 | } |
| 380 | recv1 := time.Now() |
| 381 | |
| 382 | req2 := <-globalReq |
| 383 | recv2 := time.Now() |
nothing calls this directly
no test coverage detected