@@ -17,7 +17,7 @@ app.listen(12345);
1717
1818describe ( 'Hooks' , ( ) => {
1919
20- it ( "should have some hooks registered" , ( done ) => {
20+ it ( "should have no hooks registered" , ( done ) => {
2121 Parse . Hooks . getFunctions ( ) . then ( ( res ) => {
2222 expect ( res . constructor ) . toBe ( Array . prototype . constructor ) ;
2323 done ( ) ;
@@ -27,7 +27,7 @@ describe('Hooks', () => {
2727 } ) ;
2828 } ) ;
2929
30- it ( "should have some triggers registered" , ( done ) => {
30+ it ( "should have no triggers registered" , ( done ) => {
3131 Parse . Hooks . getTriggers ( ) . then ( ( res ) => {
3232 expect ( res . constructor ) . toBe ( Array . prototype . constructor ) ;
3333 done ( ) ;
@@ -291,15 +291,15 @@ describe('Hooks', () => {
291291 console . error ( err ) ;
292292 fail ( "Should not fail calling a function" ) ;
293293 done ( ) ;
294- } )
294+ } ) ;
295295 } ) ;
296296
297297 it ( "should run the function on the test server" , ( done ) => {
298298
299299 app . post ( "/SomeFunctionError" , function ( req , res ) {
300300 res . json ( { error : { code : 1337 , error : "hacking that one!" } } ) ;
301301 } ) ;
302- // The function is delete as the DB is dropped between calls
302+ // The function is deleted as the DB is dropped between calls
303303 Parse . Hooks . createFunction ( "SOME_TEST_FUNCTION" , hookServerURL + "/SomeFunctionError" ) . then ( function ( ) {
304304 return Parse . Cloud . run ( "SOME_TEST_FUNCTION" )
305305 } , ( err ) => {
@@ -317,6 +317,57 @@ describe('Hooks', () => {
317317 } ) ;
318318 } ) ;
319319
320+ it ( "should provide X-Parse-Webhook-Key when defined" , ( done ) => {
321+ app . post ( "/ExpectingKey" , function ( req , res ) {
322+ if ( req . get ( 'X-Parse-Webhook-Key' ) === 'hook' ) {
323+ res . json ( { success : "correct key provided" } ) ;
324+ } else {
325+ res . json ( { error : "incorrect key provided" } ) ;
326+ }
327+ } ) ;
328+
329+ Parse . Hooks . createFunction ( "SOME_TEST_FUNCTION" , hookServerURL + "/ExpectingKey" ) . then ( function ( ) {
330+ return Parse . Cloud . run ( "SOME_TEST_FUNCTION" )
331+ } , ( err ) => {
332+ console . error ( err ) ;
333+ fail ( "Should not fail creating a function" ) ;
334+ done ( ) ;
335+ } ) . then ( function ( res ) {
336+ expect ( res ) . toBe ( "correct key provided" ) ;
337+ done ( ) ;
338+ } , ( err ) => {
339+ console . error ( err ) ;
340+ fail ( "Should not fail calling a function" ) ;
341+ done ( ) ;
342+ } ) ;
343+ } ) ;
344+
345+ it ( "should not pass X-Parse-Webhook-Key if not provided" , ( done ) => {
346+ setServerConfiguration ( Object . assign ( { } , defaultConfiguration , { webhookKey : undefined } ) ) ;
347+ app . post ( "/ExpectingKeyAlso" , function ( req , res ) {
348+ if ( req . get ( 'X-Parse-Webhook-Key' ) === 'hook' ) {
349+ res . json ( { success : "correct key provided" } ) ;
350+ } else {
351+ res . json ( { error : "incorrect key provided" } ) ;
352+ }
353+ } ) ;
354+
355+ Parse . Hooks . createFunction ( "SOME_TEST_FUNCTION" , hookServerURL + "/ExpectingKeyAlso" ) . then ( function ( ) {
356+ return Parse . Cloud . run ( "SOME_TEST_FUNCTION" )
357+ } , ( err ) => {
358+ console . error ( err ) ;
359+ fail ( "Should not fail creating a function" ) ;
360+ done ( ) ;
361+ } ) . then ( function ( res ) {
362+ fail ( "Should not succeed calling that function" ) ;
363+ done ( ) ;
364+ } , ( err ) => {
365+ expect ( err . code ) . toBe ( 141 ) ;
366+ expect ( err . message ) . toEqual ( "incorrect key provided" ) ;
367+ done ( ) ;
368+ } ) ;
369+ } ) ;
370+
320371
321372 it ( "should run the beforeSave hook on the test server" , ( done ) => {
322373 var triggerCount = 0 ;
0 commit comments