Skip to content

Commit

Permalink
fix(local-process): make content folder check work in more cases
Browse files Browse the repository at this point in the history
no issue
- return true for content folder check if everyone has read & write
permissions
  • Loading branch information
acburdine committed Feb 6, 2018
1 parent d791101 commit 710a9d4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
9 changes: 8 additions & 1 deletion lib/utils/local-process.js
Expand Up @@ -184,7 +184,14 @@ Please ensure the content folder has correct permissions and try again.`));
}

const stat = fs.lstatSync(path.join(cwd, 'content'));
return stat.uid === process.getuid();

if (stat.uid === process.getuid()) {
return true;
}

const Mode = require('stat-mode');
const mode = new Mode(stat);
return mode.others.write && mode.others.read;
}

/**
Expand Down
43 changes: 37 additions & 6 deletions test/unit/utils/local-process-spec.js
Expand Up @@ -329,38 +329,51 @@ describe('Unit: Utils > local-process', function () {
});

describe('_checkContentFolder', function () {
const LocalProcess = require(modulePath);
let LocalProcess;
let modeStub;

beforeEach(() => {
modeStub = sandbox.stub();
LocalProcess = proxyquire(modulePath, {
'stat-mode': modeStub
});
});

it('skips if windows', function () {
const statStub = sandbox.stub(fs, 'lstatSync');
const instance = new LocalProcess({}, {
platform: {windows: true}
}, {});
modeStub.returns({others: {write: false, read: false}});

const result = instance._checkContentFolder('/var/www/ghost');

expect(result).to.be.true;
expect(statStub.called).to.be.false;
expect(modeStub.called).to.be.false;
});

it('returns false if getuid and lstatSync don\'t match', function () {
const statStub = sandbox.stub(fs, 'lstatSync').returns({uid: 2});
it('returns true if getuid and lstatSync match', function () {
const statStub = sandbox.stub(fs, 'lstatSync').returns({uid: 1});
const uidStub = sandbox.stub(process, 'getuid').returns(1);
modeStub.returns({others: {write: false, read: false}});

const instance = new LocalProcess({}, {
platform: {linux: true}
}, {});
const result = instance._checkContentFolder('/var/www/ghost');

expect(result).to.be.false;
expect(result).to.be.true;
expect(statStub.calledOnce).to.be.true;
expect(statStub.calledWithExactly('/var/www/ghost/content')).to.be.true;
expect(uidStub.calledOnce).to.be.true;
expect(modeStub.called).to.be.false;
});

it('returns true if getuid and lstatSync match', function () {
const statStub = sandbox.stub(fs, 'lstatSync').returns({uid: 1});
it('returns true if getuid and lstatSync don\'t match, but current user has read&write permissions', function () {
const statStub = sandbox.stub(fs, 'lstatSync').returns({uid: 2});
const uidStub = sandbox.stub(process, 'getuid').returns(1);
modeStub.returns({others: {write: true, read: true}});

const instance = new LocalProcess({}, {
platform: {linux: true}
Expand All @@ -371,6 +384,24 @@ describe('Unit: Utils > local-process', function () {
expect(statStub.calledOnce).to.be.true;
expect(statStub.calledWithExactly('/var/www/ghost/content')).to.be.true;
expect(uidStub.calledOnce).to.be.true;
expect(modeStub.calledOnce).to.be.true;
});

it('returns false if getuid and lstatSync don\'t match, and current user doesn\'t have read&write permissions', function () {
const statStub = sandbox.stub(fs, 'lstatSync').returns({uid: 2});
const uidStub = sandbox.stub(process, 'getuid').returns(1);
modeStub.returns({others: {write: false, read: false}});

const instance = new LocalProcess({}, {
platform: {linux: true}
}, {});
const result = instance._checkContentFolder('/var/www/ghost');

expect(result).to.be.false;
expect(statStub.calledOnce).to.be.true;
expect(statStub.calledWithExactly('/var/www/ghost/content')).to.be.true;
expect(uidStub.calledOnce).to.be.true;
expect(modeStub.calledOnce).to.be.true;
});
});
});

0 comments on commit 710a9d4

Please sign in to comment.