Skip to content

Commit

Permalink
fixup! fix(arborist): shrinkwrap throws trying to read a folder witho…
Browse files Browse the repository at this point in the history
…ut permissions
  • Loading branch information
Nitzan Uziely committed Jan 20, 2022
1 parent f945b37 commit bfbd139
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions workspaces/arborist/test/shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const calcDepFlags = require('../lib/calc-dep-flags.js')
const fs = require('fs')
const Arborist = require('../lib/arborist/index.js')
const rimraf = require('rimraf')
const { execSync } = require('child_process')

const t = require('tap')

Expand Down Expand Up @@ -1601,13 +1602,30 @@ t.test('setting lockfileVersion from the file contents', async t => {
t.test('load should return error correctly when it cant access folder', async t => {
const dir = t.testdir({})
try {
fs.chmodSync(dir, '000')
const err = removePermissions(dir)
const res = await Shrinkwrap.load({ path: dir })
t.ok(res.loadingError, 'loading error should exist')
t.strictSame(res.loadingError.errno, -13)
t.strictSame(res.loadingError.code, 'EACCES')
t.strictSame(res.loadingError.code, err)
} finally {
fs.chmodSync(dir, '777')
restorePermissions(dir)
}

function removePermissions(dir) {
if (process.platform === 'win32') {
execSync(`icacls ${dir} /deny "everyone:R"`)
return 'EPERM'
}

fs.chmodSync(dir, '000')
return 'EACCES'
}

function restorePermissions(dir) {
if (process.platform === 'win32') {
execSync(`icacls ${dir} /grant "everyone:R"`)
} else {
fs.chmodSync(dir, '777')
}
}
})
})

0 comments on commit bfbd139

Please sign in to comment.