add alias tests

This commit is contained in:
Girish Ramakrishnan 2016-06-24 10:39:34 -05:00
parent 69fc2408b4
commit 1898fe20fb
2 changed files with 91 additions and 53 deletions

View File

@ -343,6 +343,17 @@ Cloudron.prototype.addUser = function (username, email) {
return res.body;
};
Cloudron.prototype.setAliases = function (owner, aliases) {
var res = request.put(this._origin + '/api/v1/mailboxes/' + owner.username + '/aliases')
.query({ access_token: this._credentials.accessToken })
.send({ aliases: aliases })
.end();
common.verifyResponse2xx(res, 'Could not set aliases');
return res.body;
};
Cloudron.prototype.resetPassword = function (resetToken, password) {
var res = request.get(this._origin + '/api/v1/session/password/reset.html').query({ reset_token: resetToken }).end();
common.verifyResponse2xx(res, 'Could not get password setup site');
@ -614,18 +625,18 @@ Cloudron.prototype.checkForUpdates = function () {
.end();
};
Cloudron.prototype.sendMail = function (owner, to, callback) {
Cloudron.prototype.sendMail = function (account, to, callback) {
var transport = nodemailer.createTransport(smtpTransport({
host: this._adminFqdn,
port: 587,
auth: {
user: owner.username,
pass: owner.password
user: account.username,
pass: account.password
}
}));
var mailOptions = {
from: owner.username + '@'+ this._box.domain,
from: (account.from || account.username) + '@'+ this._box.domain,
to: to,
subject: 'Hi from e2e test - ' + this._box.domain,
text: 'This release depends on you'
@ -634,10 +645,10 @@ Cloudron.prototype.sendMail = function (owner, to, callback) {
transport.sendMail(mailOptions, callback);
};
Cloudron.prototype.checkMail = function (owner, callback) {
Cloudron.prototype.checkMail = function (account, callback) {
var imap = new ImapProbe({
user: owner.username,
password: owner.password,
user: account.username,
password: account.password,
host: this._adminFqdn,
port: 993, // imap port
tls: true,
@ -647,8 +658,7 @@ Cloudron.prototype.checkMail = function (owner, callback) {
imap.probe({
subject: new RegExp('^Hi from e2e test - ' + this._box.domain + '$'),
to: new RegExp(owner.username + '@' + this._box.domain),
to: new RegExp((account.to || account.username) + '@' + this._box.domain),
body: /This release depends on you/
}, callback);
};

View File

@ -12,7 +12,8 @@ var AppStore = require('../appstore.js'),
dnsSync = require('dns-sync'),
ImapProbe = require('../imap-probe.js'),
mailer = require('../mailer.js'),
sleep = require('sleep').sleep;
sleep = require('sleep').sleep,
_ = require('underscore');
require('colors');
@ -65,41 +66,64 @@ describe('Cloudron backup testing', function () {
cloudron.setCredentials(owner.password, token);
});
it('send mail to cloudron user', function (done) {
mailer.sendMailToCloudronUser(owner.username + '@' + box.domain, done);
describe('mail tests as normal user', function () {
it('can send mail to cloudron user', function (done) {
mailer.sendMailToCloudronUser(owner.username + '@' + cloudron.fqdn(), done);
});
it('did receive mail', function (done) {
cloudron.checkMail(owner, done);
});
it('can send mail from cloudron user', function (done) {
cloudron.sendMail(owner, 'test+fromcloudron@cloudron.io', done);
});
it('did send mail from cloudron user', function (done) {
imap.probe({
subject: new RegExp('^Hi from e2e test$'),
to: /test+fromcloudron@cloudron.io/,
body: /This release depends on you/
}, done);
});
it('can save a sieve script', function (done) {
cloudron.saveSieveScript(owner, done);
});
});
it('can save a sieve script', function (done) {
cloudron.saveSieveScript(owner, done);
describe('mail alias tests', function () {
it('can set aliases', function () {
cloudron.setAliases(owner, ['admin', 'mail']);
});
it('can send email to alias', function (done) {
mailer.sendMailToCloudronUser('admin@' + box.domain, done);
});
it('did receive mail as alias (using owner name creds)', function (done) {
cloudron.checkMail(_.extend(owner, { to: 'admin' }), done);
});
it('did receive mail to alias (using alias creds)', function (done) {
cloudron.checkMail({ username: 'admin', password: owner.password, to: 'admin' }, done);
});
});
it('can receive mail', function (done) {
cloudron.checkMail(owner, done);
});
describe('app pre-restore', function () {
var location = 'test' + (Math.random() * 10000).toFixed();
it('can install app', function () {
var manifest = appStore.getManifest(common.TESTAPP_ID, common.TESTAPP_VERSION);
appId = cloudron.installApp(location, manifest);
});
it('can send mail', function (done) {
cloudron.sendMail(owner, 'test+fromcloudron@cloudron.io', done);
});
it('can populate the addons', function () {
cloudron.populateAddons(cloudron.appFqdn(location));
});
it('sent mail successfully', function (done) {
imap.probe({
subject: new RegExp('^Hi from e2e test$'),
body: /This release depends on you/
}, done);
});
var location = 'test' + (Math.random() * 10000).toFixed();
it('can install app', function () {
var manifest = appStore.getManifest(common.TESTAPP_ID, common.TESTAPP_VERSION);
appId = cloudron.installApp(location, manifest);
});
it('can populate the addons', function () {
cloudron.populateAddons(cloudron.appFqdn(location));
});
it('can check the addons', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
it('can check the addons', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
});
});
it('can backup the box', function () {
@ -127,24 +151,28 @@ describe('Cloudron backup testing', function () {
cloudron.setCredentials(owner.password, token);
});
it('retains old mail', function (done) {
cloudron.checkMail(owner, done);
describe('mail tests as normal user', function() {
it('retains old mail', function (done) {
cloudron.checkMail(owner, owner.username, done);
});
it('can check sieve script', function (done) {
cloudron.checkSieveScript(owner, done);
});
});
it('can check sieve script', function (done) {
cloudron.checkSieveScript(owner, done);
});
describe('app tests', function () {
it('wait for app', function () {
cloudron.waitForApp(appId);
});
it('wait for app', function () {
cloudron.waitForApp(appId);
});
it('can check the addons', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
});
it('can check the addons', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
});
it('can uninstall app', function () {
cloudron.uninstallApp(appId);
it('can uninstall app', function () {
cloudron.uninstallApp(appId);
});
});
it('can delete the cloudron', function () {