Skip to content

Commit 0ce7099

Browse files
authored
feat(root): allow --allow-root to disable root user check (#1374)
1 parent c505d04 commit 0ce7099

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/command.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Command {
146146
findValidInstall(commandName, !argv.dir);
147147
}
148148

149-
if (!this.allowRoot) {
149+
if (!this.allowRoot && !argv.allowRoot) {
150150
const checkRootUser = require('./utils/check-root-user');
151151
// Check if user is trying to install as `root`
152152
checkRootUser(commandName);

test/unit/command-spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,30 @@ describe('Unit: Command', function () {
241241
}
242242
});
243243

244+
it('doesn\'t check for root when --allow-root is passed', async function () {
245+
const checkRootUserStub = sinon.stub().throws('let them be freeee');
246+
class ShortCircuit {
247+
constructor() {
248+
throw new Error('you shall not pass');
249+
}
250+
}
251+
const Command = proxyquire(modulePath, {
252+
'./utils/check-root-user': checkRootUserStub,
253+
'./system': ShortCircuit
254+
});
255+
256+
const TestCommand = class extends Command {};
257+
TestCommand.global = true;
258+
259+
try {
260+
await TestCommand._run('test', {dir: '.', allowRoot: true});
261+
} catch (e) {
262+
expect(e).to.exist;
263+
expect(e.message).to.equal('you shall not pass');
264+
expect(checkRootUserStub.calledOnce).to.be.false;
265+
}
266+
});
267+
244268
it('Changes directory if needed', async function () {
245269
sinon.stub(process, 'exit').throws(new Error('exit_stub'));
246270
const outStub = sinon.stub(process.stderr, 'write');

0 commit comments

Comments
 (0)