@@ -7,6 +7,7 @@ const fs = require('fs');
77const path = require ( 'path' ) ;
88
99const blockedFile = process . env . BLOCKEDFILE ;
10+ const blockedFileURL = new URL ( 'file://' + process . env . BLOCKEDFILE ) ;
1011const blockedFolder = process . env . BLOCKEDFOLDER ;
1112const allowedFolder = process . env . ALLOWEDFOLDER ;
1213const regularFile = __filename ;
@@ -21,15 +22,12 @@ const regularFile = __filename;
2122 resource : path . toNamespacedPath ( blockedFile ) ,
2223 } ) ) ;
2324 assert . throws ( ( ) => {
24- fs . readFile ( path . join ( blockedFolder , 'anyfile' ) , ( ) => { } ) ;
25+ fs . readFile ( blockedFileURL , ( ) => { } ) ;
2526 } , common . expectsError ( {
2627 code : 'ERR_ACCESS_DENIED' ,
2728 permission : 'FileSystemRead' ,
28- resource : path . toNamespacedPath ( path . join ( blockedFolder , 'anyfile' ) ) ,
29+ resource : path . toNamespacedPath ( blockedFile ) ,
2930 } ) ) ;
30-
31- // doesNotThrow
32- fs . readFile ( regularFile , ( ) => { } ) ;
3331}
3432
3533// fs.createReadStream
@@ -44,6 +42,16 @@ const regularFile = __filename;
4442 permission : 'FileSystemRead' ,
4543 resource : path . toNamespacedPath ( blockedFile ) ,
4644 } ) ) . then ( common . mustCall ( ) ) ;
45+ assert . rejects ( ( ) => {
46+ return new Promise ( ( _resolve , reject ) => {
47+ const stream = fs . createReadStream ( blockedFileURL ) ;
48+ stream . on ( 'error' , reject ) ;
49+ } ) ;
50+ } , common . expectsError ( {
51+ code : 'ERR_ACCESS_DENIED' ,
52+ permission : 'FileSystemRead' ,
53+ resource : path . toNamespacedPath ( blockedFile ) ,
54+ } ) ) . then ( common . mustCall ( ) ) ;
4755
4856 assert . rejects ( ( ) => {
4957 return new Promise ( ( _resolve , reject ) => {
@@ -66,6 +74,13 @@ const regularFile = __filename;
6674 permission : 'FileSystemRead' ,
6775 resource : path . toNamespacedPath ( blockedFile ) ,
6876 } ) ) ;
77+ assert . throws ( ( ) => {
78+ fs . stat ( blockedFileURL , ( ) => { } ) ;
79+ } , common . expectsError ( {
80+ code : 'ERR_ACCESS_DENIED' ,
81+ permission : 'FileSystemRead' ,
82+ resource : path . toNamespacedPath ( blockedFile ) ,
83+ } ) ) ;
6984 assert . throws ( ( ) => {
7085 fs . stat ( path . join ( blockedFolder , 'anyfile' ) , ( ) => { } ) ;
7186 } , common . expectsError ( {
@@ -89,6 +104,13 @@ const regularFile = __filename;
89104 permission : 'FileSystemRead' ,
90105 resource : path . toNamespacedPath ( blockedFile ) ,
91106 } ) ) ;
107+ assert . throws ( ( ) => {
108+ fs . access ( blockedFileURL , fs . constants . R_OK , ( ) => { } ) ;
109+ } , common . expectsError ( {
110+ code : 'ERR_ACCESS_DENIED' ,
111+ permission : 'FileSystemRead' ,
112+ resource : path . toNamespacedPath ( blockedFile ) ,
113+ } ) ) ;
92114 assert . throws ( ( ) => {
93115 fs . access ( path . join ( blockedFolder , 'anyfile' ) , fs . constants . R_OK , ( ) => { } ) ;
94116 } , common . expectsError ( {
@@ -112,6 +134,13 @@ const regularFile = __filename;
112134 permission : 'FileSystemRead' ,
113135 resource : path . toNamespacedPath ( blockedFile ) ,
114136 } ) ) ;
137+ assert . throws ( ( ) => {
138+ fs . copyFile ( blockedFileURL , path . join ( blockedFolder , 'any-other-file' ) , ( ) => { } ) ;
139+ } , common . expectsError ( {
140+ code : 'ERR_ACCESS_DENIED' ,
141+ permission : 'FileSystemRead' ,
142+ resource : path . toNamespacedPath ( blockedFile ) ,
143+ } ) ) ;
115144 assert . throws ( ( ) => {
116145 fs . copyFile ( blockedFile , path . join ( __dirname , 'any-other-file' ) , ( ) => { } ) ;
117146 } , common . expectsError ( {
@@ -131,6 +160,14 @@ const regularFile = __filename;
131160 // cpSync calls statSync before reading blockedFile
132161 resource : path . toNamespacedPath ( blockedFolder ) ,
133162 } ) ) ;
163+ assert . throws ( ( ) => {
164+ fs . cpSync ( blockedFileURL , path . join ( blockedFolder , 'any-other-file' ) ) ;
165+ } , common . expectsError ( {
166+ code : 'ERR_ACCESS_DENIED' ,
167+ permission : 'FileSystemRead' ,
168+ // cpSync calls statSync before reading blockedFile
169+ resource : path . toNamespacedPath ( blockedFolder ) ,
170+ } ) ) ;
134171 assert . throws ( ( ) => {
135172 fs . cpSync ( blockedFile , path . join ( __dirname , 'any-other-file' ) ) ;
136173 } , common . expectsError ( {
@@ -149,6 +186,13 @@ const regularFile = __filename;
149186 permission : 'FileSystemRead' ,
150187 resource : path . toNamespacedPath ( blockedFile ) ,
151188 } ) ) ;
189+ assert . throws ( ( ) => {
190+ fs . open ( blockedFileURL , 'r' , ( ) => { } ) ;
191+ } , common . expectsError ( {
192+ code : 'ERR_ACCESS_DENIED' ,
193+ permission : 'FileSystemRead' ,
194+ resource : path . toNamespacedPath ( blockedFile ) ,
195+ } ) ) ;
152196 assert . throws ( ( ) => {
153197 fs . open ( path . join ( blockedFolder , 'anyfile' ) , 'r' , ( ) => { } ) ;
154198 } , common . expectsError ( {
@@ -237,6 +281,13 @@ const regularFile = __filename;
237281 permission : 'FileSystemRead' ,
238282 resource : path . toNamespacedPath ( blockedFile ) ,
239283 } ) ) ;
284+ assert . throws ( ( ) => {
285+ fs . watchFile ( blockedFileURL , common . mustNotCall ( ) ) ;
286+ } , common . expectsError ( {
287+ code : 'ERR_ACCESS_DENIED' ,
288+ permission : 'FileSystemRead' ,
289+ resource : path . toNamespacedPath ( blockedFile ) ,
290+ } ) ) ;
240291}
241292
242293// fs.rename
@@ -248,6 +299,13 @@ const regularFile = __filename;
248299 permission : 'FileSystemRead' ,
249300 resource : path . toNamespacedPath ( blockedFile ) ,
250301 } ) ) ;
302+ assert . throws ( ( ) => {
303+ fs . rename ( blockedFileURL , 'newfile' , ( ) => { } ) ;
304+ } , common . expectsError ( {
305+ code : 'ERR_ACCESS_DENIED' ,
306+ permission : 'FileSystemRead' ,
307+ resource : path . toNamespacedPath ( blockedFile ) ,
308+ } ) ) ;
251309}
252310
253311// fs.openAsBlob
@@ -259,6 +317,13 @@ const regularFile = __filename;
259317 permission : 'FileSystemRead' ,
260318 resource : path . toNamespacedPath ( blockedFile ) ,
261319 } ) ) ;
320+ assert . throws ( ( ) => {
321+ fs . openAsBlob ( blockedFileURL ) ;
322+ } , common . expectsError ( {
323+ code : 'ERR_ACCESS_DENIED' ,
324+ permission : 'FileSystemRead' ,
325+ resource : path . toNamespacedPath ( blockedFile ) ,
326+ } ) ) ;
262327}
263328
264329// fs.exists
@@ -267,6 +332,9 @@ const regularFile = __filename;
267332 fs . exists ( blockedFile , ( exists ) => {
268333 assert . equal ( exists , false ) ;
269334 } ) ;
335+ fs . exists ( blockedFileURL , ( exists ) => {
336+ assert . equal ( exists , false ) ;
337+ } ) ;
270338}
271339
272340// fs.statfs
@@ -278,4 +346,11 @@ const regularFile = __filename;
278346 permission : 'FileSystemRead' ,
279347 resource : path . toNamespacedPath ( blockedFile ) ,
280348 } ) ) ;
281- }
349+ assert . throws ( ( ) => {
350+ fs . statfs ( blockedFileURL , ( ) => { } ) ;
351+ } , common . expectsError ( {
352+ code : 'ERR_ACCESS_DENIED' ,
353+ permission : 'FileSystemRead' ,
354+ resource : path . toNamespacedPath ( blockedFile ) ,
355+ } ) ) ;
356+ }
0 commit comments