|
1 | 1 | const t = require('tap')
|
2 | 2 | const Minipass = require('minipass')
|
3 | 3 | const EE = require('events')
|
| 4 | +const fs = require('fs') |
4 | 5 |
|
5 | 6 | const isPipe = (stdio = 'pipe', fd) =>
|
6 | 7 | stdio === 'pipe' || stdio === null ? true
|
@@ -214,3 +215,33 @@ t.test('expose process', t => {
|
214 | 215 | t.end()
|
215 | 216 | setTimeout(() => p.process.exit(0))
|
216 | 217 | })
|
| 218 | + |
| 219 | +t.test('infer ownership', t => { |
| 220 | + const { lstatSync } = fs |
| 221 | + t.teardown(() => fs.lstatSync = lstatSync) |
| 222 | + fs.lstatSync = (path) => ({ uid: 420, gid: 69 }) |
| 223 | + const getuid = process.getuid |
| 224 | + t.teardown(() => process.getuid = getuid) |
| 225 | + |
| 226 | + t.test('as non-root, do not change uid/gid, regardless of arguments', t => { |
| 227 | + process.getuid = () => 1234 |
| 228 | + return t.resolveMatch(promiseSpawn('whoami', [], { uid: 4321, gid: 9876 }), { |
| 229 | + code: 0, |
| 230 | + signal: null, |
| 231 | + stdout: Buffer.from('UID undefined\nGID undefined\n'), |
| 232 | + stderr: Buffer.alloc(0), |
| 233 | + }) |
| 234 | + }) |
| 235 | + |
| 236 | + t.test('as root, change uid/gid to folder, regardless of arguments', t => { |
| 237 | + process.getuid = () => 0 |
| 238 | + return t.resolveMatch(promiseSpawn('whoami', [], { uid: 4321, gid: 9876 }), { |
| 239 | + code: 0, |
| 240 | + signal: null, |
| 241 | + stdout: Buffer.from('UID 420\nGID 69\n'), |
| 242 | + stderr: Buffer.alloc(0), |
| 243 | + }) |
| 244 | + }) |
| 245 | + |
| 246 | + t.end() |
| 247 | +}) |
0 commit comments