This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent removal of a user's home directory (#6)
Fixes: npm/npm#14012 PR-URL: #6 Credit: @helio-frota Reviewed-By: @zkat
- Loading branch information
1 parent
acff37c
commit 16136ea
Showing
3 changed files
with
52 additions
and
1 deletion.
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,46 @@ | ||
var path = require('path') | ||
|
||
var test = require('tap').test | ||
var mkdtemp = require('tmp').dir | ||
var mkdirp = require('mkdirp') | ||
|
||
var vacuum = require('../vacuum.js') | ||
|
||
// CONSTANTS | ||
var TEMP_OPTIONS = { | ||
unsafeCleanup: true, | ||
mode: '0700' | ||
} | ||
|
||
var BASE_PATH = path.join('foo') | ||
var HOME_PATH = path.join(BASE_PATH, 'foo', 'bar') | ||
|
||
var messages = [] | ||
function log () { messages.push(Array.prototype.slice.call(arguments).join(' ')) } | ||
|
||
var homePath, basePath, realHome | ||
test('xXx setup xXx', function (t) { | ||
mkdtemp(TEMP_OPTIONS, function (er, tmpdir) { | ||
t.ifError(er, 'temp directory exists') | ||
|
||
homePath = path.resolve(tmpdir, HOME_PATH) | ||
basePath = path.resolve(tmpdir, BASE_PATH) | ||
|
||
realHome = process.env.HOME | ||
process.env.HOME = homePath | ||
|
||
mkdirp(homePath, function (er) { | ||
t.ifError(er, 'made test path') | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
|
||
test('do not remove home directory', function (t) { | ||
vacuum(homePath, {purge: false, base: basePath, log: log}, function (er) { | ||
t.ifError(er, 'cleaned up to base') | ||
t.equal(messages[0], 'quitting because cannot remove home directory ' + homePath) | ||
process.env.HOME = realHome | ||
t.end() | ||
}) | ||
}) |
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