-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 6fc01a5. This was the wrong thing to do. BREAKING CHANGE: behavior for setting uid/gid on extracted contents was restored to what it was in pacote@2
- Loading branch information
Showing
2 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict' | ||
|
||
const BB = require('bluebird') | ||
|
||
const fs = require('fs') | ||
const mockTar = require('./util/mock-tarball') | ||
const npmlog = require('npmlog') | ||
const path = require('path') | ||
const pipe = BB.promisify(require('mississippi').pipe) | ||
const requireInject = require('require-inject') | ||
const test = require('tap').test | ||
|
||
require('./util/test-dir')(__filename) | ||
|
||
npmlog.level = process.env.LOGLEVEL || 'silent' | ||
|
||
test('accepts gid and uid opts', { | ||
skip: !process.getuid | ||
}, function (t) { | ||
const pkg = { | ||
'package.json': { | ||
data: JSON.stringify({ | ||
name: 'foo', | ||
version: '1.0.0' | ||
}) | ||
}, | ||
'foo/index.js': 'console.log("hello world!")' | ||
} | ||
const NEWUID = process.getuid() + 1 | ||
const NEWGID = process.getgid() + 1 | ||
// All of this only happens on uid === 0 | ||
process.getuid = () => 0 | ||
const updatedPaths = [] | ||
const fsClone = Object.create(fs) | ||
fsClone.chown = (p, uid, gid, cb) => { | ||
process.nextTick(() => { | ||
t.deepEqual({ | ||
uid: uid, | ||
gid: gid | ||
}, { | ||
uid: NEWUID, | ||
gid: NEWGID | ||
}, 'correct owner set on ' + p) | ||
updatedPaths.push(path.relative('.', p)) | ||
cb(null) | ||
}) | ||
} | ||
const extractStream = requireInject('../lib/extract-stream', { | ||
fs: fsClone | ||
}) | ||
return mockTar(pkg, {stream: true}).then(tarStream => { | ||
return pipe(tarStream, extractStream('./target', { | ||
uid: NEWUID, | ||
gid: NEWGID, | ||
log: npmlog | ||
})) | ||
}).then(() => { | ||
t.deepEqual(updatedPaths, [ | ||
'target', | ||
'target/package.json', | ||
'target/foo', | ||
'target/foo/index.js' | ||
], 'extracted files had correct uid/gid set') | ||
}) | ||
}) |