From a5c45bfc537b1783f08dd7b4c937cad2fb014f1c Mon Sep 17 00:00:00 2001 From: morrigan Date: Sat, 8 Feb 2020 12:11:16 +0100 Subject: [PATCH] Additional check --- src/noise.ts | 4 ++-- test/noise.test.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/noise.ts b/src/noise.ts index 304b3d3..33bd737 100644 --- a/src/noise.ts +++ b/src/noise.ts @@ -181,8 +181,8 @@ export class Noise implements INoiseConnection { await handshake.exchange(); await handshake.finish(); - if (this.useNoisePipes && remotePeer) { - KeyCache.store(remotePeer, handshake.getRemoteStaticKey()); + if (this.useNoisePipes && handshake.remotePeer) { + KeyCache.store(handshake.remotePeer, handshake.getRemoteStaticKey()); } } catch (e) { throw new Error(`Error occurred during XX handshake: ${e.message}`); diff --git a/test/noise.test.ts b/test/noise.test.ts index 38a23e4..b15a338 100644 --- a/test/noise.test.ts +++ b/test/noise.test.ts @@ -270,12 +270,13 @@ describe("Noise", () => { const staticKeysResponder = generateKeypair(); const noiseResp = new Noise(staticKeysResponder.privateKey); + const ikInitSpy = sandbox.spy(noiseInit, "performIKHandshake"); const xxFallbackInitSpy = sandbox.spy(noiseInit, "performXXFallbackHandshake"); const xxRespSpy = sandbox.spy(noiseResp, "performXXHandshake"); // Prepare key cache for noise pipes KeyCache.resetStorage(); - KeyCache.store(localPeer, staticKeysResponder.publicKey); + KeyCache.store(remotePeer, staticKeysResponder.publicKey); const [inboundConnection, outboundConnection] = DuplexPair(); @@ -291,6 +292,7 @@ describe("Noise", () => { const response = await wrappedInbound.readLP(); expect(response.toString()).equal("test fallback"); + assert(ikInitSpy.calledOnce, "IK handshake was not called."); assert(xxFallbackInitSpy.calledOnce, "XX Fallback method was not called."); assert(xxRespSpy.calledOnce, "XX method was not called."); } catch (e) {