1+ 'use strict'
2+
3+ const common = require ( '../../common' ) ;
4+
5+ const assert = require ( 'assert' ) ;
6+ const fs = require ( 'fs' ) ;
7+ const path = require ( 'path' ) ;
8+
9+ const blockedFolder = process . env . BLOCKEDFOLDER ;
10+ const allowedFolder = process . env . ALLOWEDFOLDER ;
11+ const traversalPath = allowedFolder + '../file.md'
12+
13+ {
14+ assert . ok ( process . permission . has ( 'fs.read' , allowedFolder ) ) ;
15+ assert . ok ( process . permission . has ( 'fs.write' , allowedFolder ) ) ;
16+ assert . ok ( ! process . permission . has ( 'fs.read' , blockedFolder ) ) ;
17+ assert . ok ( ! process . permission . has ( 'fs.write' , blockedFolder ) ) ;
18+ }
19+
20+ {
21+ assert . throws ( ( ) => {
22+ fs . writeFile ( traversalPath , 'test' , ( error ) => {
23+ assert . ifError ( error ) ;
24+ } ) ;
25+ } , common . expectsError ( {
26+ code : 'ERR_ACCESS_DENIED' ,
27+ permission : 'FileSystemWrite' ,
28+ resource : path . toNamespacedPath ( path . resolve ( traversalPath ) ) ,
29+ } ) ) ;
30+ }
31+
32+ {
33+ assert . throws ( ( ) => {
34+ fs . readFile ( traversalPath , ( error ) => {
35+ assert . ifError ( error ) ;
36+ } ) ;
37+ } , common . expectsError ( {
38+ code : 'ERR_ACCESS_DENIED' ,
39+ permission : 'FileSystemRead' ,
40+ resource : path . toNamespacedPath ( path . resolve ( traversalPath ) ) ,
41+ } ) ) ;
42+ }
43+
44+ {
45+ assert . ok ( ! process . permission . has ( 'fs.read' , traversalPath ) ) ;
46+ assert . ok ( ! process . permission . has ( 'fs.write' , traversalPath ) ) ;
47+ }
0 commit comments