fix(peer): allow empty peer names
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
572970d255
commit
d5a962996b
3 changed files with 9 additions and 9 deletions
|
|
@ -98,7 +98,7 @@ The `Transport` manages a WebSocket server (gorilla/websocket) and outbound conn
|
|||
| Timeout | −3.0 (floored at 0) |
|
||||
| Default (new peer) | 50.0 |
|
||||
|
||||
**Peer name validation**: Names must be 1–64 characters, start and end with an alphanumeric character, and contain only alphanumeric, hyphen, underscore, or space characters.
|
||||
**Peer name validation**: Empty names are permitted. Non-empty names must be 1–64 characters, start and end with an alphanumeric character, and contain only alphanumeric, hyphen, underscore, or space characters.
|
||||
|
||||
### message.go — Protocol Messages
|
||||
|
||||
|
|
|
|||
12
node/peer.go
12
node/peer.go
|
|
@ -51,9 +51,8 @@ const (
|
|||
PeerAuthAllowlist
|
||||
)
|
||||
|
||||
// Peer name validation constants
|
||||
// Peer name validation constants.
|
||||
const (
|
||||
PeerNameMinLength = 1
|
||||
PeerNameMaxLength = 64
|
||||
)
|
||||
|
||||
|
|
@ -72,11 +71,12 @@ func safeKeyPrefix(key string) string {
|
|||
}
|
||||
|
||||
// validatePeerName checks if a peer name is valid.
|
||||
// Peer names must be 1-64 characters, start and end with alphanumeric,
|
||||
// and contain only alphanumeric, hyphens, underscores, and spaces.
|
||||
// Empty names are permitted. Non-empty names must be 1-64 characters,
|
||||
// start and end with alphanumeric, and contain only alphanumeric,
|
||||
// hyphens, underscores, and spaces.
|
||||
func validatePeerName(name string) error {
|
||||
if len(name) < PeerNameMinLength {
|
||||
return coreerr.E("validatePeerName", "peer name too short", nil)
|
||||
if name == "" {
|
||||
return nil
|
||||
}
|
||||
if len(name) > PeerNameMaxLength {
|
||||
return coreerr.E("validatePeerName", "peer name too long", nil)
|
||||
|
|
|
|||
|
|
@ -543,7 +543,7 @@ func TestPeerRegistry_PeerNameValidation(t *testing.T) {
|
|||
peerName string
|
||||
shouldErr bool
|
||||
}{
|
||||
{"empty name rejected", "", true},
|
||||
{"empty name allowed", "", false},
|
||||
{"single char", "A", false},
|
||||
{"simple name", "MyPeer", false},
|
||||
{"name with hyphen", "my-peer", false},
|
||||
|
|
@ -697,7 +697,7 @@ func TestValidatePeerName(t *testing.T) {
|
|||
peerName string
|
||||
shouldErr bool
|
||||
}{
|
||||
{"empty rejected", "", true},
|
||||
{"empty allowed", "", false},
|
||||
{"single alphanumeric", "A", false},
|
||||
{"simple alphanumeric", "TestPeer", false},
|
||||
{"with hyphens", "test-peer", false},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue