@@ -52,6 +52,14 @@ test('handler without full options throws', function (t) {
52
52
t . throws ( handler . bind ( null , { path : '/' } ) , / m u s t p r o v i d e a ' s e c r e t ' o p t i o n / , 'throws if no secret option' )
53
53
} )
54
54
55
+ test ( 'handler without full options throws in array' , function ( t ) {
56
+ t . plan ( 2 )
57
+
58
+ t . throws ( handler . bind ( null , [ { } ] ) , / m u s t p r o v i d e a ' p a t h ' o p t i o n / , 'throws if no path option' )
59
+
60
+ t . throws ( handler . bind ( null , [ { path : '/' } ] ) , / m u s t p r o v i d e a ' s e c r e t ' o p t i o n / , 'throws if no secret option' )
61
+ } )
62
+
55
63
56
64
test ( 'handler ignores invalid urls' , function ( t ) {
57
65
var options = { path : '/some/url' , secret : 'bogus' }
@@ -113,6 +121,30 @@ test('handler accepts valid urls', function (t) {
113
121
setTimeout ( t . ok . bind ( t , true , 'done' ) )
114
122
} )
115
123
124
+ test ( 'handler accepts valid urls in Array' , function ( t ) {
125
+ var options = [ { path : '/some/url' , secret : 'bogus' } , { path : '/someOther/url' , secret : 'bogus' } ]
126
+ , h = handler ( options )
127
+
128
+ t . plan ( 1 )
129
+
130
+ h ( mkReq ( '/some/url' ) , mkRes ( ) , function ( err ) {
131
+ t . error ( err )
132
+ t . fail ( false , 'should not call' )
133
+ } )
134
+
135
+ h ( mkReq ( '/someOther/url' ) , mkRes ( ) , function ( err ) {
136
+ t . error ( err )
137
+ t . fail ( false , 'should not call' )
138
+ } )
139
+
140
+ h ( mkReq ( '/some/url?test=param' ) , mkRes ( ) , function ( err ) {
141
+ t . error ( err )
142
+ t . fail ( false , 'should not call' )
143
+ } )
144
+
145
+ setTimeout ( t . ok . bind ( t , true , 'done' ) )
146
+ } )
147
+
116
148
117
149
test ( 'handler can reject events' , function ( t ) {
118
150
var acceptableEvents = {
@@ -206,7 +238,35 @@ test('handler accepts a signed blob', function (t) {
206
238
req . headers [ 'x-github-event' ] = 'push'
207
239
208
240
h . on ( 'push' , function ( event ) {
209
- t . deepEqual ( event , { event : 'push' , id : 'bogus' , payload : obj , url : '/' , host : undefined , protocol : undefined } )
241
+ t . deepEqual ( event , { event : 'push' , id : 'bogus' , payload : obj , url : '/' , host : undefined , protocol : undefined , path : '/' } )
242
+ t . equal ( res . $statusCode , 200 , 'correct status code' )
243
+ t . deepEqual ( res . $headers , { 'content-type' : 'application/json' } )
244
+ t . equal ( res . $end , '{"ok":true}' , 'got correct content' )
245
+ } )
246
+
247
+ h ( req , res , function ( err ) {
248
+ t . error ( err )
249
+ t . fail ( true , 'should not get here!' )
250
+ } )
251
+
252
+ process . nextTick ( function ( ) {
253
+ req . end ( json )
254
+ } )
255
+ } )
256
+
257
+ test ( 'handler accepts multi blob in Array' , function ( t ) {
258
+ t . plan ( 4 )
259
+
260
+ var obj = { some : 'github' , object : 'with' , properties : true }
261
+ , json = JSON . stringify ( obj )
262
+ , h = handler ( [ { path : '/' , secret : 'bogus' } , { path : '/some/url' , secret : 'bogus' } ] )
263
+ , req = mkReq ( '/some/url' )
264
+ , res = mkRes ( )
265
+ req . headers [ 'x-hub-signature' ] = signBlob ( 'bogus' , json )
266
+ req . headers [ 'x-github-event' ] = 'push'
267
+
268
+ h . on ( 'push' , function ( event ) {
269
+ t . deepEqual ( event , { event : 'push' , id : 'bogus' , payload : obj , url : '/some/url' , host : undefined , protocol : undefined , path : '/some/url' } )
210
270
t . equal ( res . $statusCode , 200 , 'correct status code' )
211
271
t . deepEqual ( res . $headers , { 'content-type' : 'application/json' } )
212
272
t . equal ( res . $end , '{"ok":true}' , 'got correct content' )
@@ -240,7 +300,7 @@ test('handler accepts a signed blob with alt event', function (t) {
240
300
} )
241
301
242
302
h . on ( 'issue' , function ( event ) {
243
- t . deepEqual ( event , { event : 'issue' , id : 'bogus' , payload : obj , url : '/' , host : undefined , protocol : undefined } )
303
+ t . deepEqual ( event , { event : 'issue' , id : 'bogus' , payload : obj , url : '/' , host : undefined , protocol : undefined , path : '/' } )
244
304
t . equal ( res . $statusCode , 200 , 'correct status code' )
245
305
t . deepEqual ( res . $headers , { 'content-type' : 'application/json' } )
246
306
t . equal ( res . $end , '{"ok":true}' , 'got correct content' )
0 commit comments