devbox/internal/hub/sharename_test.go
shoemoney 38766fdcd5 feat(M7): SSE reconnect backoff + share-name validation 🛡️
- daemon: exponential backoff (1s→30s) + ±25% jitter on SSE reconnect so a fleet
  that drops together doesn't reconnect in lockstep; a long-lived stream resets it
- hub: ValidateShareName rejects path separators, traversal, control/non-ASCII
  chars, reserved Windows device names (CON/NUL/COM1…), and case-clashes with an
  existing share (Foo vs foo would collide on case-insensitive filesystems)
- tests for both
2026-06-23 01:26:04 -05:00

38 lines
1.2 KiB
Go

package hub
import "testing"
func TestValidateShareName(t *testing.T) {
existing := []string{"projects", "Repos"}
cases := []struct {
name string
ok bool
}{
{"projects", true}, // exact match of an existing share is fine (idempotent publish)
{"my-app_2", true}, // letters, digits, dash, underscore
{"web.staging", true},
{"", false}, // empty
{" lead", false}, // whitespace
{"trail ", false},
{"a/b", false}, // path separator (sub-paths are mount-side, not in the name)
{"a\\b", false}, // backslash
{"..", false}, // traversal
{".hidden", false}, // leading dot
{"-flag", false}, // leading dash
{"sp ace", false}, // interior space
{"emoji🎉", false}, // non-ASCII
{"CON", false}, // reserved Windows device name
{"lpt3", false}, // reserved (case-insensitive)
{"repos", false}, // case-clashes with existing "Repos"
{"REPOS", false}, // case-clash
}
for _, c := range cases {
err := ValidateShareName(c.name, existing)
if c.ok && err != nil {
t.Errorf("ValidateShareName(%q) = %v, want ok", c.name, err)
}
if !c.ok && err == nil {
t.Errorf("ValidateShareName(%q) = ok, want error", c.name)
}
}
}