Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit e0e1b62

Browse files
committedAug 12, 2019
fix: fail properly if uid-number raises an error
1 parent 355ad53 commit e0e1b62

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed
 

‎index.js

+6
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ function runCmd (note, cmd, pkg, env, stage, wd, opts, cb) {
265265
runCmd_(cmd, pkg, env, wd, opts, stage, unsafe, 0, 0, cb)
266266
} else {
267267
uidNumber(user, group, function (er, uid, gid) {
268+
if (er) {
269+
er.code = 'EUIDLOOKUP'
270+
opts.log.resume()
271+
process.nextTick(dequeue)
272+
return cb(er)
273+
}
268274
runCmd_(cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb)
269275
})
270276
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "count-to-10-working-postinstall",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"postinstall": "node postinstall.js"
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
console.log('line 1')
4+
console.log('line 2')
5+
console.error('some error')

‎test/index.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test('makeEnv', function (t) {
2626
const env = lifecycle.makeEnv(pkg, {
2727
config,
2828
nodeOptions: '--inspect-brk --abort-on-uncaught-exception'
29-
}, null, process.env)
29+
}, null, Object.assign({}, process.env))
3030

3131
t.equal('myPackage', env.npm_package_name, 'package data is included')
3232
t.equal('Mike Sherov', env.npm_package_contributors_0_name, 'nested package data is included')
@@ -186,3 +186,32 @@ test("reports child's output", function (t) {
186186
})
187187
.catch(t.end)
188188
})
189+
190+
test('fails when given an invalid user id', {
191+
skip: process.platform === 'win32' ? 'windows always in unsafe mode' : false
192+
}, function (t) {
193+
const fixture = path.join(__dirname, 'fixtures', 'count-to-10-working-postinstall')
194+
const dir = fixture
195+
196+
const pkg = require(path.join(fixture, 'package.json'))
197+
t.rejects(lifecycle(pkg, 'postinstall', fixture, {
198+
stdio: 'pipe',
199+
log: {
200+
level: 'silent',
201+
info: noop,
202+
warn: noop,
203+
silly: noop,
204+
verbose: noop,
205+
pause: noop,
206+
resume: noop,
207+
clearProgress: noop,
208+
showProgress: noop
209+
},
210+
dir,
211+
user: 'this-user-name-does-not-exist-at-least-i-sure-hope-not',
212+
group: 'maybe-there-are-a-bunch-of-us-who-do-not-exist',
213+
unsafePerm: false,
214+
config: {}
215+
}), { code: 'EUIDLOOKUP' })
216+
t.end()
217+
})

0 commit comments

Comments
 (0)
This repository has been archived.