4
0

integrations_sshpass_internal_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // integrations_sshpass_internal_test.go - #1708: applyIntegrationSSHAuth con
  2. // un pool que solo implementa Run (los fakes clásicos de la app): la
  3. // aplicación de credencial es opcional y no debe romper el camino SSH.
  4. package httpapi
  5. import (
  6. "testing"
  7. "time"
  8. "github.com/gnacho/netpulse/server-go/internal/rintegration"
  9. )
  10. type runOnlyPool struct {
  11. runs int
  12. }
  13. func (p *runOnlyPool) Run(host, cmd string, _ time.Duration) (string, error) {
  14. p.runs++
  15. return "", nil
  16. }
  17. // TestApplyIntegrationSSHAuthWithoutSetter: sin capacidad de contraseña en
  18. // el pool, el comando SSH sigue ejecutándose con la llave de siempre.
  19. func TestApplyIntegrationSSHAuthWithoutSetter(t *testing.T) {
  20. pool := &runOnlyPool{}
  21. mgr := rintegration.NewManager(t.TempDir())
  22. s := &server{pool: pool, integrations: mgr}
  23. if err := mgr.WriteSSHPassword("wrt", "pw"); err != nil {
  24. t.Fatal(err)
  25. }
  26. row := rintegration.Row{Slug: "wrt", Host: "10.0.0.9", Username: "admin"}
  27. if _, err := s.runIntegrationSSH(row, "true", time.Second); err != nil {
  28. t.Fatalf("runIntegrationSSH: %v", err)
  29. }
  30. if pool.runs != 1 {
  31. t.Fatalf("runs = %d, quiero 1", pool.runs)
  32. }
  33. }