diff --git a/cloudron.js b/cloudron.js index f190e91..a85f7f0 100644 --- a/cloudron.js +++ b/cloudron.js @@ -5,6 +5,7 @@ var assert = require('assert'), common = require('./common.js'), debug = require('debug')('e2e:cloudron'), + dns = require('dns'), querystring = require('querystring'), request = require('superagent-sync'), sleep = require('sleep').sleep, @@ -253,3 +254,37 @@ Cloudron.prototype.reboot = function () { common.verifyResponse2(res, 'Box could not be rebooted'); this.waitForBox(); }; + +Cloudron.prototype.checkSPF = function (callback) { + dns.resolveTxt(this._box.domain, function (error, records) { + if (error) return callback(error); + if (records.length !== 1) return callback(new Error('Got ' + records.length + ' TXT records. Expecting 1')); + + if (records[0].search(new RegExp('^v=spf1 ip4:' + this._box.ip + ' ~all$')) !== 0) return callback(new Error('Bad SPF record. ' + records[0])); + + callback(); + }); +}; + +Cloudron.prototype.checkDKIM = function (callback) { + dns.resolveTxt('mail._domainkey.' + this._box.domain, function (error, records) { + if (error) return callback(error); + if (records.length !== 1) return callback(new Error('Got ' + records.length + ' TXT records. Expecting 1')); + + if (records[0].search(/^"v=DKIM1; t=s; p=.*"$/) !== 0) return callback(new Error('Bad DKIM record. ' + records[0])); + + callback(); + }); +}; + +Cloudron.prototype.checkDMARC = function (callback) { + dns.resolveTxt('_dmarc.' + this._box.domain, function (error, records) { + if (error) return callback(error); + if (records.length !== 1) return callback(new Error('Got ' + records.length + ' TXT records. Expecting 1')); + + if (records[0].search(/^"v=DMARC1; p=none; pct=100; rua=mailto:.*; ruf=.*"$/) !== 0) return callback(new Error('Bad DMARC record. ' + records[0])); + + callback(); + }); +}; + diff --git a/test/new-user-test.js b/test/new-user-test.js index 625ced0..d92d113 100644 --- a/test/new-user-test.js +++ b/test/new-user-test.js @@ -9,6 +9,7 @@ 'use strict'; var AppStore = require('../appstore.js'), + async = require('async'), Cloudron = require('../cloudron.js'), common = require('../common.js'), request = require('superagent-sync'), @@ -59,6 +60,14 @@ describe('Appstore new user flow', function () { cloudron = new Cloudron(box); }); + it('has setup DNS records correctly', function (done) { + async.series([ + cloudron.checkSPF, + cloudron.checkDKIM, + cloudron.CheckDMARC + ], done); + }); + it('can activate the box', function () { cloudron.activate(owner); });