check sieve script

This commit is contained in:
Girish Ramakrishnan 2016-05-18 19:34:12 -07:00
parent df9f5f2e2e
commit 83986baf1f
2 changed files with 53 additions and 0 deletions

View File

@ -11,6 +11,7 @@ var assert = require('assert'),
once = require('once'),
request = require('superagent-sync'),
sleep = require('sleep').sleep,
tls = require('tls'),
url = require('url'),
util = require('util');
@ -521,3 +522,47 @@ Cloudron.prototype.checkMail = function (owner, callback) {
imap.connect();
};
Cloudron.prototype.saveSieveScript = function (owner, callback) {
var authString = 'AUTHENTICATE "PLAIN" "' + new Buffer('\0' + owner.username + '\0' + owner.password).toString('base64') + '"';
callback = once(callback);
var socket = tls.connect(4190, this._adminFqdn, { rejectUnauthorized: false }, function (error) {
if (error) return callback(error);
socket.write(authString + '\n');
socket.write('PUTSCRIPT \"hutsefluts\" {6+}\nkeep;\nQUIT\n');
setTimeout(function () { socket.end(); callback(new Error('Could not auth with sieve')); }, 5000); // give it 5 seconds
});
socket.on('data', function (chunk) {
if (chunk.toString('utf8').indexOf('OK "Logged in."') !== -1) return callback();
});
socket.on('end', function () { });
socket.on('error', callback);
};
Cloudron.prototype.checSieveScript = function (owner, callback) {
var authString = 'AUTHENTICATE "PLAIN" "' + new Buffer('\0' + owner.username + '\0' + owner.password).toString('base64') + '"';
callback = once(callback);
var socket = tls.connect(4190, this._adminFqdn, { rejectUnauthorized: false }, function (error) {
if (error) return callback(error);
socket.write(authString + '\n');
socket.write('LISTSCRIPTS\nQUIT\n');
setTimeout(function () { socket.end(); callback(new Error('Could not auth with sieve')); }, 5000); // give it 5 seconds
});
socket.on('data', function (chunk) {
if (chunk.toString('utf8').indexOf('"hutsefluts"') !== -1) return callback();
});
socket.on('end', function () { });
socket.on('error', callback);
};

View File

@ -59,6 +59,10 @@ describe('Cloudron backup testing', function () {
mailer.sendMailToCloudronUser(owner.username + '@' + box.domain, done);
});
it('can save a sieve script', function (done) {
cloudron.saveSieveScript(owner, done);
});
var location = 'test' + (Math.random() * 10000).toFixed();
it('can install app', function () {
var manifest = appStore.getManifest(common.TESTAPP_ID, common.TESTAPP_VERSION);
@ -114,6 +118,10 @@ describe('Cloudron backup testing', function () {
cloudron.checkMail(owner, done);
});
it('can check sieve script', function (done) {
cloudron.checkSieveScript(owner, done);
});
it('can delete the cloudron', function () {
appStore.deleteCloudron(box);
});