integrations_pinheal_test.go 941 B

1234567891011121314151617181920212223242526272829
  1. package httpapi
  2. import "testing"
  3. func TestHealPusherPinAddsPinForHTTPS(t *testing.T) {
  4. orig := serverFPWithError
  5. serverFPWithError = func(string) (string, error) { return "sha256-test-pin", nil }
  6. defer func() { serverFPWithError = orig }()
  7. env := map[string]string{
  8. "NETPULSE_SERVER": "https://np.example:3000",
  9. "NETPULSE_INTERVAL": "45s",
  10. }
  11. out := healPusherPin(env, "https://np.example:3000")
  12. if out["NETPULSE_SERVER_FP"] != "sha256-test-pin" {
  13. t.Fatalf("pin not merged: got %q", out["NETPULSE_SERVER_FP"])
  14. }
  15. if out["NETPULSE_INTERVAL"] != "45s" {
  16. t.Fatalf("existing keys must be preserved, got %q", out["NETPULSE_INTERVAL"])
  17. }
  18. }
  19. func TestHealPusherPinNoopForHTTP(t *testing.T) {
  20. env := map[string]string{"NETPULSE_SERVER": "http://127.0.0.1:3000"}
  21. out := healPusherPin(env, "http://127.0.0.1:3000")
  22. if _, ok := out["NETPULSE_SERVER_FP"]; ok {
  23. t.Fatal("pin must not be added for a plain http server URL")
  24. }
  25. }