@@ -698,6 +698,57 @@ const regularFile = __filename;
698698 } ) ;
699699}
700700
701+ // fs.realpath (JS implementation, walks the path with lstat)
702+ {
703+ assert . throws ( ( ) => {
704+ fs . realpathSync ( blockedFile ) ;
705+ } , common . expectsError ( {
706+ code : 'ERR_ACCESS_DENIED' ,
707+ permission : 'FileSystemRead' ,
708+ } ) ) ;
709+ assert . throws ( ( ) => {
710+ fs . realpathSync ( bufferBlockedFile ) ;
711+ } , common . expectsError ( {
712+ code : 'ERR_ACCESS_DENIED' ,
713+ permission : 'FileSystemRead' ,
714+ } ) ) ;
715+ assert . throws ( ( ) => {
716+ fs . realpathSync ( path . join ( blockedFolder , 'anyfile' ) ) ;
717+ } , common . expectsError ( {
718+ code : 'ERR_ACCESS_DENIED' ,
719+ permission : 'FileSystemRead' ,
720+ } ) ) ;
721+ // Must not act as a file-existence oracle: a non-existent path inside a
722+ // blocked folder must be denied, not reported as ENOENT.
723+ assert . throws ( ( ) => {
724+ fs . realpathSync ( path . join ( blockedFolder , 'does-not-exist' ) ) ;
725+ } , common . expectsError ( {
726+ code : 'ERR_ACCESS_DENIED' ,
727+ permission : 'FileSystemRead' ,
728+ } ) ) ;
729+ fs . realpath ( blockedFile , common . expectsError ( {
730+ code : 'ERR_ACCESS_DENIED' ,
731+ permission : 'FileSystemRead' ,
732+ } ) ) ;
733+ assert . throws ( ( ) => {
734+ fs . realpathSync ( blockedFile ) ;
735+ } , common . expectsError ( {
736+ message : 'Access to this API has been restricted. Use --allow-fs-read to manage permissions.' ,
737+ code : 'ERR_ACCESS_DENIED' ,
738+ permission : 'FileSystemRead' ,
739+ resource : blockedFile ,
740+ } ) ) ;
741+ assert . rejects ( async ( ) => {
742+ await fsPromises . realpath ( blockedFile ) ;
743+ } , common . expectsError ( {
744+ code : 'ERR_ACCESS_DENIED' ,
745+ permission : 'FileSystemRead' ,
746+ } ) ) . then ( common . mustCall ( ) ) ;
747+
748+ // doesNotThrow
749+ assert . strictEqual ( typeof fs . realpathSync ( regularFile ) , 'string' ) ;
750+ }
751+
701752// fs.realpath.native
702753{
703754 fs . realpath . native ( blockedFile , common . expectsError ( {
0 commit comments