check right handshake is used in noise pipes tests

This commit is contained in:
Yusef Napora 2019-12-04 13:17:09 -05:00
parent c64dd2c19d
commit a7d5094883
1 changed files with 14 additions and 12 deletions

View File

@ -176,25 +176,17 @@ func TestHandshakeXX(t *testing.T) {
// Test IK handshake
func TestHandshakeIK(t *testing.T) {
initTransport := newTestTransport(t, crypto.Ed25519, 2048)
respTransport := newTestTransport(t, crypto.Ed25519, 2048)
// do initial XX handshake
initConn, respConn := connect(t, initTransport, respTransport)
initConn.Close()
respConn.Close()
// turn on pipes, this will turn on IK
initTransport.NoisePipesSupport = true
respTransport.NoisePipesSupport = true
initTransport := newTestTransportPipes(t, crypto.Ed25519, 2048)
respTransport := newTestTransportPipes(t, crypto.Ed25519, 2048)
// add responder's static key to initiator's key cache
respTransport.NoiseKeypair = GenerateKeypair()
keycache := make(map[peer.ID]([32]byte))
keycache[respTransport.LocalID] = respTransport.NoiseKeypair.public_key
initTransport.NoiseStaticKeyCache = keycache
// do IK handshake
initConn, respConn = connect(t, initTransport, respTransport)
initConn, respConn := connect(t, initTransport, respTransport)
defer initConn.Close()
defer respConn.Close()
@ -213,6 +205,11 @@ func TestHandshakeIK(t *testing.T) {
if !bytes.Equal(before, after) {
t.Errorf("Message mismatch. %v != %v", before, after)
}
// make sure IK was actually used
if !(initConn.ik_complete && respConn.ik_complete) {
t.Error("Expected IK handshake to be used")
}
}
// Test noise pipes
@ -241,4 +238,9 @@ func TestHandshakeXXfallback(t *testing.T) {
if !bytes.Equal(before, after) {
t.Errorf("Message mismatch. %v != %v", before, after)
}
// make sure XX was actually used
if !(initConn.xx_complete && respConn.xx_complete) {
t.Error("Expected XXfallback handshake to be used")
}
}