@@ -819,6 +819,48 @@ t.test('sendFile disabled', t => {
819819 } )
820820} )
821821
822+ t . test ( 'allowedPath option' , t => {
823+ t . plan ( 3 )
824+
825+ const pluginOptions = {
826+ root : path . join ( __dirname , '/static' ) ,
827+ allowedPath : ( pathName ) => pathName !== '/foobar.html'
828+ }
829+ const fastify = Fastify ( )
830+ fastify . register ( fastifyStatic , pluginOptions )
831+
832+ fastify . listen ( 0 , err => {
833+ t . error ( err )
834+
835+ fastify . server . unref ( )
836+
837+ t . test ( '/foobar.html not found' , t => {
838+ t . plan ( 2 + GENERIC_ERROR_RESPONSE_CHECK_COUNT )
839+ simple . concat ( {
840+ method : 'GET' ,
841+ url : 'http://localhost:' + fastify . server . address ( ) . port + '/foobar.html' ,
842+ followRedirect : false
843+ } , ( err , response , body ) => {
844+ t . error ( err )
845+ t . strictEqual ( response . statusCode , 404 )
846+ genericErrorResponseChecks ( t , response )
847+ } )
848+ } )
849+
850+ t . test ( '/index.css found' , t => {
851+ t . plan ( 2 )
852+ simple . concat ( {
853+ method : 'GET' ,
854+ url : 'http://localhost:' + fastify . server . address ( ) . port + '/index.css' ,
855+ followRedirect : false
856+ } , ( err , response , body ) => {
857+ t . error ( err )
858+ t . strictEqual ( response . statusCode , 200 )
859+ } )
860+ } )
861+ } )
862+ } )
863+
822864t . test ( 'prefix default' , t => {
823865 t . plan ( 1 )
824866 const pluginOptions = { root : path . join ( __dirname , 'static' ) }
0 commit comments