Skip to content

Commit 73df77a

Browse files
committed
test: add more tests for validate
1 parent ca99ce9 commit 73df77a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"pull-length-prefixed": "^1.3.1",
7373
"pull-pushable": "^2.2.0",
7474
"pull-stream": "^3.6.9",
75+
"sinon": "^7.3.2",
7576
"time-cache": "~0.3.0"
7677
},
7778
"contributors": [

test/pubsub.spec.js

+39
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const chai = require('chai')
55
chai.use(require('dirty-chai'))
66
chai.use(require('chai-spies'))
77
const expect = chai.expect
8+
const sinon = require('sinon')
89
const series = require('async/series')
910
const parallel = require('async/parallel')
1011

@@ -36,6 +37,10 @@ class PubsubImplementation extends PubsubBaseProtocol {
3637
}
3738

3839
describe('pubsub base protocol', () => {
40+
afterEach(() => {
41+
sinon.restore()
42+
})
43+
3944
describe('fresh nodes', () => {
4045
let nodeA
4146
let nodeB
@@ -109,6 +114,40 @@ describe('pubsub base protocol', () => {
109114
})
110115
})
111116
})
117+
118+
it('validate with strict signing off will validate a present signature', (done) => {
119+
const message = {
120+
from: psA.peerId.id,
121+
data: 'hello',
122+
seqno: randomSeqno(),
123+
topicIDs: ['test-topic']
124+
}
125+
126+
sinon.stub(psA, 'strictSigning').value(false)
127+
128+
psA._buildMessage(message, (err, signedMessage) => {
129+
expect(err).to.not.exist()
130+
131+
psA.validate(signedMessage, (err, verified) => {
132+
expect(verified).to.eql(true)
133+
done(err)
134+
})
135+
})
136+
})
137+
138+
it('validate with strict signing requires a signature', (done) => {
139+
const message = {
140+
from: psA.peerId.id,
141+
data: 'hello',
142+
seqno: randomSeqno(),
143+
topicIDs: ['test-topic']
144+
}
145+
146+
psA.validate(message, (err, verified) => {
147+
expect(verified).to.eql(false)
148+
done(err)
149+
})
150+
})
112151
})
113152

114153
describe('dial the pubsub protocol on mount', () => {

0 commit comments

Comments
 (0)