netadd: split ValidatenodeAnn into sig and field checks
Check that the node ann doesnt contain more than 1 DNS addr. This will ensure that we now start rejecting new node announcements with multiple DNS addrs since this check is called in the gossiper before persisting a node ann to our local graph. It also validates the DNS fields according to BOLT #7 specs.
This commit is contained in:
1 parent
670b26ba3d
commit
f0a20c9d04
3 files changed
+182
-2
No files matched your search
@@ -0,0 +1,87 @@
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestValidateDNSAddr tests hostname and port validation per BOLT #7.
|
||||
func TestValidateDNSAddr(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
hostname string
|
||||
port uint16
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "empty hostname",
|
||||
hostname: "",
|
||||
port: 9735,
|
||||
err: ErrEmptyDNSHostname,
|
||||
},
|
||||
{
|
||||
name: "zero port",
|
||||
hostname: "example.com",
|
||||
port: 0,
|
||||
err: ErrZeroPort,
|
||||
},
|
||||
{
|
||||
name: "hostname too long",
|
||||
hostname: strings.Repeat("a", 256),
|
||||
port: 9735,
|
||||
err: fmt.Errorf("%w: DNS hostname length 256",
|
||||
ErrHostnameTooLong),
|
||||
},
|
||||
{
|
||||
name: "hostname with invalid ASCII space",
|
||||
hostname: "exa mple.com",
|
||||
port: 9735,
|
||||
err: fmt.Errorf("%w: hostname 'exa mple.com' contains "+
|
||||
"invalid character ' ' at position 3",
|
||||
ErrInvalidHostnameCharacter),
|
||||
},
|
||||
{
|
||||
name: "hostname with invalid ASCII underscore",
|
||||
hostname: "example_node.com",
|
||||
port: 9735,
|
||||
err: fmt.Errorf("%w: hostname 'example_node.com' "+
|
||||
"contains invalid character '_' at position 7",
|
||||
ErrInvalidHostnameCharacter),
|
||||
},
|
||||
{
|
||||
name: "hostname with non-ASCII character",
|
||||
hostname: "example❄️.com",
|
||||
port: 9735,
|
||||
err: fmt.Errorf("%w: hostname 'example❄️.com' "+
|
||||
"contains invalid character '❄' at position 7",
|
||||
ErrInvalidHostnameCharacter),
|
||||
},
|
||||
{
|
||||
name: "valid hostname",
|
||||
hostname: "example.com",
|
||||
port: 9735,
|
||||
},
|
||||
{
|
||||
name: "valid hostname with numbers",
|
||||
hostname: "node101.example.com",
|
||||
port: 9735,
|
||||
},
|
||||
{
|
||||
name: "valid hostname with hyphens",
|
||||
hostname: "my-node.example-domain.com",
|
||||
port: 9735,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := ValidateDNSAddr(tc.hostname, tc.port)
|
||||
require.Equal(t, err, tc.err)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user