From 4ad1f5f0fb53a4bea8a632429140cbe66cf1c53a Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Fri, 30 Aug 2019 23:55:34 +0200 Subject: [PATCH] Add input validation --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e9d92d0..a23a75c 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ const url = require("url"); const asExpression = require("as-expression"); const dotty = require("dotty"); const getJson = require("axios-get-json-response"); -const { ValidationError, validateValue, required, isString, arrayOf, allowExtraProperties } = require("validatem"); +const { ValidationError, validateValue, validateArguments, required, isString, arrayOf, allowExtraProperties } = require("validatem"); let LookupFailed = createError("LookupFailed"); let MethodNotAvailable = createError("MethodNotAvailable"); @@ -155,11 +155,15 @@ function attemptWellKnown(host) { module.exports = { LookupFailed: LookupFailed, - discover: function (host) { + discover: function (hostname) { + validateArguments(arguments, [ + ["hostname", required, isString] + ]); + return Promise.try(() => { - return attemptWellKnown(host); + return attemptWellKnown(hostname); }).catch(MethodNotAvailable, () => { - return attemptLiteralHostname(host); + return attemptLiteralHostname(hostname); }).catch(MethodNotAvailable, () => { throwLookupError("none of the autodiscovery methods were available"); });