| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ const fs = require('fs'); | |||
| 7 | 7 | const path = require('path'); | |
| 8 | 8 | ||
| 9 | 9 | const blockedFile = process.env.BLOCKEDFILE; | |
| 10 | + const blockedFileURL = new URL('file://' + process.env.BLOCKEDFILE); | ||
| 10 | 11 | const blockedFolder = process.env.BLOCKEDFOLDER; | |
| 11 | 12 | const allowedFolder = process.env.ALLOWEDFOLDER; | |
| 12 | 13 | const regularFile = __filename; | |
@@ -21,15 +22,12 @@ const regularFile = __filename; | |||
| 21 | 22 | resource: path.toNamespacedPath(blockedFile), | |
| 22 | 23 | })); | |
| 23 | 24 | assert.throws(() => { | |
| 24 | - fs.readFile(path.join(blockedFolder, 'anyfile'), () => {}); | ||
| 25 | + fs.readFile(blockedFileURL, () => {}); | ||
| 25 | 26 | }, common.expectsError({ | |
| 26 | 27 | code: 'ERR_ACCESS_DENIED', | |
| 27 | 28 | permission: 'FileSystemRead', | |
| 28 | - resource: path.toNamespacedPath(path.join(blockedFolder, 'anyfile')), | ||
| 29 | + resource: path.toNamespacedPath(blockedFile), | ||
| 29 | 30 | })); | |
| 30 | - | ||
| 31 | - // doesNotThrow | ||
| 32 | - fs.readFile(regularFile, () => {}); | ||
| 33 | 31 | } | |
| 34 | 32 | ||
| 35 | 33 | // fs.createReadStream | |
@@ -44,6 +42,16 @@ const regularFile = __filename; | |||
| 44 | 42 | permission: 'FileSystemRead', | |
| 45 | 43 | resource: path.toNamespacedPath(blockedFile), | |
| 46 | 44 | })).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()); | ||
| 47 | 55 | ||
| 48 | 56 | assert.rejects(() => { | |
| 49 | 57 | return new Promise((_resolve, reject) => { | |
@@ -66,6 +74,13 @@ const regularFile = __filename; | |||
| 66 | 74 | permission: 'FileSystemRead', | |
| 67 | 75 | resource: path.toNamespacedPath(blockedFile), | |
| 68 | 76 | })); | |
| 77 | + assert.throws(() => { | ||
| 78 | + fs.stat(blockedFileURL, () => {}); | ||
| 79 | + }, common.expectsError({ | ||
| 80 | + code: 'ERR_ACCESS_DENIED', | ||
| 81 | + permission: 'FileSystemRead', | ||
| 82 | + resource: path.toNamespacedPath(blockedFile), | ||
| 83 | + })); | ||
| 69 | 84 | assert.throws(() => { | |
| 70 | 85 | fs.stat(path.join(blockedFolder, 'anyfile'), () => {}); | |
| 71 | 86 | }, common.expectsError({ | |
@@ -89,6 +104,13 @@ const regularFile = __filename; | |||
| 89 | 104 | permission: 'FileSystemRead', | |
| 90 | 105 | resource: path.toNamespacedPath(blockedFile), | |
| 91 | 106 | })); | |
| 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 | + })); | ||
| 92 | 114 | assert.throws(() => { | |
| 93 | 115 | fs.access(path.join(blockedFolder, 'anyfile'), fs.constants.R_OK, () => {}); | |
| 94 | 116 | }, common.expectsError({ | |
@@ -112,6 +134,13 @@ const regularFile = __filename; | |||
| 112 | 134 | permission: 'FileSystemRead', | |
| 113 | 135 | resource: path.toNamespacedPath(blockedFile), | |
| 114 | 136 | })); | |
| 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 | + })); | ||
| 115 | 144 | assert.throws(() => { | |
| 116 | 145 | fs.copyFile(blockedFile, path.join(__dirname, 'any-other-file'), () => {}); | |
| 117 | 146 | }, common.expectsError({ | |
@@ -131,6 +160,14 @@ const regularFile = __filename; | |||
| 131 | 160 | // cpSync calls statSync before reading blockedFile | |
| 132 | 161 | resource: path.toNamespacedPath(blockedFolder), | |
| 133 | 162 | })); | |
| 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 | + })); | ||
| 134 | 171 | assert.throws(() => { | |
| 135 | 172 | fs.cpSync(blockedFile, path.join(__dirname, 'any-other-file')); | |
| 136 | 173 | }, common.expectsError({ | |
@@ -149,6 +186,13 @@ const regularFile = __filename; | |||
| 149 | 186 | permission: 'FileSystemRead', | |
| 150 | 187 | resource: path.toNamespacedPath(blockedFile), | |
| 151 | 188 | })); | |
| 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 | + })); | ||
| 152 | 196 | assert.throws(() => { | |
| 153 | 197 | fs.open(path.join(blockedFolder, 'anyfile'), 'r', () => {}); | |
| 154 | 198 | }, common.expectsError({ | |
@@ -237,6 +281,13 @@ const regularFile = __filename; | |||
| 237 | 281 | permission: 'FileSystemRead', | |
| 238 | 282 | resource: path.toNamespacedPath(blockedFile), | |
| 239 | 283 | })); | |
| 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 | + })); | ||
| 240 | 291 | } | |
| 241 | 292 | ||
| 242 | 293 | // fs.rename | |
@@ -248,6 +299,13 @@ const regularFile = __filename; | |||
| 248 | 299 | permission: 'FileSystemRead', | |
| 249 | 300 | resource: path.toNamespacedPath(blockedFile), | |
| 250 | 301 | })); | |
| 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 | + })); | ||
| 251 | 309 | } | |
| 252 | 310 | ||
| 253 | 311 | // fs.openAsBlob | |
@@ -259,6 +317,13 @@ const regularFile = __filename; | |||
| 259 | 317 | permission: 'FileSystemRead', | |
| 260 | 318 | resource: path.toNamespacedPath(blockedFile), | |
| 261 | 319 | })); | |
| 320 | + assert.throws(() => { | ||
| 321 | + fs.openAsBlob(blockedFileURL); | ||
| 322 | + }, common.expectsError({ | ||
| 323 | + code: 'ERR_ACCESS_DENIED', | ||
| 324 | + permission: 'FileSystemRead', | ||
| 325 | + resource: path.toNamespacedPath(blockedFile), | ||
| 326 | + })); | ||
| 262 | 327 | } | |
| 263 | 328 | ||
| 264 | 329 | // fs.exists | |
@@ -267,6 +332,9 @@ const regularFile = __filename; | |||
| 267 | 332 | fs.exists(blockedFile, (exists) => { | |
| 268 | 333 | assert.equal(exists, false); | |
| 269 | 334 | }); | |
| 335 | + fs.exists(blockedFileURL, (exists) => { | ||
| 336 | + assert.equal(exists, false); | ||
| 337 | + }); | ||
| 270 | 338 | } | |
| 271 | 339 | ||
| 272 | 340 | // fs.statfs | |
@@ -278,4 +346,11 @@ const regularFile = __filename; | |||
| 278 | 346 | permission: 'FileSystemRead', | |
| 279 | 347 | resource: path.toNamespacedPath(blockedFile), | |
| 280 | 348 | })); | |
| 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments