Previously the advertised device name defaulted to the machine hostname. Since the alias is broadcast in plaintext over multicast to the whole subnet every few seconds while the TUI is open, that leaks the hostname to anyone on the network — a privacy problem on a laptop joining untrusted Wi-Fi (the reason LocalSend randomises its aliases). Now first run generates a random "Colour Object" name from public-domain word lists (e.g. "Crimson Quasar"): 56 colours x 44 celestial objects = 2464 combinations. It is generated once and persisted, so a device keeps the same name across restarts. The hostname is still carried in DeviceModel, and the alias remains overridable via --alias or Settings. Word lists are original and use only generic colours and public-domain astronomy terms, so there is no copyright or trademark exposure. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// randomAlias must always be a "Colour Object" pair drawn from the curated,
|
|
// copyright-safe word lists.
|
|
func TestRandomAliasFormat(t *testing.T) {
|
|
colours := make(map[string]bool, len(aliasColours))
|
|
for _, w := range aliasColours {
|
|
colours[w] = true
|
|
}
|
|
objects := make(map[string]bool, len(aliasObjects))
|
|
for _, w := range aliasObjects {
|
|
objects[w] = true
|
|
}
|
|
|
|
for i := 0; i < 500; i++ {
|
|
a := randomAlias()
|
|
parts := strings.SplitN(a, " ", 2)
|
|
if len(parts) != 2 {
|
|
t.Fatalf("alias %q is not two words", a)
|
|
}
|
|
if !colours[parts[0]] {
|
|
t.Fatalf("alias %q: colour %q not in aliasColours", a, parts[0])
|
|
}
|
|
if !objects[parts[1]] {
|
|
t.Fatalf("alias %q: object %q not in aliasObjects", a, parts[1])
|
|
}
|
|
}
|
|
}
|
|
|
|
// The word lists must contain no duplicates, or the real pool is smaller than
|
|
// it looks.
|
|
func TestAliasWordsUnique(t *testing.T) {
|
|
for _, list := range []struct {
|
|
name string
|
|
words []string
|
|
}{
|
|
{"aliasColours", aliasColours},
|
|
{"aliasObjects", aliasObjects},
|
|
} {
|
|
seen := make(map[string]bool, len(list.words))
|
|
for _, w := range list.words {
|
|
if seen[w] {
|
|
t.Errorf("%s: duplicate word %q", list.name, w)
|
|
}
|
|
seen[w] = true
|
|
}
|
|
}
|
|
}
|
|
|
|
// Sanity check that the generator actually varies (not stuck on one value).
|
|
func TestRandomAliasVaries(t *testing.T) {
|
|
seen := make(map[string]struct{})
|
|
for i := 0; i < 200; i++ {
|
|
seen[randomAlias()] = struct{}{}
|
|
}
|
|
if len(seen) < 10 {
|
|
t.Fatalf("randomAlias produced only %d distinct values over 200 draws", len(seen))
|
|
}
|
|
}
|