Skip to content

Commit

Permalink
test: add more tests for validate
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed Jul 8, 2019
1 parent ca99ce9 commit 73df77a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
39 changes: 39 additions & 0 deletions test/pubsub.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -36,6 +37,10 @@ class PubsubImplementation extends PubsubBaseProtocol {
}

describe('pubsub base protocol', () => {
afterEach(() => {
sinon.restore()
})

describe('fresh nodes', () => {
let nodeA
let nodeB
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 73df77a

Please sign in to comment.