mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Deleted tests for removed apps service modules
no-issue The companion moduleis for these tests have been deleted.
This commit is contained in:
parent
29948da3bc
commit
a77b38cb09
3 changed files with 0 additions and 284 deletions
|
@ -1,46 +0,0 @@
|
||||||
var should = require('should'),
|
|
||||||
sinon = require('sinon'),
|
|
||||||
EventEmitter = require('events').EventEmitter,
|
|
||||||
_ = require('lodash'),
|
|
||||||
|
|
||||||
// Stuff we are testing
|
|
||||||
AppDependencies = require('../../../../server/services/apps/dependencies');
|
|
||||||
|
|
||||||
describe('Apps', function () {
|
|
||||||
afterEach(function () {
|
|
||||||
sinon.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Dependencies', function () {
|
|
||||||
it('can install by package.json', function (done) {
|
|
||||||
var deps = new AppDependencies(process.cwd()),
|
|
||||||
fakeEmitter = new EventEmitter();
|
|
||||||
|
|
||||||
deps.spawnCommand = sinon.stub().returns(fakeEmitter);
|
|
||||||
|
|
||||||
deps.install().then(function () {
|
|
||||||
deps.spawnCommand.calledWith('npm').should.equal(true);
|
|
||||||
done();
|
|
||||||
}).catch(done);
|
|
||||||
|
|
||||||
_.delay(function () {
|
|
||||||
fakeEmitter.emit('exit');
|
|
||||||
}, 30);
|
|
||||||
});
|
|
||||||
it('does not install when no package.json', function (done) {
|
|
||||||
var deps = new AppDependencies(__dirname),
|
|
||||||
fakeEmitter = new EventEmitter();
|
|
||||||
|
|
||||||
deps.spawnCommand = sinon.stub().returns(fakeEmitter);
|
|
||||||
|
|
||||||
deps.install().then(function () {
|
|
||||||
deps.spawnCommand.called.should.equal(false);
|
|
||||||
done();
|
|
||||||
}).catch(done);
|
|
||||||
|
|
||||||
_.defer(function () {
|
|
||||||
fakeEmitter.emit('exit');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,137 +0,0 @@
|
||||||
var should = require('should'),
|
|
||||||
sinon = require('sinon'),
|
|
||||||
_ = require('lodash'),
|
|
||||||
Promise = require('bluebird'),
|
|
||||||
|
|
||||||
// Stuff we are testing
|
|
||||||
AppPermissions = require('../../../../server/services/apps/permissions');
|
|
||||||
|
|
||||||
describe('Apps', function () {
|
|
||||||
afterEach(function () {
|
|
||||||
sinon.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Permissions', function () {
|
|
||||||
var noGhostPackageJson = {
|
|
||||||
name: 'myapp',
|
|
||||||
version: '0.0.1',
|
|
||||||
description: 'My example app',
|
|
||||||
main: 'index.js',
|
|
||||||
scripts: {
|
|
||||||
test: 'echo \'Error: no test specified\' && exit 1'
|
|
||||||
},
|
|
||||||
author: 'Ghost',
|
|
||||||
license: 'MIT',
|
|
||||||
dependencies: {
|
|
||||||
'ghost-app': '0.0.1'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
validGhostPackageJson = {
|
|
||||||
name: 'myapp',
|
|
||||||
version: '0.0.1',
|
|
||||||
description: 'My example app',
|
|
||||||
main: 'index.js',
|
|
||||||
scripts: {
|
|
||||||
test: 'echo \'Error: no test specified\' && exit 1'
|
|
||||||
},
|
|
||||||
author: 'Ghost',
|
|
||||||
license: 'MIT',
|
|
||||||
dependencies: {
|
|
||||||
'ghost-app': '0.0.1'
|
|
||||||
},
|
|
||||||
ghost: {
|
|
||||||
permissions: {
|
|
||||||
posts: ['browse', 'read', 'edit', 'add', 'delete'],
|
|
||||||
users: ['browse', 'read', 'edit', 'add', 'delete'],
|
|
||||||
settings: ['browse', 'read', 'edit', 'add', 'delete']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
it('has default permissions to read and browse posts', function () {
|
|
||||||
should.exist(AppPermissions.DefaultPermissions);
|
|
||||||
|
|
||||||
should.exist(AppPermissions.DefaultPermissions.posts);
|
|
||||||
|
|
||||||
AppPermissions.DefaultPermissions.posts.should.containEql('browse');
|
|
||||||
AppPermissions.DefaultPermissions.posts.should.containEql('read');
|
|
||||||
|
|
||||||
// Make it hurt to add more so additional checks are added here
|
|
||||||
_.keys(AppPermissions.DefaultPermissions).length.should.equal(1);
|
|
||||||
});
|
|
||||||
it('uses default permissions if no package.json', function (done) {
|
|
||||||
var perms = new AppPermissions('test');
|
|
||||||
|
|
||||||
// No package.json in this directory
|
|
||||||
sinon.stub(perms, 'checkPackageContentsExists').returns(Promise.resolve(false));
|
|
||||||
|
|
||||||
perms.read().then(function (readPerms) {
|
|
||||||
should.exist(readPerms);
|
|
||||||
|
|
||||||
readPerms.should.equal(AppPermissions.DefaultPermissions);
|
|
||||||
|
|
||||||
done();
|
|
||||||
}).catch(done);
|
|
||||||
});
|
|
||||||
it('uses default permissions if no ghost object in package.json', function (done) {
|
|
||||||
var perms = new AppPermissions('test'),
|
|
||||||
noGhostPackageJsonContents = JSON.stringify(noGhostPackageJson, null, 2);
|
|
||||||
|
|
||||||
// package.json IS in this directory
|
|
||||||
sinon.stub(perms, 'checkPackageContentsExists').returns(Promise.resolve(true));
|
|
||||||
// no ghost property on package
|
|
||||||
sinon.stub(perms, 'getPackageContents').returns(Promise.resolve(noGhostPackageJsonContents));
|
|
||||||
|
|
||||||
perms.read().then(function (readPerms) {
|
|
||||||
should.exist(readPerms);
|
|
||||||
|
|
||||||
readPerms.should.equal(AppPermissions.DefaultPermissions);
|
|
||||||
|
|
||||||
done();
|
|
||||||
}).catch(done);
|
|
||||||
});
|
|
||||||
it('rejects when reading malformed package.json', function (done) {
|
|
||||||
var perms = new AppPermissions('test');
|
|
||||||
|
|
||||||
// package.json IS in this directory
|
|
||||||
sinon.stub(perms, 'checkPackageContentsExists').returns(Promise.resolve(true));
|
|
||||||
// malformed JSON on package
|
|
||||||
sinon.stub(perms, 'getPackageContents').returns(Promise.reject(new Error('package.json file is malformed')));
|
|
||||||
|
|
||||||
perms.read().then(function (readPerms) {
|
|
||||||
done(new Error('should not resolve'));
|
|
||||||
}).catch(function (err) {
|
|
||||||
err.message.should.equal('package.json file is malformed');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('reads from package.json in root of app directory', function (done) {
|
|
||||||
var perms = new AppPermissions('test'),
|
|
||||||
validGhostPackageJsonContents = validGhostPackageJson;
|
|
||||||
|
|
||||||
// package.json IS in this directory
|
|
||||||
sinon.stub(perms, 'checkPackageContentsExists').returns(Promise.resolve(true));
|
|
||||||
// valid ghost property on package
|
|
||||||
sinon.stub(perms, 'getPackageContents').returns(Promise.resolve(validGhostPackageJsonContents));
|
|
||||||
|
|
||||||
perms.read().then(function (readPerms) {
|
|
||||||
should.exist(readPerms);
|
|
||||||
|
|
||||||
readPerms.should.not.equal(AppPermissions.DefaultPermissions);
|
|
||||||
|
|
||||||
should.exist(readPerms.posts);
|
|
||||||
readPerms.posts.length.should.equal(5);
|
|
||||||
|
|
||||||
should.exist(readPerms.users);
|
|
||||||
readPerms.users.length.should.equal(5);
|
|
||||||
|
|
||||||
should.exist(readPerms.settings);
|
|
||||||
readPerms.settings.length.should.equal(5);
|
|
||||||
|
|
||||||
_.keys(readPerms).length.should.equal(3);
|
|
||||||
|
|
||||||
done();
|
|
||||||
}).catch(done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,101 +0,0 @@
|
||||||
const should = require('should'),
|
|
||||||
sinon = require('sinon'),
|
|
||||||
path = require('path'),
|
|
||||||
AppSandbox = require('../../../../server/services/apps/sandbox');
|
|
||||||
|
|
||||||
describe('Apps', function () {
|
|
||||||
afterEach(function () {
|
|
||||||
sinon.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('sinon', function () {
|
|
||||||
function makeAppPath(fileName) {
|
|
||||||
return path.resolve(__dirname, '..', '..', '..', 'utils', 'fixtures', 'app', fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
it('loads apps in a sinon', function () {
|
|
||||||
var appBox = new AppSandbox(),
|
|
||||||
appPath = makeAppPath('good.js'),
|
|
||||||
GoodApp,
|
|
||||||
appProxy = sinon.stub(),
|
|
||||||
app;
|
|
||||||
|
|
||||||
GoodApp = appBox.loadApp(appPath);
|
|
||||||
|
|
||||||
should.exist(GoodApp);
|
|
||||||
|
|
||||||
app = new GoodApp(appProxy);
|
|
||||||
|
|
||||||
app.install(appProxy);
|
|
||||||
|
|
||||||
app.app.something.should.equal(42);
|
|
||||||
app.app.util.util().should.equal(42);
|
|
||||||
app.app.nested.other.should.equal(42);
|
|
||||||
app.app.path.should.equal(appPath);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not allow apps to require blacklisted modules at top level', function () {
|
|
||||||
var appBox = new AppSandbox(),
|
|
||||||
badAppPath = makeAppPath('badtop.js'),
|
|
||||||
loadApp = function () {
|
|
||||||
appBox.loadApp(badAppPath);
|
|
||||||
};
|
|
||||||
|
|
||||||
loadApp.should.throw('Unsafe App require: knex');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not allow apps to require blacklisted modules at install', function () {
|
|
||||||
var appBox = new AppSandbox(),
|
|
||||||
badAppPath = makeAppPath('badinstall.js'),
|
|
||||||
BadApp,
|
|
||||||
appProxy = sinon.stub(),
|
|
||||||
app,
|
|
||||||
installApp = function () {
|
|
||||||
app.install(appProxy);
|
|
||||||
};
|
|
||||||
|
|
||||||
BadApp = appBox.loadApp(badAppPath);
|
|
||||||
|
|
||||||
app = new BadApp(appProxy);
|
|
||||||
|
|
||||||
installApp.should.throw('Unsafe App require: knex');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not allow apps to require blacklisted modules from other requires', function () {
|
|
||||||
var appBox = new AppSandbox(),
|
|
||||||
badAppPath = makeAppPath('badrequire.js'),
|
|
||||||
BadApp,
|
|
||||||
loadApp = function () {
|
|
||||||
BadApp = appBox.loadApp(badAppPath);
|
|
||||||
};
|
|
||||||
|
|
||||||
loadApp.should.throw('Unsafe App require: knex');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not allow apps to require modules relatively outside their directory', function () {
|
|
||||||
var appBox = new AppSandbox(),
|
|
||||||
badAppPath = makeAppPath('badoutside.js'),
|
|
||||||
BadApp,
|
|
||||||
loadApp = function () {
|
|
||||||
BadApp = appBox.loadApp(badAppPath);
|
|
||||||
};
|
|
||||||
|
|
||||||
loadApp.should.throw(/^Unsafe App require[\w\W]*example$/);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does allow INTERNAL apps to require modules relatively outside their directory', function () {
|
|
||||||
var appBox = new AppSandbox({internal: true}),
|
|
||||||
badAppPath = makeAppPath('badoutside.js'),
|
|
||||||
InternalApp,
|
|
||||||
loadApp = function () {
|
|
||||||
InternalApp = appBox.loadApp(badAppPath);
|
|
||||||
};
|
|
||||||
|
|
||||||
InternalApp = appBox.loadApp(badAppPath);
|
|
||||||
|
|
||||||
loadApp.should.not.throw(/^Unsafe App require[\w\W]*example$/);
|
|
||||||
|
|
||||||
InternalApp.should.be.a.Function();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Add table
Reference in a new issue