add test for peer id mismatch

This commit is contained in:
Yusef Napora 2020-02-03 10:49:15 -05:00
parent 9f6c7d6cde
commit 7aa706618c
1 changed files with 20 additions and 0 deletions

View File

@ -144,6 +144,26 @@ func TestKeys(t *testing.T) {
}
}
func TestPeerIDMismatchFailsHandshake(t *testing.T) {
initTransport := newTestTransport(t, crypto.Ed25519, 2048)
respTransport := newTestTransport(t, crypto.Ed25519, 2048)
init, resp := newConnPair(t)
var initErr error
done := make(chan struct{})
go func() {
defer close(done)
_, initErr = initTransport.SecureOutbound(context.TODO(), init, "a-random-peer-id")
}()
_, _ = respTransport.SecureInbound(context.TODO(), resp)
<-done
if initErr == nil {
t.Fatal("expected initiator to fail with peer ID mismatch error")
}
}
func makeLargePlaintext(size int) []byte {
buf := make([]byte, size)
rand.Read(buf)