|
| 1 | +import dns from 'dns'; |
| 2 | +import Test, { TestParameters, Result } from '../Test'; |
| 3 | +import logger from '../logger'; |
| 4 | + |
| 5 | +class DMARC extends Test { |
| 6 | + public name = 'DMARC'; |
| 7 | + |
| 8 | + public async test({ url }: TestParameters): Promise<Result> { |
| 9 | + logger.info(`Starting ${this.constructor.name} test...`); |
| 10 | + |
| 11 | + const response: any = await new Promise((resolve, reject) => { |
| 12 | + dns.resolveTxt(`_dmarc.${(new URL(url).hostname)}`, (err, records) => { |
| 13 | + if (err) { |
| 14 | + reject(err); |
| 15 | + } |
| 16 | + |
| 17 | + resolve(records); |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + if (response.length === 0) { |
| 22 | + return { |
| 23 | + status: 'WARNING', |
| 24 | + title: this.constructor.name, |
| 25 | + description: 'No DMARC record found for this domain.', |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + const record = response.shift().shift(); |
| 30 | + |
| 31 | + if (record.includes('p=none')) { |
| 32 | + return { |
| 33 | + status: 'ERROR', |
| 34 | + title: this.constructor.name, |
| 35 | + description: 'Email that fails DMARC Compliance tests will be delivered to the recipient\'s inbox.', |
| 36 | + }; |
| 37 | + } |
| 38 | + |
| 39 | + if (record.includes('p=quarantine')) { |
| 40 | + return { |
| 41 | + status: 'WARNING', |
| 42 | + title: this.constructor.name, |
| 43 | + description: 'Email that fails DMARC Compliance tests will be marked as spam.', |
| 44 | + }; |
| 45 | + } |
| 46 | + |
| 47 | + if (record.includes('p=reject')) { |
| 48 | + return { |
| 49 | + status: 'SUCCESS', |
| 50 | + title: this.constructor.name, |
| 51 | + description: 'Email that fails DMARC Compliance tests will be rejected.', |
| 52 | + }; |
| 53 | + } |
| 54 | + |
| 55 | + return { |
| 56 | + status: 'ERROR', |
| 57 | + title: this.constructor.name, |
| 58 | + description: 'Invalid DMARC policy found!', |
| 59 | + }; |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +export default DMARC; |
0 commit comments