backup_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // backup_test.go — issue #218: el download de la BD completa queda
  2. // restringido a admin y avisa explícitamente de que contiene secrets kv.
  3. package httpapi_test
  4. import (
  5. "net/http"
  6. "testing"
  7. )
  8. func TestBackupDownloadAdminHeaderYGate(t *testing.T) {
  9. srv := makeTestServer(t)
  10. _, adminCookie, _ := loginCookie(t, srv.URL, "admin", "test123456")
  11. // Admin: 200 + aviso explícito de que la descarga lleva secrets.
  12. req, _ := http.NewRequest("GET", srv.URL+"/api/backup/download", nil)
  13. req.AddCookie(&http.Cookie{Name: "session", Value: adminCookie})
  14. res, err := http.DefaultClient.Do(req)
  15. if err != nil {
  16. t.Fatalf("download: %v", err)
  17. }
  18. res.Body.Close()
  19. if res.StatusCode != http.StatusOK {
  20. t.Fatalf("download admin: got %d want 200", res.StatusCode)
  21. }
  22. if res.Header.Get("X-Netpulse-Backup-Contains-Credentials") != "true" {
  23. t.Fatal("la descarga debe avisar de que contiene credenciales")
  24. }
  25. // Sin sesión: no debe servir el backup.
  26. res2, err := http.Get(srv.URL + "/api/backup/download")
  27. if err != nil {
  28. t.Fatalf("download sin sesión: %v", err)
  29. }
  30. res2.Body.Close()
  31. if res2.StatusCode == http.StatusOK {
  32. t.Fatal("el download sin sesión debe rechazarse")
  33. }
  34. }