diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 8e62f3d..97d3f98 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -11,7 +11,6 @@ jobs: name: Node.js uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: - os: 'ubuntu-latest' version: '16, 18, 20, 22, 23' secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/test/fs.test.ts b/test/fs.test.ts index 957422b..1f451ef 100644 --- a/test/fs.test.ts +++ b/test/fs.test.ts @@ -23,8 +23,32 @@ describe('test/fs.test.ts', () => { assert.equal(stats.isDirectory(), true); assert.equal(stats.isFile(), false); assert.equal(await exists(__dirname + '/nonexistent'), false); + }); + + it('should throw error on Linux', async () => { + if (process.platform !== 'linux') { + return; + } + await assert.rejects(async () => { + await exists('/root/../../../../../etc/passwd'); + }, (err: any) => { + // Error: EACCES: permission denied, stat '/root/../../../../../etc/passwd' + assert.equal(err.code, 'EACCES'); + return true; + }); + }); - assert.equal(await exists('/root/../../../../../etc/passwd'), false); + it('should throw error on win32', async () => { + if (process.platform !== 'win32') { + return; + } + await assert.rejects(async () => { + await exists('C:\\Windows\\System32\\drivers\\etc\\hosts'); + }, (err: any) => { + // Error: EACCES: permission denied, stat 'C:\Windows\System32\drivers\etc\hosts' + assert.equal(err.code, 'EPERM'); + return true; + }); }); }); });