Additional check

This commit is contained in:
morrigan 2020-02-08 12:11:16 +01:00
parent 36e3462a82
commit a5c45bfc53
2 changed files with 5 additions and 3 deletions

View File

@ -181,8 +181,8 @@ export class Noise implements INoiseConnection {
await handshake.exchange(); await handshake.exchange();
await handshake.finish(); await handshake.finish();
if (this.useNoisePipes && remotePeer) { if (this.useNoisePipes && handshake.remotePeer) {
KeyCache.store(remotePeer, handshake.getRemoteStaticKey()); KeyCache.store(handshake.remotePeer, handshake.getRemoteStaticKey());
} }
} catch (e) { } catch (e) {
throw new Error(`Error occurred during XX handshake: ${e.message}`); throw new Error(`Error occurred during XX handshake: ${e.message}`);

View File

@ -270,12 +270,13 @@ describe("Noise", () => {
const staticKeysResponder = generateKeypair(); const staticKeysResponder = generateKeypair();
const noiseResp = new Noise(staticKeysResponder.privateKey); const noiseResp = new Noise(staticKeysResponder.privateKey);
const ikInitSpy = sandbox.spy(noiseInit, "performIKHandshake");
const xxFallbackInitSpy = sandbox.spy(noiseInit, "performXXFallbackHandshake"); const xxFallbackInitSpy = sandbox.spy(noiseInit, "performXXFallbackHandshake");
const xxRespSpy = sandbox.spy(noiseResp, "performXXHandshake"); const xxRespSpy = sandbox.spy(noiseResp, "performXXHandshake");
// Prepare key cache for noise pipes // Prepare key cache for noise pipes
KeyCache.resetStorage(); KeyCache.resetStorage();
KeyCache.store(localPeer, staticKeysResponder.publicKey); KeyCache.store(remotePeer, staticKeysResponder.publicKey);
const [inboundConnection, outboundConnection] = DuplexPair(); const [inboundConnection, outboundConnection] = DuplexPair();
@ -291,6 +292,7 @@ describe("Noise", () => {
const response = await wrappedInbound.readLP(); const response = await wrappedInbound.readLP();
expect(response.toString()).equal("test fallback"); expect(response.toString()).equal("test fallback");
assert(ikInitSpy.calledOnce, "IK handshake was not called.");
assert(xxFallbackInitSpy.calledOnce, "XX Fallback method was not called."); assert(xxFallbackInitSpy.calledOnce, "XX Fallback method was not called.");
assert(xxRespSpy.calledOnce, "XX method was not called."); assert(xxRespSpy.calledOnce, "XX method was not called.");
} catch (e) { } catch (e) {