@@ -454,53 +454,6 @@ runtimes.forEach((runtimeCase) => {
454454 assert ( ( await response . text ( ) ) === "still processing\n" ) ;
455455 } ) ;
456456
457- it ( "Handles invalid URL" , async ( ) => {
458- const webhooks = new Webhooks ( {
459- secret : "mySecret" ,
460- } ) ;
461-
462- let middlewareWasRan : ( ) => void ;
463- const untilMiddlewareIsRan = new Promise < void > ( function ( resolve ) {
464- middlewareWasRan = resolve ;
465- } ) ;
466- const actualMiddleware = createNodeMiddleware ( webhooks ) ;
467- const mockedMiddleware = async function (
468- ...[ req , ...rest ] : Parameters < typeof actualMiddleware >
469- ) {
470- req . url = "//" ;
471- await actualMiddleware ( req , ...rest ) ;
472- middlewareWasRan ( ) ;
473- } ;
474-
475- const server = createServer ( mockedMiddleware ) . listen ( await getPort ( ) ) ;
476-
477- const { port } = server . address ( ) as AddressInfo ;
478-
479- const response = await fetch (
480- `http://localhost:${ port } /api/github/webhooks` ,
481- {
482- method : "POST" ,
483- headers : {
484- "Content-Type" : "application/json" ,
485- "X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
486- "X-GitHub-Event" : "push" ,
487- "X-Hub-Signature-256" : signatureSha256 ,
488- } ,
489- body : pushEventPayload ,
490- } ,
491- ) ;
492-
493- await untilMiddlewareIsRan ;
494-
495- assert ( response . status === 422 ) ;
496- assert (
497- ( await response . text ( ) ) ===
498- '{"error":"Request URL could not be parsed: //"}' ,
499- ) ;
500-
501- server . close ( ) ;
502- } ) ;
503-
504457 it ( "Handles invalid signature" , async ( ) => {
505458 const webhooks = new Webhooks ( {
506459 secret : "mySecret" ,
@@ -591,5 +544,45 @@ runtimes.forEach((runtimeCase) => {
591544
592545 closeTestServer ( ) ;
593546 } ) ;
547+
548+ [ "/" , "/api/github/webhooks" ] . forEach ( ( webhooksPath ) => {
549+ [ "" , "/" , "//" , "///" ] . forEach ( ( trailing ) => {
550+ it ( `Handles trailing slashes - webhooksPath "${ webhooksPath } " with trailing "${ trailing } "` , async ( ) => {
551+ const webhooks = new Webhooks ( {
552+ secret : "mySecret" ,
553+ } ) ;
554+
555+ webhooks . on ( "push" , ( event ) => {
556+ assert ( event . id === "123e4567-e89b-12d3-a456-426655440000" ) ;
557+ } ) ;
558+
559+ const { port, closeTestServer } = await instantiateTestServer (
560+ runtime ,
561+ target ,
562+ webhooks ,
563+ { path : webhooksPath } ,
564+ ) ;
565+
566+ const response = await fetch (
567+ `http://localhost:${ port } ${ webhooksPath } ${ trailing } ` ,
568+ {
569+ method : "POST" ,
570+ headers : {
571+ "Content-Type" : "application/json" ,
572+ "X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
573+ "X-GitHub-Event" : "push" ,
574+ "X-Hub-Signature-256" : signatureSha256 ,
575+ } ,
576+ body : pushEventPayload ,
577+ } ,
578+ ) ;
579+
580+ assert ( response . status === 200 ) ;
581+ assert ( ( await response . text ( ) ) === "ok\n" ) ;
582+
583+ closeTestServer ( ) ;
584+ } ) ;
585+ } ) ;
586+ } ) ;
594587 } ) ;
595588} ) ;
0 commit comments