2017-11-20 19:59:23 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
2018-01-18 13:41:10 -08:00
|
|
|
/* global xdescribe:false */
|
2015-07-20 00:09:47 -07:00
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
2017-11-20 19:59:23 +01:00
|
|
|
var async = require('async'),
|
2016-11-08 17:33:43 +05:30
|
|
|
child_process = require('child_process'),
|
2015-07-20 00:09:47 -07:00
|
|
|
config = require('../../config.js'),
|
2017-01-26 15:38:29 -08:00
|
|
|
constants = require('../../constants.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
database = require('../../database.js'),
|
|
|
|
|
expect = require('expect.js'),
|
2017-11-20 19:59:23 +01:00
|
|
|
fs = require('fs'),
|
|
|
|
|
nock = require('nock'),
|
2015-10-27 18:38:13 +01:00
|
|
|
path = require('path'),
|
2015-07-20 00:09:47 -07:00
|
|
|
paths = require('../../paths.js'),
|
|
|
|
|
server = require('../../server.js'),
|
|
|
|
|
settings = require('../../settings.js'),
|
2017-11-20 19:59:23 +01:00
|
|
|
superagent = require('superagent');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
var SERVER_URL = 'http://localhost:' + config.get('port');
|
|
|
|
|
|
2016-04-13 16:50:20 -07:00
|
|
|
var USERNAME = 'superadmin', PASSWORD = 'Foobar?1337', EMAIL ='silly@me.com';
|
2015-07-20 00:09:47 -07:00
|
|
|
var token = null;
|
|
|
|
|
|
|
|
|
|
function setup(done) {
|
2017-11-27 15:30:55 -08:00
|
|
|
config._reset();
|
|
|
|
|
config.setFqdn('example-settings-test.com');
|
2018-01-10 20:40:15 -08:00
|
|
|
config.setAdminFqdn('my.example-settings-test.com');
|
2015-10-28 16:00:51 +01:00
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
async.series([
|
2017-11-20 19:59:23 +01:00
|
|
|
server.start.bind(null),
|
|
|
|
|
database._clear.bind(null),
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
function createAdmin(callback) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
|
2018-01-18 13:41:10 -08:00
|
|
|
.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);
|
|
|
|
|
|
|
|
|
|
// stash token for further use
|
|
|
|
|
token = result.body.token;
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
], done);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanup(done) {
|
|
|
|
|
database._clear(function (error) {
|
|
|
|
|
expect(!error).to.be.ok();
|
|
|
|
|
|
|
|
|
|
server.stop(done);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe('Settings API', function () {
|
|
|
|
|
before(setup);
|
|
|
|
|
after(cleanup);
|
|
|
|
|
|
|
|
|
|
describe('autoupdate_pattern', function () {
|
|
|
|
|
it('can get auto update pattern (default)', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.get(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
|
expect(res.body.pattern).to.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set autoupdate_pattern without pattern', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can set autoupdate_pattern', function (done) {
|
|
|
|
|
var eventPattern = null;
|
|
|
|
|
settings.events.on(settings.AUTOUPDATE_PATTERN_KEY, function (pattern) {
|
|
|
|
|
eventPattern = pattern;
|
|
|
|
|
});
|
|
|
|
|
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ pattern: '00 30 11 * * 1-5' })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
|
expect(eventPattern === '00 30 11 * * 1-5').to.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can set autoupdate_pattern to never', function (done) {
|
|
|
|
|
var eventPattern = null;
|
|
|
|
|
settings.events.on(settings.AUTOUPDATE_PATTERN_KEY, function (pattern) {
|
|
|
|
|
eventPattern = pattern;
|
|
|
|
|
});
|
|
|
|
|
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ pattern: constants.AUTOUPDATE_PATTERN_NEVER })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
|
expect(eventPattern).to.eql(constants.AUTOUPDATE_PATTERN_NEVER);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set invalid autoupdate_pattern', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ pattern: '1 3 x 5 6' })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('cloudron_name', function () {
|
|
|
|
|
var name = 'foobar';
|
|
|
|
|
|
|
|
|
|
it('get default succeeds', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.get(SERVER_URL + '/api/v1/settings/cloudron_name')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
|
expect(res.body.name).to.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set without name', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/cloudron_name')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set empty name', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/cloudron_name')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ name: '' })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('set succeeds', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/cloudron_name')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ name: name })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(202);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('get succeeds', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.get(SERVER_URL + '/api/v1/settings/cloudron_name')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
|
expect(res.body.name).to.eql(name);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('cloudron_avatar', function () {
|
|
|
|
|
it('get default succeeds', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.get(SERVER_URL + '/api/v1/settings/cloudron_avatar')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
|
expect(res.body).to.be.a(Buffer);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set without data', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/cloudron_avatar')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('set succeeds', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/cloudron_avatar')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.attach('avatar', paths.CLOUDRON_DEFAULT_AVATAR_FILE)
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(202);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('get succeeds', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.get(SERVER_URL + '/api/v1/settings/cloudron_avatar')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
|
expect(res.body.toString()).to.eql(fs.readFileSync(paths.CLOUDRON_DEFAULT_AVATAR_FILE, 'utf-8'));
|
|
|
|
|
done(err);
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
2015-10-26 00:59:20 -07:00
|
|
|
|
2017-11-20 19:59:23 +01:00
|
|
|
xdescribe('Certificates API', function () {
|
|
|
|
|
var validCert0, validKey0, // example.com
|
|
|
|
|
validCert1, validKey1; // *.example.com
|
2015-10-27 18:38:13 +01:00
|
|
|
|
2016-11-08 17:33:43 +05:30
|
|
|
before(function () {
|
2017-11-20 19:59:23 +01:00
|
|
|
child_process.execSync('openssl req -subj "/CN=example.com/O=My Company Name LTD./C=US" -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout /tmp/server.key -out /tmp/server.crt');
|
2016-11-08 17:33:43 +05:30
|
|
|
validKey0 = fs.readFileSync('/tmp/server.key', 'utf8');
|
|
|
|
|
validCert0 = fs.readFileSync('/tmp/server.crt', 'utf8');
|
|
|
|
|
|
2017-11-20 19:59:23 +01:00
|
|
|
child_process.execSync('openssl req -subj "/CN=*.example.com/O=My Company Name LTD./C=US" -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout /tmp/server.key -out /tmp/server.crt');
|
2016-11-08 17:33:43 +05:30
|
|
|
validKey1 = fs.readFileSync('/tmp/server.key', 'utf8');
|
|
|
|
|
validCert1 = fs.readFileSync('/tmp/server.crt', 'utf8');
|
|
|
|
|
});
|
2015-10-27 18:38:13 +01:00
|
|
|
|
|
|
|
|
it('cannot set certificate without token', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/certificate')
|
2018-01-18 13:41:10 -08:00
|
|
|
.end(function (error, result) {
|
|
|
|
|
expect(result.statusCode).to.equal(401);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-27 18:38:13 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set certificate without certificate', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/certificate')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ key: validKey1 })
|
|
|
|
|
.end(function (error, result) {
|
|
|
|
|
expect(result.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-27 18:38:13 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set certificate without key', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/certificate')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ cert: validCert1 })
|
|
|
|
|
.end(function (error, result) {
|
|
|
|
|
expect(result.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-28 12:12:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set certificate with cert not being a string', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/certificate')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ cert: 1234, key: validKey1 })
|
|
|
|
|
.end(function (error, result) {
|
|
|
|
|
expect(result.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-28 12:12:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set certificate with key not being a string', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/certificate')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ cert: validCert1, key: true })
|
|
|
|
|
.end(function (error, result) {
|
|
|
|
|
expect(result.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-28 16:00:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set non wildcard certificate', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/certificate')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ cert: validCert0, key: validKey0 })
|
|
|
|
|
.end(function (error, result) {
|
|
|
|
|
expect(result.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-27 18:38:13 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can set certificate', function (done) {
|
2015-12-15 09:12:52 -08:00
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/certificate')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ cert: validCert1, key: validKey1 })
|
|
|
|
|
.end(function (error, result) {
|
|
|
|
|
expect(result.statusCode).to.equal(202);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-27 18:38:13 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('did set the certificate', function (done) {
|
2015-10-28 16:00:51 +01:00
|
|
|
var cert = fs.readFileSync(path.join(paths.NGINX_CERT_DIR, 'host.cert'), 'utf-8');
|
|
|
|
|
expect(cert).to.eql(validCert1);
|
2015-10-27 18:38:13 +01:00
|
|
|
|
2015-10-28 16:00:51 +01:00
|
|
|
var key = fs.readFileSync(path.join(paths.NGINX_CERT_DIR, 'host.key'), 'utf-8');
|
|
|
|
|
expect(key).to.eql(validKey1);
|
2015-10-27 18:38:13 +01:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-05-03 12:10:16 -07:00
|
|
|
|
|
|
|
|
describe('time_zone', function () {
|
|
|
|
|
it('succeeds', function (done) {
|
|
|
|
|
superagent.get(SERVER_URL + '/api/v1/settings/time_zone')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
|
expect(res.body.timeZone).to.be('America/Los_Angeles');
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-05-03 12:10:16 -07:00
|
|
|
});
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2016-08-01 15:10:45 +02:00
|
|
|
describe('appstore_config', function () {
|
|
|
|
|
it('get appstore_config fails', function (done) {
|
|
|
|
|
superagent.get(SERVER_URL + '/api/v1/settings/appstore_config')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
|
expect(res.body).to.eql({});
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-08-01 15:10:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set without data', function (done) {
|
|
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(400);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-08-01 15:10:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('set fails with wrong appstore token', function (done) {
|
|
|
|
|
var scope = nock(config.apiServerOrigin()).post('/api/v1/users/nebulon/cloudrons?accessToken=sometoken').reply(401);
|
|
|
|
|
|
|
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ userId: 'nebulon', token: 'sometoken' })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(scope.isDone()).to.be.ok();
|
|
|
|
|
expect(res.statusCode).to.equal(406);
|
|
|
|
|
expect(res.body.message).to.equal('invalid appstore token');
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-08-01 15:10:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('set succeeds for unknown cloudron', function (done) {
|
|
|
|
|
var scope = nock(config.apiServerOrigin()).post('/api/v1/users/nebulon/cloudrons?accessToken=sometoken').reply(201, { cloudron: { id: 'cloudron0' }});
|
|
|
|
|
|
|
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ userId: 'nebulon', token: 'sometoken' })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(scope.isDone()).to.be.ok();
|
|
|
|
|
expect(res.statusCode).to.equal(202);
|
|
|
|
|
expect(res.body).to.eql({ userId: 'nebulon', token: 'sometoken', cloudronId: 'cloudron0' });
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-08-01 15:10:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('set fails with wrong appstore user', function (done) {
|
|
|
|
|
var scope = nock(config.apiServerOrigin()).get('/api/v1/users/nebulon/cloudrons/cloudron0?accessToken=sometoken').reply(403);
|
|
|
|
|
|
|
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ userId: 'nebulon', token: 'sometoken' })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(scope.isDone()).to.be.ok();
|
|
|
|
|
expect(res.statusCode).to.equal(406);
|
|
|
|
|
expect(res.body.message).to.equal('wrong user');
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-08-01 15:10:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('get succeeds', function (done) {
|
|
|
|
|
superagent.get(SERVER_URL + '/api/v1/settings/appstore_config')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
|
expect(res.body).to.eql({ userId: 'nebulon', token: 'sometoken', cloudronId: 'cloudron0' });
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-08-01 15:10:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('set succeeds with cloudronId', function (done) {
|
|
|
|
|
var scope = nock(config.apiServerOrigin()).get('/api/v1/users/nebulon/cloudrons/cloudron0?accessToken=someothertoken').reply(200, { cloudron: { id: 'cloudron0' }});
|
|
|
|
|
|
|
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ userId: 'nebulon', token: 'someothertoken' })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(scope.isDone()).to.be.ok();
|
|
|
|
|
expect(res.statusCode).to.equal(202);
|
|
|
|
|
expect(res.body).to.eql({ userId: 'nebulon', token: 'someothertoken', cloudronId: 'cloudron0' });
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-08-01 15:10:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('set succeeds with cloudronId but unkown one (reregister)', function (done) {
|
|
|
|
|
var scope0 = nock(config.apiServerOrigin()).get('/api/v1/users/nebulon/cloudrons/cloudron0?accessToken=someothertoken').reply(404);
|
|
|
|
|
var scope1 = nock(config.apiServerOrigin()).post('/api/v1/users/nebulon/cloudrons?accessToken=someothertoken').reply(201, { cloudron: { id: 'cloudron1' }});
|
|
|
|
|
|
|
|
|
|
superagent.post(SERVER_URL + '/api/v1/settings/appstore_config')
|
2018-01-18 13:41:10 -08:00
|
|
|
.query({ access_token: token })
|
|
|
|
|
.send({ userId: 'nebulon', token: 'someothertoken' })
|
|
|
|
|
.end(function (err, res) {
|
|
|
|
|
expect(scope0.isDone()).to.be.ok();
|
|
|
|
|
expect(scope1.isDone()).to.be.ok();
|
|
|
|
|
expect(res.statusCode).to.equal(202);
|
|
|
|
|
expect(res.body).to.eql({ userId: 'nebulon', token: 'someothertoken', cloudronId: 'cloudron1' });
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-08-01 15:10:45 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|