fix new-user-test

This commit is contained in:
Girish Ramakrishnan 2017-03-30 20:03:07 -07:00
parent 8530238990
commit 915f460c6e
3 changed files with 17 additions and 12 deletions

View File

@ -9,11 +9,13 @@ var assert = require('assert'),
dns = require('dns'), dns = require('dns'),
ImapProbe = require('./imap-probe.js'), ImapProbe = require('./imap-probe.js'),
querystring = require('querystring'), querystring = require('querystring'),
net = require('net'),
nodemailer = require('nodemailer'), nodemailer = require('nodemailer'),
once = require('once'), once = require('once'),
request = require('superagent-sync'), request = require('superagent-sync'),
smtpTransport = require('nodemailer-smtp-transport'), smtpTransport = require('nodemailer-smtp-transport'),
sleep = require('./shell.js').sleep, sleep = require('./shell.js').sleep,
superagent = require('superagent'),
tcpBomb = require('./tcpbomb.js'), tcpBomb = require('./tcpbomb.js'),
tls = require('tls'), tls = require('tls'),
url = require('url'), url = require('url'),
@ -782,17 +784,18 @@ Cloudron.prototype.checkTcpRateLimit = function (port, times, callback) {
}); });
}; };
Cloudron.prototype.checkNginxRateLimit = function (times, callback) { Cloudron.prototype.checkNginxRateLimit = function (owner, times, callback) {
var ok = 0; var ok = 0;
var that = this;
async.times(times, function (n, done) { async.times(times, function (n, done) {
var client = new net.Socket(); superagent.post('https://' + that._adminFqdn + '/api/v1/developer/login').send({ username: owner.username, password: owner.password }).end(function (error, result) {
if (!error && result.statusCode === 200) ++ok;
var res = request.post('https://' + this._box.ip + '/api/v1/developer/login').send({ username: owner.username, password: owner.password }).end();
if (res.statusCode === 200) ++ok; done();
});
}, function () {
callback(ok == times ? new Error('All requests succeeded') : null);
}); });
callback(ok == times ? new Error('All requests succeeded') : null);
}; };

View File

@ -14,7 +14,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"async": "^1.4.0", "async": "^2.2.0",
"aws-sdk": "^2.2.23", "aws-sdk": "^2.2.23",
"colors": "^1.1.0", "colors": "^1.1.0",
"debug": "^2.2.0", "debug": "^2.2.0",

View File

@ -133,17 +133,19 @@ describe('Appstore new user flow', function () {
}); });
it('does TCP ratelimiting', function (done) { it('does TCP ratelimiting', function (done) {
this.timeout(12000);
async.series([ async.series([
cloudron.checkTcpRateLimit.bind(cloudron, 202, 5), // ssh cloudron.checkTcpRateLimit.bind(cloudron, 202, 5), // ssh
cloudron.checkTcpRateLimit.bind(cloudron, 25, 50), // mail cloudron.checkTcpRateLimit.bind(cloudron, 25, 50), // mail
cloudron.checkTcpRateLimit.bind(cloudron, 587, 50), // msa cloudron.checkTcpRateLimit.bind(cloudron, 587, 60), // msa
cloudron.checkTcpRateLimit.bind(cloudron, 993, 50), // imap cloudron.checkTcpRateLimit.bind(cloudron, 993, 60), // imap
cloudron.checkTcpRateLimit.bind(cloudron, 4190, 50), // sieve cloudron.checkTcpRateLimit.bind(cloudron, 4190, 60), // sieve
], done); ], done);
}); });
it('does nginx ratelimiting', function (done) { it('does nginx ratelimiting', function (done) {
cloudron.checkNginxRateLimit(10, done); cloudron.checkNginxRateLimit(owner, 10, done);
}); });
it('can delete the cloudron', function () { it('can delete the cloudron', function () {