ctl_unix_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //go:build !windows
  2. package ctl
  3. import (
  4. "os"
  5. "path/filepath"
  6. "strings"
  7. "testing"
  8. "github.com/slackhq/nebula/localapi"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. )
  12. // TestResolveSocketDiagnosesAnOverlongOverride: the CLI applies the daemon's own rule to
  13. // the override, so it says what the daemon's log says rather than dialing a path the
  14. // kernel would truncate and reporting the generic failure. The rule is sun_path's, which
  15. // a named pipe does not have, so this is a unix test.
  16. func TestResolveSocketDiagnosesAnOverlongOverride(t *testing.T) {
  17. cfg := filepath.Join(t.TempDir(), "config.yml")
  18. long := "/" + strings.Repeat("x", 120)
  19. require.NoError(t, os.WriteFile(cfg, []byte("local_api:\n control:\n socket: "+long+"\n"), 0600))
  20. _, err := resolveSocket("", cfg)
  21. require.Error(t, err)
  22. require.ErrorContains(t, err, "too long for this platform")
  23. assert.ErrorContains(t, err, localapi.CtlSocketKey)
  24. }
  25. // TestResolveSocketRefusesARelativeOverride: the CLI applies the daemon's rule here too,
  26. // so a relative path in the config is reported as the daemon's log reports it rather
  27. // than resolved against wherever nebula ctl happened to be run from.
  28. func TestResolveSocketRefusesARelativeOverride(t *testing.T) {
  29. cfg := filepath.Join(t.TempDir(), "config.yml")
  30. require.NoError(t, os.WriteFile(cfg, []byte("local_api:\n control:\n socket: run/ctl.sock\n"), 0600))
  31. _, err := resolveSocket("", cfg)
  32. require.Error(t, err)
  33. require.ErrorContains(t, err, "must be an absolute path")
  34. assert.ErrorContains(t, err, localapi.CtlSocketKey)
  35. }