@@ -5,6 +5,7 @@ const chai = require('chai')
5
5
chai . use ( require ( 'dirty-chai' ) )
6
6
chai . use ( require ( 'chai-spies' ) )
7
7
const expect = chai . expect
8
+ const sinon = require ( 'sinon' )
8
9
const series = require ( 'async/series' )
9
10
const parallel = require ( 'async/parallel' )
10
11
@@ -36,6 +37,10 @@ class PubsubImplementation extends PubsubBaseProtocol {
36
37
}
37
38
38
39
describe ( 'pubsub base protocol' , ( ) => {
40
+ afterEach ( ( ) => {
41
+ sinon . restore ( )
42
+ } )
43
+
39
44
describe ( 'fresh nodes' , ( ) => {
40
45
let nodeA
41
46
let nodeB
@@ -109,6 +114,40 @@ describe('pubsub base protocol', () => {
109
114
} )
110
115
} )
111
116
} )
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
+ } )
112
151
} )
113
152
114
153
describe ( 'dial the pubsub protocol on mount' , ( ) => {
0 commit comments