Add type checking.

This commit is contained in:
Tweak authored and GitHub committed 2023-01-19 18:33:29 -07:00
1 parent 70c86de305
commit 59c9cd0329
1 file changed
+6 -4
+6 -4
View File
@@ -1,14 +1,15 @@
const { checkIfValidIP, checkIfValidFQDN, checkInvalidDomain } = require('./utils.js');
const { checkIfValidIP, checkIfValidFQDN, checkInvalidDomain, isString } = require('./utils.js');
function checkRecords(data) {
const recordType = Object.keys(data.target)[0];
const value = data.target[recordType].value;
// Check if the domain is invalid
if (checkInvalidDomain(data.target[recordType].name) === true) return false;
// Check A record
if (recordType.toLowerCase() === 'a') {
for (const record of data.target[recordType].value) {
if (!Array.isArray(value)) return false;
for (const record of value) {
if (checkIfValidIP(record) == false) return false;
}
return true;
@@ -16,7 +17,8 @@ function checkRecords(data) {
// Check CNAME record
if (recordType.toLowerCase() === 'cname') {
return checkIfValidFQDN(data.target[recordType].value);
if (!isString(value)) return false;
return checkIfValidFQDN(value);
}
return false;