@@ -317,15 +317,61 @@ describe("documentation worker", () => {
317317 expect ( response . headers . get ( "location" ) ) . toBe ( `${ base } ${ path } /?view=1` ) ;
318318 }
319319 expect ( ( await request ( "/doc/6.4.0/missing-directory" ) ) . status ) . toBe ( 404 ) ;
320- expect ( ( await request ( "/doc" ) ) . headers . get ( "location" ) ) . toBe ( `${ base } /documentation/` ) ;
320+ for ( const path of [ "/doc" , "/doc/" , "/doc?smoke=1" , "/doc/?smoke=1" ] ) {
321+ const response = await request ( path ) ;
322+ expect ( response . status ) . toBe ( 308 ) ;
323+ expect ( response . headers . get ( "location" ) ) . toBe ( `${ base } /documentation.html${ path . includes ( "?" ) ? "?smoke=1" : "" } ` ) ;
324+ }
325+ } ) ;
326+
327+ it ( "passes neighboring website paths through without changing requests or responses" , async ( ) => {
328+ const originFetch = vi . spyOn ( globalThis , "fetch" ) ;
329+ try {
330+ for ( const [ path , method , status ] of [
331+ [ "/documentation.html?smoke=1" , "GET" , 200 ] ,
332+ [ "/documentation/" , "HEAD" , 404 ] ,
333+ [ "/documents/submit?draft=1" , "POST" , 201 ] ,
334+ [ "/doc-latest-news.html" , "GET" , 200 ] ,
335+ [ "/robots.txt.bak?download=1" , "GET" , 404 ] ,
336+ ] as const ) {
337+ const incoming = new Request ( `${ base } ${ path } ` , {
338+ method, headers : { "X-Request-Test" : "preserved" } ,
339+ body : method === "POST" ? "submission bytes" : undefined ,
340+ } ) ;
341+ const upstream = new Response ( method === "HEAD" ? null : "origin content" , {
342+ status,
343+ headers : {
344+ "Content-Type" : "text/html" ,
345+ "X-Robots-Tag" : "index, follow" ,
346+ Link : '<https://www.gecode.dev/documentation/>; rel="canonical"' ,
347+ } ,
348+ } ) ;
349+ originFetch . mockResolvedValueOnce ( upstream ) ;
350+ const context = createExecutionContext ( ) ;
351+ const response = await worker . fetch ( incoming , env , context ) ;
352+ await waitOnExecutionContext ( context ) ;
353+ expect ( originFetch ) . toHaveBeenLastCalledWith ( incoming ) ;
354+ expect ( response ) . toBe ( upstream ) ;
355+ expect ( response . status ) . toBe ( status ) ;
356+ expect ( response . headers . get ( "x-robots-tag" ) ) . toBe ( "index, follow" ) ;
357+ expect ( response . headers . get ( "link" ) ) . toBe ( '<https://www.gecode.dev/documentation/>; rel="canonical"' ) ;
358+ if ( method === "POST" ) expect ( await incoming . text ( ) ) . toBe ( "submission bytes" ) ;
359+ }
360+ const staging = await request ( "https://docs-staging.gecode.dev/documentation.html" ) ;
361+ expect ( staging . status ) . toBe ( 404 ) ;
362+ expect ( staging . headers . get ( "x-robots-tag" ) ) . toBe ( "noindex" ) ;
363+ expect ( originFetch ) . toHaveBeenCalledTimes ( 5 ) ;
364+ } finally {
365+ originFetch . mockRestore ( ) ;
366+ }
321367 } ) ;
322368
323369 it ( "returns explicit errors" , async ( ) => {
324370 expect ( ( await request ( "/doc/6.4.0/missing.html" ) ) . status ) . toBe ( 404 ) ;
325371 const method = await request ( "/doc/6.4.0/index.html" , { method : "POST" } ) ;
326372 expect ( method . status ) . toBe ( 405 ) ;
327373 expect ( method . headers . get ( "allow" ) ) . toBe ( "GET, HEAD" ) ;
328- expect ( ( await request ( "/doc/%2e%2e/secret " ) ) . status ) . toBe ( 400 ) ;
374+ expect ( ( await request ( "/doc/6.4.0/% " ) ) . status ) . toBe ( 400 ) ;
329375 expect ( ( await request ( "/doc/6.4.0/%252e%252e/secret" ) ) . status ) . toBe ( 400 ) ;
330376 expect ( ( await request ( "/doc/6.4.0/reference%2fPageChange.html" ) ) . status ) . toBe ( 400 ) ;
331377 } ) ;
0 commit comments