fix(trustedagents): skip empty-hostname entries in Load and SetForTest (PILOT-137)#5
Conversation
…t (PILOT-137)
Load() silently accepted list entries with a non-zero node_id but an
empty hostname, which produced a trusted peer with an empty-string
name (IsTrusted returned ("", true)). Now both Load() and
SetForTest drop entries whose Hostname is empty, matching the
existing guard that drops NodeID==0 entries.
Verification: go build + go vet clean. All 28 tests pass including
two new tests (TestEmptyHostnameSkipped, TestLoadEmptyHostnameSkipped)
that confirm empty-hostname entries are excluded and valid neighbours
are unaffected.
Closes PILOT-137
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
🦾 Matthew PR Check — #5 PILOT-137Status
VerdictCLEAN — all CI green, mergeable, no blockers. 🤖 matthew-pr-worker auto-check • 2026-05-28T16:43 UTC |
🦜 Matthew Explains — #5 PILOT-137What this doesAdds a guard to Why it mattersPrevents silent trust of misconfigured or malformed agent entries. An entry with a valid-looking RiskLow — the change is defensive: it skips entries it would have previously accepted. No behavioral change for well-formed configs. 🤖 matthew-pr-worker auto-review • 2026-05-28T16:43 UTC |
What failed
Load()intrustedagents/data.goparsed list entries with non-zeronode_idbut emptyhostname, silently trusting peers with an empty-string name.IsTrusted(42)would return("", true)if a JSON entry had{"hostname":"","node_id":42}.Root cause
The entry filter in
Load()(andSetForTest) skipped onlyNodeID == 0entries, allowing entries with emptyHostnamethrough to the trust map.Fix
Added an empty-hostname guard alongside the existing zero-node-id guard in both
Load()andSetForTest:Verification
go build ./...— cleango vet ./...— cleango test ./...— all 28 tests pass including two new tests:TestEmptyHostnameSkipped—SetForTestdrops empty-hostname entriesTestLoadEmptyHostnameSkipped—Loaddrops empty-hostname entriesCloses PILOT-137