From 1933bc79b91a9d89666ae896f4b65e18200be4f9 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Tue, 17 May 2016 23:31:50 -0700 Subject: [PATCH] check mx records --- cloudron.js | 12 ++++++++++++ test/custom-domain-test.js | 1 + test/new-user-test.js | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cloudron.js b/cloudron.js index c169b77..934a5a9 100644 --- a/cloudron.js +++ b/cloudron.js @@ -395,6 +395,18 @@ Cloudron.prototype.checkSPF = function (callback) { }); }; +Cloudron.prototype.checkMX = function (callback) { + var that = this; + dns.resolveMx(this._box.domain, function (error, records) { + if (error) return callback(error); + if (records.length !== 1) return callback(new Error('Got ' + JSON.stringify(records) + ' MX records. Expecting 1 length array')); + + if (records[0].exchange !== this._adminFqdn) return callback(new Error('Bad MX record. ' + records[0])); + + callback(null, records); + }); +}; + Cloudron.prototype.checkDKIM = function (callback) { dns.resolveTxt('cloudron._domainkey.' + this._box.domain, function (error, records) { if (error) return callback(error); diff --git a/test/custom-domain-test.js b/test/custom-domain-test.js index 3b073c1..0dcf7ba 100644 --- a/test/custom-domain-test.js +++ b/test/custom-domain-test.js @@ -159,6 +159,7 @@ describe('Custom domain test', function () { // cloudron.checkA.bind(cloudron), // this is at user's discretion cloudron.checkSPF.bind(cloudron), cloudron.checkDKIM.bind(cloudron), + cloudron.checkMX.bind(cloudron), // cloudron.checkDMARC.bind(cloudron) ], done); }); diff --git a/test/new-user-test.js b/test/new-user-test.js index 105147e..51a6dec 100644 --- a/test/new-user-test.js +++ b/test/new-user-test.js @@ -87,6 +87,7 @@ describe('Appstore new user flow', function () { async.series([ cloudron.checkA.bind(cloudron), cloudron.checkSPF.bind(cloudron), + cloudron.checkMX.bind(cloudron), cloudron.checkDKIM.bind(cloudron), cloudron.checkDMARC.bind(cloudron) ], done); @@ -113,7 +114,8 @@ describe('Appstore new user flow', function () { expectError('checkA', cloudron.checkA.bind(cloudron)), expectError('checkSPF', cloudron.checkSPF.bind(cloudron)), expectError('checkDKIM', cloudron.checkDKIM.bind(cloudron)), - expectError('checkDMARC', cloudron.checkDMARC.bind(cloudron)) + expectError('checkDMARC', cloudron.checkDMARC.bind(cloudron)), + expectError('checkMX', cloudron.checkMX.bind(cloudron)) ], done); });