diff --git a/package.json b/package.json
index 0b551e27a..4d858e013 100644
--- a/package.json
+++ b/package.json
@@ -58,7 +58,7 @@
"semver": "^4.3.6",
"serve-favicon": "^2.2.0",
"split": "^1.0.0",
- "superagent": "~0.21.0",
+ "superagent": "^1.5.0",
"supererror": "^0.7.1",
"tail-stream": "https://registry.npmjs.org/tail-stream/-/tail-stream-0.2.1.tgz",
"underscore": "^1.7.0",
diff --git a/src/apphealthmonitor.js b/src/apphealthmonitor.js
index d7e3268e3..a049b681f 100644
--- a/src/apphealthmonitor.js
+++ b/src/apphealthmonitor.js
@@ -92,8 +92,10 @@ function checkAppHealth(app, callback) {
.redirects(0)
.timeout(HEALTHCHECK_INTERVAL)
.end(function (error, res) {
-
- if (error || res.status >= 400) { // 2xx and 3xx are ok
+ if (error && !error.response) {
+ debugApp(app, 'not alive (network error): %s', error.message);
+ setHealth(app, appdb.HEALTH_UNHEALTHY, callback);
+ } if (res.statusCode >= 400) { // 2xx and 3xx are ok
debugApp(app, 'not alive : %s', error || res.status);
setHealth(app, appdb.HEALTH_UNHEALTHY, callback);
} else {
diff --git a/src/apps.js b/src/apps.js
index d5ca05b91..033ceae0a 100644
--- a/src/apps.js
+++ b/src/apps.js
@@ -291,10 +291,10 @@ function purchase(appStoreId, callback) {
var url = config.apiServerOrigin() + '/api/v1/apps/' + appStoreId + '/purchase';
superagent.post(url).query({ token: config.token() }).end(function (error, res) {
- if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
- if (res.status === 402) return callback(new AppsError(AppsError.BILLING_REQUIRED));
- if (res.status === 404) return callback(new AppsError(AppsError.NOT_FOUND));
- if (res.status !== 201 && res.status !== 200) return callback(new Error(util.format('App purchase failed. %s %j', res.status, res.body)));
+ if (error && !error.response) return callback(new AppsError(AppsError.EXTERNAL_ERROR, error));
+ if (res.statusCode === 402) return callback(new AppsError(AppsError.BILLING_REQUIRED));
+ if (res.statusCode === 404) return callback(new AppsError(AppsError.NOT_FOUND));
+ if (res.statusCode !== 201 && res.statusCode !== 200) return callback(new Error(util.format('App purchase failed. %s %j', res.status, res.body)));
callback(null);
});
diff --git a/src/apptask.js b/src/apptask.js
index ca911df55..e86d21d7b 100644
--- a/src/apptask.js
+++ b/src/apptask.js
@@ -201,8 +201,8 @@ function downloadIcon(app, callback) {
.get(iconUrl)
.buffer(true)
.end(function (error, res) {
- if (error) return callback(new Error('Error downloading icon:' + error.message));
- if (res.status !== 200) return callback(null); // ignore error. this can also happen for apps installed with cloudron-cli
+ if (error && !error.response) return callback(new Error('Network error downloading icon:' + error.message));
+ if (res.statusCode !== 200) return callback(null); // ignore error. this can also happen for apps installed with cloudron-cli
if (!safe.fs.writeFileSync(path.join(paths.APPICONS_DIR, app.id + '.png'), res.body)) return callback(new Error('Error saving icon:' + safe.error.message));
diff --git a/src/cloudron.js b/src/cloudron.js
index a4368717c..950fab500 100644
--- a/src/cloudron.js
+++ b/src/cloudron.js
@@ -178,7 +178,7 @@ function setTimeZone(ip, callback) {
debug('setTimeZone ip:%s', ip);
superagent.get('http://www.telize.com/geoip/' + ip).end(function (error, result) {
- if (error || result.statusCode !== 200) {
+ if ((error && !error.response) || result.statusCode !== 200) {
debug('Failed to get geo location', error);
return callback(null);
}
@@ -260,8 +260,8 @@ function getCloudronDetails(callback) {
.get(config.apiServerOrigin() + '/api/v1/boxes/' + config.fqdn())
.query({ token: config.token() })
.end(function (error, result) {
- if (error) return callback(error);
- if (result.status !== 200) return callback(new CloudronError(CloudronError.EXTERNAL_ERROR, util.format('%s %j', result.status, result.body)));
+ if (error && !error.response) return callback(error);
+ if (result.statusCode !== 200) return callback(new CloudronError(CloudronError.EXTERNAL_ERROR, util.format('%s %j', result.status, result.body)));
gCloudronDetails = result.body.box;
@@ -318,7 +318,7 @@ function sendHeartbeat() {
var url = config.apiServerOrigin() + '/api/v1/boxes/' + config.fqdn() + '/heartbeat';
superagent.post(url).query({ token: config.token(), version: config.version() }).timeout(10000).end(function (error, result) {
- if (error) debug('Error sending heartbeat.', error);
+ if (error && !error.response) debug('Network error sending heartbeat.', error);
else if (result.statusCode !== 200) debug('Server responded to heartbeat with %s %s', result.statusCode, result.text);
else debug('Heartbeat sent to %s', url);
});
@@ -466,10 +466,10 @@ function migrate(size, region, callback) {
.query({ token: config.token() })
.send({ size: size, region: region, restoreKey: restoreKey })
.end(function (error, result) {
- if (error) return unlock(error);
- if (result.status === 409) return unlock(new CloudronError(CloudronError.BAD_STATE));
- if (result.status === 404) return unlock(new CloudronError(CloudronError.NOT_FOUND));
- if (result.status !== 202) return unlock(new CloudronError(CloudronError.EXTERNAL_ERROR, util.format('%s %j', result.status, result.body)));
+ if (error && !error.response) return unlock(error);
+ if (result.statusCode === 409) return unlock(new CloudronError(CloudronError.BAD_STATE));
+ if (result.statusCode === 404) return unlock(new CloudronError(CloudronError.NOT_FOUND));
+ if (result.statusCode !== 202) return unlock(new CloudronError(CloudronError.EXTERNAL_ERROR, util.format('%s %j', result.status, result.body)));
return unlock(null);
});
@@ -526,8 +526,8 @@ function doUpgrade(boxUpdateInfo, callback) {
.query({ token: config.token() })
.send({ version: boxUpdateInfo.version })
.end(function (error, result) {
- if (error) return upgradeError(new Error('Error making upgrade request: ' + error));
- if (result.status !== 202) return upgradeError(new Error(util.format('Server not ready to upgrade. statusCode: %s body: %j', result.status, result.body)));
+ if (error && !error.response) return upgradeError(new Error('Network error making upgrade request: ' + error));
+ if (result.statusCode !== 202) return upgradeError(new Error(util.format('Server not ready to upgrade. statusCode: %s body: %j', result.status, result.body)));
progress.set(progress.UPDATE, 10, 'Updating base system');
@@ -555,8 +555,8 @@ function doUpdate(boxUpdateInfo, callback) {
superagent.get(config.apiServerOrigin() + '/api/v1/boxes/' + config.fqdn() + '/sourcetarballurl')
.query({ token: config.token(), boxVersion: boxUpdateInfo.version })
.end(function (error, result) {
- if (error) return updateError(new Error('Error fetching sourceTarballUrl: ' + error));
- if (result.status !== 200) return updateError(new Error('Error fetching sourceTarballUrl status: ' + result.status));
+ if (error && !error.response) return updateError(new Error('Network error fetching sourceTarballUrl: ' + error));
+ if (result.statusCode !== 200) return updateError(new Error('Error fetching sourceTarballUrl status: ' + result.statusCode));
if (!safe.query(result, 'body.url')) return updateError(new Error('Error fetching sourceTarballUrl response: ' + JSON.stringify(result.body)));
// NOTE: the args here are tied to the installer revision, box code and appstore provisioning logic
@@ -591,8 +591,8 @@ function doUpdate(boxUpdateInfo, callback) {
debug('updating box %j', args);
superagent.post(INSTALLER_UPDATE_URL).send(args).end(function (error, result) {
- if (error) return updateError(error);
- if (result.status !== 202) return updateError(new Error('Error initiating update: ' + JSON.stringify(result.body)));
+ if (error && !error.response) return updateError(error);
+ if (result.statusCode !== 202) return updateError(new Error('Error initiating update: ' + JSON.stringify(result.body)));
progress.set(progress.UPDATE, 10, 'Updating cloudron software');
diff --git a/src/developer.js b/src/developer.js
index 3ac0d294e..75ec790e3 100644
--- a/src/developer.js
+++ b/src/developer.js
@@ -38,6 +38,7 @@ function DeveloperError(reason, errorOrMessage) {
}
util.inherits(DeveloperError, Error);
DeveloperError.INTERNAL_ERROR = 'Internal Error';
+DeveloperError.EXTERNAL_ERROR = 'External Error';
function enabled(callback) {
assert.strictEqual(typeof callback, 'function');
@@ -77,8 +78,8 @@ function getNonApprovedApps(callback) {
var url = config.apiServerOrigin() + '/api/v1/boxes/' + config.fqdn() + '/apps';
superagent.get(url).query({ token: config.token(), boxVersion: config.version() }).end(function (error, result) {
- if (error) return callback(new DeveloperError(DeveloperError.INTERNAL_ERROR, error));
- if (result.status !== 200) return callback(new DeveloperError(DeveloperError.INTERNAL_ERROR, util.format('App listing failed. %s %j', result.status, result.body)));
+ if (error && !error.response) return callback(new DeveloperError(DeveloperError.EXTERNAL_ERROR, error));
+ if (result.statusCode !== 200) return callback(new DeveloperError(DeveloperError.EXTERNAL_ERROR, util.format('App listing failed. %s %j', result.status, result.body)));
callback(null, result.body.apps || []);
});
diff --git a/src/dns/caas.js b/src/dns/caas.js
index 00d52f3ce..f9f3a5ef9 100644
--- a/src/dns/caas.js
+++ b/src/dns/caas.js
@@ -40,9 +40,9 @@ function add(dnsConfig, zoneName, subdomain, type, values, callback) {
.query({ token: dnsConfig.token })
.send(data)
.end(function (error, result) {
- if (error) return callback(error);
- if (result.status === 420) return callback(new SubdomainError(SubdomainError.STILL_BUSY));
- if (result.status !== 201) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.status, result.body)));
+ if (error && !error.response) return callback(error);
+ if (result.statusCode === 420) return callback(new SubdomainError(SubdomainError.STILL_BUSY));
+ if (result.statusCode !== 201) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
return callback(null, result.body.changeId);
});
@@ -63,8 +63,8 @@ function get(dnsConfig, zoneName, subdomain, type, callback) {
.get(config.apiServerOrigin() + '/api/v1/domains/' + fqdn)
.query({ token: dnsConfig.token, type: type })
.end(function (error, result) {
- if (error) return callback(error);
- if (result.status !== 200) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.status, result.body)));
+ if (error && !error.response) return callback(error);
+ if (result.statusCode !== 200) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
return callback(null, result.body.values);
});
@@ -107,10 +107,10 @@ function del(dnsConfig, zoneName, subdomain, type, values, callback) {
.query({ token: dnsConfig.token })
.send(data)
.end(function (error, result) {
- if (error) return callback(error);
- if (result.status === 420) return callback(new SubdomainError(SubdomainError.STILL_BUSY));
- if (result.status === 404) return callback(new SubdomainError(SubdomainError.NOT_FOUND));
- if (result.status !== 204) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.status, result.body)));
+ if (error && !error.response) return callback(error);
+ if (result.statusCode === 420) return callback(new SubdomainError(SubdomainError.STILL_BUSY));
+ if (result.statusCode === 404) return callback(new SubdomainError(SubdomainError.NOT_FOUND));
+ if (result.statusCode !== 204) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
return callback(null);
});
@@ -127,8 +127,8 @@ function getChangeStatus(dnsConfig, changeId, callback) {
.get(config.apiServerOrigin() + '/api/v1/domains/' + config.fqdn() + '/status/' + changeId)
.query({ token: dnsConfig.token })
.end(function (error, result) {
- if (error) return callback(error);
- if (result.status !== 200) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.status, result.body)));
+ if (error && !error.response) return callback(error);
+ if (result.statusCode !== 200) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
return callback(null, result.body.status);
});
diff --git a/src/oauthproxy.js b/src/oauthproxy.js
index 4870672ba..9e3d681c0 100644
--- a/src/oauthproxy.js
+++ b/src/oauthproxy.js
@@ -92,7 +92,7 @@ function authenticate(req, res, next) {
.post(config.internalAdminOrigin() + '/api/v1/oauth/token')
.query(query).send(data)
.end(function (error, result) {
- if (error) {
+ if (error && !error.response) {
console.error(error);
return res.send(500, 'Unable to contact the oauth server.');
}
diff --git a/src/routes/cloudron.js b/src/routes/cloudron.js
index 8c40ea298..8e2ccd588 100644
--- a/src/routes/cloudron.js
+++ b/src/routes/cloudron.js
@@ -59,7 +59,7 @@ function activate(req, res, next) {
// Now let the api server know we got activated
superagent.post(config.apiServerOrigin() + '/api/v1/boxes/' + config.fqdn() + '/setup/done').query({ setupToken:req.query.setupToken }).end(function (error, result) {
- if (error) return next(new HttpError(500, error));
+ if (error && !error.response) return next(new HttpError(500, error));
if (result.statusCode === 403) return next(new HttpError(403, 'Invalid token'));
if (result.statusCode === 409) return next(new HttpError(409, 'Already setup'));
if (result.statusCode !== 201) return next(new HttpError(500, result.text ? result.text.message : 'Internal error'));
@@ -75,7 +75,7 @@ function setupTokenAuth(req, res, next) {
if (typeof req.query.setupToken !== 'string') return next(new HttpError(400, 'no setupToken provided'));
superagent.get(config.apiServerOrigin() + '/api/v1/boxes/' + config.fqdn() + '/setup/verify').query({ setupToken:req.query.setupToken }).end(function (error, result) {
- if (error) return next(new HttpError(500, error));
+ if (error && !error.response) return next(new HttpError(500, error));
if (result.statusCode === 403) return next(new HttpError(403, 'Invalid token'));
if (result.statusCode === 409) return next(new HttpError(409, 'Already setup'));
if (result.statusCode !== 200) return next(new HttpError(500, result.text ? result.text.message : 'Internal error'));
diff --git a/src/routes/test/apps-test.js b/src/routes/test/apps-test.js
index fc9c6b65d..1efd7825c 100644
--- a/src/routes/test/apps-test.js
+++ b/src/routes/test/apps-test.js
@@ -27,7 +27,7 @@ var appdb = require('../../appdb.js'),
nock = require('nock'),
paths = require('../../paths.js'),
redis = require('redis'),
- request = require('superagent'),
+ superagent = require('superagent'),
safe = require('safetydance'),
server = require('../../server.js'),
settings = require('../../settings.js'),
@@ -114,11 +114,10 @@ function setup(done) {
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, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(result.statusCode).to.eql(201);
expect(scope1.isDone()).to.be.ok();
@@ -137,11 +136,10 @@ function setup(done) {
},
function (callback) {
- request.post(SERVER_URL + '/api/v1/users')
+ superagent.post(SERVER_URL + '/api/v1/users')
.query({ access_token: token })
.send({ username: USERNAME_1, email: EMAIL_1 })
.end(function (err, res) {
- expect(err).to.not.be.ok();
expect(res.statusCode).to.equal(201);
callback(null);
@@ -198,174 +196,174 @@ describe('App API', function () {
});
it('app install fails - missing manifest', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, password: PASSWORD })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql('manifest is required');
- done(err);
+ done();
});
});
it('app install fails - missing appId', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ manifest: APP_MANIFEST, password: PASSWORD })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql('appStoreId is required');
- done(err);
+ done();
});
});
it('app install fails - invalid json', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send('garbage')
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
- done(err);
+ done();
});
});
it('app install fails - invalid location', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: '!awesome', accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql('Hostname can only contain alphanumerics and hyphen');
- done(err);
+ done();
});
});
it('app install fails - invalid location type', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: 42, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql('location is required');
- done(err);
+ done();
});
});
it('app install fails - reserved admin location', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: constants.ADMIN_LOCATION, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql(constants.ADMIN_LOCATION + ' is reserved');
- done(err);
+ done();
});
});
it('app install fails - reserved api location', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: constants.API_LOCATION, accessRestriction: null, oauthProxy: true })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql(constants.API_LOCATION + ' is reserved');
- done(err);
+ done();
});
});
it('app install fails - portBindings must be object', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION, portBindings: 23, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql('portBindings must be an object');
- done(err);
+ done();
});
});
it('app install fails - accessRestriction is required', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION, portBindings: {}, oauthProxy: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql('accessRestriction is required');
- done(err);
+ done();
});
});
it('app install fails - accessRestriction type is wrong', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION, portBindings: {}, accessRestriction: '', oauthProxy: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql('accessRestriction is required');
- done(err);
+ done();
});
});
it('app install fails - accessRestriction no users not allowed', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST_1, password: PASSWORD, location: APP_LOCATION, portBindings: {}, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql('accessRestriction must specify one user');
- done(err);
+ done();
});
});
it('app install fails - accessRestriction too many users not allowed', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST_1, password: PASSWORD, location: APP_LOCATION, portBindings: {}, accessRestriction: { users: [ 'one', 'two' ] }, oauthProxy: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql('accessRestriction must specify one user');
- done(err);
+ done();
});
});
it('app install fails - oauthProxy is required', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION, portBindings: {}, accessRestriction: null })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(res.body.message).to.eql('oauthProxy must be a boolean');
- done(err);
+ done();
});
});
it('app install fails for non admin', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token_1 })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION, portBindings: null, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
- done(err);
+ done();
});
});
it('app install fails due to purchase failure', function (done) {
var fake = nock(config.apiServerOrigin()).post('/api/v1/apps/test/purchase?token=APPSTORE_TOKEN').reply(402, {});
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION, portBindings: null, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(402);
expect(fake.isDone()).to.be.ok();
- done(err);
+ done();
});
});
it('app install succeeds with purchase', function (done) {
var fake = nock(config.apiServerOrigin()).post('/api/v1/apps/test/purchase?token=APPSTORE_TOKEN').reply(201, {});
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION, portBindings: null, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
@@ -373,14 +371,14 @@ describe('App API', function () {
expect(res.body.id).to.be.a('string');
APP_ID = res.body.id;
expect(fake.isDone()).to.be.ok();
- done(err);
+ done();
});
});
it('app install fails because of conflicting location', function (done) {
var fake = nock(config.apiServerOrigin()).post('/api/v1/apps/test/purchase?token=APPSTORE_TOKEN').reply(201, {});
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION, portBindings: null, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
@@ -391,120 +389,120 @@ describe('App API', function () {
});
it('can get app status', function (done) {
- request.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
+ superagent.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body.id).to.eql(APP_ID);
expect(res.body.installationState).to.be.ok();
- done(err);
+ done();
});
});
it('cannot get invalid app status', function (done) {
- request.get(SERVER_URL + '/api/v1/apps/kubachi')
+ superagent.get(SERVER_URL + '/api/v1/apps/kubachi')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(404);
- done(err);
+ done();
});
});
it('can get all apps', function (done) {
- request.get(SERVER_URL + '/api/v1/apps')
+ superagent.get(SERVER_URL + '/api/v1/apps')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body.apps).to.be.an('array');
expect(res.body.apps[0].id).to.eql(APP_ID);
expect(res.body.apps[0].installationState).to.be.ok();
- done(err);
+ done();
});
});
it('non admin can get all apps', function (done) {
- request.get(SERVER_URL + '/api/v1/apps')
+ superagent.get(SERVER_URL + '/api/v1/apps')
.query({ access_token: token_1 })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body.apps).to.be.an('array');
expect(res.body.apps[0].id).to.eql(APP_ID);
expect(res.body.apps[0].installationState).to.be.ok();
- done(err);
+ done();
});
});
it('can get appBySubdomain', function (done) {
- request.get(SERVER_URL + '/api/v1/subdomains/' + APP_LOCATION)
+ superagent.get(SERVER_URL + '/api/v1/subdomains/' + APP_LOCATION)
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body.id).to.eql(APP_ID);
expect(res.body.installationState).to.be.ok();
- done(err);
+ done();
});
});
it('cannot get invalid app by Subdomain', function (done) {
- request.get(SERVER_URL + '/api/v1/subdomains/tikaloma')
+ superagent.get(SERVER_URL + '/api/v1/subdomains/tikaloma')
.end(function (err, res) {
expect(res.statusCode).to.equal(404);
- done(err);
+ done();
});
});
it('cannot uninstall invalid app', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/whatever/uninstall')
+ superagent.post(SERVER_URL + '/api/v1/apps/whatever/uninstall')
.send({ password: PASSWORD })
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(404);
- done(err);
+ done();
});
});
it('cannot uninstall app without password', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
- done(err);
+ done();
});
});
it('cannot uninstall app with wrong password', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
.send({ password: PASSWORD+PASSWORD })
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
- done(err);
+ done();
});
});
it('non admin cannot uninstall app', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
.send({ password: PASSWORD })
.query({ access_token: token_1 })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
- done(err);
+ done();
});
});
it('can uninstall app', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
.send({ password: PASSWORD })
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(202);
- done(err);
+ done();
});
});
it('app install succeeds already purchased', function (done) {
var fake = nock(config.apiServerOrigin()).post('/api/v1/apps/test/purchase?token=APPSTORE_TOKEN').reply(200, {});
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION_2, portBindings: null, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
@@ -512,7 +510,7 @@ describe('App API', function () {
expect(res.body.id).to.be.a('string');
APP_ID = res.body.id;
expect(fake.isDone()).to.be.ok();
- done(err);
+ done();
});
});
@@ -522,7 +520,7 @@ describe('App API', function () {
settings.setDeveloperMode(true, function (error) {
expect(error).to.be(null);
- request.post(SERVER_URL + '/api/v1/developer/login')
+ superagent.post(SERVER_URL + '/api/v1/developer/login')
.send({ username: USERNAME, password: PASSWORD })
.end(function (error, result) {
expect(error).to.not.be.ok();
@@ -533,7 +531,7 @@ describe('App API', function () {
// overwrite non dev token
token = result.body.token;
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, location: APP_LOCATION+APP_LOCATION, portBindings: null, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
@@ -541,18 +539,18 @@ describe('App API', function () {
expect(res.body.id).to.be.a('string');
expect(fake.isDone()).to.be.ok();
APP_ID = res.body.id;
- done(err);
+ done();
});
});
});
});
it('can uninstall app without password but developer token', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(202);
- done(err);
+ done();
});
});
});
@@ -629,7 +627,7 @@ describe('App installation', function () {
var count = 0;
function checkInstallStatus() {
- request.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
+ superagent.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
@@ -640,7 +638,7 @@ describe('App installation', function () {
});
}
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appId: APP_ID, appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION, portBindings: null, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
@@ -706,7 +704,7 @@ describe('App installation', function () {
it('installation - is up and running', function (done) {
expect(appResult.httpPort).to.be(undefined);
setTimeout(function () {
- request.get('http://localhost:' + appEntry.httpPort + appResult.manifest.healthCheckPath)
+ superagent.get('http://localhost:' + appEntry.httpPort + appResult.manifest.healthCheckPath)
.end(function (err, res) {
expect(!err).to.be.ok();
expect(res.statusCode).to.equal(200);
@@ -843,7 +841,7 @@ describe('App installation', function () {
});
xit('logs - stdout and stderr', function (done) {
- request.get(SERVER_URL + '/api/v1/apps/' + APP_ID + '/logs')
+ superagent.get(SERVER_URL + '/api/v1/apps/' + APP_ID + '/logs')
.query({ access_token: token })
.end(function (err, res) {
var data = '';
@@ -857,7 +855,7 @@ describe('App installation', function () {
});
xit('logStream - requires event-stream accept header', function (done) {
- request.get(SERVER_URL + '/api/v1/apps/' + APP_ID + '/logstream')
+ superagent.get(SERVER_URL + '/api/v1/apps/' + APP_ID + '/logstream')
.query({ access_token: token, fromLine: 0 })
.end(function (err, res) {
expect(res.statusCode).to.be(400);
@@ -896,7 +894,7 @@ describe('App installation', function () {
});
it('non admin cannot stop app', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/stop')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/stop')
.query({ access_token: token_1 })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
@@ -905,7 +903,7 @@ describe('App installation', function () {
});
it('can stop app', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/stop')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/stop')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(202);
@@ -916,7 +914,7 @@ describe('App installation', function () {
it('did stop the app', function (done) {
// give the app a couple of seconds to die
setTimeout(function () {
- request.get('http://localhost:' + appEntry.httpPort + appResult.manifest.healthCheckPath)
+ superagent.get('http://localhost:' + appEntry.httpPort + appResult.manifest.healthCheckPath)
.end(function (err, res) {
expect(err).to.be.ok();
done();
@@ -925,7 +923,7 @@ describe('App installation', function () {
});
it('nonadmin cannot start app', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/start')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/start')
.query({ access_token: token_1 })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
@@ -934,7 +932,7 @@ describe('App installation', function () {
});
it('can start app', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/start')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/start')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(202);
@@ -944,7 +942,7 @@ describe('App installation', function () {
it('did start the app', function (done) {
setTimeout(function () {
- request.get('http://localhost:' + appEntry.httpPort + appResult.manifest.healthCheckPath)
+ superagent.get('http://localhost:' + appEntry.httpPort + appResult.manifest.healthCheckPath)
.end(function (err, res) {
expect(!err).to.be.ok();
expect(res.statusCode).to.equal(200);
@@ -956,7 +954,7 @@ describe('App installation', function () {
it('can uninstall app', function (done) {
var count = 0;
function checkUninstallStatus() {
- request.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
+ superagent.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
.query({ access_token: token })
.end(function (err, res) {
if (res.statusCode === 404) return done(null);
@@ -965,7 +963,7 @@ describe('App installation', function () {
});
}
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
.send({ password: PASSWORD })
.query({ access_token: token })
.end(function (err, res) {
@@ -1099,7 +1097,7 @@ describe('App installation - port bindings', function () {
var count = 0;
function checkInstallStatus() {
- request.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
+ superagent.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
@@ -1110,7 +1108,7 @@ describe('App installation - port bindings', function () {
});
}
- request.post(SERVER_URL + '/api/v1/apps/install')
+ superagent.post(SERVER_URL + '/api/v1/apps/install')
.query({ access_token: token })
.send({ appId: APP_ID, appStoreId: APP_STORE_ID, manifest: APP_MANIFEST, password: PASSWORD, location: APP_LOCATION, portBindings: { ECHO_SERVER_PORT: 7171 }, accessRestriction: null, oauthProxy: false })
.end(function (err, res) {
@@ -1166,7 +1164,7 @@ describe('App installation - port bindings', function () {
var tryCount = 20;
expect(appResult.httpPort).to.be(undefined);
(function healthCheck() {
- request.get('http://localhost:' + appEntry.httpPort + appResult.manifest.healthCheckPath)
+ superagent.get('http://localhost:' + appEntry.httpPort + appResult.manifest.healthCheckPath)
.end(function (err, res) {
if (err || res.statusCode !== 200) {
if (--tryCount === 0) return done(new Error('Timedout'));
@@ -1256,7 +1254,7 @@ describe('App installation - port bindings', function () {
assert.strictEqual(typeof count, 'number');
assert.strictEqual(typeof done, 'function');
- request.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
+ superagent.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
@@ -1268,7 +1266,7 @@ describe('App installation - port bindings', function () {
}
it('cannot reconfigure app with missing location', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
.query({ access_token: token })
.send({ appId: APP_ID, password: PASSWORD, portBindings: { ECHO_SERVER_PORT: 7172 }, accessRestriction: null, oauthProxy: true })
.end(function (err, res) {
@@ -1278,7 +1276,7 @@ describe('App installation - port bindings', function () {
});
it('cannot reconfigure app with missing accessRestriction', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
.query({ access_token: token })
.send({ appId: APP_ID, password: PASSWORD, location: APP_LOCATION_NEW, portBindings: { ECHO_SERVER_PORT: 7172 }, oauthProxy: false })
.end(function (err, res) {
@@ -1288,7 +1286,7 @@ describe('App installation - port bindings', function () {
});
it('cannot reconfigure app with missing oauthProxy', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
.query({ access_token: token })
.send({ appId: APP_ID, password: PASSWORD, location: APP_LOCATION_NEW, portBindings: { ECHO_SERVER_PORT: 7172 }, accessRestriction: null })
.end(function (err, res) {
@@ -1298,7 +1296,7 @@ describe('App installation - port bindings', function () {
});
it('cannot reconfigure app with only the cert, no key', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
.query({ access_token: token })
.send({ appId: APP_ID, password: PASSWORD, location: APP_LOCATION_NEW, portBindings: { ECHO_SERVER_PORT: 7172 }, accessRestriction: null, oauthProxy: true, cert: validCert1 })
.end(function (err, res) {
@@ -1308,7 +1306,7 @@ describe('App installation - port bindings', function () {
});
it('cannot reconfigure app with only the key, no cert', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
.query({ access_token: token })
.send({ appId: APP_ID, password: PASSWORD, location: APP_LOCATION_NEW, portBindings: { ECHO_SERVER_PORT: 7172 }, accessRestriction: null, oauthProxy: true, key: validKey1 })
.end(function (err, res) {
@@ -1318,7 +1316,7 @@ describe('App installation - port bindings', function () {
});
it('cannot reconfigure app with cert not bein a string', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
.query({ access_token: token })
.send({ appId: APP_ID, password: PASSWORD, location: APP_LOCATION_NEW, portBindings: { ECHO_SERVER_PORT: 7172 }, accessRestriction: null, oauthProxy: true, cert: 1234, key: validKey1 })
.end(function (err, res) {
@@ -1328,7 +1326,7 @@ describe('App installation - port bindings', function () {
});
it('cannot reconfigure app with key not bein a string', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
.query({ access_token: token })
.send({ appId: APP_ID, password: PASSWORD, location: APP_LOCATION_NEW, portBindings: { ECHO_SERVER_PORT: 7172 }, accessRestriction: null, oauthProxy: true, cert: validCert1, key: 1234 })
.end(function (err, res) {
@@ -1338,7 +1336,7 @@ describe('App installation - port bindings', function () {
});
it('non admin cannot reconfigure app', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
.query({ access_token: token_1 })
.send({ appId: APP_ID, password: PASSWORD, location: APP_LOCATION_NEW, portBindings: { ECHO_SERVER_PORT: 7172 }, accessRestriction: null, oauthProxy: true })
.end(function (err, res) {
@@ -1348,7 +1346,7 @@ describe('App installation - port bindings', function () {
});
it('can reconfigure app', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
.query({ access_token: token })
.send({ appId: APP_ID, password: PASSWORD, location: APP_LOCATION_NEW, portBindings: { ECHO_SERVER_PORT: 7172 }, accessRestriction: null, oauthProxy: true })
.end(function (err, res) {
@@ -1432,7 +1430,7 @@ describe('App installation - port bindings', function () {
});
it('can reconfigure app with custom certificate', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/configure')
.query({ access_token: token })
.send({ appId: APP_ID, password: PASSWORD, location: APP_LOCATION_NEW, portBindings: { ECHO_SERVER_PORT: 7172 }, accessRestriction: null, oauthProxy: true, cert: validCert1, key: validKey1 })
.end(function (err, res) {
@@ -1442,7 +1440,7 @@ describe('App installation - port bindings', function () {
});
it('can stop app', function (done) {
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/stop')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/stop')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(202);
@@ -1467,7 +1465,7 @@ describe('App installation - port bindings', function () {
it('can uninstall app', function (done) {
var count = 0;
function checkUninstallStatus() {
- request.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
+ superagent.get(SERVER_URL + '/api/v1/apps/' + APP_ID)
.query({ access_token: token })
.end(function (err, res) {
if (res.statusCode === 404) return done(null);
@@ -1476,7 +1474,7 @@ describe('App installation - port bindings', function () {
});
}
- request.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
+ superagent.post(SERVER_URL + '/api/v1/apps/' + APP_ID + '/uninstall')
.send({ password: PASSWORD })
.query({ access_token: token })
.end(function (err, res) {
diff --git a/src/routes/test/backups-test.js b/src/routes/test/backups-test.js
index 08981ed49..074bc61f0 100644
--- a/src/routes/test/backups-test.js
+++ b/src/routes/test/backups-test.js
@@ -11,7 +11,7 @@ var appdb = require('../../appdb.js'),
config = require('../../config.js'),
database = require('../../database.js'),
expect = require('expect.js'),
- request = require('superagent'),
+ superagent = require('superagent'),
server = require('../../server.js'),
settings = require('../../settings.js'),
nock = require('nock'),
@@ -33,11 +33,10 @@ function setup(done) {
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, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(result.statusCode).to.eql(201);
expect(scope1.isDone()).to.be.ok();
@@ -74,22 +73,22 @@ describe('Backups API', function () {
after(cleanup);
describe('get', function () {
- it('cannot get backups with appstore request failing', function (done) {
+ it('cannot get backups with appstore superagent failing', function (done) {
var req = nock(config.apiServerOrigin()).get('/api/v1/boxes/' + config.fqdn() + '/backups?token=BACKUP_TOKEN').reply(401, {});
- request.get(SERVER_URL + '/api/v1/backups')
+ superagent.get(SERVER_URL + '/api/v1/backups')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(503);
expect(req.isDone()).to.be.ok();
- done(err);
+ done();
});
});
it('can get backups', function (done) {
var req = nock(config.apiServerOrigin()).get('/api/v1/boxes/' + config.fqdn() + '/backups?token=BACKUP_TOKEN').reply(200, { backups: ['foo', 'bar']});
- request.get(SERVER_URL + '/api/v1/backups')
+ superagent.get(SERVER_URL + '/api/v1/backups')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
@@ -97,26 +96,24 @@ describe('Backups API', function () {
expect(res.body.backups).to.be.an(Array);
expect(res.body.backups[0]).to.eql('foo');
expect(res.body.backups[1]).to.eql('bar');
- done(err);
+ done();
});
});
});
describe('create', function () {
it('fails due to mising token', function (done) {
- request.post(SERVER_URL + '/api/v1/backups')
+ superagent.post(SERVER_URL + '/api/v1/backups')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('fails due to wrong token', function (done) {
- request.post(SERVER_URL + '/api/v1/backups')
+ superagent.post(SERVER_URL + '/api/v1/backups')
.query({ access_token: token.toUpperCase() })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -127,10 +124,9 @@ describe('Backups API', function () {
.post('/api/v1/boxes/' + config.fqdn() + '/awscredentials?token=BACKUP_TOKEN')
.reply(201, { credentials: { AccessKeyId: 'accessKeyId', SecretAccessKey: 'secretAccessKey', SessionToken: 'sessionToken' } });
- request.post(SERVER_URL + '/api/v1/backups')
+ superagent.post(SERVER_URL + '/api/v1/backups')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(202);
function checkAppstoreServerCalled() {
diff --git a/src/routes/test/clients-test.js b/src/routes/test/clients-test.js
index 7a59182dd..3defb2bc4 100644
--- a/src/routes/test/clients-test.js
+++ b/src/routes/test/clients-test.js
@@ -46,7 +46,6 @@ describe('OAuth Clients API', function () {
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(result.statusCode).to.equal(201);
expect(scope1.isDone()).to.be.ok();
@@ -73,7 +72,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ appId: 'someApp', redirectURI: 'http://foobar.com', scope: 'profile' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(412);
done();
});
@@ -89,7 +87,6 @@ describe('OAuth Clients API', function () {
superagent.post(SERVER_URL + '/api/v1/oauth/clients')
.send({ appId: 'someApp', redirectURI: 'http://foobar.com', scope: 'profile' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -100,7 +97,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ redirectURI: 'http://foobar.com', scope: 'profile' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -111,7 +107,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ appId: '', redirectURI: 'http://foobar.com', scope: 'profile' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -122,7 +117,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ appId: 'someApp', redirectURI: 'http://foobar.com' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -133,7 +127,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ appId: 'someApp', redirectURI: 'http://foobar.com', scope: '' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -144,7 +137,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ appId: 'someApp', scope: 'profile' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -155,7 +147,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ appId: 'someApp', redirectURI: '', scope: 'profile' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -166,7 +157,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ appId: 'someApp', redirectURI: 'foobar', scope: 'profile' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -177,7 +167,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ appId: 'someApp', redirectURI: 'http://foobar.com', scope: 'profile' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(201);
expect(result.body.id).to.be.a('string');
expect(result.body.appId).to.be.a('string');
@@ -211,7 +200,6 @@ describe('OAuth Clients API', function () {
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
@@ -230,7 +218,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ appId: CLIENT_0.appId, redirectURI: CLIENT_0.redirectURI, scope: CLIENT_0.scope })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(201);
CLIENT_0 = result.body;
@@ -252,7 +239,6 @@ describe('OAuth Clients API', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients/' + CLIENT_0.id)
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(412);
done();
});
@@ -267,7 +253,6 @@ describe('OAuth Clients API', function () {
it('fails without token', function (done) {
superagent.get(SERVER_URL + '/api/v1/oauth/clients/' + CLIENT_0.id)
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -278,7 +263,6 @@ describe('OAuth Clients API', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients/' + CLIENT_0.id.toUpperCase())
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(404);
done();
});
@@ -288,7 +272,6 @@ describe('OAuth Clients API', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients/' + CLIENT_0.id)
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
expect(result.body).to.eql(CLIENT_0);
done();
@@ -318,7 +301,6 @@ describe('OAuth Clients API', function () {
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
@@ -337,7 +319,6 @@ describe('OAuth Clients API', function () {
.query({ access_token: token })
.send({ appId: CLIENT_0.appId, redirectURI: CLIENT_0.redirectURI, scope: CLIENT_0.scope })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(201);
CLIENT_0 = result.body;
@@ -359,7 +340,6 @@ describe('OAuth Clients API', function () {
superagent.del(SERVER_URL + '/api/v1/oauth/clients/' + CLIENT_0.id)
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(412);
done();
});
@@ -374,7 +354,6 @@ describe('OAuth Clients API', function () {
it('fails without token', function (done) {
superagent.del(SERVER_URL + '/api/v1/oauth/clients/' + CLIENT_0.id)
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -385,7 +364,6 @@ describe('OAuth Clients API', function () {
superagent.del(SERVER_URL + '/api/v1/oauth/clients/' + CLIENT_0.id.toUpperCase())
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(404);
done();
});
@@ -395,13 +373,11 @@ describe('OAuth Clients API', function () {
superagent.del(SERVER_URL + '/api/v1/oauth/clients/' + CLIENT_0.id)
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(204);
superagent.get(SERVER_URL + '/api/v1/oauth/clients/' + CLIENT_0.id)
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(404);
done();
@@ -443,7 +419,6 @@ describe('Clients', function () {
.query({ setupToken: 'somesetuptoken' })
.send({ username: USER_0.username, password: USER_0.password, email: USER_0.email })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(result.statusCode).to.eql(201);
expect(scope1.isDone()).to.be.ok();
@@ -473,7 +448,6 @@ describe('Clients', function () {
it('fails due to missing token', function (done) {
superagent.get(SERVER_URL + '/api/v1/oauth/clients')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -483,7 +457,6 @@ describe('Clients', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients')
.query({ access_token: '' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -493,7 +466,6 @@ describe('Clients', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients')
.query({ access_token: token.toUpperCase() })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -503,7 +475,6 @@ describe('Clients', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
expect(result.body.clients.length).to.eql(1);
@@ -521,7 +492,6 @@ describe('Clients', function () {
it('fails due to missing token', function (done) {
superagent.get(SERVER_URL + '/api/v1/oauth/clients/cid-webadmin/tokens')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -531,7 +501,6 @@ describe('Clients', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients/cid-webadmin/tokens')
.query({ access_token: '' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -541,7 +510,6 @@ describe('Clients', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients/cid-webadmin/tokens')
.query({ access_token: token.toUpperCase() })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -551,7 +519,6 @@ describe('Clients', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients/CID-WEBADMIN/tokens')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(404);
done();
});
@@ -561,7 +528,6 @@ describe('Clients', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients/cid-webadmin/tokens')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
expect(result.body.tokens.length).to.eql(1);
@@ -579,7 +545,6 @@ describe('Clients', function () {
it('fails due to missing token', function (done) {
superagent.del(SERVER_URL + '/api/v1/oauth/clients/cid-webadmin/tokens')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -589,7 +554,6 @@ describe('Clients', function () {
superagent.del(SERVER_URL + '/api/v1/oauth/clients/cid-webadmin/tokens')
.query({ access_token: '' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -599,7 +563,6 @@ describe('Clients', function () {
superagent.del(SERVER_URL + '/api/v1/oauth/clients/cid-webadmin/tokens')
.query({ access_token: token.toUpperCase() })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -609,7 +572,6 @@ describe('Clients', function () {
superagent.del(SERVER_URL + '/api/v1/oauth/clients/CID-WEBADMIN/tokens')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(404);
done();
});
@@ -619,7 +581,6 @@ describe('Clients', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/clients/cid-webadmin/tokens')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
expect(result.body.tokens.length).to.eql(1);
@@ -628,14 +589,12 @@ describe('Clients', function () {
superagent.del(SERVER_URL + '/api/v1/oauth/clients/cid-webadmin/tokens')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(204);
// further calls with this token should not work
superagent.get(SERVER_URL + '/api/v1/profile')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
diff --git a/src/routes/test/cloudron-test.js b/src/routes/test/cloudron-test.js
index b78ef40fc..190c6b5f0 100644
--- a/src/routes/test/cloudron-test.js
+++ b/src/routes/test/cloudron-test.js
@@ -11,7 +11,7 @@ var async = require('async'),
database = require('../../database.js'),
expect = require('expect.js'),
nock = require('nock'),
- request = require('superagent'),
+ superagent = require('superagent'),
server = require('../../server.js'),
shell = require('../../shell.js');
@@ -54,10 +54,9 @@ describe('Cloudron', function () {
after(cleanup);
it('fails due to missing setupToken', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.send({ username: '', password: 'somepassword', email: 'admin@foo.bar' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -66,11 +65,10 @@ describe('Cloudron', function () {
it('fails due to empty username', function (done) {
var scope = nock(config.apiServerOrigin()).get('/api/v1/boxes/' + config.fqdn() + '/setup/verify?setupToken=somesetuptoken').reply(200, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: '', password: 'somepassword', email: 'admin@foo.bar' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
expect(scope.isDone()).to.be.ok();
done();
@@ -80,11 +78,10 @@ describe('Cloudron', function () {
it('fails due to empty password', function (done) {
var scope = nock(config.apiServerOrigin()).get('/api/v1/boxes/' + config.fqdn() + '/setup/verify?setupToken=somesetuptoken').reply(200, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: 'someuser', password: '', email: 'admin@foo.bar' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
expect(scope.isDone()).to.be.ok();
done();
@@ -94,11 +91,10 @@ describe('Cloudron', function () {
it('fails due to empty email', function (done) {
var scope = nock(config.apiServerOrigin()).get('/api/v1/boxes/' + config.fqdn() + '/setup/verify?setupToken=somesetuptoken').reply(200, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: 'someuser', password: 'somepassword', email: '' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
expect(scope.isDone()).to.be.ok();
done();
@@ -108,11 +104,10 @@ describe('Cloudron', function () {
it('fails due to empty name', function (done) {
var scope = nock(config.apiServerOrigin()).get('/api/v1/boxes/' + config.fqdn() + '/setup/verify?setupToken=somesetuptoken').reply(200, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: 'someuser', password: '', email: 'admin@foo.bar', name: '' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
expect(scope.isDone()).to.be.ok();
done();
@@ -122,11 +117,10 @@ describe('Cloudron', function () {
it('fails due to invalid email', function (done) {
var scope = nock(config.apiServerOrigin()).get('/api/v1/boxes/' + config.fqdn() + '/setup/verify?setupToken=somesetuptoken').reply(200, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: 'someuser', password: 'somepassword', email: 'invalidemail' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
expect(scope.isDone()).to.be.ok();
done();
@@ -137,11 +131,10 @@ describe('Cloudron', function () {
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, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: 'someuser', password: 'somepassword', email: 'admin@foo.bar', name: 'tester' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(201);
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
@@ -152,11 +145,10 @@ describe('Cloudron', function () {
it('fails the second time', function (done) {
var scope = nock(config.apiServerOrigin()).get('/api/v1/boxes/' + config.fqdn() + '/setup/verify?setupToken=somesetuptoken').reply(200, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: 'someuser', password: 'somepassword', email: 'admin@foo.bar' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(409);
expect(scope.isDone()).to.be.ok();
done();
@@ -175,11 +167,10 @@ describe('Cloudron', function () {
config._reset();
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
@@ -196,19 +187,17 @@ describe('Cloudron', function () {
after(cleanup);
it('cannot get without token', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/config')
+ superagent.get(SERVER_URL + '/api/v1/cloudron/config')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('succeeds without appstore', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/config')
+ superagent.get(SERVER_URL + '/api/v1/cloudron/config')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
expect(result.body.apiServerOrigin).to.eql('http://localhost:6060');
expect(result.body.webServerOrigin).to.eql(null);
@@ -230,10 +219,9 @@ describe('Cloudron', function () {
it('succeeds', function (done) {
var scope = nock(config.apiServerOrigin()).get('/api/v1/boxes/localhost?token=' + config.token()).reply(200, { box: { region: 'sfo', size: '1gb' }});
- request.get(SERVER_URL + '/api/v1/cloudron/config')
+ superagent.get(SERVER_URL + '/api/v1/cloudron/config')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
expect(result.body.apiServerOrigin).to.eql('http://localhost:6060');
expect(result.body.webServerOrigin).to.eql(null);
@@ -267,11 +255,10 @@ describe('Cloudron', function () {
config._reset();
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
@@ -284,11 +271,10 @@ describe('Cloudron', function () {
},
function setupBackupConfig(callback) {
- request.post(SERVER_URL + '/api/v1/settings/backup_config')
+ superagent.post(SERVER_URL + '/api/v1/settings/backup_config')
.send({ provider: 'caas', token: 'BACKUP_TOKEN', bucket: 'Bucket', prefix: 'Prefix' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
callback();
@@ -301,65 +287,59 @@ describe('Cloudron', function () {
after(cleanup);
it('fails without token', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/migrate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/migrate')
.send({ size: 'small', region: 'sfo'})
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('fails without password', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/migrate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/migrate')
.send({ size: 'small', region: 'sfo'})
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails with missing size', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/migrate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/migrate')
.send({ region: 'sfo', password: PASSWORD })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails with wrong size type', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/migrate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/migrate')
.send({ size: 4, region: 'sfo', password: PASSWORD })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails with missing region', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/migrate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/migrate')
.send({ size: 'small', password: PASSWORD })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails with wrong region type', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/migrate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/migrate')
.send({ size: 'small', region: 4, password: PASSWORD })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -383,11 +363,10 @@ describe('Cloudron', function () {
injectShellMock();
- request.post(SERVER_URL + '/api/v1/cloudron/migrate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/migrate')
.send({ size: 'small', region: 'sfo', password: PASSWORD })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(202);
function checkAppstoreServerCalled() {
@@ -420,11 +399,10 @@ describe('Cloudron', function () {
injectShellMock();
- request.post(SERVER_URL + '/api/v1/cloudron/migrate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/migrate')
.send({ size: 'small', region: 'sfo', password: PASSWORD })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(202);
function checkAppstoreServerCalled() {
@@ -452,11 +430,10 @@ describe('Cloudron', function () {
config._reset();
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
@@ -473,125 +450,112 @@ describe('Cloudron', function () {
after(cleanup);
it('fails without token', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ type: 'ticket', subject: 'some subject', description: 'some description' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('fails without type', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ subject: 'some subject', description: 'some description' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails with empty type', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ type: '', subject: 'some subject', description: 'some description' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails with unknown type', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ type: 'foobar', subject: 'some subject', description: 'some description' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('succeeds with ticket type', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ type: 'ticket', subject: 'some subject', description: 'some description' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(201);
done();
});
});
it('succeeds with app type', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ type: 'app', subject: 'some subject', description: 'some description' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(201);
done();
});
});
it('fails without description', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ type: 'ticket', subject: 'some subject' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails with empty subject', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ type: 'ticket', subject: '', description: 'some description' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails with empty description', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ type: 'ticket', subject: 'some subject', description: '' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('succeeds with feedback type', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ type: 'feedback', subject: 'some subject', description: 'some description' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(201);
done();
});
});
it('fails without subject', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/feedback')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/feedback')
.send({ type: 'ticket', description: 'some description' })
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
});
});
-
-
diff --git a/src/routes/test/developer-test.js b/src/routes/test/developer-test.js
index bab7eebfe..f230555c7 100644
--- a/src/routes/test/developer-test.js
+++ b/src/routes/test/developer-test.js
@@ -11,7 +11,7 @@ var async = require('async'),
database = require('../../database.js'),
expect = require('expect.js'),
nock = require('nock'),
- request = require('superagent'),
+ superagent = require('superagent'),
server = require('../../server.js'),
settings = require('../../settings.js');
@@ -43,11 +43,10 @@ describe('Developer API', function () {
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, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
@@ -67,9 +66,8 @@ describe('Developer API', function () {
settings.setDeveloperMode(true, function (error) {
expect(error).to.be(null);
- request.get(SERVER_URL + '/api/v1/developer')
+ superagent.get(SERVER_URL + '/api/v1/developer')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -80,10 +78,9 @@ describe('Developer API', function () {
settings.setDeveloperMode(true, function (error) {
expect(error).to.be(null);
- request.get(SERVER_URL + '/api/v1/developer')
+ superagent.get(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
done();
});
@@ -94,10 +91,9 @@ describe('Developer API', function () {
settings.setDeveloperMode(false, function (error) {
expect(error).to.be(null);
- request.get(SERVER_URL + '/api/v1/developer')
+ superagent.get(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(412);
done();
});
@@ -114,11 +110,10 @@ describe('Developer API', function () {
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, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
@@ -135,82 +130,74 @@ describe('Developer API', function () {
after(cleanup);
it('fails without token', function (done) {
- request.post(SERVER_URL + '/api/v1/developer')
+ superagent.post(SERVER_URL + '/api/v1/developer')
.send({ enabled: true })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('fails due to missing password', function (done) {
- request.post(SERVER_URL + '/api/v1/developer')
+ superagent.post(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.send({ enabled: true })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails due to empty password', function (done) {
- request.post(SERVER_URL + '/api/v1/developer')
+ superagent.post(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.send({ password: '', enabled: true })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(403);
done();
});
});
it('fails due to wrong password', function (done) {
- request.post(SERVER_URL + '/api/v1/developer')
+ superagent.post(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.send({ password: PASSWORD.toUpperCase(), enabled: true })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(403);
done();
});
});
it('fails due to missing enabled property', function (done) {
- request.post(SERVER_URL + '/api/v1/developer')
+ superagent.post(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.send({ password: PASSWORD })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails due to wrong enabled property type', function (done) {
- request.post(SERVER_URL + '/api/v1/developer')
+ superagent.post(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.send({ password: PASSWORD, enabled: 'true' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('succeeds enabling', function (done) {
- request.post(SERVER_URL + '/api/v1/developer')
+ superagent.post(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.send({ password: PASSWORD, enabled: true })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
- request.get(SERVER_URL + '/api/v1/developer')
+ superagent.get(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
done();
});
@@ -218,17 +205,15 @@ describe('Developer API', function () {
});
it('succeeds disabling', function (done) {
- request.post(SERVER_URL + '/api/v1/developer')
+ superagent.post(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.send({ password: PASSWORD, enabled: false })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
- request.get(SERVER_URL + '/api/v1/developer')
+ superagent.get(SERVER_URL + '/api/v1/developer')
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(412);
done();
});
@@ -247,11 +232,10 @@ describe('Developer API', function () {
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, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
@@ -268,79 +252,71 @@ describe('Developer API', function () {
after(cleanup);
it('fails without body', function (done) {
- request.post(SERVER_URL + '/api/v1/developer/login')
+ superagent.post(SERVER_URL + '/api/v1/developer/login')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('fails without username', function (done) {
- request.post(SERVER_URL + '/api/v1/developer/login')
+ superagent.post(SERVER_URL + '/api/v1/developer/login')
.send({ password: PASSWORD })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('fails without password', function (done) {
- request.post(SERVER_URL + '/api/v1/developer/login')
+ superagent.post(SERVER_URL + '/api/v1/developer/login')
.send({ username: USERNAME })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('fails with empty username', function (done) {
- request.post(SERVER_URL + '/api/v1/developer/login')
+ superagent.post(SERVER_URL + '/api/v1/developer/login')
.send({ username: '', password: PASSWORD })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('fails with empty password', function (done) {
- request.post(SERVER_URL + '/api/v1/developer/login')
+ superagent.post(SERVER_URL + '/api/v1/developer/login')
.send({ username: USERNAME, password: '' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('fails with unknown username', function (done) {
- request.post(SERVER_URL + '/api/v1/developer/login')
+ superagent.post(SERVER_URL + '/api/v1/developer/login')
.send({ username: USERNAME.toUpperCase(), password: PASSWORD })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('fails with wrong password', function (done) {
- request.post(SERVER_URL + '/api/v1/developer/login')
+ superagent.post(SERVER_URL + '/api/v1/developer/login')
.send({ username: USERNAME, password: PASSWORD.toUpperCase() })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('with username succeeds', function (done) {
- request.post(SERVER_URL + '/api/v1/developer/login')
+ superagent.post(SERVER_URL + '/api/v1/developer/login')
.send({ username: USERNAME, password: PASSWORD })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
expect(result.body.expiresAt).to.be.a('number');
expect(result.body.token).to.be.a('string');
@@ -349,10 +325,9 @@ describe('Developer API', function () {
});
it('with email succeeds', function (done) {
- request.post(SERVER_URL + '/api/v1/developer/login')
+ superagent.post(SERVER_URL + '/api/v1/developer/login')
.send({ username: EMAIL, password: PASSWORD })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
expect(result.body.expiresAt).to.be.a('number');
expect(result.body.token).to.be.a('string');
diff --git a/src/routes/test/oauth2-test.js b/src/routes/test/oauth2-test.js
index 8e7969c90..6a8b7af70 100644
--- a/src/routes/test/oauth2-test.js
+++ b/src/routes/test/oauth2-test.js
@@ -319,7 +319,6 @@ describe('OAuth2', function () {
it('fails due to missing redirect_uri param', function (done) {
superagent.get(SERVER_URL + '/api/v1/oauth/dialog/authorize')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text.indexOf('')).to.not.equal(-1);
expect(result.text.indexOf('Invalid request. redirect_uri query param is not set.')).to.not.equal(-1);
expect(result.statusCode).to.equal(200);
@@ -330,7 +329,6 @@ describe('OAuth2', function () {
it('fails due to missing client_id param', function (done) {
superagent.get(SERVER_URL + '/api/v1/oauth/dialog/authorize?redirect_uri=http://someredirect')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text.indexOf('')).to.not.equal(-1);
expect(result.text.indexOf('Invalid request. client_id query param is not set.')).to.not.equal(-1);
expect(result.statusCode).to.equal(200);
@@ -341,7 +339,6 @@ describe('OAuth2', function () {
it('fails due to missing response_type param', function (done) {
superagent.get(SERVER_URL + '/api/v1/oauth/dialog/authorize?redirect_uri=http://someredirect&client_id=someclientid')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text.indexOf('')).to.not.equal(-1);
expect(result.text.indexOf('Invalid request. response_type query param is not set.')).to.not.equal(-1);
expect(result.statusCode).to.equal(200);
@@ -352,7 +349,6 @@ describe('OAuth2', function () {
it('fails for unkown grant type', function (done) {
superagent.get(SERVER_URL + '/api/v1/oauth/dialog/authorize?redirect_uri=http://someredirect&client_id=someclientid&response_type=foobar')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text.indexOf('')).to.not.equal(-1);
expect(result.text.indexOf('Invalid request. Only token and code response types are supported.')).to.not.equal(-1);
expect(result.statusCode).to.equal(200);
@@ -363,7 +359,6 @@ describe('OAuth2', function () {
it('succeeds for grant type code', function (done) {
superagent.get(SERVER_URL + '/api/v1/oauth/dialog/authorize?redirect_uri=http://someredirect&client_id=someclientid&response_type=code')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text).to.eql('');
expect(result.statusCode).to.equal(200);
done();
@@ -373,7 +368,6 @@ describe('OAuth2', function () {
it('succeeds for grant type token', function (done) {
superagent.get(SERVER_URL + '/api/v1/oauth/dialog/authorize?redirect_uri=http://someredirect&client_id=someclientid&response_type=token')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text).to.eql('');
expect(result.statusCode).to.equal(200);
done();
@@ -388,7 +382,6 @@ describe('OAuth2', function () {
it('fails without prior authentication call and not returnTo query', function (done) {
superagent.get(SERVER_URL + '/api/v1/session/login')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text.indexOf('')).to.not.equal(-1);
expect(result.text.indexOf('Invalid login request. No returnTo provided.')).to.not.equal(-1);
expect(result.statusCode).to.equal(200);
@@ -401,7 +394,6 @@ describe('OAuth2', function () {
superagent.get(SERVER_URL + '/api/v1/session/login?returnTo=http://someredirect')
.redirects(0)
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(302);
expect(result.headers.location).to.eql('http://someredirect');
@@ -413,7 +405,6 @@ describe('OAuth2', function () {
superagent.get(SERVER_URL + '/api/v1/oauth/dialog/authorize?redirect_uri=http://someredirect&response_type=code')
.redirects(0)
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text.indexOf('')).to.not.equal(-1);
expect(result.text.indexOf('Invalid request. client_id query param is not set.')).to.not.equal(-1);
expect(result.statusCode).to.equal(200);
@@ -1289,7 +1280,6 @@ describe('Password', function () {
it('reset request succeeds', function (done) {
superagent.get(SERVER_URL + '/api/v1/session/password/resetRequest.html')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text.indexOf('')).to.not.equal(-1);
expect(result.statusCode).to.equal(200);
done();
@@ -1299,7 +1289,6 @@ describe('Password', function () {
it('setup fails due to missing reset_token', function (done) {
superagent.get(SERVER_URL + '/api/v1/session/password/setup.html')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -1309,7 +1298,6 @@ describe('Password', function () {
superagent.get(SERVER_URL + '/api/v1/session/password/setup.html')
.query({ reset_token: hat(256) })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -1319,7 +1307,6 @@ describe('Password', function () {
superagent.get(SERVER_URL + '/api/v1/session/password/setup.html')
.query({ reset_token: USER_0.resetToken })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(200);
expect(result.text.indexOf('')).to.not.equal(-1);
done();
@@ -1329,7 +1316,6 @@ describe('Password', function () {
it('reset fails due to missing reset_token', function (done) {
superagent.get(SERVER_URL + '/api/v1/session/password/reset.html')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -1339,7 +1325,6 @@ describe('Password', function () {
superagent.get(SERVER_URL + '/api/v1/session/password/reset.html')
.query({ reset_token: hat(256) })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -1349,7 +1334,6 @@ describe('Password', function () {
superagent.get(SERVER_URL + '/api/v1/session/password/reset.html')
.query({ reset_token: USER_0.resetToken })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text.indexOf('')).to.not.equal(-1);
expect(result.statusCode).to.equal(200);
done();
@@ -1359,7 +1343,6 @@ describe('Password', function () {
it('sent succeeds', function (done) {
superagent.get(SERVER_URL + '/api/v1/session/password/sent.html')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text.indexOf('')).to.not.equal(-1);
expect(result.statusCode).to.equal(200);
done();
@@ -1375,7 +1358,6 @@ describe('Password', function () {
superagent.post(SERVER_URL + '/api/v1/session/password/resetRequest')
.send({ identifier: USER_0.email })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.text.indexOf('')).to.not.equal(-1);
expect(result.statusCode).to.equal(200);
done();
@@ -1391,7 +1373,6 @@ describe('Password', function () {
superagent.post(SERVER_URL + '/api/v1/session/password/reset')
.send({ password: 'somepassword' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -1401,7 +1382,6 @@ describe('Password', function () {
superagent.post(SERVER_URL + '/api/v1/session/password/reset')
.send({ resetToken: hat(256) })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
@@ -1411,7 +1391,6 @@ describe('Password', function () {
superagent.post(SERVER_URL + '/api/v1/session/password/reset')
.send({ password: '', resetToken: hat(256) })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -1421,7 +1400,6 @@ describe('Password', function () {
superagent.post(SERVER_URL + '/api/v1/session/password/reset')
.send({ password: '', resetToken: '' })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -1439,7 +1417,6 @@ describe('Password', function () {
superagent.post(SERVER_URL + '/api/v1/session/password/reset')
.send({ password: 'somepassword', resetToken: USER_0.resetToken })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(scope.isDone()).to.be.ok();
expect(result.statusCode).to.equal(200);
done();
diff --git a/src/routes/test/settings-test.js b/src/routes/test/settings-test.js
index c95eba93a..9068c889c 100644
--- a/src/routes/test/settings-test.js
+++ b/src/routes/test/settings-test.js
@@ -13,7 +13,7 @@ var appdb = require('../../appdb.js'),
expect = require('expect.js'),
path = require('path'),
paths = require('../../paths.js'),
- request = require('superagent'),
+ superagent = require('superagent'),
server = require('../../server.js'),
settings = require('../../settings.js'),
fs = require('fs'),
@@ -38,11 +38,10 @@ function setup(done) {
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, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result).to.be.ok();
expect(result.statusCode).to.eql(201);
expect(scope1.isDone()).to.be.ok();
@@ -78,17 +77,17 @@ describe('Settings API', function () {
describe('autoupdate_pattern', function () {
it('can get auto update pattern (default)', function (done) {
- request.get(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
+ superagent.get(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body.pattern).to.be.ok();
- done(err);
+ done();
});
});
it('cannot set autoupdate_pattern without pattern', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
+ superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
@@ -102,7 +101,7 @@ describe('Settings API', function () {
eventPattern = pattern;
});
- request.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
+ superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
.query({ access_token: token })
.send({ pattern: '00 30 11 * * 1-5' })
.end(function (err, res) {
@@ -118,7 +117,7 @@ describe('Settings API', function () {
eventPattern = pattern;
});
- request.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
+ superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
.query({ access_token: token })
.send({ pattern: 'never' })
.end(function (err, res) {
@@ -129,7 +128,7 @@ describe('Settings API', function () {
});
it('cannot set invalid autoupdate_pattern', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
+ superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
.query({ access_token: token })
.send({ pattern: '1 3 x 5 6' })
.end(function (err, res) {
@@ -143,17 +142,17 @@ describe('Settings API', function () {
var name = 'foobar';
it('get default succeeds', function (done) {
- request.get(SERVER_URL + '/api/v1/settings/cloudron_name')
+ superagent.get(SERVER_URL + '/api/v1/settings/cloudron_name')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body.name).to.be.ok();
- done(err);
+ done();
});
});
it('cannot set without name', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/cloudron_name')
+ superagent.post(SERVER_URL + '/api/v1/settings/cloudron_name')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
@@ -162,7 +161,7 @@ describe('Settings API', function () {
});
it('cannot set empty name', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/cloudron_name')
+ superagent.post(SERVER_URL + '/api/v1/settings/cloudron_name')
.query({ access_token: token })
.send({ name: '' })
.end(function (err, res) {
@@ -172,7 +171,7 @@ describe('Settings API', function () {
});
it('set succeeds', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/cloudron_name')
+ superagent.post(SERVER_URL + '/api/v1/settings/cloudron_name')
.query({ access_token: token })
.send({ name: name })
.end(function (err, res) {
@@ -182,29 +181,29 @@ describe('Settings API', function () {
});
it('get succeeds', function (done) {
- request.get(SERVER_URL + '/api/v1/settings/cloudron_name')
+ superagent.get(SERVER_URL + '/api/v1/settings/cloudron_name')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body.name).to.eql(name);
- done(err);
+ done();
});
});
});
describe('cloudron_avatar', function () {
it('get default succeeds', function (done) {
- request.get(SERVER_URL + '/api/v1/settings/cloudron_avatar')
+ superagent.get(SERVER_URL + '/api/v1/settings/cloudron_avatar')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body).to.be.a(Buffer);
- done(err);
+ done();
});
});
it('cannot set without data', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/cloudron_avatar')
+ superagent.post(SERVER_URL + '/api/v1/settings/cloudron_avatar')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
@@ -213,7 +212,7 @@ describe('Settings API', function () {
});
it('set succeeds', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/cloudron_avatar')
+ superagent.post(SERVER_URL + '/api/v1/settings/cloudron_avatar')
.query({ access_token: token })
.attach('avatar', paths.CLOUDRON_DEFAULT_AVATAR_FILE)
.end(function (err, res) {
@@ -223,7 +222,7 @@ describe('Settings API', function () {
});
it('get succeeds', function (done) {
- request.get(SERVER_URL + '/api/v1/settings/cloudron_avatar')
+ superagent.get(SERVER_URL + '/api/v1/settings/cloudron_avatar')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
@@ -235,17 +234,17 @@ describe('Settings API', function () {
describe('dns_config', function () {
it('get dns_config fails', function (done) {
- request.get(SERVER_URL + '/api/v1/settings/dns_config')
+ superagent.get(SERVER_URL + '/api/v1/settings/dns_config')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body).to.eql({});
- done(err);
+ done();
});
});
it('cannot set without data', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/dns_config')
+ superagent.post(SERVER_URL + '/api/v1/settings/dns_config')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
@@ -254,7 +253,7 @@ describe('Settings API', function () {
});
it('set succeeds', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/dns_config')
+ superagent.post(SERVER_URL + '/api/v1/settings/dns_config')
.query({ access_token: token })
.send({ provider: 'route53', accessKeyId: 'accessKey', secretAccessKey: 'secretAccessKey' })
.end(function (err, res) {
@@ -264,12 +263,12 @@ describe('Settings API', function () {
});
it('get succeeds', function (done) {
- request.get(SERVER_URL + '/api/v1/settings/dns_config')
+ superagent.get(SERVER_URL + '/api/v1/settings/dns_config')
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body).to.eql({ provider: 'route53', accessKeyId: 'accessKey', secretAccessKey: 'secretAccessKey', region: 'us-east-1', endpoint: null });
- done(err);
+ done();
});
});
});
@@ -284,75 +283,68 @@ describe('Settings API', function () {
var validKey1 = '-----BEGIN RSA PRIVATE KEY-----\nMIIBOQIBAAJBALQUp/TtlYxwAEWVnD4bNcr0SJmuUnWWme7rhGE333PsxdGvxwWd\nlWBjeOBq27JHmzdZ3NS/J7Z4nSs2JyXYRkkCAwEAAQJALV2eykcoC48TonQEPmkg\nbhaIS57syw67jMLsQImQ02UABKzqHPEKLXPOZhZPS9hsC/hGIehwiYCXMUlrl+WF\nAQIhAOntBI6qaecNjAAVG7UbZclMuHROUONmZUF1KNq6VyV5AiEAxRLkfHWy52CM\njOQrX347edZ30f4QczvugXwsyuU9A1ECIGlGZ8Sk4OBA8n6fAUcyO06qnmCJVlHg\npTUeOvKk5c9RAiBs28+8dCNbrbhVhx/yQr9FwNM0+ttJW/yWJ+pyNQhr0QIgJTT6\nxwCWYOtbioyt7B9l+ENy3AMSO3Uq+xmIKkvItK4=\n-----END RSA PRIVATE KEY-----';
it('cannot set certificate without token', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/certificate')
+ superagent.post(SERVER_URL + '/api/v1/settings/certificate')
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
});
it('cannot set certificate without certificate', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/certificate')
+ superagent.post(SERVER_URL + '/api/v1/settings/certificate')
.query({ access_token: token })
.send({ key: validKey1 })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('cannot set certificate without key', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/certificate')
+ superagent.post(SERVER_URL + '/api/v1/settings/certificate')
.query({ access_token: token })
.send({ cert: validCert1 })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('cannot set certificate with cert not being a string', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/certificate')
+ superagent.post(SERVER_URL + '/api/v1/settings/certificate')
.query({ access_token: token })
.send({ cert: 1234, key: validKey1 })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('cannot set certificate with key not being a string', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/certificate')
+ superagent.post(SERVER_URL + '/api/v1/settings/certificate')
.query({ access_token: token })
.send({ cert: validCert1, key: true })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('cannot set non wildcard certificate', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/certificate')
+ superagent.post(SERVER_URL + '/api/v1/settings/certificate')
.query({ access_token: token })
.send({ cert: validCert0, key: validKey0 })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('can set certificate', function (done) {
- request.post(SERVER_URL + '/api/v1/settings/certificate')
+ superagent.post(SERVER_URL + '/api/v1/settings/certificate')
.query({ access_token: token })
.send({ cert: validCert1, key: validKey1 })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(202);
done();
});
diff --git a/src/routes/test/simpleauth-test.js b/src/routes/test/simpleauth-test.js
index 8dc1a9310..162ea88d9 100644
--- a/src/routes/test/simpleauth-test.js
+++ b/src/routes/test/simpleauth-test.js
@@ -12,7 +12,7 @@ var clientdb = require('../../clientdb.js'),
config = require('../../config.js'),
database = require('../../database.js'),
expect = require('expect.js'),
- request = require('superagent'),
+ superagent = require('superagent'),
server = require('../../server.js'),
simpleauth = require('../../simpleauth.js'),
nock = require('nock');
@@ -109,7 +109,7 @@ describe('SimpleAuth API', function () {
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, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
.end(function (error, result) {
@@ -146,10 +146,9 @@ describe('SimpleAuth API', function () {
it('cannot login without clientId', function (done) {
var body = {};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(400);
done();
});
@@ -160,10 +159,9 @@ describe('SimpleAuth API', function () {
clientId: 'someclientid'
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(400);
done();
});
@@ -175,10 +173,9 @@ describe('SimpleAuth API', function () {
username: USERNAME
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(400);
done();
});
@@ -191,10 +188,9 @@ describe('SimpleAuth API', function () {
password: PASSWORD
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(401);
done();
});
@@ -207,10 +203,9 @@ describe('SimpleAuth API', function () {
password: PASSWORD
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(401);
done();
});
@@ -223,10 +218,9 @@ describe('SimpleAuth API', function () {
password: ''
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(401);
done();
});
@@ -239,10 +233,9 @@ describe('SimpleAuth API', function () {
password: PASSWORD+PASSWORD
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(401);
done();
});
@@ -255,10 +248,9 @@ describe('SimpleAuth API', function () {
password: PASSWORD
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(401);
done();
});
@@ -271,10 +263,9 @@ describe('SimpleAuth API', function () {
password: PASSWORD
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(401);
done();
});
@@ -287,7 +278,7 @@ describe('SimpleAuth API', function () {
password: PASSWORD
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
expect(error).to.be(null);
@@ -299,7 +290,7 @@ describe('SimpleAuth API', function () {
expect(result.body.user.email).to.be.a('string');
expect(result.body.user.admin).to.be.a('boolean');
- request.get(SERVER_URL + '/api/v1/profile')
+ superagent.get(SERVER_URL + '/api/v1/profile')
.query({ access_token: result.body.accessToken })
.end(function (error, result) {
expect(error).to.be(null);
@@ -318,7 +309,7 @@ describe('SimpleAuth API', function () {
password: PASSWORD
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
expect(error).to.be(null);
@@ -330,7 +321,7 @@ describe('SimpleAuth API', function () {
expect(result.body.user.email).to.be.a('string');
expect(result.body.user.admin).to.be.a('boolean');
- request.get(SERVER_URL + '/api/v1/profile')
+ superagent.get(SERVER_URL + '/api/v1/profile')
.query({ access_token: result.body.accessToken })
.end(function (error, result) {
expect(error).to.be(null);
@@ -349,10 +340,9 @@ describe('SimpleAuth API', function () {
password: PASSWORD
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(401);
done();
});
@@ -369,7 +359,7 @@ describe('SimpleAuth API', function () {
password: PASSWORD
};
- request.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
+ superagent.post(SIMPLE_AUTH_ORIGIN + '/api/v1/login')
.send(body)
.end(function (error, result) {
expect(error).to.be(null);
@@ -382,35 +372,32 @@ describe('SimpleAuth API', function () {
});
it('fails without access_token', function (done) {
- request.get(SIMPLE_AUTH_ORIGIN + '/api/v1/logout')
+ superagent.get(SIMPLE_AUTH_ORIGIN + '/api/v1/logout')
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(400);
done();
});
});
it('fails with unkonwn access_token', function (done) {
- request.get(SIMPLE_AUTH_ORIGIN + '/api/v1/logout')
+ superagent.get(SIMPLE_AUTH_ORIGIN + '/api/v1/logout')
.query({ access_token: accessToken+accessToken })
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(401);
done();
});
});
it('succeeds', function (done) {
- request.get(SIMPLE_AUTH_ORIGIN + '/api/v1/logout')
+ superagent.get(SIMPLE_AUTH_ORIGIN + '/api/v1/logout')
.query({ access_token: accessToken })
.end(function (error, result) {
expect(error).to.be(null);
expect(result.statusCode).to.equal(200);
- request.get(SERVER_URL + '/api/v1/profile')
+ superagent.get(SERVER_URL + '/api/v1/profile')
.query({ access_token: accessToken })
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(401);
done();
diff --git a/src/routes/test/user-test.js b/src/routes/test/user-test.js
index 4bde4fccb..5e08b201e 100644
--- a/src/routes/test/user-test.js
+++ b/src/routes/test/user-test.js
@@ -10,7 +10,7 @@ var config = require('../../config.js'),
database = require('../../database.js'),
tokendb = require('../../tokendb.js'),
expect = require('expect.js'),
- request = require('superagent'),
+ superagent = require('superagent'),
nock = require('nock'),
server = require('../../server.js'),
userdb = require('../../userdb.js');
@@ -50,7 +50,7 @@ describe('User API', function () {
after(cleanup);
it('device is in first time mode', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/status')
+ superagent.get(SERVER_URL + '/api/v1/cloudron/status')
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body.activated).to.not.be.ok();
@@ -61,21 +61,21 @@ describe('User API', function () {
it('create admin fails due to missing parameters', function (done) {
var scope = nock(config.apiServerOrigin()).get('/api/v1/boxes/' + config.fqdn() + '/setup/verify?setupToken=somesetuptoken').reply(200, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME_0 })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
expect(scope.isDone()).to.be.ok();
- done(err);
+ done();
});
});
it('create admin fails because only POST is allowed', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.get(SERVER_URL + '/api/v1/cloudron/activate')
.end(function (err, res) {
expect(res.statusCode).to.equal(404);
- done(err);
+ done();
});
});
@@ -83,7 +83,7 @@ describe('User API', function () {
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, {});
- request.post(SERVER_URL + '/api/v1/cloudron/activate')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
.query({ setupToken: 'somesetuptoken' })
.send({ username: USERNAME_0, password: PASSWORD, email: EMAIL })
.end(function (err, res) {
@@ -99,16 +99,16 @@ describe('User API', function () {
});
it('device left first time mode', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/status')
+ superagent.get(SERVER_URL + '/api/v1/cloudron/status')
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body.activated).to.be.ok();
- done(err);
+ done();
});
});
it('can get userInfo with token', function (done) {
- request.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
@@ -119,7 +119,7 @@ describe('User API', function () {
// stash for further use
user_0 = res.body;
- done(err);
+ done();
});
});
@@ -131,10 +131,9 @@ describe('User API', function () {
expect(error).to.not.be.ok();
setTimeout(function () {
- request.get(SERVER_URL + '/api/v1/users/' + user_0.username)
+ superagent.get(SERVER_URL + '/api/v1/users/' + user_0.username)
.query({ access_token: token })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(401);
done();
});
@@ -143,46 +142,46 @@ describe('User API', function () {
});
it('can get userInfo with token', function (done) {
- request.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
expect(res.body.username).to.equal(USERNAME_0);
expect(res.body.email).to.equal(EMAIL);
expect(res.body.admin).to.be.ok();
- done(err);
+ done();
});
});
it('cannot get userInfo only with basic auth', function (done) {
- request.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.auth(USERNAME_0, PASSWORD)
.end(function (err, res) {
expect(res.statusCode).to.equal(401);
- done(err);
+ done();
});
});
it('cannot get userInfo with invalid token (token length)', function (done) {
- request.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.query({ access_token: 'x' + token })
.end(function (err, res) {
expect(res.statusCode).to.equal(401);
- done(err);
+ done();
});
});
it('cannot get userInfo with invalid token (wrong token)', function (done) {
- request.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.query({ access_token: token.toUpperCase() })
.end(function (err, res) {
expect(res.statusCode).to.equal(401);
- done(err);
+ done();
});
});
it('can get userInfo with token in auth header', function (done) {
- request.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.set('Authorization', 'Bearer ' + token)
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
@@ -191,30 +190,30 @@ describe('User API', function () {
expect(res.body.admin).to.be.ok();
expect(res.body.password).to.not.be.ok();
expect(res.body.salt).to.not.be.ok();
- done(err);
+ done();
});
});
it('cannot get userInfo with invalid token in auth header', function (done) {
- request.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.set('Authorization', 'Bearer ' + 'x' + token)
.end(function (err, res) {
expect(res.statusCode).to.equal(401);
- done(err);
+ done();
});
});
it('cannot get userInfo with invalid token (wrong token)', function (done) {
- request.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.get(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.set('Authorization', 'Bearer ' + 'x' + token.toUpperCase())
.end(function (err, res) {
expect(res.statusCode).to.equal(401);
- done(err);
+ done();
});
});
it('create second user succeeds', function (done) {
- request.post(SERVER_URL + '/api/v1/users')
+ superagent.post(SERVER_URL + '/api/v1/users')
.query({ access_token: token })
.send({ username: USERNAME_1, email: EMAIL_1 })
.end(function (err, res) {
@@ -228,90 +227,86 @@ describe('User API', function () {
it('set second user as admin succeeds', function (done) {
// TODO is USERNAME_1 in body and url redundant?
- request.post(SERVER_URL + '/api/v1/users/' + USERNAME_1 + '/admin')
+ superagent.post(SERVER_URL + '/api/v1/users/' + USERNAME_1 + '/admin')
.query({ access_token: token })
.send({ username: USERNAME_1, admin: true })
.end(function (err, res) {
expect(res.statusCode).to.equal(204);
- done(err);
+ done();
});
});
it('remove first user from admins succeeds', function (done) {
- request.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/admin')
+ superagent.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/admin')
.query({ access_token: token_1 })
.send({ username: USERNAME_0, admin: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(204);
- done(err);
+ done();
});
});
it('remove second user by first, now normal, user fails', function (done) {
- request.del(SERVER_URL + '/api/v1/users/' + USERNAME_1)
+ superagent.del(SERVER_URL + '/api/v1/users/' + USERNAME_1)
.query({ access_token: token })
.send({ password: PASSWORD })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
- done(err);
+ done();
});
});
it('remove second user from admins and thus last admin fails', function (done) {
- request.post(SERVER_URL + '/api/v1/users/' + USERNAME_1 + '/admin')
+ superagent.post(SERVER_URL + '/api/v1/users/' + USERNAME_1 + '/admin')
.query({ access_token: token_1 })
.send({ username: USERNAME_1, admin: false })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
- done(err);
+ done();
});
});
it('reset first user as admin succeeds', function (done) {
- request.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/admin')
+ superagent.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/admin')
.query({ access_token: token_1 })
.send({ username: USERNAME_0, admin: true })
.end(function (err, res) {
expect(res.statusCode).to.equal(204);
- done(err);
+ done();
});
});
it('create user missing username fails', function (done) {
- request.post(SERVER_URL + '/api/v1/users')
+ superagent.post(SERVER_URL + '/api/v1/users')
.query({ access_token: token })
.send({ email: EMAIL_2 })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('create user missing email fails', function (done) {
- request.post(SERVER_URL + '/api/v1/users')
+ superagent.post(SERVER_URL + '/api/v1/users')
.query({ access_token: token })
.send({ username: USERNAME_2 })
.end(function (error, result) {
- expect(error).to.not.be.ok();
expect(result.statusCode).to.equal(400);
done();
});
});
it('create second and third user', function (done) {
- request.post(SERVER_URL + '/api/v1/users')
+ superagent.post(SERVER_URL + '/api/v1/users')
.query({ access_token: token })
.send({ username: USERNAME_2, email: EMAIL_2 })
.end(function (error, res) {
- expect(error).to.not.be.ok();
expect(res.statusCode).to.equal(201);
- request.post(SERVER_URL + '/api/v1/users')
+ superagent.post(SERVER_URL + '/api/v1/users')
.query({ access_token: token })
.send({ username: USERNAME_3, email: EMAIL_3 })
.end(function (error, res) {
- expect(error).to.not.be.ok();
expect(res.statusCode).to.equal(201);
// HACK to get a token for second user (passwords are generated and the user should have gotten a password setup link...)
@@ -321,10 +316,9 @@ describe('User API', function () {
});
it('second user userInfo', function (done) {
- request.get(SERVER_URL + '/api/v1/users/' + USERNAME_2)
+ superagent.get(SERVER_URL + '/api/v1/users/' + USERNAME_2)
.query({ access_token: token_1 })
.end(function (error, result) {
- expect(error).to.be(null);
expect(result.statusCode).to.equal(200);
expect(result.body.username).to.equal(USERNAME_2);
expect(result.body.email).to.equal(EMAIL_2);
@@ -335,17 +329,17 @@ describe('User API', function () {
});
it('create user with same username should fail', function (done) {
- request.post(SERVER_URL + '/api/v1/users')
+ superagent.post(SERVER_URL + '/api/v1/users')
.query({ access_token: token })
.send({ username: USERNAME_2, email: EMAIL })
.end(function (err, res) {
expect(res.statusCode).to.equal(409);
- done(err);
+ done();
});
});
it('list users', function (done) {
- request.get(SERVER_URL + '/api/v1/users')
+ superagent.get(SERVER_URL + '/api/v1/users')
.query({ access_token: token_2 })
.end(function (error, res) {
expect(error).to.be(null);
@@ -367,106 +361,106 @@ describe('User API', function () {
});
it('user removes himself is not allowed', function (done) {
- request.del(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.del(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.query({ access_token: token })
.send({ password: PASSWORD })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
- done(err);
+ done();
});
});
it('admin cannot remove normal user without giving a password', function (done) {
- request.del(SERVER_URL + '/api/v1/users/' + USERNAME_3)
+ superagent.del(SERVER_URL + '/api/v1/users/' + USERNAME_3)
.query({ access_token: token })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
- done(err);
+ done();
});
});
it('admin cannot remove normal user with empty password', function (done) {
- request.del(SERVER_URL + '/api/v1/users/' + USERNAME_3)
+ superagent.del(SERVER_URL + '/api/v1/users/' + USERNAME_3)
.query({ access_token: token })
.send({ password: '' })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
- done(err);
+ done();
});
});
it('admin cannot remove normal user with giving wrong password', function (done) {
- request.del(SERVER_URL + '/api/v1/users/' + USERNAME_3)
+ superagent.del(SERVER_URL + '/api/v1/users/' + USERNAME_3)
.query({ access_token: token })
.send({ password: PASSWORD + PASSWORD })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
- done(err);
+ done();
});
});
it('admin removes normal user', function (done) {
- request.del(SERVER_URL + '/api/v1/users/' + USERNAME_3)
+ superagent.del(SERVER_URL + '/api/v1/users/' + USERNAME_3)
.query({ access_token: token })
.send({ password: PASSWORD })
.end(function (err, res) {
expect(res.statusCode).to.equal(204);
- done(err);
+ done();
});
});
it('admin removes himself should not be allowed', function (done) {
- request.del(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.del(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.query({ access_token: token })
.send({ password: PASSWORD })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
- done(err);
+ done();
});
});
// Change email
it('change email fails due to missing token', function (done) {
- request.put(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.put(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.send({ password: PASSWORD, email: EMAIL_0_NEW })
.end(function (error, result) {
expect(result.statusCode).to.equal(401);
- done(error);
+ done();
});
});
it('change email fails due to missing password', function (done) {
- request.put(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.put(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.query({ access_token: token })
.send({ email: EMAIL_0_NEW })
.end(function (error, result) {
expect(result.statusCode).to.equal(400);
- done(error);
+ done();
});
});
it('change email fails due to wrong password', function (done) {
- request.put(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.put(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.query({ access_token: token })
.send({ password: PASSWORD+PASSWORD, email: EMAIL_0_NEW })
.end(function (error, result) {
expect(result.statusCode).to.equal(403);
- done(error);
+ done();
});
});
it('change email fails due to invalid email', function (done) {
- request.put(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.put(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.query({ access_token: token })
.send({ password: PASSWORD, email: 'foo@bar' })
.end(function (error, result) {
expect(result.statusCode).to.equal(400);
- done(error);
+ done();
});
});
it('change email succeeds', function (done) {
- request.put(SERVER_URL + '/api/v1/users/' + USERNAME_0)
+ superagent.put(SERVER_URL + '/api/v1/users/' + USERNAME_0)
.query({ access_token: token })
.send({ password: PASSWORD, email: EMAIL_0_NEW })
.end(function (error, result) {
@@ -477,52 +471,52 @@ describe('User API', function () {
// Change password
it('change password fails due to missing current password', function (done) {
- request.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/password')
+ superagent.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/password')
.query({ access_token: token })
.send({ newPassword: 'some wrong password' })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
- done(err);
+ done();
});
});
it('change password fails due to missing new password', function (done) {
- request.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/password')
+ superagent.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/password')
.query({ access_token: token })
.send({ password: PASSWORD })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
- done(err);
+ done();
});
});
it('change password fails due to wrong password', function (done) {
- request.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/password')
+ superagent.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/password')
.query({ access_token: token })
.send({ password: 'some wrong password', newPassword: 'newpassword' })
.end(function (err, res) {
expect(res.statusCode).to.equal(403);
- done(err);
+ done();
});
});
it('change password fails due to invalid password', function (done) {
- request.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/password')
+ superagent.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/password')
.query({ access_token: token })
.send({ password: PASSWORD, newPassword: 'five' })
.end(function (err, res) {
expect(res.statusCode).to.equal(400);
- done(err);
+ done();
});
});
it('change password succeeds', function (done) {
- request.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/password')
+ superagent.post(SERVER_URL + '/api/v1/users/' + USERNAME_0 + '/password')
.query({ access_token: token })
.send({ password: PASSWORD, newPassword: 'new_password' })
.end(function (err, res) {
expect(res.statusCode).to.equal(204);
- done(err);
+ done();
});
});
});
diff --git a/src/storage/caas.js b/src/storage/caas.js
index 647249dfc..edf918275 100644
--- a/src/storage/caas.js
+++ b/src/storage/caas.js
@@ -24,7 +24,7 @@ function getBackupCredentials(backupConfig, callback) {
var url = config.apiServerOrigin() + '/api/v1/boxes/' + config.fqdn() + '/awscredentials';
superagent.post(url).query({ token: backupConfig.token }).end(function (error, result) {
- if (error) return callback(error);
+ if (error && !error.response) return callback(error);
if (result.statusCode !== 201) return callback(new Error(result.text));
if (!result.body || !result.body.credentials) return callback(new Error('Unexpected response'));
@@ -49,7 +49,7 @@ function getAllPaged(backupConfig, page, perPage, callback) {
var url = config.apiServerOrigin() + '/api/v1/boxes/' + config.fqdn() + '/backups';
superagent.get(url).query({ token: backupConfig.token }).end(function (error, result) {
- if (error) return callback(error);
+ if (error && !error.response) return callback(error);
if (result.statusCode !== 200) return callback(new Error(result.text));
if (!result.body || !util.isArray(result.body.backups)) return callback(new Error('Unexpected response'));
diff --git a/src/test/server-test.js b/src/test/server-test.js
index 629296d3c..a8d4bee8d 100644
--- a/src/test/server-test.js
+++ b/src/test/server-test.js
@@ -11,7 +11,7 @@ var progress = require('../progress.js'),
database = require('../database.js'),
expect = require('expect.js'),
nock = require('nock'),
- request = require('superagent'),
+ superagent = require('superagent'),
server = require('../server.js');
var SERVER_URL = 'http://localhost:' + config.get('port');
@@ -46,7 +46,7 @@ describe('Server', function () {
});
it('is reachable', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/status', function (err, res) {
+ superagent.get(SERVER_URL + '/api/v1/cloudron/status', function (err, res) {
expect(res.statusCode).to.equal(200);
done(err);
});
@@ -79,32 +79,32 @@ describe('Server', function () {
});
});
- it('random bad requests', function (done) {
- request.get(SERVER_URL + '/random', function (err, res) {
- expect(err).to.not.be.ok();
+ it('random bad superagents', function (done) {
+ superagent.get(SERVER_URL + '/random', function (err, res) {
+ expect(err).to.be.ok();
expect(res.statusCode).to.equal(404);
- done(err);
+ done();
});
});
it('version', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/status', function (err, res) {
+ superagent.get(SERVER_URL + '/api/v1/cloudron/status', function (err, res) {
expect(err).to.not.be.ok();
expect(res.statusCode).to.equal(200);
expect(res.body.version).to.equal('0.5.0');
- done(err);
+ done();
});
});
it('status route is GET', function (done) {
- request.post(SERVER_URL + '/api/v1/cloudron/status')
+ superagent.post(SERVER_URL + '/api/v1/cloudron/status')
.end(function (err, res) {
expect(res.statusCode).to.equal(404);
- request.get(SERVER_URL + '/api/v1/cloudron/status')
+ superagent.get(SERVER_URL + '/api/v1/cloudron/status')
.end(function (err, res) {
expect(res.statusCode).to.equal(200);
- done(err);
+ done();
});
});
});
@@ -122,18 +122,16 @@ describe('Server', function () {
});
it('config fails due missing token', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/config', function (err, res) {
- expect(err).to.not.be.ok();
+ superagent.get(SERVER_URL + '/api/v1/cloudron/config', function (err, res) {
expect(res.statusCode).to.equal(401);
- done(err);
+ done();
});
});
it('config fails due wrong token', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/config').query({ access_token: 'somewrongtoken' }).end(function (err, res) {
- expect(err).to.not.be.ok();
+ superagent.get(SERVER_URL + '/api/v1/cloudron/config').query({ access_token: 'somewrongtoken' }).end(function (err, res) {
expect(res.statusCode).to.equal(401);
- done(err);
+ done();
});
});
});
@@ -150,8 +148,7 @@ describe('Server', function () {
});
it('succeeds with no progress', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/progress', function (error, result) {
- expect(error).to.not.be.ok();
+ superagent.get(SERVER_URL + '/api/v1/cloudron/progress', function (error, result) {
expect(result.statusCode).to.equal(200);
expect(result.body.update).to.be(null);
expect(result.body.backup).to.be(null);
@@ -162,8 +159,7 @@ describe('Server', function () {
it('succeeds with update progress', function (done) {
progress.set(progress.UPDATE, 13, 'This is some status string');
- request.get(SERVER_URL + '/api/v1/cloudron/progress', function (error, result) {
- expect(error).to.not.be.ok();
+ superagent.get(SERVER_URL + '/api/v1/cloudron/progress', function (error, result) {
expect(result.statusCode).to.equal(200);
expect(result.body.update).to.be.an('object');
expect(result.body.update.percent).to.be.a('number');
@@ -179,8 +175,7 @@ describe('Server', function () {
it('succeeds with no progress after clearing the update', function (done) {
progress.clear(progress.UPDATE);
- request.get(SERVER_URL + '/api/v1/cloudron/progress', function (error, result) {
- expect(error).to.not.be.ok();
+ superagent.get(SERVER_URL + '/api/v1/cloudron/progress', function (error, result) {
expect(result.statusCode).to.equal(200);
expect(result.body.update).to.be(null);
expect(result.body.backup).to.be(null);
@@ -211,8 +206,9 @@ describe('Server', function () {
});
it('is not reachable anymore', function (done) {
- request.get(SERVER_URL + '/api/v1/cloudron/status', function (error, result) {
+ superagent.get(SERVER_URL + '/api/v1/cloudron/status', function (error, result) {
expect(error).to.not.be(null);
+ expect(!error.response).to.be.ok();
done();
});
});
@@ -226,15 +222,15 @@ describe('Server', function () {
});
it('responds to OPTIONS', function (done) {
- request('OPTIONS', SERVER_URL + '/api/v1/cloudron/status')
+ superagent('OPTIONS', SERVER_URL + '/api/v1/cloudron/status')
.set('Access-Control-Request-Method', 'GET')
- .set('Access-Control-Request-Headers', 'accept, origin, x-requested-with')
+ .set('Access-Control-Request-Headers', 'accept, origin, x-superagented-with')
.set('Origin', 'http://localhost')
- .end(function (res) {
+ .end(function (error, res) {
expect(res.headers['access-control-allow-methods']).to.be('GET, PUT, DELETE, POST, OPTIONS');
expect(res.headers['access-control-allow-credentials']).to.be('true');
- expect(res.headers['access-control-allow-headers']).to.be('accept, origin, x-requested-with'); // mirrored from request
- expect(res.headers['access-control-allow-origin']).to.be('http://localhost'); // mirrors from request
+ expect(res.headers['access-control-allow-headers']).to.be('accept, origin, x-superagented-with'); // mirrored from superagent
+ expect(res.headers['access-control-allow-origin']).to.be('http://localhost'); // mirrors from superagent
done();
});
});
diff --git a/src/updatechecker.js b/src/updatechecker.js
index 0c6fb2f90..dcf3ab674 100644
--- a/src/updatechecker.js
+++ b/src/updatechecker.js
@@ -53,7 +53,7 @@ function getAppUpdates(callback) {
.timeout(10 * 1000)
.end(function (error, result) {
- if (error) return callback(error);
+ if (error && !error.response) return callback(error);
if (result.statusCode !== 200 || !result.body.appVersions) {
return callback(new Error(util.format('Error checking app update: %s %s', result.statusCode, result.text)));
@@ -88,8 +88,8 @@ function getBoxUpdates(callback) {
.get(config.get('boxVersionsUrl'))
.timeout(10 * 1000)
.end(function (error, result) {
- if (error) return callback(error);
- if (result.status !== 200) return callback(new Error(util.format('Bad status: %s %s', result.status, result.text)));
+ if (error && !error.response) return callback(error);
+ if (result.statusCode !== 200) return callback(new Error(util.format('Bad status: %s %s', result.statusCode, result.text)));
var versions = safe.JSON.parse(result.text);
diff --git a/src/webhooks.js b/src/webhooks.js
index d90111fc9..5ff8a5187 100644
--- a/src/webhooks.js
+++ b/src/webhooks.js
@@ -32,7 +32,7 @@ function backupDone(filename, app, appBackupIds, callback) {
};
superagent.post(url).send(data).query({ token: config.token() }).end(function (error, result) {
- if (error) return callback(error);
+ if (error && !error.response) return callback(error);
if (result.statusCode !== 200) return callback(new Error(result.text));
if (!result.body) return callback(new Error('Unexpected response'));