From 8d69e5f3b95dfbc495f3fb4a7ee9d8feb88d18c8 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Tue, 21 Nov 2017 01:56:24 +0100 Subject: [PATCH] More test cleanups to support domains api --- src/routes/test/eventlog-test.js | 8 -------- src/routes/test/groups-test.js | 4 +++- src/routes/test/oauth2-test.js | 12 ++++++++---- src/routes/test/server-test.js | 21 ++++++++++++--------- src/routes/test/sysadmin-test.js | 2 +- src/test/dns-test.js | 3 ++- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/routes/test/eventlog-test.js b/src/routes/test/eventlog-test.js index 700ed5b0f..885f8a830 100644 --- a/src/routes/test/eventlog-test.js +++ b/src/routes/test/eventlog-test.js @@ -10,7 +10,6 @@ var async = require('async'), config = require('../../config.js'), database = require('../../database.js'), expect = require('expect.js'), - nock = require('nock'), superagent = require('superagent'), server = require('../../server.js'), tokendb = require('../../tokendb.js'); @@ -23,25 +22,18 @@ var token = null; var USER_1_ID = null, token_1; function setup(done) { - config.setVersion('1.2.3'); - async.series([ server.start.bind(server), database._clear, function createAdmin(callback) { - var scope1 = nock(config.apiServerOrigin()).get('/api/v1/boxes/' + config.fqdn() + '/setup/verify?setupToken=somesetuptoken').reply(200, {}); - var scope2 = nock(config.apiServerOrigin()).post('/api/v1/boxes/' + config.fqdn() + '/setup/done?setupToken=somesetuptoken').reply(201, {}); - superagent.post(SERVER_URL + '/api/v1/cloudron/activate') .query({ setupToken: 'somesetuptoken' }) .send({ username: USERNAME, password: PASSWORD, email: EMAIL }) .end(function (error, result) { expect(result).to.be.ok(); expect(result.statusCode).to.eql(201); - expect(scope1.isDone()).to.be.ok(); - expect(scope2.isDone()).to.be.ok(); // stash token for further use token = result.body.token; diff --git a/src/routes/test/groups-test.js b/src/routes/test/groups-test.js index 677a41964..3e7f4c5e4 100644 --- a/src/routes/test/groups-test.js +++ b/src/routes/test/groups-test.js @@ -28,6 +28,8 @@ var groupObject; var server; function setup(done) { + config.set('provider', 'caas'); + async.series([ server.start.bind(server), @@ -223,7 +225,7 @@ describe('Groups API', function () { var group0Object, group1Object; before(function (done) { groups.create('group0', function (e, r) { - group0Object = r; + group0Object = r; groups.create('group1', function (e, r) { group1Object = r; done(); diff --git a/src/routes/test/oauth2-test.js b/src/routes/test/oauth2-test.js index 5a9f47401..cb6e718f4 100644 --- a/src/routes/test/oauth2-test.js +++ b/src/routes/test/oauth2-test.js @@ -154,6 +154,7 @@ describe('OAuth2', function () { appStoreId: '', manifest: { version: '0.1.0', addons: { } }, location: 'test', + domain: 'example.com', portBindings: {}, accessRestriction: null, memoryLimit: 0, @@ -165,6 +166,7 @@ describe('OAuth2', function () { appStoreId: '', manifest: { version: '0.1.0', addons: { } }, location: 'test1', + domain: 'example.com', portBindings: {}, accessRestriction: { users: [ 'foobar' ] }, memoryLimit: 0, @@ -176,6 +178,7 @@ describe('OAuth2', function () { appStoreId: '', manifest: { version: '0.1.0', addons: { } }, location: 'test2', + domain: 'example.com', portBindings: {}, accessRestriction: { users: [ USER_0.id ] }, memoryLimit: 0, @@ -187,6 +190,7 @@ describe('OAuth2', function () { appStoreId: '', manifest: { version: '0.1.0', addons: { } }, location: 'test3', + domain: 'example.com', portBindings: {}, accessRestriction: { groups: [ 'someothergroup', 'admin', 'anothergroup' ] }, memoryLimit: 0, @@ -302,10 +306,10 @@ describe('OAuth2', function () { clientdb.add.bind(null, CLIENT_6.id, CLIENT_6.appId, CLIENT_6.type, CLIENT_6.clientSecret, CLIENT_6.redirectURI, CLIENT_6.scope), clientdb.add.bind(null, CLIENT_7.id, CLIENT_7.appId, CLIENT_7.type, CLIENT_7.clientSecret, CLIENT_7.redirectURI, CLIENT_7.scope), clientdb.add.bind(null, CLIENT_9.id, CLIENT_9.appId, CLIENT_9.type, CLIENT_9.clientSecret, CLIENT_9.redirectURI, CLIENT_9.scope), - appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.portBindings, APP_0), - appdb.add.bind(null, APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.portBindings, APP_1), - appdb.add.bind(null, APP_2.id, APP_2.appStoreId, APP_2.manifest, APP_2.location, APP_2.portBindings, APP_2), - appdb.add.bind(null, APP_3.id, APP_3.appStoreId, APP_3.manifest, APP_3.location, APP_3.portBindings, APP_3), + appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0), + appdb.add.bind(null, APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.domain, APP_1.portBindings, APP_1), + appdb.add.bind(null, APP_2.id, APP_2.appStoreId, APP_2.manifest, APP_2.location, APP_2.domain, APP_2.portBindings, APP_2), + appdb.add.bind(null, APP_3.id, APP_3.appStoreId, APP_3.manifest, APP_3.location, APP_3.domain, APP_3.portBindings, APP_3), function (callback) { user.create(USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, null /* source */, function (error, userObject) { expect(error).to.not.be.ok(); diff --git a/src/routes/test/server-test.js b/src/routes/test/server-test.js index 47f9ccf6f..ec161c819 100644 --- a/src/routes/test/server-test.js +++ b/src/routes/test/server-test.js @@ -22,6 +22,7 @@ var token = null; var server; function setup(done) { + config.set('provider', 'caas'); config.setVersion('1.2.3'); async.series([ @@ -67,11 +68,12 @@ describe('REST API', function () { superagent.post(SERVER_URL + '/api/v1/users') .query({ access_token: token }) .set('content-type', 'application/json') - .send("some invalid non-strict json") - .end(function (error, result) { - expect(result.statusCode).to.equal(400); - expect(result.body.message).to.be('Failed to parse body'); - done(); + .send('some invalid non-strict json') + .end(function (error, result) { + expect(result.statusCode).to.equal(400); + expect(result.body.message).to.be('Bad JSON'); + + done(); }); }); @@ -79,10 +81,11 @@ describe('REST API', function () { superagent.post(SERVER_URL + '/api/v1/users') .query({ access_token: token }) .set('content-type', 'application/x-www-form-urlencoded') - .send("some string") - .end(function (error, result) { - expect(result.statusCode).to.equal(400); - done(); + .send('some string') + .end(function (error, result) { + expect(result.statusCode).to.equal(400); + + done(); }); }); }); diff --git a/src/routes/test/sysadmin-test.js b/src/routes/test/sysadmin-test.js index 5decafe51..fc28b24e8 100644 --- a/src/routes/test/sysadmin-test.js +++ b/src/routes/test/sysadmin-test.js @@ -58,7 +58,7 @@ function setup(done) { function addApp(callback) { var manifest = { version: '0.0.1', manifestVersion: 1, dockerImage: 'foo', healthCheckPath: '/', httpPort: 3, title: 'ok', addons: { } }; - appdb.add('appid', 'appStoreId', manifest, 'location', [ ] /* portBindings */, { }, callback); + appdb.add('appid', 'appStoreId', manifest, 'location', 'example.com', [ ] /* portBindings */, { }, callback); }, function createSettings(callback) { diff --git a/src/test/dns-test.js b/src/test/dns-test.js index 1ad8ca6e1..fcbc0241f 100644 --- a/src/test/dns-test.js +++ b/src/test/dns-test.js @@ -31,7 +31,8 @@ describe('dns provider', function () { async.series([ database.initialize, - settings.initialize + settings.initialize, + database._clear ], done); });