@@ -392,6 +392,33 @@ describe('strong-error-handler', function() {
392392 } ) ;
393393 } ) ;
394394
395+ it ( 'honours expose=true when status=5xx' , function ( done ) {
396+ // Mock an error reported by fs.readFile
397+ const error = new ErrorWithProps ( {
398+ name : 'Error' ,
399+ message : 'ENOENT: no such file or directory, open "/etc/passwd"' ,
400+ errno : - 2 ,
401+ code : 'ENOENT' ,
402+ expose : true ,
403+ syscall : 'open' ,
404+ path : '/etc/password' ,
405+ } ) ;
406+ givenErrorHandlerForError ( error ) ;
407+
408+ requestJson ( ) . end ( function ( err , res ) {
409+ if ( err ) return done ( err ) ;
410+
411+ expect ( res . body ) . to . have . property ( 'error' ) ;
412+ expect ( res . body . error ) . to . eql ( {
413+ statusCode : 500 ,
414+ name : 'Internal Server Error' ,
415+ message : 'ENOENT: no such file or directory, open "/etc/passwd"' ,
416+ } ) ;
417+
418+ done ( ) ;
419+ } ) ;
420+ } ) ;
421+
395422 it ( 'handles array argument as 500 when debug=false' , function ( done ) {
396423 const errors = [ new Error ( 'ERR1' ) , new Error ( 'ERR2' ) , 'ERR STRING' ] ;
397424 givenErrorHandlerForError ( errors ) ;
@@ -702,6 +729,29 @@ describe('strong-error-handler', function() {
702729 } ) ;
703730 } ) ;
704731
732+ it ( 'honours expose=true when status=5xx' , function ( done ) {
733+ const error = new ErrorWithProps ( {
734+ name : 'Error' ,
735+ message : 'Server out of disk space' ,
736+ details : 'some details' ,
737+ extra : 'sensitive data' ,
738+ expose : true ,
739+ } ) ;
740+ givenErrorHandlerForError ( error ) ;
741+
742+ requestHTML ( )
743+ . end ( function ( err , res ) {
744+ expect ( res . statusCode ) . to . eql ( 500 ) ;
745+ const body = res . error . text ;
746+ expect ( body ) . to . not . match ( / s o m e d e t a i l s / ) ;
747+ expect ( body ) . to . not . match ( / s e n s i t i v e d a t a / ) ;
748+ // only have the following
749+ expect ( body ) . to . match ( / < t i t l e > I n t e r n a l S e r v e r E r r o r < \/ t i t l e > / ) ;
750+ expect ( body ) . to . match ( / 5 0 0 ( .* ?) S e r v e r o u t o f d i s k s p a c e / ) ;
751+ done ( ) ;
752+ } ) ;
753+ } ) ;
754+
705755 function requestHTML ( url ) {
706756 return request . get ( url || '/' )
707757 . set ( 'Accept' , 'text/html' )
@@ -777,6 +827,30 @@ describe('strong-error-handler', function() {
777827 } ) ;
778828 } ) ;
779829
830+ it ( 'honours expose=true when status=5xx' , function ( done ) {
831+ const error = new ErrorWithProps ( {
832+ name : 'Error' ,
833+ message : 'Server out of disk space' ,
834+ details : 'some details' ,
835+ extra : 'sensitive data' ,
836+ expose : true ,
837+ } ) ;
838+ givenErrorHandlerForError ( error ) ;
839+
840+ requestXML ( )
841+ . end ( function ( err , res ) {
842+ expect ( res . statusCode ) . to . eql ( 500 ) ;
843+ const body = res . error . text ;
844+ expect ( body ) . to . not . match ( / s o m e d e t a i l s / ) ;
845+ expect ( body ) . to . not . match ( / s e n s i t i v e d a t a / ) ;
846+ // only have the following
847+ expect ( body ) . to . match ( / < s t a t u s C o d e > 5 0 0 < \/ s t a t u s C o d e > / ) ;
848+ expect ( body ) . to . match ( / < n a m e > I n t e r n a l S e r v e r E r r o r < \/ n a m e > / ) ;
849+ expect ( body ) . to . match ( / < m e s s a g e > S e r v e r o u t o f d i s k s p a c e < \/ m e s s a g e > / ) ;
850+ done ( ) ;
851+ } ) ;
852+ } ) ;
853+
780854 it ( 'honors options.rootProperty' , function ( done ) {
781855 const error = new ErrorWithProps ( {
782856 name : 'ValidationError' ,
0 commit comments