diff --git a/cmd/devp2p/internal/v5test/discv5tests.go b/cmd/devp2p/internal/v5test/discv5tests.go index 4dc2507693..ec10db6ba4 100644 --- a/cmd/devp2p/internal/v5test/discv5tests.go +++ b/cmd/devp2p/internal/v5test/discv5tests.go @@ -54,6 +54,7 @@ func (s *Suite) AllTests() []utesting.Test { {Name: "PingMultiIP", Fn: s.TestPingMultiIP}, {Name: "HandshakeResend", Fn: s.TestHandshakeResend}, {Name: "TalkRequest", Fn: s.TestTalkRequest}, + {Name: "FindnodeWrongIP", Fn: s.TestFindnodeWrongIP}, {Name: "FindnodeZeroDistance", Fn: s.TestFindnodeZeroDistance}, {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) { t.Log(`This test checks that the remote node returns itself for FINDNODE with distance zero.`)