p2p/discover/v5wire: add tests for invalid handshake and auth data size (#29708)
This commit is contained in:
parent
86a1f0c394
commit
905e325cd8
|
@ -30,6 +30,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/common/mclock"
|
"github.com/ethereum/go-ethereum/common/mclock"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
@ -283,9 +284,38 @@ func TestDecodeErrorsV5(t *testing.T) {
|
||||||
b = make([]byte, 63)
|
b = make([]byte, 63)
|
||||||
net.nodeA.expectDecodeErr(t, errInvalidHeader, b)
|
net.nodeA.expectDecodeErr(t, errInvalidHeader, b)
|
||||||
|
|
||||||
// TODO some more tests would be nice :)
|
t.Run("invalid-handshake-datasize", func(t *testing.T) {
|
||||||
// - check invalid authdata sizes
|
requiredNumber := 108
|
||||||
// - check invalid handshake data sizes
|
|
||||||
|
testDataFile := filepath.Join("testdata", "v5.1-ping-handshake"+".txt")
|
||||||
|
enc := hexFile(testDataFile)
|
||||||
|
//delete some byte from handshake to make it invalid
|
||||||
|
enc = enc[:len(enc)-requiredNumber]
|
||||||
|
net.nodeB.expectDecodeErr(t, errMsgTooShort, enc)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("invalid-auth-datasize", func(t *testing.T) {
|
||||||
|
testPacket := []byte{}
|
||||||
|
testDataFiles := []string{"v5.1-whoareyou", "v5.1-ping-handshake"}
|
||||||
|
for counter, name := range testDataFiles {
|
||||||
|
file := filepath.Join("testdata", name+".txt")
|
||||||
|
enc := hexFile(file)
|
||||||
|
if counter == 0 {
|
||||||
|
//make whoareyou header
|
||||||
|
testPacket = enc[:sizeofStaticPacketData-1]
|
||||||
|
testPacket = append(testPacket, 255)
|
||||||
|
}
|
||||||
|
if counter == 1 {
|
||||||
|
//append invalid auth size
|
||||||
|
testPacket = append(testPacket, enc[sizeofStaticPacketData:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wantErr := "invalid auth size"
|
||||||
|
if _, err := net.nodeB.decode(testPacket); strings.HasSuffix(err.Error(), wantErr) {
|
||||||
|
t.Fatal(fmt.Errorf("(%s) got err %q, want %q", net.nodeB.ln.ID().TerminalString(), err, wantErr))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// This test checks that all test vectors can be decoded.
|
// This test checks that all test vectors can be decoded.
|
||||||
|
|
Loading…
Reference in New Issue