diff --git a/dnsconfig.js b/dnsconfig.js index 3cd55b011..aa94cdc1d 100644 --- a/dnsconfig.js +++ b/dnsconfig.js @@ -67,7 +67,21 @@ for (var subdomain in domains) { // Handle MX records if (domainData.record.MX) { for (var mx in domainData.record.MX) { - records.push(MX(subdomainName, 10 + parseInt(mx), domainData.record.MX[mx] + ".")); + var mxRecord = domainData.record.MX[mx]; + + if (typeof mxRecord === "string") { + records.push( + MX(subdomainName, 10 + parseInt(mx), domainData.record.MX[mx] + ".") + ); + } else { + records.push( + MX( + subdomainName, + parseInt(mxRecord.priority), + mxRecord.target + "." + ) + ); + } } } @@ -88,6 +102,23 @@ for (var subdomain in domains) { } } + // Handle TLSA records + if (domainData.record.TLSA) { + for (var tlsa in domainData.record.TLSA) { + var tlsaRecord = domainData.record.TLSA[tlsa]; + + records.push( + TLSA( + subdomainName, + tlsaRecord.usage, + tlsaRecord.selector, + tlsaRecord.matchingType, + tlsaRecord.certificate + ) + ); + } + } + // Handle TXT records if (domainData.record.TXT) { if (Array.isArray(domainData.record.TXT)) { diff --git a/tests/json.test.js b/tests/json.test.js index 3894f9567..ba51a9e75 100644 --- a/tests/json.test.js +++ b/tests/json.test.js @@ -1,7 +1,6 @@ const t = require("ava"); const fs = require("fs-extra"); const path = require("path"); -const { promisify } = require("util"); const ignoredRootJSONFiles = ["package-lock.json", "package.json"]; diff --git a/tests/records.test.js b/tests/records.test.js index fbbeee156..52fb1f677 100644 --- a/tests/records.test.js +++ b/tests/records.test.js @@ -2,7 +2,7 @@ const t = require("ava"); const fs = require("fs-extra"); const path = require("path"); -const validRecordTypes = new Set(["A", "AAAA", "CAA", "CNAME", "DS", "MX", "NS", "SRV", "TXT", "URL"]); +const validRecordTypes = new Set(["A", "AAAA", "CAA", "CNAME", "DS", "MX", "NS", "SRV", "TLSA", "TXT", "URL"]); const hostnameRegex = /^(?=.{1,253}$)(?:(?:[_a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)\.)+[a-zA-Z]{2,63}$/; const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}$/; const ipv6Regex = @@ -98,8 +98,8 @@ function validateRecordValues(t, data, file) { value.forEach((record, idx) => { t.true( - typeof record === "string", - `${file}: Record value for ${key} should be a string at index ${idx}` + typeof record === "string" || typeof record === "object", + `${file}: Record value for ${key} should be a string or an object at index ${idx}` ); if (key === "A") { @@ -112,7 +112,22 @@ function validateRecordValues(t, data, file) { const expandedIPv6 = expandIPv6(record); t.true(ipv6Regex.test(expandedIPv6), `${file}: Invalid IPv6 address for ${key} at index ${idx}`); t.true(validateIPv6(expandedIPv6), `${file}: Invalid IPv6 address for ${key} at index ${idx}`); - } else if (["MX", "NS"].includes(key)) { + } else if (key === "MX") { + t.true( + typeof record === "object" || typeof record === "string", + `${file}: Record value for ${key} should be an object or a string at index ${idx}` + ); + + if (typeof record === "string") { + t.true(isValidHostname(record), `${file}: Invalid hostname for ${key} at index ${idx}`); + } else { + t.true(isValidHostname(record.target), `${file}: Invalid target for ${key} at index ${idx}`); + t.true( + Number.isInteger(record.priority) && record.priority >= 0 && record.priority <= 65535, + `${file}: Invalid priority for ${key} at index ${idx}` + ); + } + } else if (key === "NS") { t.true(isValidHostname(record), `${file}: Invalid hostname for ${key} at index ${idx}`); } }); @@ -140,8 +155,8 @@ function validateRecordValues(t, data, file) { } } - // CAA, DS, SRV validations - if (["CAA", "DS", "SRV"].includes(key)) { + // CAA, DS, SRV, TLSA validations + if (["CAA", "DS", "SRV", "TLSA"].includes(key)) { t.true(Array.isArray(value), `${file}: Record value for ${key} should be an array`); value.forEach((record, idx) => { @@ -153,41 +168,55 @@ function validateRecordValues(t, data, file) { if (key === "CAA") { t.true( ["issue", "issuewild", "iodef"].includes(record.tag), - `${file}: Invalid tag for CAA at index ${idx}` + `${file}: Invalid tag for ${key} at index ${idx}` ); - t.true(typeof record.value === "string", `${file}: Invalid value for CAA at index ${idx}`); + t.true(typeof record.value === "string", `${file}: Invalid value for ${key} at index ${idx}`); t.true( isValidHostname(record.value) || record.value === ";", - `${file}: Value must be a hostname or semicolon for CAA at index ${idx}` + `${file}: Value must be a hostname or semicolon for ${key} at index ${idx}` ); } else if (key === "DS") { t.true( Number.isInteger(record.key_tag) && record.key_tag >= 0 && record.key_tag <= 65535, - `${file}: Invalid key_tag for DS at index ${idx}` + `${file}: Invalid key_tag for ${key} at index ${idx}` ); t.true( Number.isInteger(record.algorithm) && record.algorithm >= 0 && record.algorithm <= 255, - `${file}: Invalid algorithm for DS at index ${idx}` + `${file}: Invalid algorithm for ${key} at index ${idx}` ); t.true( Number.isInteger(record.digest_type) && record.digest_type >= 0 && record.digest_type <= 255, - `${file}: Invalid digest_type for DS at index ${idx}` + `${file}: Invalid digest_type for ${key} at index ${idx}` ); - t.true(isValidHexadecimal(record.digest), `${file}: Invalid digest for DS at index ${idx}`); + t.true(isValidHexadecimal(record.digest), `${file}: Invalid digest for ${key} at index ${idx}`); } else if (key === "SRV") { t.true( Number.isInteger(record.priority) && record.priority >= 0 && record.priority <= 65535, - `${file}: Invalid priority for SRV at index ${idx}` + `${file}: Invalid priority for ${key} at index ${idx}` ); t.true( Number.isInteger(record.weight) && record.weight >= 0 && record.weight <= 65535, - `${file}: Invalid weight for SRV at index ${idx}` + `${file}: Invalid weight for ${key} at index ${idx}` ); t.true( Number.isInteger(record.port) && record.port >= 0 && record.port <= 65535, - `${file}: Invalid port for SRV at index ${idx}` + `${file}: Invalid port for ${key} at index ${idx}` ); - t.true(isValidHostname(record.target), `${file}: Invalid target for SRV at index ${idx}`); + t.true(isValidHostname(record.target), `${file}: Invalid target for ${key} at index ${idx}`); + } else if (key === "TLSA") { + t.true( + Number.isInteger(record.usage) && record.usage >= 0 && record.usage <= 255, + `${file}: Invalid usage for ${key} at index ${idx}` + ); + t.true( + Number.isInteger(record.selector) && record.selector >= 0 && record.selector <= 255, + `${file}: Invalid selector for ${key} at index ${idx}` + ); + t.true( + Number.isInteger(record.matchingType) && record.matchingType >= 0 && record.matchingType <= 255, + `${file}: Invalid matchingType for ${key} at index ${idx}` + ); + t.true(isValidHexadecimal(record.certificate), `${file}: Invalid certificate for ${key} at index ${idx}`); } }); }