channeldb/addr_test: add invalid TCP cases
These are invalid length IP addresses that earlier would not fail to serialize.
This commit is contained in:
parent
02b7bb356a
commit
e2e00f9dd2
@ -14,19 +14,23 @@ type unknownAddrType struct{}
|
||||
func (t unknownAddrType) Network() string { return "unknown" }
|
||||
func (t unknownAddrType) String() string { return "unknown" }
|
||||
|
||||
var testIP4 = net.ParseIP("192.168.1.1")
|
||||
var testIP6 = net.ParseIP("2001:0db8:0000:0000:0000:ff00:0042:8329")
|
||||
|
||||
var addrTests = []struct {
|
||||
expAddr net.Addr
|
||||
serErr string
|
||||
}{
|
||||
// Valid addresses.
|
||||
{
|
||||
expAddr: &net.TCPAddr{
|
||||
IP: net.ParseIP("192.168.1.1"),
|
||||
IP: testIP4,
|
||||
Port: 12345,
|
||||
},
|
||||
},
|
||||
{
|
||||
expAddr: &net.TCPAddr{
|
||||
IP: net.ParseIP("2001:0db8:0000:0000:0000:ff00:0042:8329"),
|
||||
IP: testIP6,
|
||||
Port: 65535,
|
||||
},
|
||||
},
|
||||
@ -42,10 +46,44 @@ var addrTests = []struct {
|
||||
Port: 80,
|
||||
},
|
||||
},
|
||||
|
||||
// Invalid addresses.
|
||||
{
|
||||
expAddr: unknownAddrType{},
|
||||
serErr: ErrUnknownAddressType.Error(),
|
||||
},
|
||||
{
|
||||
expAddr: &net.TCPAddr{
|
||||
// Remove last byte of IPv4 address.
|
||||
IP: testIP4[:len(testIP4)-1],
|
||||
Port: 12345,
|
||||
},
|
||||
serErr: "unable to encode",
|
||||
},
|
||||
{
|
||||
expAddr: &net.TCPAddr{
|
||||
// Add an extra byte of IPv4 address.
|
||||
IP: append(testIP4, 0xff),
|
||||
Port: 12345,
|
||||
},
|
||||
serErr: "unable to encode",
|
||||
},
|
||||
{
|
||||
expAddr: &net.TCPAddr{
|
||||
// Remove last byte of IPv6 address.
|
||||
IP: testIP6[:len(testIP6)-1],
|
||||
Port: 65535,
|
||||
},
|
||||
serErr: "unable to encode",
|
||||
},
|
||||
{
|
||||
expAddr: &net.TCPAddr{
|
||||
// Add an extra byte to the IPv6 address.
|
||||
IP: append(testIP6, 0xff),
|
||||
Port: 65535,
|
||||
},
|
||||
serErr: "unable to encode",
|
||||
},
|
||||
}
|
||||
|
||||
// TestAddrSerialization tests that the serialization method used by channeldb
|
||||
|
Loading…
Reference in New Issue
Block a user