Skip to content

Commit

Permalink
fix(doctor): improve permission denied error message (#627)
Browse files Browse the repository at this point in the history
no issue

- improve error message and tests for permissions checks, when permission denied
  • Loading branch information
aileen authored and acburdine committed Feb 6, 2018
1 parent 4702ce8 commit 9af537e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/commands/doctor/checks/check-permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ module.exports = function checkPermissions(type, task) {
}

if (error.stderr && error.stderr.match(/Permission denied/i)) {
// We can't access some files or directories.
// Print the help command to fix that
// CASE: We can't access the files or directories.
// Print the help command for folder permissions to fix that
errMsg = 'Ghost can\'t access some files or directories to check for correct permissions.';

errMsg = `Ghost can't access some files or directories to check for correct permissions.
${checkTypes.folder.help}`;

return Promise.reject(new errors.SystemError({message: errMsg, err: error, task: task}));
return Promise.reject(new errors.SystemError({
message: errMsg,
help: checkTypes.folder.help,
err: error,
task: task
}));
}

error.task = task;
Expand Down
2 changes: 2 additions & 0 deletions test/unit/commands/doctor/checks/content-folder-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('Unit: Doctor Checks > Checking content folder ownership', function ()
expect(error).to.be.an.instanceof(errors.SystemError);
expect(error.message).to.match(/Your installation folder contains some directories or files with incorrect permissions:/);
expect(error.message).to.match(/- \.\/content\/images/);
expect(error.message).to.match(/sudo chown -R ghost:ghost \.\/content/);
expect(execaStub.called).to.be.true;
});
});
Expand All @@ -59,6 +60,7 @@ describe('Unit: Doctor Checks > Checking content folder ownership', function ()
expect(error).to.be.an.instanceof(errors.SystemError);
expect(error.message).to.match(/Your installation folder contains a directory or file with incorrect permissions:/);
expect(error.message).to.match(/- .\/content\/images\/test.jpg/);
expect(error.message).to.match(/sudo chown -R ghost:ghost \.\/content/);
expect(execaStub.called).to.be.true;
});
});
Expand Down
2 changes: 2 additions & 0 deletions test/unit/commands/doctor/checks/file-permissions-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('Unit: Doctor Checks > Checking file permissions', function () {
expect(error).to.be.an.instanceof(errors.SystemError);
expect(error.message).to.match(/Your installation folder contains some directories or files with incorrect permissions:/);
expect(error.message).to.match(/- \.\/system\/apps/);
expect(error.message).to.match(/sudo find \.\/content \.\/system \.ghost-cli \*\.json -type f -exec chmod 664 \{\} \\;/);
expect(execaStub.called).to.be.true;
});
});
Expand All @@ -54,6 +55,7 @@ describe('Unit: Doctor Checks > Checking file permissions', function () {
expect(error).to.be.an.instanceof(errors.SystemError);
expect(error.message).to.match(/Your installation folder contains a directory or file with incorrect permissions:/);
expect(error.message).to.match(/- .\/content\/images\/test.jpg/);
expect(error.message).to.match(/sudo find \.\/content \.\/system \.ghost-cli \*\.json -type f -exec chmod 664 \{\} \\;/);
expect(execaStub.called).to.be.true;
});
});
Expand Down
2 changes: 2 additions & 0 deletions test/unit/commands/doctor/checks/folder-permissions-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('Unit: Doctor Checks > Checking folder permissions', function () {
expect(error).to.be.an.instanceof(errors.SystemError);
expect(error.message).to.match(/Your installation folder contains some directories or files with incorrect permissions:/);
expect(error.message).to.match(/- \.\/system\/apps/);
expect(error.message).to.match(/sudo find \.\/ -type d -exec chmod 775 \{\} \\;/);
expect(execaStub.called).to.be.true;
});
});
Expand All @@ -54,6 +55,7 @@ describe('Unit: Doctor Checks > Checking folder permissions', function () {
expect(error).to.be.an.instanceof(errors.SystemError);
expect(error.message).to.match(/Your installation folder contains a directory or file with incorrect permissions:/);
expect(error.message).to.match(/- .\/content\/images\/test.jpg/);
expect(error.message).to.match(/sudo find \.\/ -type d -exec chmod 775 \{\} \\;/);
expect(execaStub.called).to.be.true;
});
});
Expand Down

0 comments on commit 9af537e

Please sign in to comment.