mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-07 23:48:36 +00:00
cmd/devp2p/v5test: test FINDNODE wrong-ip challenge
This commit is contained in:
parent
29e0a6f404
commit
24e0739177
1 changed files with 25 additions and 0 deletions
|
|
@ -54,6 +54,7 @@ func (s *Suite) AllTests() []utesting.Test {
|
||||||
{Name: "PingMultiIP", Fn: s.TestPingMultiIP},
|
{Name: "PingMultiIP", Fn: s.TestPingMultiIP},
|
||||||
{Name: "HandshakeResend", Fn: s.TestHandshakeResend},
|
{Name: "HandshakeResend", Fn: s.TestHandshakeResend},
|
||||||
{Name: "TalkRequest", Fn: s.TestTalkRequest},
|
{Name: "TalkRequest", Fn: s.TestTalkRequest},
|
||||||
|
{Name: "FindnodeWrongIP", Fn: s.TestFindnodeWrongIP},
|
||||||
{Name: "FindnodeZeroDistance", Fn: s.TestFindnodeZeroDistance},
|
{Name: "FindnodeZeroDistance", Fn: s.TestFindnodeZeroDistance},
|
||||||
{Name: "FindnodeResults", Fn: s.TestFindnodeResults},
|
{Name: "FindnodeResults", Fn: s.TestFindnodeResults},
|
||||||
}
|
}
|
||||||
|
|
@ -232,6 +233,30 @@ and expects an empty TALKRESP response.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Suite) TestFindnodeWrongIP(t *utesting.T) {
|
||||||
|
t.Log(`This test establishes a session on one IP, then sends FINDNODE from another IP.
|
||||||
|
The remote node should challenge the second endpoint with WHOAREYOU instead of returning NODES.`)
|
||||||
|
|
||||||
|
conn, l1, l2 := s.listen2(t)
|
||||||
|
defer conn.close()
|
||||||
|
|
||||||
|
ping := &v5wire.Ping{ReqID: conn.nextReqID()}
|
||||||
|
if resp := conn.reqresp(l1, ping); resp.Kind() != v5wire.PongMsg {
|
||||||
|
t.Fatal("expected PONG, got", resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
req := &v5wire.Findnode{ReqID: conn.nextReqID(), Distances: []uint{0}}
|
||||||
|
conn.write(l2, req, nil)
|
||||||
|
switch resp := conn.read(l2).(type) {
|
||||||
|
case *v5wire.Whoareyou:
|
||||||
|
t.Log("got WHOAREYOU for FINDNODE on wrong IP as expected")
|
||||||
|
case *v5wire.Nodes:
|
||||||
|
t.Fatalf("unexpected NODES response on wrong IP: %+v", resp)
|
||||||
|
default:
|
||||||
|
t.Fatal("expected WHOAREYOU, got", resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Suite) TestFindnodeZeroDistance(t *utesting.T) {
|
func (s *Suite) TestFindnodeZeroDistance(t *utesting.T) {
|
||||||
t.Log(`This test checks that the remote node returns itself for FINDNODE with distance zero.`)
|
t.Log(`This test checks that the remote node returns itself for FINDNODE with distance zero.`)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue