More test cleanups to support domains api

This commit is contained in:
Johannes Zellner
2017-11-21 01:56:24 +01:00
parent 5dab697fd6
commit 8d69e5f3b9
6 changed files with 26 additions and 24 deletions

View File

@@ -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;

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();
});
});
});

View File

@@ -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) {

View File

@@ -31,7 +31,8 @@ describe('dns provider', function () {
async.series([
database.initialize,
settings.initialize
settings.initialize,
database._clear
], done);
});