(t *testing.T)
| 532 | } |
| 533 | |
| 534 | func (h *serverHelper) start(t *testing.T) (hostKey []byte, err error) { |
| 535 | if h.server != nil { |
| 536 | return nil, fmt.Errorf("server already running") |
| 537 | } |
| 538 | cfg := config.SSHConfig{} |
| 539 | structutils.Defaults(&cfg) |
| 540 | cfg.Listen = h.listen |
| 541 | if err := cfg.GenerateHostKey(); err != nil { |
| 542 | return nil, err |
| 543 | } |
| 544 | private, err := ssh.ParsePrivateKey([]byte(cfg.HostKeys[0])) |
| 545 | if err != nil { |
| 546 | return nil, err |
| 547 | } |
| 548 | hostKey = private.PublicKey().Marshal() |
| 549 | logger := log.NewTestLogger(t) |
| 550 | readyChannel := make(chan struct{}, 1) |
| 551 | h.shutdownChannel = make(chan struct{}, 1) |
| 552 | errChannel := make(chan error, 1) |
| 553 | handler := newFullHandler( |
| 554 | readyChannel, |
| 555 | h.shutdownChannel, |
| 556 | h.passwords, |
| 557 | h.pubKeys, |
| 558 | ) |
| 559 | server, err := sshserver.New(cfg, handler, logger) |
| 560 | if err != nil { |
| 561 | return hostKey, err |
| 562 | } |
| 563 | lifecycle := service.NewLifecycle(server) |
| 564 | h.lifecycle = lifecycle |
| 565 | go func() { |
| 566 | err = lifecycle.Run() |
| 567 | if err != nil { |
| 568 | errChannel <- err |
| 569 | } |
| 570 | }() |
| 571 | //Wait for the server to be ready |
| 572 | select { |
| 573 | case err := <-errChannel: |
| 574 | return hostKey, err |
| 575 | case <-readyChannel: |
| 576 | } |
| 577 | h.server = server |
| 578 | return hostKey, nil |
| 579 | } |
| 580 | |
| 581 | func (h *serverHelper) stop() { |
| 582 | if h.lifecycle != nil { |
nothing calls this directly
no test coverage detected