fix(peer): reject empty peer names
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
ee623a7343
commit
572970d255
2 changed files with 2 additions and 5 deletions
|
|
@ -75,9 +75,6 @@ func safeKeyPrefix(key string) string {
|
||||||
// Peer names must be 1-64 characters, start and end with alphanumeric,
|
// Peer names must be 1-64 characters, start and end with alphanumeric,
|
||||||
// and contain only alphanumeric, hyphens, underscores, and spaces.
|
// and contain only alphanumeric, hyphens, underscores, and spaces.
|
||||||
func validatePeerName(name string) error {
|
func validatePeerName(name string) error {
|
||||||
if name == "" {
|
|
||||||
return nil // Empty names are allowed (optional field)
|
|
||||||
}
|
|
||||||
if len(name) < PeerNameMinLength {
|
if len(name) < PeerNameMinLength {
|
||||||
return coreerr.E("validatePeerName", "peer name too short", nil)
|
return coreerr.E("validatePeerName", "peer name too short", nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -543,7 +543,7 @@ func TestPeerRegistry_PeerNameValidation(t *testing.T) {
|
||||||
peerName string
|
peerName string
|
||||||
shouldErr bool
|
shouldErr bool
|
||||||
}{
|
}{
|
||||||
{"empty name allowed", "", false},
|
{"empty name rejected", "", true},
|
||||||
{"single char", "A", false},
|
{"single char", "A", false},
|
||||||
{"simple name", "MyPeer", false},
|
{"simple name", "MyPeer", false},
|
||||||
{"name with hyphen", "my-peer", false},
|
{"name with hyphen", "my-peer", false},
|
||||||
|
|
@ -697,7 +697,7 @@ func TestValidatePeerName(t *testing.T) {
|
||||||
peerName string
|
peerName string
|
||||||
shouldErr bool
|
shouldErr bool
|
||||||
}{
|
}{
|
||||||
{"empty allowed", "", false},
|
{"empty rejected", "", true},
|
||||||
{"single alphanumeric", "A", false},
|
{"single alphanumeric", "A", false},
|
||||||
{"simple alphanumeric", "TestPeer", false},
|
{"simple alphanumeric", "TestPeer", false},
|
||||||
{"with hyphens", "test-peer", false},
|
{"with hyphens", "test-peer", false},
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue