From a77b38cb097efcf0c22d3967eea7fbecef4588c0 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Mon, 15 Apr 2019 13:15:02 +0200 Subject: [PATCH] Deleted tests for removed apps service modules no-issue The companion moduleis for these tests have been deleted. --- .../unit/services/apps/dependencies_spec.js | 46 ------ .../unit/services/apps/permissions_spec.js | 137 ------------------ core/test/unit/services/apps/sandbox_spec.js | 101 ------------- 3 files changed, 284 deletions(-) delete mode 100644 core/test/unit/services/apps/dependencies_spec.js delete mode 100644 core/test/unit/services/apps/permissions_spec.js delete mode 100644 core/test/unit/services/apps/sandbox_spec.js diff --git a/core/test/unit/services/apps/dependencies_spec.js b/core/test/unit/services/apps/dependencies_spec.js deleted file mode 100644 index d0dacb771c..0000000000 --- a/core/test/unit/services/apps/dependencies_spec.js +++ /dev/null @@ -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'); - }); - }); - }); -}); diff --git a/core/test/unit/services/apps/permissions_spec.js b/core/test/unit/services/apps/permissions_spec.js deleted file mode 100644 index 08bdce53ec..0000000000 --- a/core/test/unit/services/apps/permissions_spec.js +++ /dev/null @@ -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); - }); - }); -}); diff --git a/core/test/unit/services/apps/sandbox_spec.js b/core/test/unit/services/apps/sandbox_spec.js deleted file mode 100644 index 80b88f7aeb..0000000000 --- a/core/test/unit/services/apps/sandbox_spec.js +++ /dev/null @@ -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(); - }); - }); -});