@@ -399,9 +399,27 @@ describe('static routes', () => {
399399 expect ( ( await get ( '/public/ghae/schema.docs-ghae.graphql' ) ) . statusCode ) . toBe ( 200 )
400400 } )
401401
402- it ( 'does not serve repo contents that live outside the /assets directory' , async ( ) => {
403- expect ( ( await get ( '/package.json' , { followRedirects : true } ) ) . statusCode ) . toBe ( 404 )
404- expect ( ( await get ( '/README.md' , { followRedirects : true } ) ) . statusCode ) . toBe ( 404 )
405- expect ( ( await get ( '/server.js' , { followRedirects : true } ) ) . statusCode ) . toBe ( 404 )
402+ test ( 'does not serve repo contents that live outside the /assets directory' , async ( ) => {
403+ const paths = [ '/package.json' , '/README.md' , '/server.js' , '/.git' , '/.env' ]
404+ for ( const path of paths ) {
405+ const res = await get ( path )
406+ expect ( res . statusCode ) . toBe ( 404 )
407+ expect ( res . headers [ 'content-type' ] ) . toMatch ( 'text/plain' )
408+ expect ( res . headers [ 'cache-control' ] ) . toMatch ( / m a x - a g e = [ 1 - 9 ] / )
409+ expect ( res . headers [ 'cache-control' ] ) . toMatch ( 'public' )
410+ }
411+ expect . assertions ( 4 * paths . length )
412+ } )
413+
414+ test ( 'junk requests with or without query strings is 404' , async ( ) => {
415+ const paths = [ '/env' , '/xmlrpc.php' , '/wp-login.php' ]
416+ for ( const path of paths ) {
417+ const res = await get ( `${ path } ?r=${ Math . random ( ) } ` )
418+ expect ( res . statusCode ) . toBe ( 404 )
419+ expect ( res . headers [ 'content-type' ] ) . toMatch ( 'text/plain' )
420+ expect ( res . headers [ 'cache-control' ] ) . toMatch ( / m a x - a g e = [ 1 - 9 ] / )
421+ expect ( res . headers [ 'cache-control' ] ) . toMatch ( 'public' )
422+ }
423+ expect . assertions ( 4 * paths . length )
406424 } )
407425} )
0 commit comments