From 73df77aa8dec3d5302f00889fc835e30c2a82964 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Mon, 8 Jul 2019 12:45:27 +0200 Subject: [PATCH] test: add more tests for validate --- package.json | 1 + test/pubsub.spec.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/package.json b/package.json index 2a69cba707..4cdc1c95ac 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "pull-length-prefixed": "^1.3.1", "pull-pushable": "^2.2.0", "pull-stream": "^3.6.9", + "sinon": "^7.3.2", "time-cache": "~0.3.0" }, "contributors": [ diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index dfff9c8c8b..11f10bc106 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -5,6 +5,7 @@ const chai = require('chai') chai.use(require('dirty-chai')) chai.use(require('chai-spies')) const expect = chai.expect +const sinon = require('sinon') const series = require('async/series') const parallel = require('async/parallel') @@ -36,6 +37,10 @@ class PubsubImplementation extends PubsubBaseProtocol { } describe('pubsub base protocol', () => { + afterEach(() => { + sinon.restore() + }) + describe('fresh nodes', () => { let nodeA let nodeB @@ -109,6 +114,40 @@ describe('pubsub base protocol', () => { }) }) }) + + it('validate with strict signing off will validate a present signature', (done) => { + const message = { + from: psA.peerId.id, + data: 'hello', + seqno: randomSeqno(), + topicIDs: ['test-topic'] + } + + sinon.stub(psA, 'strictSigning').value(false) + + psA._buildMessage(message, (err, signedMessage) => { + expect(err).to.not.exist() + + psA.validate(signedMessage, (err, verified) => { + expect(verified).to.eql(true) + done(err) + }) + }) + }) + + it('validate with strict signing requires a signature', (done) => { + const message = { + from: psA.peerId.id, + data: 'hello', + seqno: randomSeqno(), + topicIDs: ['test-topic'] + } + + psA.validate(message, (err, verified) => { + expect(verified).to.eql(false) + done(err) + }) + }) }) describe('dial the pubsub protocol on mount', () => {