add test to check user mail

This commit is contained in:
Girish Ramakrishnan 2016-05-18 17:46:42 -07:00
parent eced14521a
commit a2b9e4f66a
4 changed files with 76 additions and 4 deletions

View File

@ -6,9 +6,10 @@ var assert = require('assert'),
common = require('./common.js'),
debug = require('debug')('e2e:cloudron'),
dns = require('dns'),
Imap = require('imap'),
querystring = require('querystring'),
once = require('once'),
request = require('superagent-sync'),
semver = require('semver'),
sleep = require('sleep').sleep,
url = require('url'),
util = require('util');
@ -473,3 +474,50 @@ Cloudron.prototype.setDnsConfig = function (dnsConfig) {
common.verifyResponse2xx(res, 'Could not set dns config');
};
Cloudron.prototype.checkMail = function (owner, callback) {
callback = once(callback);
var imap = new Imap({
user: owner.username,
password: owner.password,
host: this._adminFqdn,
port: 993,
tls: true,
tlsOptions: {
rejectUnauthorized: false
}
});
// see mailer.sendMailToCloudronUser
imap.once('ready', function() {
imap.openBox('INBOX', false /* openReadOnly */, function (error, box) {
if (error) return callback(error);
if (box.messages.total !== 1) callback(new Error('Expecting one mail in inbox. Saw ' + box.messages.total));
var f = imap.seq.fetch('1:1', { bodies: [ 'TEXT' ] });
f.on('message', function (msg, seq) {
msg.on('body', function (stream, info) {
var buffer = '';
stream.on('data', function (chunk) { buffer += chunk.toString('utf8'); });
stream.on('end', function () {
imap.end();
if (buffer.indexOf('The release depends on you') !== -1) return callback();
callback(new Error('Failed to get message body: ' + buffer));
});
stream.on('error', callback);
});
});
f.on('end', function () { });
f.on('error', callback);
});
});
imap.once('error', callback);
imap.once('end', function () { });
imap.connect();
};

View File

@ -8,6 +8,7 @@ var assert = require('assert'),
util = require('util');
exports = module.exports = {
sendMailToCloudronUser: sendMailToCloudronUser,
sendEndToEndTestResult: sendEndToEndTestResult
};
@ -48,3 +49,16 @@ function sendEndToEndTestResult(topic, versionInfo, stdout, stderr, callback) {
send(mailOptions, callback);
}
function sendMailToCloudronUser(email, callback) {
debug('Sending test mail to %s', email);
var mailOptions = {
to: email,
subject: 'Hi from e2e test',
text: 'I hope you get this. The release depends on you!'
};
send(mailOptions, callback);
}

View File

@ -19,8 +19,9 @@
"colors": "^1.1.0",
"debug": "^2.2.0",
"dns-sync": "^0.1.3",
"imap": "^0.8.17",
"mocha": "^2.2.5",
"once": "^1.3.2",
"once": "^1.3.3",
"postmark": "^1.0.0",
"readline-sync": "^1.2.19",
"safetydance": "0.0.17",

View File

@ -2,6 +2,7 @@
* This tests a flow for cloudron owner creating a cloudron
* with a custom domain from the appstore. Owner creates a cloudron, activates
* it, installs and app and deletes the cloudron eventually
*
*/
'use strict';
@ -12,8 +13,7 @@ var AppStore = require('../appstore.js'),
AWS = require('aws-sdk'),
Cloudron = require('../cloudron.js'),
common = require('../common.js'),
dns = require('dns'),
request = require('superagent-sync');
mailer = require('../mailer.js');
require('colors');
@ -101,6 +101,11 @@ describe('Custom domain test', function () {
cloudron.setCredentials(owner.password, token);
});
it('send mail to cloudron user', function (done) {
mailer.sendMailToCloudronUser(owner.username + '@' + CUSTOM_DOMAIN, done);
});
it('can set dns credentials', function () {
cloudron.setDnsConfig({ provider: 'route53', accessKeyId: process.env.AWS_STAGING_ACCESS_KEY, secretAccessKey: process.env.AWS_STAGING_SECRET_KEY });
});
@ -153,6 +158,10 @@ describe('Custom domain test', function () {
cloudron.uninstallApp(appId);
});
it('can check mail', function (done) {
cloudron.checkMail(owner, done);
});
// check this after activation
it('has setup DNS records correctly', function (done) {
async.series([