-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Do not drop perms in git when not root
Forward port of 5f33040 Fix npm/cli#476 for pacote v10. Fix #22
- Loading branch information
Showing
2 changed files
with
41 additions
and
16 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 |
---|---|---|
@@ -1,19 +1,43 @@ | ||
const t = require('tap') | ||
const gitOpts = require('../../../lib/util/git/opts.js') | ||
const gitEnv = require('../../../lib/util/git/env.js') | ||
t.match(gitOpts({ | ||
foo: 'bar', | ||
env: { override: 'for some reason' }, | ||
}, { | ||
uid: 420, | ||
gid: 69, | ||
abc: 'def', | ||
}), { | ||
foo: 'bar', | ||
env: { override: 'for some reason' }, | ||
uid: 420, | ||
gid: 69, | ||
abc: undefined, | ||
}, 'copied relevant opts, not irrelevant ones') | ||
|
||
t.match(gitOpts().env, gitEnv(), 'got the git env by default') | ||
|
||
t.test('as root', t => { | ||
process.getuid = () => 0 | ||
t.match(gitOpts({ | ||
foo: 'bar', | ||
env: { override: 'for some reason' }, | ||
}, { | ||
uid: 420, | ||
gid: 69, | ||
abc: 'def', | ||
}), { | ||
foo: 'bar', | ||
env: { override: 'for some reason' }, | ||
uid: 420, | ||
gid: 69, | ||
abc: undefined, | ||
}, 'copied relevant opts, not irrelevant ones') | ||
t.end() | ||
}) | ||
|
||
t.test('as non-root', t => { | ||
process.getuid = () => 999 | ||
t.match(gitOpts({ | ||
foo: 'bar', | ||
env: { override: 'for some reason' }, | ||
}, { | ||
uid: 420, | ||
gid: 69, | ||
abc: 'def', | ||
}), { | ||
foo: 'bar', | ||
env: { override: 'for some reason' }, | ||
uid: undefined, | ||
gid: undefined, | ||
abc: undefined, | ||
}, 'do not set uid/gid as non-root') | ||
t.end() | ||
}) |